Skip to content

Commit

Permalink
greatly improve the highlighting tooltip UX
Browse files Browse the repository at this point in the history
- prompt tempates
- More compact
-
  • Loading branch information
blackforestboi committed Jun 11, 2024
1 parent 5504648 commit 898c756
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion external/@worldbrain/memex-common
10 changes: 5 additions & 5 deletions src/common-ui/components/prompt-templates/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ const Header = styled.div`
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 15px 15px 0px 24px;
padding: 15px 15px 0px 15px;
height: 30px;
align-items: center;
`
Expand All @@ -454,9 +454,9 @@ const ButtonBox = styled.div`
`

const SectionTitle = styled.div`
color: ${(props) => props.theme.colors.greyScale4};
font-size: 14px;
font-weight: 400;
color: ${(props) => props.theme.colors.white};
font-size: 16px;
font-weight: 600;
flex: 1;
white-space: nowrap;
`
Expand Down Expand Up @@ -494,7 +494,7 @@ const Title = styled.div`
`

const ContentBlock = styled.div`
padding: 5px 15px 15px 15px;
padding: 5px;
overflow: scroll;
width: 100%;
box-sizing: border-box;
Expand Down
1 change: 1 addition & 0 deletions src/content-scripts/content_script/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,7 @@ export async function main(
analyticsBG,
pageActivityIndicatorBG,
localStorageAPI: browser.storage.local,
syncSettingsBG: syncSettingsBG,
})
components.tooltip?.resolve()
},
Expand Down
39 changes: 37 additions & 2 deletions src/in-page-ui/tooltip/content_script/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ import {
getRemoteEventEmitter,
} from 'src/util/webextensionRPC'
import { AnnotationPrivacyLevels } from '@worldbrain/memex-common/lib/annotations/types'
import PromptTemplatesComponent from 'src/common-ui/components/prompt-templates'
import { RemoteSyncSettingsInterface } from 'src/sync-settings/background/types'
import {
SyncSettingsStore,
createSyncSettingsStore,
} from 'src/sync-settings/util'

interface TooltipRootProps {
mount: InPageUIRootMount
Expand All @@ -42,6 +48,7 @@ interface TooltipRootProps {
contentSharingBG: ContentSharingInterface
authBG: AuthRemoteFunctionsInterface
spacesBG: RemoteCollectionsInterface
syncSettingsBG: RemoteSyncSettingsInterface
bgScriptsBG: RemoteBGScriptInterface<'caller'>
pageActivityIndicatorBG: RemotePageActivityIndicatorInterface
localStorageAPI: Storage.LocalStorageArea
Expand All @@ -56,6 +63,7 @@ interface TooltipRootState {
showSpacePicker: boolean
spaceSearchResults: any[]
askAITabActive?: boolean
aiPrompt?: string
}

class TooltipRoot extends React.Component<TooltipRootProps, TooltipRootState> {
Expand All @@ -65,6 +73,7 @@ class TooltipRoot extends React.Component<TooltipRootProps, TooltipRootState> {
showSpacePicker: false,
spaceSearchResults: [],
askAITabActive: false,
aiPrompt: null,
}
private summarisePageEvents: TypedRemoteEventEmitter<'pageSummary'>

Expand Down Expand Up @@ -141,18 +150,23 @@ class TooltipRoot extends React.Component<TooltipRootProps, TooltipRootState> {
const annotation = this.props.annotationsCache.annotations.byId[
annotationId
]
this.setState({ currentAnnotation: annotation })
this.setState({
currentAnnotation: annotation,
currentAnnotationLists: [],
})
}

selectSpaceForAnnotation = async (listId: number) => {
const { currentAnnotation } = this.state

if (!currentAnnotation) {
return
}

const isListAlreadySelected = this.state.currentAnnotationLists.some(
(currentList) => currentList.localId === listId,
)

if (isListAlreadySelected) {
return
}
Expand All @@ -167,7 +181,7 @@ class TooltipRoot extends React.Component<TooltipRootProps, TooltipRootState> {

const existing = this.props.annotationsCache.annotations.byId[
currentAnnotation.unifiedId
].unifiedListIds
]?.unifiedListIds

const unifiedListId = newList.unifiedId
const updatedUnifiedListIdLists: UnifiedList['unifiedId'][] = [
Expand Down Expand Up @@ -306,6 +320,20 @@ class TooltipRoot extends React.Component<TooltipRootProps, TooltipRootState> {
}
}

renderPromptTemplates = () => {
return (
<PromptTemplatesComponent
syncSettingsBG={this.props.syncSettingsBG}
getRootElement={this.props.getRootElement}
onTemplateSelect={(text: string) =>
this.setState({
aiPrompt: text,
})
}
/>
)
}

renderSpacePicker = (buttonRef?) => {
if (this.state.showSpacePicker) {
const CollectionsPickerElement = (
Expand Down Expand Up @@ -351,6 +379,9 @@ class TooltipRoot extends React.Component<TooltipRootProps, TooltipRootState> {
offsetX={12}
offsetY={-10}
closeComponent={() => this.toggleSpacePicker(false)}
blockedBackground
blockedBackgroundTransparent
instaClose
>
{CollectionsPickerElement}
</PopoutBox>
Expand Down Expand Up @@ -378,6 +409,7 @@ class TooltipRoot extends React.Component<TooltipRootProps, TooltipRootState> {
renderSpacePicker={(buttonRef) =>
this.renderSpacePicker(buttonRef)
}
promptTemplates={this.renderPromptTemplates}
saveAnnotation={this.saveAnnotation}
getAnnotationData={this.getAnnotationData}
currentAnnotationLists={
Expand All @@ -394,6 +426,8 @@ class TooltipRoot extends React.Component<TooltipRootProps, TooltipRootState> {
spaceSearchResults={this.state.spaceSearchResults}
addNewSpaceViaWikiLinks={this.addNewSpaceViaWikiLinks}
isAskAIOpen={this.state.askAITabActive}
showSpacePicker={this.state.showSpacePicker}
aiPrompt={this.state.aiPrompt}
/>
</ThemeProvider>
</StyleSheetManager>
Expand Down Expand Up @@ -423,6 +457,7 @@ export function setupUIContainer(
localStorageAPI={props.localStorageAPI}
getRootElement={props.getRootElement}
inPageUI={props.inPageUI}
syncSettingsBG={props.syncSettingsBG}
/>,
mount.rootElement,
)
Expand Down
1 change: 1 addition & 0 deletions src/in-page-ui/tooltip/content_script/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export const insertTooltip = async (params: TooltipInsertDependencies) => {
localStorageAPI: params.localStorageAPI,
getRootElement: () => target,
inPageUI: params.inPageUI,
syncSettingsBG: params.syncSettingsBG,
},
)

Expand Down
2 changes: 2 additions & 0 deletions src/in-page-ui/tooltip/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { AnalyticsCoreInterface } from '@worldbrain/memex-common/lib/analyt
import type { RemoteBGScriptInterface } from 'src/background-script/types'
import type { Storage } from 'webextension-polyfill'
import type { SharedInPageUIState } from '../shared-state/shared-in-page-ui-state'
import { RemoteSyncSettingsInterface } from 'src/sync-settings/background/types'

export interface TooltipDependencies extends AnnotationFunctions {
inPageUI: SharedInPageUIState
Expand All @@ -23,4 +24,5 @@ export interface TooltipDependencies extends AnnotationFunctions {
analyticsBG: AnalyticsCoreInterface
pageActivityIndicatorBG: RemotePageActivityIndicatorInterface
localStorageAPI: Storage.LocalStorageArea
syncSettingsBG: RemoteSyncSettingsInterface
}

0 comments on commit 898c756

Please sign in to comment.