diff --git a/src/dashboard-refactor/index.tsx b/src/dashboard-refactor/index.tsx index c9d7d16af9..ea98ef0671 100644 --- a/src/dashboard-refactor/index.tsx +++ b/src/dashboard-refactor/index.tsx @@ -905,7 +905,7 @@ export class DashboardContainer extends StatefulUIElement< isShown: !searchResults.isSortMenuShown, }) } - searchResults={searchResults.pageData} + searchResults={searchResults.pageData} // TODO: Why is this being passed down multiple times? searchFilters={searchFilters} searchQuery={searchFilters.searchQuery} isDisplayed={searchFilters.searchFiltersOpen} @@ -950,13 +950,13 @@ export class DashboardContainer extends StatefulUIElement< onPageNotesSortSelection={(day, pageId) => (sortingFn) => this.processEvent('setPageNotesSort', { day, - pageId, + pageResultId: pageId, sortingFn, })} onPageNotesTypeSelection={(day, pageId) => (noteType) => this.processEvent('setPageNotesType', { day, - pageId, + pageResultId: pageId, noteType, })} onShowAllNotesClick={() => @@ -1008,36 +1008,45 @@ export class DashboardContainer extends StatefulUIElement< }} spaceSearchSuggestions={this.state.spaceSearchSuggestions} pageInteractionProps={{ - onClick: (day, pageId) => async (event) => + onClick: (day, pageResultId) => async (event) => this.processEvent('clickPageResult', { day, - pageId, + pageResultId: pageResultId, synthEvent: event, }), - onMatchingTextToggleClick: (day, pageId) => async () => + onMatchingTextToggleClick: ( + day, + pageResultId, + ) => async () => this.processEvent('onMatchingTextToggleClick', { day, - pageId, + pageResultId: pageResultId, }), - onNotesBtnClick: (day, pageId) => (e) => { + onNotesBtnClick: (day, pageResultId) => (e) => { + // TODO: Multiple processEvent calls should never happen from a single user action. Needs to be unified + // These are also running concurrently, potentially introducing race conditions this.processEvent('toggleNoteSidebarOn', null) - const pageData = searchResults.pageData.byId[pageId] + const pageResult = + searchResults.results[-1].pages.byId[pageResultId] + const pageData = + searchResults.pageData.byId[pageResult.pageId] this.processEvent('setActivePage', { activeDay: day, - activePageID: pageId, + activePageID: pageResult.pageId, activePage: true, }) if (e.shiftKey) { this.processEvent('setPageNotesShown', { day, - pageId, + pageResultId: pageResultId, areShown: !searchResults.results[day].pages - .byId[pageId].areNotesShown, + .byId[pageResultId].areNotesShown, }) return } + // TODO: Explain why a setTimeout is needed here setTimeout( () => { this.notesSidebarRef.current.toggleSidebarShowForPageId( @@ -1048,38 +1057,33 @@ export class DashboardContainer extends StatefulUIElement< this.props.inPageMode ? 200 : 0, ) }, - onAIResultBtnClick: (day, pageId) => () => { + onAIResultBtnClick: (day, pageResultId) => async () => { this.processEvent('toggleNoteSidebarOn', null) - const pageData = searchResults.pageData.byId[pageId] + const pageResult = + searchResults.results[-1].pages.byId[pageResultId] + const pageData = + searchResults.pageData.byId[pageResult.pageId] - this.notesSidebarRef.current.toggleAIShowForPageId( + await this.notesSidebarRef.current.toggleAIShowForPageId( pageData.fullUrl, ) }, - onTagPickerBtnClick: (day, pageId) => () => - this.processEvent('setPageTagPickerShown', { - day, - pageId, - isShown: !searchResults.results[day].pages.byId[ - pageId - ].isTagPickerShown, - }), onListPickerFooterBtnClick: (day, pageId) => () => this.processEvent('setPageListPickerShown', { day, - pageId, + pageResultId: pageId, show: 'footer', }), onListPickerBarBtnClick: (day, pageId) => () => this.processEvent('setPageListPickerShown', { day, - pageId, + pageResultId: pageId, show: 'lists-bar', }), onCopyPasterBtnClick: (day, pageId) => (event) => this.processEvent('setPageCopyPasterShown', { day, - pageId, + pageResultId: pageId, isShown: !searchResults.results[day].pages.byId[ pageId ].isCopyPasterShown, @@ -1088,7 +1092,7 @@ export class DashboardContainer extends StatefulUIElement< onCopyPasterDefaultExecute: (day, pageId) => (event) => this.processEvent('setCopyPasterDefaultExecute', { day, - pageId, + pageResultId: pageId, isShown: !searchResults.results[day].pages.byId[ pageId ].isCopyPasterShown, @@ -1097,13 +1101,13 @@ export class DashboardContainer extends StatefulUIElement< onTrashBtnClick: (day, pageId) => (instaDelete) => this.processEvent('setDeletingPageArgs', { day, - pageId, + pageResultId: pageId, instaDelete, }), onShareBtnClick: (day, pageId) => () => this.processEvent('setPageShareMenuShown', { day, - pageId, + pageResultId: pageId, isShown: !searchResults.results[day].pages.byId[ pageId ].isShareMenuShown, @@ -1114,7 +1118,7 @@ export class DashboardContainer extends StatefulUIElement< } this.processEvent('setPageHover', { day, - pageId, + pageResultId: pageId, hover: 'main-content', }) @@ -1128,25 +1132,25 @@ export class DashboardContainer extends StatefulUIElement< onFooterHover: (day, pageId) => () => this.processEvent('setPageHover', { day, - pageId, + pageResultId: pageId, hover: 'footer', }), onTagsHover: (day, pageId) => () => this.processEvent('setPageHover', { day, - pageId, + pageResultId: pageId, hover: 'tags', }), onListsHover: (day, pageId) => () => this.processEvent('setPageHover', { day, - pageId, + pageResultId: pageId, hover: 'lists', }), onUnhover: (day, pageId) => () => { this.processEvent('setPageHover', { day, - pageId, + pageResultId: pageId, hover: null, }) if (this.state.focusLockUntilMouseStart) { @@ -1162,21 +1166,24 @@ export class DashboardContainer extends StatefulUIElement< onRemoveFromListBtnClick: (day, pageId) => () => { this.processEvent('removePageFromList', { day, - pageId, + pageResultId: pageId, }) }, onPageDrag: (day, pageId) => (e) => this.processEvent('dragPage', { day, - pageId, + pageResultId: pageId, dataTransfer: e.dataTransfer, }), onPageDrop: (day, pageId) => () => - this.processEvent('dropPage', { day, pageId }), + this.processEvent('dropPage', { + day, + pageResultId: pageId, + }), updatePageNotesShareInfo: (day, pageId) => (shareStates) => this.processEvent('updatePageNotesShareInfo', { day, - pageId, + pageResultId: pageId, shareStates, }), onEditTitleSave: (day, pageId) => ( @@ -1203,11 +1210,9 @@ export class DashboardContainer extends StatefulUIElement< }, }} pagePickerProps={{ - onListPickerUpdate: (pageId) => (args) => + onListPickerUpdate: (pageResultId) => (args) => this.processEvent('setPageLists', { - id: pageId, - fullPageUrl: - searchResults.pageData.byId[pageId].fullUrl, + pageResultId: pageResultId, ...this.localListPickerArgIdsToCached(args), }), }} @@ -1217,12 +1222,12 @@ export class DashboardContainer extends StatefulUIElement< onCancel: (day, pageId) => () => this.processEvent('cancelPageNewNote', { day, - pageId, + pageResultId: pageId, }), onCommentChange: (day, pageId) => (value) => this.processEvent('setPageNewNoteCommentValue', { day, - pageId, + pageResultId: pageId, value, }), addPageToList: (day, pageId) => (listId) => { @@ -1236,7 +1241,7 @@ export class DashboardContainer extends StatefulUIElement< } return this.processEvent('setPageNewNoteLists', { day, - pageId, + pageResultId: pageId, lists: [ ...this.state.searchResults.results[day].pages .byId[pageId].newNoteForm.lists, @@ -1255,7 +1260,7 @@ export class DashboardContainer extends StatefulUIElement< } return this.processEvent('setPageNewNoteLists', { day, - pageId, + pageResultId: pageId, lists: this.state.searchResults?.results[ day ].pages.byId[pageId].newNoteForm.lists.filter( @@ -1263,15 +1268,22 @@ export class DashboardContainer extends StatefulUIElement< ), }) }, - onSave: (day, pageId) => (shouldShare, isProtected) => - this.processEvent('savePageNewNote', { + onSave: (day, pageResultId) => async ( + shouldShare, + isProtected, + ) => { + const pageResult = + searchResults.results[-1].pages.byId[pageResultId] + await this.processEvent('savePageNewNote', { day, - pageId, + pageResultId: pageResultId, isProtected, shouldShare, fullPageUrl: - searchResults.pageData.byId[pageId].fullUrl, - }), + searchResults.pageData.byId[pageResult.pageId] + .fullUrl, + }) + }, addNewSpaceViaWikiLinksNewNote: (day, pageId) => ( spaceName: string, ) => { @@ -1295,7 +1307,7 @@ export class DashboardContainer extends StatefulUIElement< } this.processEvent('setPageNewNoteLists', { day, - pageId, + pageResultId: pageId, lists: [ ...this.state.searchResults.results[day].pages .byId[pageId].newNoteForm.lists, @@ -1316,7 +1328,7 @@ export class DashboardContainer extends StatefulUIElement< } this.processEvent('setPageNewNoteLists', { day, - pageId, + pageResultId: pageId, lists: this.state.searchResults.results[ day ].pages.byId[pageId].newNoteForm.lists.filter( @@ -1355,12 +1367,6 @@ export class DashboardContainer extends StatefulUIElement< }, onGoToHighlightClick: (noteId) => () => this.processEvent('goToHighlightInNewTab', { noteId }), - onTagPickerBtnClick: (noteId) => () => - this.processEvent('setNoteTagPickerShown', { - noteId, - isShown: !searchResults.noteData.byId[noteId] - .isTagPickerShown, - }), onListPickerBarBtnClick: (noteId) => () => this.processEvent('setNoteListPickerShown', { noteId, @@ -1415,10 +1421,12 @@ export class DashboardContainer extends StatefulUIElement< }, ) }, - onTrashBtnClick: (noteId, day, pageId) => (instaDelete) => + onTrashBtnClick: (noteId, day, pageResultId) => ( + instaDelete, + ) => this.processEvent('setDeletingNoteArgs', { noteId, - pageId, + pageResultId, day, }), onCommentChange: (noteId) => (event) => { diff --git a/src/dashboard-refactor/logic.ts b/src/dashboard-refactor/logic.ts index 1611657045..7923b596d5 100644 --- a/src/dashboard-refactor/logic.ts +++ b/src/dashboard-refactor/logic.ts @@ -19,12 +19,7 @@ import { MISSING_PDF_QUERY_PARAM, } from 'src/dashboard-refactor/constants' import { STORAGE_KEYS as CLOUD_STORAGE_KEYS } from 'src/personal-cloud/constants' -import { - updatePickerValues, - stateToSearchParams, - flattenNestedResults, - getListData, -} from './util' +import { updatePickerValues, stateToSearchParams, getListData } from './util' import { SPECIAL_LIST_IDS } from '@worldbrain/memex-common/lib/storage/modules/lists/constants' import type { NoResultsType, SelectableBlock } from './search-results/types' import { filterListsByQuery } from './lists-sidebar/util' @@ -256,6 +251,7 @@ export class DashboardLogic extends UILogic { searchResults: { blankSearchOldestResultTimestamp: null, results: {}, + pageIdToResultIds: {}, noResultsType: null, showMobileAppAd: false, shouldShowTagsUIs: false, @@ -940,14 +936,15 @@ export class DashboardLogic extends UILogic { const { results } = utils.pageSearchResultToState( result, + params, this.options.annotationsCache, ) - let resultsList = results[-1].pages.byId + const resultsList = results[-1].pages.byId - for (let page of Object.values(resultsList)) { - const annotations = page.noteIds?.user ?? [] - if (selectedUrls[page.id]) { + for (const page of Object.values(resultsList)) { + const annotations = page.noteIds.user ?? [] + if (selectedUrls[page.pageId]) { if (annotations.length > 0) { for (let note of annotations) { bulkEditItems[note] = { @@ -957,7 +954,7 @@ export class DashboardLogic extends UILogic { } continue } else { - bulkEditItems[page.id] = { + bulkEditItems[page.pageId] = { type: 'page', } if (annotations.length > 0) { @@ -1237,8 +1234,10 @@ export class DashboardLogic extends UILogic { noteData, pageData, results, + pageIdToResultIds, } = utils.pageSearchResultToState( result, + params, this.options.annotationsCache, ) @@ -1273,6 +1272,29 @@ export class DashboardLogic extends UILogic { return } + // Merge page ID -> result IDs indices, if we're paginating + let nextPageIdToResultIds: State['searchResults']['pageIdToResultIds'] = {} + if (event?.paginate) { + const allPageIds = new Set([ + ...Object.keys(pageIdToResultIds), + ...Object.keys( + previousState.searchResults.pageIdToResultIds, + ), + ]) + for (const pageId of allPageIds) { + const next = pageIdToResultIds[pageId] ?? [] + const prev = + previousState.searchResults.pageIdToResultIds[ + pageId + ] ?? [] + nextPageIdToResultIds[pageId] = [ + ...new Set([...prev, ...next]), + ] + } + } else { + nextPageIdToResultIds = pageIdToResultIds + } + this.emitMutation({ searchFilters: mutation.searchFilters, searchResults: { @@ -1285,6 +1307,7 @@ export class DashboardLogic extends UILogic { searchState: { $set: 'success' }, searchPaginationState: { $set: 'success' }, noResultsType: { $set: noResultsType }, + pageIdToResultIds: { $set: nextPageIdToResultIds }, ...(event?.paginate ? { results: { @@ -1323,21 +1346,20 @@ export class DashboardLogic extends UILogic { compiledSelectableBlocks = previousState.selectableBlocks } - let resultsList = results[-1].pages.byId + const resultsList = results[-1].pages.byId - for (let page of Object.values(resultsList)) { - let block: SelectableBlock = { - id: page.id, + for (const page of Object.values(resultsList)) { + const block: SelectableBlock = { + id: page.pageId, type: 'page', } compiledSelectableBlocks.push(block) - - let pageNotes = page?.noteIds?.user ?? null + const pageNotes = page.noteIds.user ?? null if (pageNotes.length > 0) { - for (let note of pageNotes) { - let noteBlock: SelectableBlock = { + for (const note of pageNotes) { + const noteBlock: SelectableBlock = { id: note, type: 'note', } @@ -1548,9 +1570,11 @@ export class DashboardLogic extends UILogic { /* END - modal event handlers */ /* START - search result event handlers */ + // TODO: Remove this event setPageSearchResult: EventHandler<'setPageSearchResult'> = ({ event }) => { const state = utils.pageSearchResultToState( event.result, + { skip: 0, limit: 10 }, this.options.annotationsCache, ) this.emitMutation({ @@ -1579,13 +1603,35 @@ export class DashboardLogic extends UILogic { > = {} const calcNextLists = updatePickerValues(event) + const pageResult = + previousState.searchResults.results[-1].pages.byId[ + event.pageResultId + ] + const pageData = + previousState.searchResults.pageData.byId[pageResult.pageId] + // If we're removing a shared list, we also need to make sure it gets removed from children annots if (removingSharedList) { - const childrenNoteIds = flattenNestedResults(previousState).byId[ - event.id - ].noteIds.user + const dependentNoteIds: string[] = [] + const pageResultIds = + previousState.searchResults.pageIdToResultIds[pageResult.pageId] + + for (const pageResultId of pageResultIds) { + const noteIdsForPage = + previousState.searchResults.results[-1].pages.byId[ + pageResultId + ].noteIds.user + + dependentNoteIds.push( + ...noteIdsForPage.filter( + (noteId) => + previousState.searchResults.noteData.byId[noteId] + .isBulkShareProtected, + ), + ) + } - for (const noteId of childrenNoteIds) { + for (const noteId of dependentNoteIds) { noteDataMutation[noteId] = { lists: { $apply: calcNextLists }, } @@ -1593,10 +1639,10 @@ export class DashboardLogic extends UILogic { } const nextPageListIds = calcNextLists( - previousState.searchResults.pageData.byId[event.id].lists, + previousState.searchResults.pageData.byId[pageResult.pageId].lists, ) this.options.annotationsCache.setPageData( - normalizeUrl(event.fullPageUrl), + pageResult.pageId, nextPageListIds, ) this.emitMutation({ @@ -1604,7 +1650,7 @@ export class DashboardLogic extends UILogic { noteData: { byId: noteDataMutation }, pageData: { byId: { - [event.id]: { + [pageResult.pageId]: { lists: { $set: nextPageListIds }, }, }, @@ -1613,7 +1659,7 @@ export class DashboardLogic extends UILogic { }) await this.options.listsBG.updateListForPage({ - url: event.fullPageUrl, + url: pageData.fullUrl, added: event.added && listData.localId, deleted: event.deleted && listData.localId, skipPageIndexing: true, @@ -1626,7 +1672,8 @@ export class DashboardLogic extends UILogic { }) => { if (event.instaDelete) { const pageLists = - previousState.searchResults.pageData.byId[event.pageId].lists + previousState.searchResults.pageData.byId[event.pageResultId] + .lists const isPageInInbox = pageLists.some( (listId) => this.options.annotationsCache.lists.byId[listId].localId === @@ -1650,10 +1697,10 @@ export class DashboardLogic extends UILogic { State['searchResults'] > = { pageData: { - byId: { $unset: [event.pageId] }, + byId: { $unset: [event.pageResultId] }, allIds: { $set: previousState.searchResults.pageData.allIds.filter( - (id) => id !== event.pageId, + (id) => id !== event.pageResultId, ), }, }, @@ -1663,12 +1710,12 @@ export class DashboardLogic extends UILogic { resultsMutation.results = { [event.day]: { pages: { - byId: { $unset: [event.pageId] }, + byId: { $unset: [event.pageResultId] }, allIds: { $set: previousState.searchResults.results[ event.day ].pages.allIds.filter( - (id) => id !== event.pageId, + (id) => id !== event.pageResultId, ), }, }, @@ -1677,14 +1724,14 @@ export class DashboardLogic extends UILogic { } else { resultsMutation.results = removeAllResultOccurrencesOfPage( previousState.searchResults.results, - event.pageId, + event.pageResultId, ) } this.emitMutation({ searchResults: resultsMutation, }) - await this.options.searchBG.delPages([event.pageId]) + await this.options.searchBG.delPages([event.pageResultId]) }, ) } else { @@ -1768,7 +1815,7 @@ export class DashboardLogic extends UILogic { previousState, event: { direction: 'down', - item: { id: event.pageId, type: 'page' }, + item: { id: event.pageResultId, type: 'page' }, }, }) @@ -1778,11 +1825,11 @@ export class DashboardLogic extends UILogic { { mustBeLocal: true, source: 'removePageFromList' }, ) const filterOutPage = (ids: string[]) => - ids.filter((id) => id !== event.pageId) + ids.filter((id) => id !== event.pageResultId) const mutation: UIMutation = { pageData: { - byId: { $unset: [event.pageId] }, + byId: { $unset: [event.pageResultId] }, allIds: { $set: filterOutPage( previousState.searchResults.pageData.allIds, @@ -1795,7 +1842,7 @@ export class DashboardLogic extends UILogic { mutation.results = { [PAGE_SEARCH_DUMMY_DAY]: { pages: { - byId: { $unset: [event.pageId] }, + byId: { $unset: [event.pageResultId] }, allIds: { $set: filterOutPage( previousState.searchResults.results[ @@ -1809,7 +1856,7 @@ export class DashboardLogic extends UILogic { } else { mutation.results = removeAllResultOccurrencesOfPage( previousState.searchResults.results, - event.pageId, + event.pageResultId, ) } this.emitMutation({ @@ -1824,7 +1871,7 @@ export class DashboardLogic extends UILogic { await this.options.listsBG.removePageFromList({ id: listData.localId, - url: event.pageId, + url: event.pageResultId, }) } @@ -1869,19 +1916,17 @@ export class DashboardLogic extends UILogic { } confirmPageDelete: EventHandler<'confirmPageDelete'> = async ({ - previousState: { - searchResults: { pageData, results }, - modals, - }, + previousState: { searchResults, modals }, }) => { if (!modals.deletingPageArgs) { throw new Error('No page ID is set for deletion') } - const { pageId, day } = modals.deletingPageArgs + const { pageResultId, day } = modals.deletingPageArgs - const pageLists = pageData.byId[pageId].lists - const isPageInInbox = pageLists.some( + const pageResult = searchResults.results[-1].pages.byId[pageResultId] + const pageData = searchResults.pageData.byId[pageResult.pageId] + const isPageInInbox = pageData.lists.some( (listId) => this.options.annotationsCache.lists.byId[listId].localId === SPECIAL_LIST_IDS.INBOX, @@ -1902,31 +1947,39 @@ export class DashboardLogic extends UILogic { async () => { const resultsMutation: UIMutation = { pageData: { - byId: { $unset: [pageId] }, + byId: { $unset: [pageResult.pageId] }, allIds: { - $set: pageData.allIds.filter((id) => id !== pageId), + $set: searchResults.pageData.allIds.filter( + (id) => id !== pageResult.pageId, + ), }, }, } + const pageResultIds = + searchResults.pageIdToResultIds[pageResult.pageId] + if (day === PAGE_SEARCH_DUMMY_DAY) { resultsMutation.results = { [day]: { pages: { - byId: { $unset: [pageId] }, + byId: { $unset: pageResultIds }, allIds: { - $set: results[day].pages.allIds.filter( - (id) => id !== pageId, + $set: searchResults.results[ + day + ].pages.allIds.filter( + (id) => !pageResultIds.includes(id), ), }, }, }, } - } else { - resultsMutation.results = removeAllResultOccurrencesOfPage( - results, - pageId, - ) + // TODO: Add support for other pages if we add them back in + // } else { + // resultsMutation.results = removeAllResultOccurrencesOfPage( + // results, + // pageId, + // ) } this.emitMutation({ @@ -1935,7 +1988,7 @@ export class DashboardLogic extends UILogic { deletingPageArgs: { $set: undefined }, }, }) - await this.options.searchBG.delPages([pageId]) + await this.options.searchBG.delPages([pageResult.pageId]) }, ) } @@ -2151,7 +2204,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { copyLoadingState: { $set: 'running', }, @@ -2166,12 +2219,12 @@ export class DashboardLogic extends UILogic { let templateCopyResult if ( !previousState.searchResults.results[event.day]?.pages.byId[ - event.pageId + event.pageResultId ].isCopyPasterShown ) { templateCopyResult = await this.handleDefaultTemplateCopy( [null], - [event.pageId], + [event.pageResultId], ) } @@ -2182,7 +2235,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { copyLoadingState: { $set: 'success', }, @@ -2201,7 +2254,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { copyLoadingState: { $set: 'pristine', }, @@ -2225,7 +2278,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { isCopyPasterShown: { $set: event.isShown }, }, }, @@ -2245,7 +2298,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { listPickerShowStatus: { $apply: (prev) => prev === event.show @@ -2270,7 +2323,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { isTagPickerShown: { $set: event.isShown }, }, }, @@ -2298,7 +2351,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { isShareMenuShown: { $set: event.isShown }, }, }, @@ -2313,30 +2366,17 @@ export class DashboardLogic extends UILogic { event, previousState, }) => { - if (event.activePageID == null && event.activeDay == null) { + if (event.activePageID == null || event.activeDay == null) { this.emitMutation({ activeDay: { $set: undefined }, activePageID: { $set: undefined }, - searchResults: { - results: { - [previousState.activeDay]: { - pages: { - byId: { - [previousState.activePageID]: { - activePage: { - $set: false, - }, - }, - }, - }, - }, - }, - }, }) return } this.emitMutation({ + activeDay: { $set: event.activeDay }, + activePageID: { $set: event.activePageID }, searchResults: { results: { [event.activeDay]: { @@ -2363,8 +2403,6 @@ export class DashboardLogic extends UILogic { }, }, }, - activeDay: { $set: event.activeDay }, - activePageID: { $set: event.activePageID }, }) } @@ -2376,7 +2414,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { areNotesShown: { $set: event.areShown }, }, }, @@ -2392,7 +2430,8 @@ export class DashboardLogic extends UILogic { previousState, }) => { const { searchResults } = previousState - const page = searchResults.results[event.day]?.pages.byId[event.pageId] + const page = + searchResults.results[event.day]?.pages.byId[event.pageResultId] const sortedNoteIds = page.noteIds[page.notesType].sort((a, b) => event.sortingFn( @@ -2407,7 +2446,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { noteIds: { [page.notesType]: { $set: sortedNoteIds, @@ -2429,7 +2468,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { notesType: { $set: event.noteType }, }, }, @@ -2443,10 +2482,10 @@ export class DashboardLogic extends UILogic { setPageHover: EventHandler<'setPageHover'> = ({ event, previousState }) => { if ( previousState.searchResults.results[event.day]?.pages.byId[ - event.pageId + event.pageResultId ].isCopyPasterShown || previousState.searchResults.results[event.day]?.pages.byId[ - event.pageId + event.pageResultId ].listPickerShowStatus !== 'hide' ) { return @@ -2458,7 +2497,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { hoverState: { $set: event.hover }, }, }, @@ -2478,7 +2517,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { newNoteForm: { isTagPickerShown: { $set: event.isShown, @@ -2499,7 +2538,7 @@ export class DashboardLogic extends UILogic { }) => { const existingLists = previousState.searchResults.results[event.day].pages.byId[ - event.pageId + event.pageResultId ].newNoteForm.lists const uniqueLists = event.lists.filter( (list) => !existingLists.includes(list), @@ -2511,7 +2550,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { newNoteForm: { lists: { $set: uniqueLists }, }, @@ -2533,7 +2572,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { newNoteForm: { inputValue: { $set: event.value }, }, @@ -2553,7 +2592,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { newNoteForm: { $set: utils.getInitialFormState(), }, @@ -2606,7 +2645,7 @@ export class DashboardLogic extends UILogic { this.processUIEvent('setPageNewNoteLists', { event: { day: event.day, - pageId: event.pageId, + pageResultId: event.pageId, lists: listsToAdd, }, previousState, @@ -2642,7 +2681,7 @@ export class DashboardLogic extends UILogic { const { annotationsBG, contentShareBG } = this.options const formState = previousState.searchResults.results[event.day].pages.byId[ - event.pageId + event.pageResultId ].newNoteForm const listsToAdd = formState.lists.map((listId) => getListData(listId, previousState, { @@ -2703,7 +2742,7 @@ export class DashboardLogic extends UILogic { comment: formState.inputValue, tags: formState.tags, lists: formState.lists ?? [], - pageUrl: event.pageId, + pageUrl: event.pageResultId, isShared: shouldSetAsAutoAdded || event.shouldShare, @@ -2719,7 +2758,7 @@ export class DashboardLogic extends UILogic { [event.day]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { newNoteForm: { $set: utils.getInitialFormState(), }, @@ -2857,19 +2896,21 @@ export class DashboardLogic extends UILogic { isNoteSidebarShown: { $set: true }, }) } + onMatchingTextToggleClick: EventHandler< 'onMatchingTextToggleClick' > = async ({ event, previousState }) => { const previousValue = - previousState.searchResults.results[-1].pages.byId[event.pageId] - ?.showAllResults + previousState.searchResults.results[-1].pages.byId[ + event.pageResultId + ]?.showAllResults this.emitMutation({ searchResults: { results: { [-1]: { pages: { byId: { - [event.pageId]: { + [event.pageResultId]: { showAllResults: { $set: !previousValue }, }, }, @@ -2895,8 +2936,8 @@ export class DashboardLogic extends UILogic { throw new Error('No note ID is set for deletion') } - const { noteId, pageId, day } = modals.deletingNoteArgs - const pageResult = searchResults.results[day].pages.byId[pageId] + const { noteId, pageResultId, day } = modals.deletingNoteArgs + const pageResult = searchResults.results[day].pages.byId[pageResultId] const pageResultNoteIds = pageResult.noteIds[ pageResult.notesType ].filter((id) => id !== noteId) @@ -2921,7 +2962,7 @@ export class DashboardLogic extends UILogic { [day]: { pages: { byId: { - [pageId]: { + [pageResultId]: { noteIds: { [pageResult.notesType]: { $set: pageResultNoteIds, @@ -4258,13 +4299,14 @@ export class DashboardLogic extends UILogic { listsSidebar: { someListIsDragging: { $set: true }, }, - searchResults: { draggedPageId: { $set: event.pageId } }, + searchResults: { draggedPageId: { $set: event.pageResultId } }, }) const crt = this.options.document.getElementById(DRAG_EL_ID) crt.style.display = 'block' event.dataTransfer.setDragImage(crt, 0, 0) - const page = previousState.searchResults.pageData.byId[event.pageId] + const page = + previousState.searchResults.pageData.byId[event.pageResultId] const action: DragToListAction<'page'> = { type: 'page', fullPageUrl: page.fullUrl, @@ -4688,7 +4730,7 @@ export class DashboardLogic extends UILogic { previousState, }) => { const pageData = - previousState?.searchResults?.pageData?.byId[event.pageId] + previousState?.searchResults?.pageData?.byId[event.pageResultId] if (!pageData) { return @@ -4717,7 +4759,7 @@ export class DashboardLogic extends UILogic { searchResults: { pageData: { byId: { - [event.pageId]: { + [event.pageResultId]: { uploadedPdfLinkLoadState: { $set: taskState, }, diff --git a/src/dashboard-refactor/search-results/components/page-result.tsx b/src/dashboard-refactor/search-results/components/page-result.tsx index 567673bcfd..bb79096ff9 100644 --- a/src/dashboard-refactor/search-results/components/page-result.tsx +++ b/src/dashboard-refactor/search-results/components/page-result.tsx @@ -912,8 +912,6 @@ export default class PageResultView extends PureComponent { } render() { - const hasTitle = this.props.fullTitle && this.props.fullTitle.length > 0 - return ( (noteId: string) => { - const pageData = this.props.pageData.byId[pageId] + const pageResult = this.props.results[-1].pages.byId[pageResultId] + const pageData = this.props.pageData.byId[pageResult.pageId] const noteData = this.props.noteData.byId[noteId] const interactionProps = bindFunctionalProps< NoteInteractionAugdProps, NoteInteractionProps - >(this.props.noteInteractionProps, noteId, day, pageId) + >(this.props.noteInteractionProps, noteId, day, pageResultId) const dummyEvent = {} as any const cachedListIds = noteData.isShared ? [ ...new Set([ - ...pageData?.lists?.filter( + ...pageData.lists.filter( (listId) => - this.props.listData.byId[listId]?.remoteId != - null, + this.props.listData.byId[listId].remoteId != null, ), ...noteData.lists, ]), @@ -473,7 +473,7 @@ export default class SearchResultsContainer extends React.Component< }, }) } - normalizedPageUrlToFilterPageLinksBy={pageId} + normalizedPageUrlToFilterPageLinksBy={pageResultId} analyticsBG={this.props.spacePickerBGProps.analyticsBG} /> )} @@ -495,7 +495,7 @@ export default class SearchResultsContainer extends React.Component< postShareHook={interactionProps.updateShareInfo} spacePickerProps={{ ...this.props.spacePickerBGProps, - normalizedPageUrlToFilterPageLinksBy: pageId, + normalizedPageUrlToFilterPageLinksBy: pageResultId, annotationsCache: this.props.annotationsCache, initialSelectedListIds: () => localListIds, selectEntry: (listId, options) => @@ -576,6 +576,7 @@ export default class SearchResultsContainer extends React.Component< notesType, isShared, noteIds, + pageResultId, }: PageResultData & PageData, day: number, { onShareBtnClick }: PageInteractionProps, @@ -589,7 +590,7 @@ export default class SearchResultsContainer extends React.Component< const boundAnnotCreateProps = bindFunctionalProps< typeof newNoteInteractionProps, NewNoteInteractionProps - >(newNoteInteractionProps, day, normalizedUrl) + >(newNoteInteractionProps, day, pageResultId) const lists = this.getLocalListIdsForCacheIds(newNoteForm.lists) return ( @@ -673,7 +674,7 @@ export default class SearchResultsContainer extends React.Component< return this.renderNoteResult( day, - normalizedUrl, + pageResultId, zIndex, )(noteId) })} @@ -708,25 +709,26 @@ export default class SearchResultsContainer extends React.Component< } private renderPageResult = ( - pageId: string, + pageResultId: string, day: number, index: number, order: number, ) => { + const pageResult = this.props.results[day].pages.byId[pageResultId] const page = { - ...this.props.pageData.byId[pageId], - ...this.props.results[day].pages.byId[pageId], + ...this.props.pageData.byId[pageResult.pageId], + ...pageResult, } const interactionProps = bindFunctionalProps< PageInteractionAugdProps, PageInteractionProps - >(this.props.pageInteractionProps, day, pageId) + >(this.props.pageInteractionProps, day, pageResultId) const pickerProps = bindFunctionalProps< PagePickerAugdProps, PagePickerProps - >(this.props.pagePickerProps, pageId) + >(this.props.pagePickerProps, pageResultId) return ( this.shiftSelectItems(page.id)} + shiftSelectItem={() => this.shiftSelectItems(page.pageId)} isBulkSelected={this.props.selectedItems?.includes( page.normalizedUrl, )} @@ -773,12 +775,7 @@ export default class SearchResultsContainer extends React.Component< {...pickerProps} {...page} lists={this.getLocalListIdsForCacheIds(page.lists)} - onTagPickerBtnClick={ - this.props.shouldShowTagsUIs - ? interactionProps.onTagPickerBtnClick - : undefined - } - hasNotes={page.noteIds['user'].length > 0} + hasNotes={page.totalAnnotationCount > 0} filterbyList={this.props.filterByList} searchType={this.props.searchType} isInFocus={page.isInFocus} diff --git a/src/dashboard-refactor/search-results/logic.test.ts b/src/dashboard-refactor/search-results/logic.test.ts index f396026d0e..7daaad954f 100644 --- a/src/dashboard-refactor/search-results/logic.test.ts +++ b/src/dashboard-refactor/search-results/logic.test.ts @@ -177,14 +177,12 @@ describe('Dashboard search results logic', () => { expect(annotationsCache.pageListIds.get(pageId)).toEqual(undefined) await searchResults.processEvent('setPageLists', { - id: pageId, - fullPageUrl: 'https://' + pageId, + pageResultId: pageId, added: listAData.unifiedId, skipPageIndexing: true, }) await searchResults.processEvent('setPageLists', { - id: pageId, - fullPageUrl: 'https://' + pageId, + pageResultId: pageId, added: listBData.unifiedId, skipPageIndexing: true, }) @@ -197,8 +195,7 @@ describe('Dashboard search results logic', () => { ) await searchResults.processEvent('setPageLists', { - id: pageId, - fullPageUrl: 'https://' + pageId, + pageResultId: pageId, deleted: listAData.unifiedId, skipPageIndexing: true, }) @@ -211,8 +208,7 @@ describe('Dashboard search results logic', () => { ) await searchResults.processEvent('setPageLists', { - id: pageId, - fullPageUrl: 'https://' + pageId, + pageResultId: pageId, added: listCData.unifiedId, skipPageIndexing: true, }) @@ -254,7 +250,7 @@ describe('Dashboard search results logic', () => { ) await searchResults.processEvent('setDeletingPageArgs', { - pageId, + pageResultId: pageId, day: PAGE_SEARCH_DUMMY_DAY, instaDelete: false, }) @@ -326,7 +322,7 @@ describe('Dashboard search results logic', () => { ).toEqual(true) await searchResults.processEvent('setDeletingPageArgs', { - pageId, + pageResultId: pageId, day: PAGE_SEARCH_DUMMY_DAY, instaDelete: true, }) @@ -393,8 +389,7 @@ describe('Dashboard search results logic', () => { ) await searchResults.processEvent('setPageLists', { - id: pageId, - fullPageUrl: 'https://' + pageId, + pageResultId: pageId, added: listData.unifiedId, skipPageIndexing: true, }) @@ -410,7 +405,7 @@ describe('Dashboard search results logic', () => { await searchResults.processEvent('removePageFromList', { day: PAGE_SEARCH_DUMMY_DAY, - pageId, + pageResultId: pageId, }) expect( @@ -443,7 +438,7 @@ describe('Dashboard search results logic', () => { ) await searchResults.processEvent('dragPage', { - pageId: page.normalizedUrl, + pageResultId: page.normalizedUrl, day: PAGE_SEARCH_DUMMY_DAY, dataTransfer, }) @@ -458,7 +453,7 @@ describe('Dashboard search results logic', () => { ) await searchResults.processEvent('dropPage', { - pageId: page.normalizedUrl, + pageResultId: page.normalizedUrl, day: PAGE_SEARCH_DUMMY_DAY, }) @@ -492,7 +487,7 @@ describe('Dashboard search results logic', () => { await searchResults.processEvent('updatePageNotesShareInfo', { day, - pageId, + pageResultId: pageId, shareStates: makeNewShareStates(notesById, { isShared: false, }), @@ -510,7 +505,7 @@ describe('Dashboard search results logic', () => { await searchResults.processEvent('updatePageNotesShareInfo', { day, - pageId, + pageResultId: pageId, shareStates: makeNewShareStates(notesById, { isShared: true, }), @@ -529,7 +524,7 @@ describe('Dashboard search results logic', () => { await searchResults.processEvent('updatePageNotesShareInfo', { day, - pageId, + pageResultId: pageId, shareStates: makeNewShareStates(notesById, { isShared: false, isBulkShareProtected: true, @@ -550,7 +545,7 @@ describe('Dashboard search results logic', () => { // NOTE: Now that they're all protected, the next call shouldn't change anything await searchResults.processEvent('updatePageNotesShareInfo', { day, - pageId, + pageResultId: pageId, shareStates: makeNewShareStates(notesById, { isShared: false, isBulkShareProtected: false, @@ -719,7 +714,7 @@ describe('Dashboard search results logic', () => { ).toBe(false) await searchResults.processEvent('setPageTagPickerShown', { day, - pageId, + pageResultId: pageId, isShown: true, }) expect( @@ -729,7 +724,7 @@ describe('Dashboard search results logic', () => { ).toBe(true) await searchResults.processEvent('setPageTagPickerShown', { day, - pageId, + pageResultId: pageId, isShown: false, }) expect( @@ -755,7 +750,7 @@ describe('Dashboard search results logic', () => { ).toBe('hide') await searchResults.processEvent('setPageListPickerShown', { day, - pageId, + pageResultId: pageId, show: 'footer', }) expect( @@ -765,7 +760,7 @@ describe('Dashboard search results logic', () => { ).toBe('footer') await searchResults.processEvent('setPageListPickerShown', { day, - pageId, + pageResultId: pageId, show: 'lists-bar', }) expect( @@ -775,7 +770,7 @@ describe('Dashboard search results logic', () => { ).toBe('lists-bar') await searchResults.processEvent('setPageListPickerShown', { day, - pageId, + pageResultId: pageId, show: 'lists-bar', }) expect( @@ -802,7 +797,7 @@ describe('Dashboard search results logic', () => { ).toBe(false) await searchResults.processEvent('setPageShareMenuShown', { day, - pageId, + pageResultId: pageId, isShown: true, }) expect( @@ -812,7 +807,7 @@ describe('Dashboard search results logic', () => { ).toBe(true) await searchResults.processEvent('setPageShareMenuShown', { day, - pageId, + pageResultId: pageId, isShown: false, }) expect( @@ -839,7 +834,7 @@ describe('Dashboard search results logic', () => { ).toEqual(false) await searchResults.processEvent('setPageNotesShown', { day, - pageId, + pageResultId: pageId, areShown: true, }) expect( @@ -852,7 +847,7 @@ describe('Dashboard search results logic', () => { ).toEqual(true) await searchResults.processEvent('setPageNotesShown', { day, - pageId, + pageResultId: pageId, areShown: false, }) expect( @@ -876,10 +871,10 @@ describe('Dashboard search results logic', () => { searchResults.state.searchResults.results[day].pages.byId[ pageId ].notesType, - ).toEqual(utils.getInitialPageResultState('').notesType) + ).toEqual(utils.getInitialPageResultState('', '').notesType) await searchResults.processEvent('setPageNotesType', { day, - pageId, + pageResultId: pageId, noteType: 'followed', }) expect( @@ -889,7 +884,7 @@ describe('Dashboard search results logic', () => { ).toEqual('followed') await searchResults.processEvent('setPageNotesType', { day, - pageId, + pageResultId: pageId, noteType: 'search', }) expect( @@ -899,7 +894,7 @@ describe('Dashboard search results logic', () => { ).toEqual('search') await searchResults.processEvent('setPageNotesType', { day, - pageId, + pageResultId: pageId, noteType: 'user', }) expect( @@ -933,7 +928,7 @@ describe('Dashboard search results logic', () => { for (const hover of states) { await searchResults.processEvent('setPageHover', { day, - pageId, + pageResultId: pageId, hover, }) expect( @@ -960,7 +955,7 @@ describe('Dashboard search results logic', () => { await searchResults.processEvent('setPageNewNoteCommentValue', { day, - pageId, + pageResultId: pageId, value: 'followed', }) expect( @@ -971,7 +966,7 @@ describe('Dashboard search results logic', () => { await searchResults.processEvent('setPageNewNoteCommentValue', { day, - pageId, + pageResultId: pageId, value: 'search', }) expect( @@ -982,7 +977,7 @@ describe('Dashboard search results logic', () => { await searchResults.processEvent('setPageNewNoteCommentValue', { day, - pageId, + pageResultId: pageId, value: 'user', }) expect( @@ -1011,7 +1006,7 @@ describe('Dashboard search results logic', () => { 'setPageNewNoteTagPickerShown', { day, - pageId, + pageResultId: pageId, isShown: true, }, ) @@ -1025,7 +1020,7 @@ describe('Dashboard search results logic', () => { 'setPageNewNoteTagPickerShown', { day, - pageId, + pageResultId: pageId, isShown: false, }, ) @@ -1055,7 +1050,7 @@ describe('Dashboard search results logic', () => { await searchResults.processEvent('setPageNewNoteCommentValue', { day, - pageId, + pageResultId: pageId, value: newNoteComment, }) @@ -1067,7 +1062,7 @@ describe('Dashboard search results logic', () => { await searchResults.processEvent('cancelPageNewNote', { day, - pageId, + pageResultId: pageId, }) expect( @@ -1094,7 +1089,7 @@ describe('Dashboard search results logic', () => { await searchResults.processEvent('setPageNewNoteCommentValue', { day, - pageId, + pageResultId: pageId, value: newNoteComment, }) @@ -1111,7 +1106,7 @@ describe('Dashboard search results logic', () => { 'savePageNewNote', { day, - pageId, + pageResultId: pageId, fullPageUrl: 'https://' + pageId, shouldShare: false, }, @@ -1182,7 +1177,7 @@ describe('Dashboard search results logic', () => { await searchResults.processEvent('savePageNewNote', { day, - pageId, + pageResultId: pageId, fullPageUrl: 'https://' + pageId, shouldShare: true, }) @@ -1209,7 +1204,7 @@ describe('Dashboard search results logic', () => { ).toBe(true) await searchResults.processEvent('setPageNotesShown', { day, - pageId, + pageResultId: pageId, areShown: false, }) expect( @@ -1221,7 +1216,7 @@ describe('Dashboard search results logic', () => { ).toBe(false) await searchResults.processEvent('setPageNotesShown', { day, - pageId, + pageResultId: pageId, areShown: true, }) expect( @@ -1243,10 +1238,10 @@ describe('Dashboard search results logic', () => { expect( searchResults.state.searchResults.results[day].pages .byId[pageId].notesType, - ).toEqual(utils.getInitialPageResultState('').notesType) + ).toEqual(utils.getInitialPageResultState('', '').notesType) await searchResults.processEvent('setPageNotesType', { day, - pageId, + pageResultId: pageId, noteType: 'followed', }) expect( @@ -1255,7 +1250,7 @@ describe('Dashboard search results logic', () => { ).toEqual('followed') await searchResults.processEvent('setPageNotesType', { day, - pageId, + pageResultId: pageId, noteType: 'search', }) expect( @@ -1264,7 +1259,7 @@ describe('Dashboard search results logic', () => { ).toEqual('search') await searchResults.processEvent('setPageNotesType', { day, - pageId, + pageResultId: pageId, noteType: 'user', }) expect( @@ -1290,7 +1285,7 @@ describe('Dashboard search results logic', () => { 'setPageNewNoteCommentValue', { day, - pageId, + pageResultId: pageId, value: 'followed', }, ) @@ -1302,7 +1297,7 @@ describe('Dashboard search results logic', () => { 'setPageNewNoteCommentValue', { day, - pageId, + pageResultId: pageId, value: 'search', }, ) @@ -1314,7 +1309,7 @@ describe('Dashboard search results logic', () => { 'setPageNewNoteCommentValue', { day, - pageId, + pageResultId: pageId, value: 'user', }, ) @@ -1342,8 +1337,7 @@ describe('Dashboard search results logic', () => { const pageId = DATA.PAGE_1.normalizedUrl await searchResults.processEvent('setPageLists', { - id: pageId, - fullPageUrl: 'https://' + pageId, + pageResultId: pageId, added: listDataA.unifiedId, skipPageIndexing: true, }) @@ -1367,7 +1361,7 @@ describe('Dashboard search results logic', () => { await searchResults.processEvent('removePageFromList', { day: DATA.DAY_1, - pageId, + pageResultId: pageId, }) expect( @@ -1430,7 +1424,7 @@ describe('Dashboard search results logic', () => { ).toEqual(true) await searchResults.processEvent('setDeletingPageArgs', { - pageId, + pageResultId: pageId, day: DATA.DAY_1, instaDelete: false, }) @@ -2656,8 +2650,7 @@ describe('Dashboard search results logic', () => { added: listDataC.unifiedId, }) await searchResults.processEvent('setPageLists', { - id: pageIdA, - fullPageUrl: DATA.PAGE_1.fullUrl, + pageResultId: pageIdA, added: listDataC.unifiedId, // This list is private, so manually adding it to the page here }) @@ -2700,8 +2693,7 @@ describe('Dashboard search results logic', () => { ) await searchResults.processEvent('setPageLists', { - id: pageIdA, - fullPageUrl: DATA.PAGE_1.fullUrl, + pageResultId: pageIdA, deleted: listDataC.unifiedId, }) @@ -2742,8 +2734,7 @@ describe('Dashboard search results logic', () => { ) await searchResults.processEvent('setPageLists', { - id: pageIdA, - fullPageUrl: DATA.PAGE_1.fullUrl, + pageResultId: pageIdA, deleted: listDataA.unifiedId, }) @@ -3831,7 +3822,7 @@ describe('Dashboard search results logic', () => { await searchResults.processEvent('setDeletingNoteArgs', { noteId, - pageId: DATA.PAGE_1.normalizedUrl, + pageResultId: DATA.PAGE_1.normalizedUrl, day: PAGE_SEARCH_DUMMY_DAY, }) expect(searchResults.state.modals.deletingNoteArgs).toEqual({ @@ -3900,7 +3891,7 @@ describe('Dashboard search results logic', () => { await searchResults.processEvent('setDeletingNoteArgs', { noteId, - pageId: DATA.PAGE_1.normalizedUrl, + pageResultId: DATA.PAGE_1.normalizedUrl, day: PAGE_SEARCH_DUMMY_DAY, }) expect(searchResults.state.modals.deletingNoteArgs).toEqual({ diff --git a/src/dashboard-refactor/search-results/types.ts b/src/dashboard-refactor/search-results/types.ts index 2b85a9079e..0181f8a90c 100644 --- a/src/dashboard-refactor/search-results/types.ts +++ b/src/dashboard-refactor/search-results/types.ts @@ -1,6 +1,5 @@ import type { TaskState } from 'ui-logic-core/lib/types' import type { UIEvent } from 'ui-logic-core' - import type { AnnotationsSorter } from 'src/sidebar/annotations-sidebar/sorting' import type { StandardSearchResponse } from 'src/search/background/types' import type { PipelineRes } from 'src/search' @@ -13,14 +12,10 @@ import type { AnnotationSharingStates, } from 'src/content-sharing/background/types' import type { AnnotationPrivacyLevels } from '@worldbrain/memex-common/lib/annotations/types' -import type { - PageAnnotationsCacheInterface, - RGBAColor, -} from 'src/annotations/cache/types' +import type { RGBAColor } from 'src/annotations/cache/types' export interface CommonInteractionProps { onCopyPasterBtnClick: React.MouseEventHandler - onTagPickerBtnClick?: React.MouseEventHandler onListPickerBarBtnClick: React.MouseEventHandler onListPickerFooterBtnClick: React.MouseEventHandler onShareBtnClick: React.MouseEventHandler @@ -108,12 +103,6 @@ export type PagePickerAugdProps = { [Key in keyof PagePickerProps]: (pageId: string) => PagePickerProps[Key] } -export type SearchResultToState = ( - result: T, - annotationsCache: PageAnnotationsCacheInterface, - extraPageResultState?: Pick, -) => Pick - export type SearchType = | 'pages' | 'notes' @@ -207,7 +196,8 @@ export interface NoteResult { } export interface PageResult { - id: string + pageId: string + pageResultId: string notesType: NotesType areNotesShown: boolean activePage: boolean @@ -251,6 +241,8 @@ export interface RootState { results: NestedResults areResultsExhausted: boolean + pageIdToResultIds: { [pageId: string]: string[] } + // Display data lookups /** Holds page data shared with all page occurrences on any day. */ pageData: NormalizedState @@ -275,7 +267,7 @@ export interface RootState { } export interface PageEventArgs { - pageId: string + pageResultId: string day: number } @@ -307,8 +299,7 @@ export type Events = UIEvent<{ // Page data state mutations (*shared with all* occurences of the page in different days) setPageLists: { - id: string - fullPageUrl: string + pageResultId: string added?: string deleted?: string skipPageIndexing?: boolean diff --git a/src/dashboard-refactor/search-results/util.ts b/src/dashboard-refactor/search-results/util.ts index 98de26d9d4..0a97ab1891 100644 --- a/src/dashboard-refactor/search-results/util.ts +++ b/src/dashboard-refactor/search-results/util.ts @@ -1,14 +1,12 @@ import type { StandardSearchResponse, - AnnotsByPageUrl, AnnotPage, + UnifiedSearchPaginationParams, } from 'src/search/background/types' import type { PageData, PageResult, - PageResultsByDay, NoteData, - SearchResultToState, NoteResult, NoteFormState, RootState, @@ -103,11 +101,12 @@ export const bindFunctionalProps = < } export const getInitialPageResultState = ( - id: string, + pageId: string, + pageResultId: string, noteIds: string[] = [], - extra: Partial = {}, ): PageResult => ({ - id, + pageId, + pageResultId, notesType: 'user', activePage: undefined, areNotesShown: false, @@ -121,7 +120,6 @@ export const getInitialPageResultState = ( hoverState: null, copyLoadingState: 'pristine', editTitleState: null, - ...extra, }) export const getInitialNoteResultState = ( @@ -202,29 +200,42 @@ const annotationToNoteData = ( } } -export const pageSearchResultToState: SearchResultToState = ( - result, - cache, - extraPageResultState, -) => { +export const formPageSearchResultId = ( + pageId: string, + resultsPage: number, +): string => `${resultsPage}-${pageId}` + +export const pageSearchResultToState = ( + result: StandardSearchResponse, + params: UnifiedSearchPaginationParams, + cache: PageAnnotationsCacheInterface, +): Pick< + RootState, + 'results' | 'noteData' | 'pageData' | 'pageIdToResultIds' +> => { const pageData = initNormalizedState() const noteData = initNormalizedState() const pageResults = initNormalizedState() + const pageIdToResultIds: RootState['pageIdToResultIds'] = {} for (const pageResult of result.docs) { - const id = pageResult.url + const pageId = pageResult.url + const resultId = formPageSearchResultId(pageId, params.skip) + const existingResultIds = pageIdToResultIds[pageId] ?? [] + pageIdToResultIds[pageId] = [...existingResultIds, resultId] + const sortedAnnots = pageResult.annotations.sort(sortByPagePosition) const noteIds = sortedAnnots.map((a) => a.url) - pageData.byId[id] = pageResultToPageData(pageResult, cache) - pageResults.byId[id] = getInitialPageResultState( - pageResult.url, + pageData.byId[pageId] = pageResultToPageData(pageResult, cache) + pageResults.byId[resultId] = getInitialPageResultState( + pageId, + resultId, noteIds, - extraPageResultState, ) - pageData.allIds.push(id) - pageResults.allIds.push(id) + pageData.allIds.push(pageId) + pageResults.allIds.push(resultId) for (const annotation of sortedAnnots) { noteData.allIds.push(annotation.url) @@ -238,6 +249,7 @@ export const pageSearchResultToState: SearchResultToState): NormalizedState => { - const allPageResults = Object.values(searchResults.results).map( - (a) => a.pages, - ) - const result = initNormalizedState() - - for (const pages of allPageResults) { - result.allIds = [...new Set([...result.allIds, ...pages.allIds])] - for (const pageId in pages.byId) { - const existing = result.byId[pageId] ?? ({} as PageResult) - result.byId[pageId] = { - ...pages.byId[pageId], - noteIds: { - followed: [], - search: [], - user: [ - ...new Set([ - ...(existing?.noteIds?.user ?? []), - ...pages.byId[pageId].noteIds.user, - ]), - ], - }, - } - } - } - - return result -} diff --git a/src/sidebar/annotations-sidebar/containers/AnnotationsSidebarContainer.tsx b/src/sidebar/annotations-sidebar/containers/AnnotationsSidebarContainer.tsx index 402056b88a..a113119c6a 100644 --- a/src/sidebar/annotations-sidebar/containers/AnnotationsSidebarContainer.tsx +++ b/src/sidebar/annotations-sidebar/containers/AnnotationsSidebarContainer.tsx @@ -143,6 +143,7 @@ export class AnnotationsSidebarContainer< } } + // TODO: Multiple processEvent calls should never happen from a single user action. Needs to be unified async toggleSidebarShowForPageId(fullPageUrl: string, spaceId?: string) { const newURL = fullPageUrl const previousURL = this.state?.fullPageUrl ?? null