Skip to content

Commit

Permalink
Merge branch 'hotfix/3.19.37'
Browse files Browse the repository at this point in the history
  • Loading branch information
blackforestboi committed May 30, 2024
2 parents eef96d7 + 7ef338c commit 43d7a42
Show file tree
Hide file tree
Showing 11 changed files with 696 additions and 39 deletions.
2 changes: 1 addition & 1 deletion external/@worldbrain/memex-common
2 changes: 1 addition & 1 deletion external/@worldbrain/memex-stemmer
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "worldbrain-extension",
"version": "3.19.35",
"version": "3.19.37",
"homepage": "https://memex.garden",
"repository": "https://github.com/WorldBrain/Memex",
"scripts": {
Expand Down
25 changes: 22 additions & 3 deletions src/content-scripts/content_script/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ import { HIGHLIGHT_COLORS_DEFAULT } from '@worldbrain/memex-common/lib/common-ui
import { PKMSyncBackgroundModule } from 'src/pkm-integrations/background'
import { injectTelegramCustomUI } from './injectionUtils/telegram'
import { renderSpacesBar } from './injectionUtils/utils'
import { getTimestampedNoteWithAIsummaryForYoutubeNotes } from './injectionUtils/youtube'
import {
injectTwitterProfileUI,
trackTwitterMessageList,
Expand All @@ -113,7 +112,6 @@ import type { InPageUIComponent } from 'src/in-page-ui/shared-state/types'
import type { RemoteCopyPasterInterface } from 'src/copy-paster/background/types'
import type { HighlightColor } from '@worldbrain/memex-common/lib/common-ui/components/highlightColorPicker/types'
import type { InPageUIInterface } from 'src/in-page-ui/background/types'
import type { Storage } from 'webextension-polyfill'
import type { PseudoSelection } from '@worldbrain/memex-common/lib/in-page-ui/types'
import {
cloneSelectionAsPseudoObject,
Expand All @@ -125,6 +123,7 @@ import {
} from '@worldbrain/memex-common/lib/subscriptions/constants'
import type { RemoteSearchInterface } from 'src/search/background/types'
import * as anchoring from '@worldbrain/memex-common/lib/annotations'
import type { TaskState } from 'ui-logic-core/lib/types'

// Content Scripts are separate bundles of javascript code that can be loaded
// on demand by the browser, as needed. This main function manages the initialisation
Expand Down Expand Up @@ -578,7 +577,17 @@ export async function main(
quality: 100,
})

let highlightCreateState: TaskState = 'pristine'
// Block nav away from current page while highlight being created
window.addEventListener('beforeunload', (e) => {
let shouldBlockUnload = highlightCreateState === 'running'
if (shouldBlockUnload) {
e.preventDefault()
}
})

const annotationsFunctions = {
// TODO: Simplify and move this logic away from here
createHighlight: (
analyticsEvent?: AnalyticsEvent<'Highlights'>,
) => async (
Expand All @@ -589,6 +598,7 @@ export async function main(
highlightColorSetting?: HighlightColor,
preventHideTooltip?: boolean,
) => {
highlightCreateState = 'running'
let anchor: Anchor
let quote: string

Expand All @@ -603,6 +613,7 @@ export async function main(
anchor = { quote, descriptor }
}
if (quote?.length === 0 && !drawRectangle) {
highlightCreateState = 'success'
return
}

Expand All @@ -618,7 +629,7 @@ export async function main(
sidebarEvents.emit('showPowerUpModal', {
limitReachedNotif: 'Bookmarks',
})

highlightCreateState = 'error'
return
}

Expand Down Expand Up @@ -647,6 +658,7 @@ export async function main(
screenshotGrabResult == null ||
screenshotGrabResult.anchor == null
) {
highlightCreateState = 'success'
return
}

Expand Down Expand Up @@ -722,8 +734,10 @@ export async function main(
}
}

highlightCreateState = 'success'
return annotationId
},
// TODO: Simplify and move this logic away from here
createAnnotation: (
analyticsEvent?: AnalyticsEvent<'Annotations'>,
) => async (
Expand All @@ -734,8 +748,10 @@ export async function main(
commentText?: string,
highlightColorSetting?: HighlightColor,
) => {
highlightCreateState = 'running'
const selectionEmpty = !selection?.toString().length
if (selectionEmpty) {
highlightCreateState = 'success'
return
}

Expand All @@ -761,6 +777,7 @@ export async function main(
sidebarEvents.emit('showPowerUpModal', {
limitReachedNotif: 'Bookmarks',
})
highlightCreateState = 'error'
return
}

Expand All @@ -787,6 +804,7 @@ export async function main(
screenshotGrabResult == null ||
screenshotGrabResult.anchor == null
) {
highlightCreateState = 'success'
return
}

Expand Down Expand Up @@ -868,6 +886,7 @@ export async function main(
)
}
}
highlightCreateState = 'success'
},
askAI: () => (
highlightedText: string,
Expand Down
10 changes: 7 additions & 3 deletions src/dashboard-refactor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2389,11 +2389,15 @@ const ListSidebarContent = styled(Rnd)<{
`}
${(props) =>
props.peeking &&
css`
css<any>`
position: absolute
height: max-content;
background-color: ${(props) => props.theme.colors.greyScale1}98;
backdrop-filter: blur(30px);
background-color: ${(props) =>
props.inPageMode
? props.theme.colors.greyScale1
: props.theme.colors.greyScale1 + '98'};
backdrop-filter: ${(props) =>
props.inPageMode ? 'unset' : 'blur(30px)'};
//box-shadow: rgb(16 30 115 / 3%) 4px 0px 16px;
margin-top: 50px;
margin-bottom: 9px;
Expand Down
34 changes: 20 additions & 14 deletions src/in-page-ui/ribbon/react/containers/ribbon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class RibbonContainer extends StatefulUIElement<
> {
private ribbonRef = React.createRef<Ribbon>()

constructor(props) {
constructor(props: RibbonContainerProps) {
super(
props,
new RibbonContainerLogic({
Expand All @@ -48,6 +48,15 @@ export default class RibbonContainer extends StatefulUIElement<
this.ribbonRef?.current?.focusCreateForm(),
}),
)

props.events.on('bookmarkPage', () =>
this.processEvent('toggleBookmark', null),
)
props.events.on('openSpacePickerInRibbon', () =>
this.processEvent('setShowListsPicker', { value: true }),
)
props.inPageUI.events.on('ribbonAction', this.handleExternalAction)
window.addEventListener('beforeunload', this.handleBeforeUnload)
}

private get normalizedPageUrl(): string | null {
Expand All @@ -56,24 +65,13 @@ export default class RibbonContainer extends StatefulUIElement<
: null
}

async componentDidMount() {
await super.componentDidMount()
this.props.inPageUI.events.on('ribbonAction', this.handleExternalAction)

this.props.events.on('bookmarkPage', () =>
this.processEvent('toggleBookmark', null),
)
this.props.events.on('openSpacePickerInRibbon', () =>
this.processEvent('setShowListsPicker', { value: true }),
)
}

async componentWillUnmount() {
await super.componentWillUnmount()
this.props.inPageUI.events.removeListener(
'ribbonAction',
this.handleExternalAction,
)
window.removeEventListener('beforeunload', this.handleBeforeUnload)
await super.componentWillUnmount()
}

componentDidUpdate(prevProps: RibbonContainerProps) {
Expand All @@ -90,6 +88,14 @@ export default class RibbonContainer extends StatefulUIElement<
}
}

// Block user nav away when some write RPC op is occurring
private handleBeforeUnload = (e: BeforeUnloadEvent) => {
let shouldBlockUnload = this.state.bookmark.loadState === 'running'
if (shouldBlockUnload) {
e.preventDefault()
}
}

private whichFeed = () => {
if (process.env.NODE_ENV === 'production') {
return 'https://memex.social/feed'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ async function setup(options?: {
) => {
const clientSchemaVersion =
downloadOptions?.clientSchemaVersion ??
STORAGE_VERSIONS[37].version
STORAGE_VERSIONS[38].version
const { batch } = await downloadClientUpdates({
getNow,
startTime: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/personal-cloud/background/index.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ export async function setupSyncBackgroundTest(
storageManager: serverStorage.manager,
storageModules: serverStorage.modules,
getSqlStorageMananager,
clientSchemaVersion: STORAGE_VERSIONS[37].version,
clientSchemaVersion: STORAGE_VERSIONS[38].version,
services: {
activityStreams: services.activityStreams,
pushMessaging: pushMessagingService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,35 @@ export class AnnotationsSidebarContainer<
)

window['_getState'] = () => ({ ...this.state })
this.listenToWindowChanges()

window.addEventListener('beforeunload', this.handleBeforeUnload)
window.addEventListener('resize', this.handleWindowResize)
}

listenToWindowChanges() {
window.addEventListener('resize', () => {
if (this.state.isWidthLocked) {
this.processEvent('adjustSidebarWidth', {
newWidth: this.state.sidebarWidth,
isWidthLocked: true,
})
}
})
async componentWillUnmount(): Promise<void> {
window.removeEventListener('beforeunload', this.handleBeforeUnload)
window.removeEventListener('resize', this.handleWindowResize)
await super.componentWillUnmount()
}

private handleWindowResize = async () => {
if (this.state.isWidthLocked) {
await this.processEvent('adjustSidebarWidth', {
newWidth: this.state.sidebarWidth,
isWidthLocked: true,
})
}
}

// Block user nav away when some write RPC op is occurring
private handleBeforeUnload = (e: BeforeUnloadEvent) => {
let shouldBlockUnload =
this.state.noteEditState === 'running' ||
this.state.noteCreateState === 'running' ||
this.state.noteColorUpdateState === 'running'
if (shouldBlockUnload) {
e.preventDefault()
}
}

private getListDetailsById: ListDetailsGetter = (listId) => {
Expand Down
Loading

0 comments on commit 43d7a42

Please sign in to comment.