Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	external/@worldbrain/memex-common
  • Loading branch information
poltak committed Jan 12, 2022
2 parents c6bbedf + e454ff2 commit d814242
Show file tree
Hide file tree
Showing 86 changed files with 1,271 additions and 968 deletions.
2 changes: 1 addition & 1 deletion external/@worldbrain/memex-common
2 changes: 1 addition & 1 deletion external/@worldbrain/memex-url-utils
6 changes: 3 additions & 3 deletions img/collections_add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions img/collections_full.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions img/sharedprotected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/activity-indicator/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const ACTIVITY_INDICATOR_ACTIVE_CACHE_KEY =
'@ActivityIndicator-active_cache'
33 changes: 32 additions & 1 deletion src/activity-indicator/ui/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'

import styled from 'styled-components'
import { StatefulUIElement } from 'src/util/ui-logic'
import { StaticListItem } from 'src/custom-lists/components/overview/sidebar/static-list-item'
import Logic, { Dependencies, State, Events } from './logic'
Expand Down Expand Up @@ -32,3 +32,34 @@ export default class FeedActivityIndicator extends StatefulUIElement<
return null
}
}

export class FeedActivityDot extends StatefulUIElement<Props, State, Events> {
constructor(props: Props) {
super(props, new Logic(props))
}

private handleFeedIndicatorClick: React.MouseEventHandler = (e) =>
this.processEvent('clickFeedEntry', null)

render() {
if (this.state.isShown) {
return (
<Dot
unread={this.state.hasFeedActivity ? 1 : 0}
onClick={this.handleFeedIndicatorClick}
/>
)
}

return null
}
}

const Dot = styled.div<{ unread: boolean }>`
border-radius: 10px;
width: 16px;
height: 16px;
background: ${(props) => (props.unread ? '#5cd9a6' : 'unset')};
border: 2px solid ${(props) => (props.unread ? '#5cd9a6' : '#5671cf')};
cursor: pointer;
`
5 changes: 4 additions & 1 deletion src/activity-indicator/ui/logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ function setupTest(
{ device }: SingleDeviceUILogicTestContext,
openFeedUrl: Dependencies['openFeedUrl'] = () => undefined,
) {
const logicInstance = new Logic({ openFeedUrl })
const logicInstance = new Logic({
activityIndicatorBG: device.backgroundModules.activityIndicator,
openFeedUrl,
})

const logic = device.createElement(logicInstance)

Expand Down
41 changes: 29 additions & 12 deletions src/activity-indicator/ui/logic.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { UILogic, UIEventHandler, UIEvent } from 'ui-logic-core'
import { ActivityIndicatorInterface } from '../background'
import { runInBackground } from 'src/util/webextensionRPC'
import { auth } from 'src/util/remote-functions-background'
import type { ActivityIndicatorInterface } from '../background'
import { getLocalStorage, setLocalStorage } from 'src/util/storage'
import { ACTIVITY_INDICATOR_ACTIVE_CACHE_KEY } from '../constants'

export interface Dependencies {
activityIndicatorBG: Pick<
ActivityIndicatorInterface,
'checkActivityStatus' | 'markActivitiesAsSeen'
>
openFeedUrl: () => void
}

Expand All @@ -23,12 +27,8 @@ type EventHandler<EventName extends keyof Events> = UIEventHandler<
>

export default class Logic extends UILogic<State, Events> {
private activityIndicatorBG: ActivityIndicatorInterface

constructor(private dependencies: Dependencies) {
super()

this.activityIndicatorBG = runInBackground()
}

getInitialState(): State {
Expand All @@ -38,11 +38,27 @@ export default class Logic extends UILogic<State, Events> {
}
}

///// IMPORTANT! THIS CODE IS DUPLICATED IN DASHBOARD-REFACTOR/LOGIC
///// FOR THE INSTANCE OF THE SIDEBAR, DON'T FORGET TO UPDATE IT TOO!

init: EventHandler<'init'> = async () => {
const activityStatus = await this.activityIndicatorBG.checkActivityStatus()
this.emitMutation({
hasFeedActivity: { $set: activityStatus === 'has-unseen' },
})
const hasActivityStored = await getLocalStorage(
ACTIVITY_INDICATOR_ACTIVE_CACHE_KEY,
)
if (hasActivityStored === true) {
this.emitMutation({
hasFeedActivity: { $set: true },
})
} else {
const activityStatus = await this.dependencies.activityIndicatorBG.checkActivityStatus()
await setLocalStorage(
ACTIVITY_INDICATOR_ACTIVE_CACHE_KEY,
activityStatus === 'has-unseen',
)
this.emitMutation({
hasFeedActivity: { $set: activityStatus === 'has-unseen' },
})
}
}

clickFeedEntry: EventHandler<'clickFeedEntry'> = async ({
Expand All @@ -51,8 +67,9 @@ export default class Logic extends UILogic<State, Events> {
this.dependencies.openFeedUrl()

if (previousState.hasFeedActivity) {
await setLocalStorage(ACTIVITY_INDICATOR_ACTIVE_CACHE_KEY, false)
this.emitMutation({ hasFeedActivity: { $set: false } })
await this.activityIndicatorBG.markActivitiesAsSeen()
await this.dependencies.activityIndicatorBG.markActivitiesAsSeen()
}
}
}
20 changes: 20 additions & 0 deletions src/annotations/background/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ export const INTEGRATION_TESTS = backgroundIntegrationTestSuite('Annotations', [
DATA.HIGHLIGHT_1.pageUrl,
selector: undefined,
tags: [],
isBulkShareProtected: false,
isShared: false,
},
],
annotsCount: 1,
Expand Down Expand Up @@ -296,6 +298,8 @@ export const INTEGRATION_TESTS = backgroundIntegrationTestSuite('Annotations', [
pageUrl: DATA.ANNOT_1.pageUrl,
selector: undefined,
tags: [],
isBulkShareProtected: false,
isShared: false,
},
],
annotsCount: 1,
Expand Down Expand Up @@ -428,6 +432,8 @@ export const INTEGRATION_TESTS = backgroundIntegrationTestSuite('Annotations', [
pageUrl: DATA.ANNOT_1.pageUrl,
selector: undefined,
tags: [],
isBulkShareProtected: false,
isShared: false,
},
],
},
Expand Down Expand Up @@ -502,6 +508,8 @@ export const INTEGRATION_TESTS = backgroundIntegrationTestSuite('Annotations', [
pageUrl: DATA.ANNOT_1.pageUrl,
selector: undefined,
tags: [DATA.TAG_1],
isBulkShareProtected: false,
isShared: false,
},
],
},
Expand Down Expand Up @@ -620,6 +628,8 @@ export const INTEGRATION_TESTS = backgroundIntegrationTestSuite('Annotations', [
pageUrl: DATA.ANNOT_1.pageUrl,
selector: undefined,
tags: [],
isBulkShareProtected: false,
isShared: false,
},
],
},
Expand Down Expand Up @@ -988,6 +998,8 @@ export const INTEGRATION_TESTS = backgroundIntegrationTestSuite('Annotations', [
pageUrl: DATA.ANNOT_1.pageUrl,
selector: undefined,
tags: [],
isBulkShareProtected: false,
isShared: false,
},
],
},
Expand Down Expand Up @@ -1181,6 +1193,8 @@ export const INTEGRATION_TESTS = backgroundIntegrationTestSuite('Annotations', [
pageUrl: DATA.ANNOT_1.pageUrl,
selector: undefined,
tags: [DATA.TAG_1],
isBulkShareProtected: false,
isShared: false,
},
],
},
Expand Down Expand Up @@ -1212,6 +1226,8 @@ export const INTEGRATION_TESTS = backgroundIntegrationTestSuite('Annotations', [
pageUrl: DATA.ANNOT_2.pageUrl,
selector: undefined,
tags: [DATA.TAG_2],
isBulkShareProtected: false,
isShared: false,
},
],
},
Expand Down Expand Up @@ -1380,6 +1396,8 @@ export const INTEGRATION_TESTS = backgroundIntegrationTestSuite('Annotations', [
pageUrl: DATA.ANNOT_1.pageUrl,
selector: undefined,
tags: [],
isBulkShareProtected: false,
isShared: false,
},
],
},
Expand Down Expand Up @@ -1411,6 +1429,8 @@ export const INTEGRATION_TESTS = backgroundIntegrationTestSuite('Annotations', [
pageUrl: DATA.ANNOT_2.pageUrl,
selector: undefined,
tags: [],
isBulkShareProtected: false,
isShared: false,
},
],
},
Expand Down
11 changes: 6 additions & 5 deletions src/annotations/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { limitSuggestionsStorageLength } from 'src/tags/background'
import { generateUrl } from 'src/annotations/utils'
import { PageIndexingBackground } from 'src/page-indexing/background'
import { Analytics } from 'src/analytics/types'
import { getUrl } from 'src/util/uri-utils'
import { getUnderlyingResourceUrl } from 'src/util/uri-utils'
import { ServerStorageModules } from 'src/storage/types'
import { GetUsersPublicDetailsResult } from '@worldbrain/memex-common/lib/user-management/types'
import type ContentSharingBackground from 'src/content-sharing/background'
Expand Down Expand Up @@ -260,7 +260,7 @@ export default class DirectLinkingBackground {
const result = await this.backend.createDirectLink(request)
await this.annotationStorage.createAnnotation({
pageTitle,
pageUrl: this._normalizeUrl(getUrl(tab.url)),
pageUrl: this._normalizeUrl(getUnderlyingResourceUrl(tab.url)),
body: request.anchor.quote,
url: result.url,
selector: request.anchor,
Expand Down Expand Up @@ -306,7 +306,8 @@ export default class DirectLinkingBackground {
},
)

url = url == null && tab != null ? getUrl(tab.url) : url
url =
url == null && tab != null ? getUnderlyingResourceUrl(tab.url) : url
url = isSocialPost
? await this.lookupSocialId(url)
: this._normalizeUrl(url)
Expand Down Expand Up @@ -360,9 +361,9 @@ export default class DirectLinkingBackground {
toCreate: CreateAnnotationParams,
{ skipPageIndexing }: { skipPageIndexing?: boolean } = {},
) {
let fullPageUrl = toCreate.pageUrl ?? getUrl(tab?.url)
let fullPageUrl = toCreate.pageUrl ?? getUnderlyingResourceUrl(tab?.url)
if (!isFullUrl(fullPageUrl)) {
fullPageUrl = getUrl(tab?.url)
fullPageUrl = getUnderlyingResourceUrl(tab?.url)
if (!isFullUrl(fullPageUrl)) {
throw new Error(
'Could not get full URL while creating annotation',
Expand Down
7 changes: 6 additions & 1 deletion src/annotations/components/AnnotationEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface AnnotationEditEventProps {
export interface AnnotationEditGeneralProps {
comment: string
editorHeight?: string
isShared?: boolean
isBulkShareProtected?: boolean
}

export interface Props
Expand Down Expand Up @@ -58,7 +60,10 @@ class AnnotationEdit extends React.Component<Props> {
}

if (e.key === 'Enter' && e.metaKey) {
return this.saveEdit(false, false)
return this.saveEdit(
this.props.isShared,
this.props.isBulkShareProtected,
)
}

if (e.key === 'Escape') {
Expand Down
Loading

0 comments on commit d814242

Please sign in to comment.