From fec9c6556e181fc68068eae3db9e8ec81208221d Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 15 May 2024 21:32:50 -0300 Subject: client: stub search index download progress --- src/static/js/client.js | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) (limited to 'src/static/js/client.js') diff --git a/src/static/js/client.js b/src/static/js/client.js index dab1ea37..769a4212 100644 --- a/src/static/js/client.js +++ b/src/static/js/client.js @@ -3447,6 +3447,17 @@ const wikiSearchInfo = initInfo('wikiSearchInfo', { workerActionCounter: 0, workerActionPromiseResolverMap: new Map(), + + downloads: Object.create(null), + }, + + event: { + whenDownloadBegins: [], + whenDownloadsBegin: [], + + whenDownloadProgresses: [], + + whenDownloadEnds: [], }, }); @@ -3481,6 +3492,18 @@ function handleSearchWorkerMessage(message) { handleSearchWorkerResultMessage(message); break; + case 'download-begun': + handleSearchWorkerDownloadBegunMessage(message); + break; + + case 'download-progress': + handleSearchWorkerDownloadProgressMessage(message); + break; + + case 'download-complete': + handleSearchWorkerDownloadCompleteMessage(message); + break; + default: console.warn(`Unknown message kind "${message.data.kind}" <- from search worker`); break; @@ -3545,6 +3568,70 @@ function handleSearchWorkerResultMessage(message) { state.workerActionPromiseResolverMap.delete(id); } +function handleSearchWorkerDownloadBegunMessage(message) { + const {event} = wikiSearchInfo; + const {context: contextKey, keys} = message.data; + + const context = getSearchWorkerDownloadContext(contextKey, true); + + for (const key of keys) { + context[key] = 0.00; + + dispatchInternalEvent(event, 'whenDownloadBegins', { + context: contextKey, + key, + }); + } + + dispatchInternalEvent(event, 'whenDownloadsBegin', { + context: contextKey, + keys, + }); +} + +function handleSearchWorkerDownloadProgressMessage(message) { + const {event} = wikiSearchInfo; + const {context: contextKey, key, progress} = message.data; + + const context = getSearchWorkerDownloadContext(contextKey); + + context[key] = progress; + + dispatchInternalEvent(event, 'whenDownloadProgresses', { + context: contextKey, + key, + progress, + }); +} + +function handleSearchWorkerDownloadCompleteMessage(message) { + const {event} = wikiSearchInfo; + const {context: contextKey, key} = message.data; + + const context = getSearchWorkerDownloadContext(contextKey); + + context[key] = 1.00; + + dispatchInternalEvent(event, 'whenDownloadEnds', { + context: contextKey, + key, + }); +} + +function getSearchWorkerDownloadContext(context, initialize = false) { + const {state} = wikiSearchInfo; + + if (context in state.downloads) { + return state.downloads[context]; + } + + if (!initialize) { + return null; + } + + return state.downloads[context] = Object.create(null); +} + async function postSearchWorkerAction(action, options) { const {state} = wikiSearchInfo; @@ -3643,6 +3730,16 @@ function getSidebarSearchReferences() { findString('group-result-kind'); } +function addSidebarSearchInternalListeners() { + const info = sidebarSearchInfo; + + if (!info.searchBox) return; + + wikiSearchInfo.event.whenDownloadsBegin.push(updateSidebarSearchStatus); + wikiSearchInfo.event.whenDownloadProgresses.push(updateSidebarSearchStatus); + wikiSearchInfo.event.whenDownloadEnds.push(updateSidebarSearchStatus); +} + function mutateSidebarSearchContent() { const info = sidebarSearchInfo; @@ -3787,6 +3884,16 @@ function clearSidebarSearch() { hideSidebarSearchResults(); } +function updateSidebarSearchStatus() { + const info = sidebarSearchInfo; + const {state} = info; + + const searchIndexDownloads = + getSearchWorkerDownloadContext('search-indexes'); + + console.log('Display:', searchIndexDownloads); +} + function showSidebarSearchResults(results) { const info = sidebarSearchInfo; @@ -4002,6 +4109,7 @@ function hideSidebarSearchResults() { } clientSteps.getPageReferences.push(getSidebarSearchReferences); +clientSteps.addInternalListeners.push(addSidebarSearchInternalListeners); clientSteps.mutatePageContent.push(mutateSidebarSearchContent); clientSteps.addPageListeners.push(addSidebarSearchListeners); clientSteps.initializeState.push(initializeSidebarSearchState); -- cgit 1.3.0-6-gf8a5