Skip to content

Commit

Permalink
add ability to open images in bigger mode
Browse files Browse the repository at this point in the history
  • Loading branch information
blackforestboi committed Jun 27, 2024
1 parent 904e9ac commit 9385783
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 2 deletions.
2 changes: 1 addition & 1 deletion external/@worldbrain/memex-common
2 changes: 2 additions & 0 deletions src/annotations/components/AnnotationCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface AnnotationCreateGeneralProps {
getRootElement: () => HTMLElement
updateSpacesSearchSuggestions?: (query: string) => void
spaceSearchSuggestions?: SpaceSearchSuggestion[]
openImageInPreview: (imageSource: string) => Promise<void>
}

export interface Props
Expand Down Expand Up @@ -522,6 +523,7 @@ export class AnnotationCreate extends React.Component<Props, State>
this.props.addNewSpaceViaWikiLinksNewNote
}
defaultMinimized={this.props.defaultMinimized}
openImageInPreview={this.props.openImageInPreview}
/>
</EditorContainer>
{this.props.comment.length > 0 &&
Expand Down
2 changes: 2 additions & 0 deletions src/annotations/components/AnnotationEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface AnnotationEditGeneralProps {
slimEditorActions?: boolean
isEditMode?: boolean
searchTerms?: string[]
openImageInPreview: (imageSource: string) => Promise<void>
}

export interface Props
Expand Down Expand Up @@ -214,6 +215,7 @@ class AnnotationEdit extends React.Component<Props> {
this.props.addNewSpaceViaWikiLinks
}
searchTerms={this.props.searchTerms}
openImageInPreview={this.props.openImageInPreview}
/>
</EditorContainer>
)
Expand Down
3 changes: 3 additions & 0 deletions src/annotations/components/AnnotationEditable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export interface AnnotationProps {
shiftSelectItem?: () => void
searchTerms?: string[]
syncSettingsBG: RemoteSyncSettingsInterface
openImageInPreview: (imageSource: string) => Promise<void>
}

export interface AnnotationEditableEventProps {
Expand Down Expand Up @@ -553,6 +554,7 @@ export default class AnnotationEditable extends React.Component<Props, State> {
)
}
searchTerms={this.props.searchTerms}
openImageInPreview={this.props.openImageInPreview}
/>
</HighlightEditContainer>
</HighlightSection>
Expand Down Expand Up @@ -854,6 +856,7 @@ export default class AnnotationEditable extends React.Component<Props, State> {
)
}
searchTerms={this.props.searchTerms}
openImageInPreview={this.props.openImageInPreview}
/>
</AnnotationEditContainer>
)
Expand Down
17 changes: 17 additions & 0 deletions src/dashboard-refactor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import { TooltipBox } from '@worldbrain/memex-common/lib/common-ui/components/to
import KeyboardShortcuts from '@worldbrain/memex-common/lib/common-ui/components/keyboard-shortcuts'
import { UpdateNotifBanner } from 'src/common-ui/containers/UpdateNotifBanner'
import { HighlightColor } from '@worldbrain/memex-common/lib/common-ui/components/highlightColorPicker/types'
import ImagePreviewModal from '@worldbrain/memex-common/lib/common-ui/image-preview-modal'

export type Props = DashboardDependencies & {
getRootElement: () => HTMLElement
Expand Down Expand Up @@ -267,6 +268,8 @@ export class DashboardContainer extends StatefulUIElement<
: undefined,
imageSupport: this.props.imageSupportBG,
getRootElement: this.props.getRootElement,
openImageInPreview: (imageSource: string) =>
this.processEvent('openImageInPreview', imageSource),
}
}

Expand Down Expand Up @@ -937,6 +940,9 @@ export class DashboardContainer extends StatefulUIElement<
)
: []
}
openImageInPreview={(imageSource: string) =>
this.processEvent('openImageInPreview', imageSource)
}
spacePickerBGProps={{
authBG: this.props.authBG,
spacesBG: this.props.listsBG,
Expand Down Expand Up @@ -1447,6 +1453,8 @@ export class DashboardContainer extends StatefulUIElement<
...opts,
})
},
openImageInPreview: () => (imageSource: string) =>
this.processEvent('openImageInPreview', imageSource),
onGoToHighlightClick: (noteId) => () =>
this.processEvent('goToHighlightInNewTab', { noteId }),
onListPickerBarBtnClick: (noteId) => () =>
Expand Down Expand Up @@ -2080,6 +2088,15 @@ export class DashboardContainer extends StatefulUIElement<
/>
</MainFrame>
{this.renderModals()}
{this.state.imageSourceForPreview?.length > 0 ? (
<ImagePreviewModal
imageSource={this.state.imageSourceForPreview}
closeModal={() =>
this.processEvent('openImageInPreview', null)
}
getRootElement={this.props.getRootElement}
/>
) : null}
<HelpBtn
currentUser={this.state.currentUser}
theme={this.state.themeVariant}
Expand Down
9 changes: 9 additions & 0 deletions src/dashboard-refactor/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export class DashboardLogic extends UILogic<State, Events> {
focusLockUntilMouseStart: false,
selectableBlocks: [],
focusedBlockId: -1,
imageSourceForPreview: null,
}
}

Expand Down Expand Up @@ -848,6 +849,14 @@ export class DashboardLogic extends UILogic<State, Events> {
})
}

openImageInPreview: EventHandler<'openImageInPreview'> = async ({
event,
}) => {
this.emitMutation({
imageSourceForPreview: { $set: event },
})
}

checkSharingAccess: EventHandler<'checkSharingAccess'> = async ({
previousState,
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface Props {
clearInbox?: () => void
imageSupport: ImageSupportInterface<'caller'>
getRootElement: () => HTMLElement
openImageInPreview: (imageSource: string) => Promise<void>
}

interface State {
Expand Down Expand Up @@ -200,6 +201,7 @@ export default class ListDetails extends PureComponent<Props, State> {
})
}}
defaultMinimized
openImageInPreview={this.props.openImageInPreview}
/>
)
}
Expand Down
3 changes: 3 additions & 0 deletions src/dashboard-refactor/search-results/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export type Props = RootState &
spaceSearchSuggestions?: SpaceSearchSuggestion[]
shiftSelectItems: (itemId: string, type: 'notes' | 'pages') => void
focusLockUntilMouseStart: boolean
openImageInPreview: (imageSource: string) => Promise<void>
}

export interface State {
Expand Down Expand Up @@ -397,6 +398,7 @@ export default class SearchResultsContainer extends React.Component<
? new Date(noteData.displayTime)
: undefined
}
openImageInPreview={this.props.openImageInPreview}
searchTerms={this.state.searchTerms}
syncSettingsBG={this.props.syncSettingsBG}
bulkSelectAnnotation={() => {
Expand Down Expand Up @@ -540,6 +542,7 @@ export default class SearchResultsContainer extends React.Component<
onBodyChange: (content) =>
interactionProps.onBodyChange(content),
setEditing: interactionProps.onEditBtnClick,
openImageInPreview: interactionProps.openImageInPreview,
}}
annotationFooterDependencies={{
onCopyPasterDefaultExecute:
Expand Down
1 change: 1 addition & 0 deletions src/dashboard-refactor/search-results/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export type NoteInteractionProps = Omit<
onCommentChange: (content: string) => void
onBodyChange: (content: string) => void
onCopyPasterDefaultExecute: () => void
openImageInPreview: (imageSource: string) => Promise<void>
}

// NOTE: Derived type - edit the original
Expand Down
2 changes: 2 additions & 0 deletions src/dashboard-refactor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export interface RootState {
spaceSearchSuggestions: SpaceSearchSuggestion[]
selectableBlocks: SelectableBlock[]
focusedBlockId: number | null
imageSourceForPreview: string
}

export type Events = UIEvent<
Expand Down Expand Up @@ -195,6 +196,7 @@ export type DashboardModalsEvents = UIEvent<{
setDeletingPageArgs: PageEventArgs & { instaDelete: boolean }
setDeletingNoteArgs: NoteDataEventArgs
checkSharingAccess: null
openImageInPreview: string
setSpaceSidebarWidth: { width: string }
setDisableMouseLeave: { disable: boolean }
selectAllCurrentItems: null
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 @@ -182,6 +182,7 @@ export const insertTooltip = async (params: TooltipInsertDependencies) => {
addNewSpaceViaWikiLinks: async (spaceName: string) => {
// Placeholder function, replace with actual implementation
},
openImageInPreview: async (src: string) => null,
},
{
annotationsBG: params.annotationsBG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export interface AnnotationsSidebarProps extends SidebarContainerState {
renderContextMenuForList: (listData: UnifiedList) => JSX.Element
renderEditMenuForList: (listData: UnifiedList) => JSX.Element
renderPageLinkMenuForList: () => JSX.Element

openImageInPreview: (imageSource: string) => Promise<void>
setActiveTab: (tab: SidebarTab) => void
setActiveAITab: (tab: SidebarAITab) => React.MouseEventHandler
setActiveSuggestionsTab: (tab: SuggestionsTab) => React.MouseEventHandler
Expand Down Expand Up @@ -753,6 +753,7 @@ export class AnnotationsSidebar extends React.Component<
onCancel={() => {
this.setState({ autoFocusCreateForm: false })
}}
openImageInPreview={this.props.openImageInPreview}
ref={this.annotationCreateRef}
getYoutubePlayer={this.props.getYoutubePlayer}
autoFocus={this.state.autoFocusCreateForm}
Expand Down Expand Up @@ -1050,6 +1051,7 @@ export class AnnotationsSidebar extends React.Component<
isShared
syncSettingsBG={this.props.syncSettingsBG}
getRootElement={this.props.getRootElement}
openImageInPreview={this.props.openImageInPreview}
isBulkShareProtected
onSpacePickerToggle={() => {
this.props.setSpacePickerAnnotationInstance(
Expand Down Expand Up @@ -1191,6 +1193,9 @@ export class AnnotationsSidebar extends React.Component<
createdWhen: annotation.createdWhen,
reference: sharedAnnotationRef,
}}
openImageInPreview={
this.props.openImageInPreview
}
getYoutubePlayer={
this.props.getYoutubePlayer
}
Expand Down Expand Up @@ -2006,6 +2011,7 @@ export class AnnotationsSidebar extends React.Component<
createNewNoteFromAISummary={
this.props.createNewNoteFromAISummary
}
openImageInPreview={this.props.openImageInPreview}
getYoutubePlayer={this.props.getYoutubePlayer}
sidebarEvents={this.props.events}
aiChatStateExternal={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { generateAnnotationCardInstanceId } from './utils'
import type { AnnotationCardInstanceLocation } from '../types'
import type { YoutubeService } from '@worldbrain/memex-common/lib/services/youtube'
import { getBlockContentYoutubePlayerId } from '@worldbrain/memex-common/lib/common-ui/components/block-content'
import ImagePreviewModal from '@worldbrain/memex-common/lib/common-ui/image-preview-modal'
import type { YoutubePlayer } from '@worldbrain/memex-common/lib/services/youtube/types'
import { AICounterIndicator } from 'src/util/subscriptions/AICountIndicator'
import SpaceContextMenu from 'src/custom-lists/ui/space-context-menu'
Expand Down Expand Up @@ -418,6 +419,8 @@ export class AnnotationsSidebarContainer<
imageSupport: this.props.imageSupport,
getRootElement: this.props.getRootElement,
copyLoadingState: annotationCardInstance?.copyLoadingState,
openImageInPreview: (imageSource: string) =>
this.processEvent('openImageInPreview', imageSource),
}
}

Expand Down Expand Up @@ -504,6 +507,8 @@ export class AnnotationsSidebarContainer<
})
},
defaultMinimized: false,
openImageInPreview: (imageSource: string) =>
this.processEvent('openImageInPreview', imageSource),
}
}

Expand Down Expand Up @@ -1174,6 +1179,12 @@ export class AnnotationsSidebarContainer<
unifiedAnnotationId,
})
}
openImageInPreview={(imageSource: string) =>
this.processEvent(
'openImageInPreview',
imageSource,
)
}
getHighlightColorSettings={() =>
this.processEvent(
'getHighlightColorSettings',
Expand Down Expand Up @@ -1865,6 +1876,15 @@ export class AnnotationsSidebarContainer<
</Rnd>
</ContainerStyled>
{this.renderModals()}
{this.state.imageSourceForPreview?.length > 0 ? (
<ImagePreviewModal
imageSource={this.state.imageSourceForPreview}
closeModal={() =>
this.processEvent('openImageInPreview', null)
}
getRootElement={this.props.getRootElement}
/>
) : null}
</ThemeProvider>
)
}
Expand Down
9 changes: 9 additions & 0 deletions src/sidebar/annotations-sidebar/containers/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ export class SidebarContainerLogic extends UILogic<
existingSourcesOption: 'pristine',
localFoldersList: [],
bulkSelectionState: [],
imageSourceForPreview: null,
}
}

Expand Down Expand Up @@ -1334,6 +1335,14 @@ export class SidebarContainerLogic extends UILogic<
// }
}

openImageInPreview: EventHandler<'openImageInPreview'> = async ({
event,
}) => {
this.emitMutation({
imageSourceForPreview: { $set: event },
})
}

setPopoutsActive: EventHandler<'setPopoutsActive'> = async ({ event }) => {
this.emitMutation({
popoutsActive: { $set: event },
Expand Down
2 changes: 2 additions & 0 deletions src/sidebar/annotations-sidebar/containers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export interface SidebarContainerState extends AnnotationConversationsState {
remoteAnnotationsLoadState: TaskState
foreignSelectedListLoadState: TaskState
selectedTextAIPreview: string
imageSourceForPreview: string
queryMode: string
isTrial: boolean
signupDate: number
Expand Down Expand Up @@ -354,6 +355,7 @@ interface SidebarEvents {
adjustSidebarWidth: { newWidth: string; isWidthLocked?: boolean }
adjustRighPositionBasedOnRibbonPosition: { position: number }
setPopoutsActive: boolean
openImageInPreview: string
checkIfKeyValid: { apiKey: string }
saveAIPrompt: { prompt: string }
removeAISuggestion: { suggestion: string }
Expand Down

0 comments on commit 9385783

Please sign in to comment.