diff --git a/dist/doboard-widget-bundle.js b/dist/doboard-widget-bundle.js index 5334013..d1a82e2 100644 --- a/dist/doboard-widget-bundle.js +++ b/dist/doboard-widget-bundle.js @@ -8618,6 +8618,10 @@ const wsSpotfix = { } }, + isActive() { + return socket !== null && socket.readyState === WebSocket.OPEN; + }, + close() { isIntentionalClose = true; if (reconnectTimer) { @@ -8756,10 +8760,13 @@ async function addTaskComment(params, taskId, commentText) { async function getAllTasks(params, nonRequesting = false) { const projectToken = params.projectToken; const sessionId = localStorage.getItem('spotfix_session_id') || ''; - if (!nonRequesting) { + let tasksData = await spotfixIndexedDB.getAll(SPOTFIX_TABLE_TASKS); + + if (!nonRequesting && (!tasksData || !tasksData.length) && !wsSpotfix.isActive()) { await getTasksDoboard(projectToken, sessionId, params.accountId, params.projectId); + tasksData = await spotfixIndexedDB.getAll(SPOTFIX_TABLE_TASKS); } - const tasksData = await spotfixIndexedDB.getAll(SPOTFIX_TABLE_TASKS); + storageSaveTasksCount(tasksData); // Get only tasks with metadata const filteredTaskData = tasksData.filter((task) => { @@ -10253,6 +10260,56 @@ class CleanTalkWidgetDoboard { changeSize(container); } spotFixRemoveHighlights(); + + const nowAI = Date.now(); + const isCacheValid = this.htmlCacheTimestamp && (nowAI - this.htmlCacheTimestamp < 60000); // 60 + + if (isCacheValid && this.cachedHTML && !this.nonRequesting) { + const issuesContainer = document.querySelector(".doboard_task_widget-all_issues-container"); + if (issuesContainer) { + issuesContainer.innerHTML = this.cachedHTML; + } + + const headerSpan = document.querySelector('.doboard_task_widget-header span'); + if (headerSpan) { + headerSpan.innerHTML = ksesFilter('All spots ' + getIssuesCounterString(this.savedIssuesQuantityOnPage, this.savedIssuesQuantityAll)); + } + + const finishedSpotsListHeader = document.getElementById('finishedTasksHeader'); + if (finishedSpotsListHeader?.classList?.contains('expanded')) { + spotFixHighlightElements(this.cachedSpotsToBeHighlighted, this); + } else { + spotFixHighlightElements(this.cachedSpotsToBeHighlighted.filter(item => !item.isFixed), this); + } + + const finishedHeader = document.getElementById('finishedTasksHeader'); + const finishedContainer = document.getElementById('finishedTasksContainer'); + if (finishedHeader && finishedContainer) { + finishedHeader.onclick = () => { + finishedContainer.classList.toggle('expanded'); + finishedHeader.classList.toggle('expanded'); + + if (finishedContainer.classList.contains('expanded')) { + spotFixHighlightElements(this.cachedSpotsToBeHighlighted, this); + } else { + spotFixRemoveHighlights(); + spotFixHighlightElements(this.cachedSpotsToBeHighlighted.filter(item => !item.isFixed), this); + } + + setTimeout(() => { + if (finishedContainer.classList.contains('expanded') && finishedContainer.children.length > 0) { + const targetIndex = Math.min(2, finishedContainer.children.length - 1); + finishedContainer.children[targetIndex].scrollIntoView({ behavior: 'smooth', block: 'nearest' }); + } + }, 350); + }; + } + + this.bindIssuesClick(); + hideContainersSpinner(false); + break; + } + // If there is no cache or it has expired, fetch fresh data. let issuesQuantityOnPage = 0; const sessionId = localStorage.getItem('spotfix_session_id'); @@ -10261,8 +10318,10 @@ class CleanTalkWidgetDoboard { let finishedTasks = []; this.allTasksData = await getAllTasks(this.params, this.nonRequesting); + const tasks = this.allTasksData; tasksFullDetails = await getTasksFullDetails(this.params, tasks, this.currentActiveTaskId, this.nonRequesting); + let spotsToBeHighlighted = []; if (tasks.length > 0) { const currentURL = window.location.href; @@ -10280,9 +10339,9 @@ class CleanTalkWidgetDoboard { const container = document.querySelector(".doboard_task_widget-all_issues-container"); if (container) { container.innerHTML = `
- `; +`; } const generateTaskHtml = (elTask, isFinishedGroup) => { @@ -10389,7 +10448,6 @@ class CleanTalkWidgetDoboard { activeTasksContainer.innerHTML += activeTasksHtml; } - if (finishedTasks.length > 0) { let finishedTasksContent = ''; for (const elTask of finishedTasks) { @@ -10409,7 +10467,7 @@ class CleanTalkWidgetDoboard { const finishedHeader = document.getElementById('finishedTasksHeader'); const finishedContainer = document.getElementById('finishedTasksContainer'); if (finishedHeader && finishedContainer) { - finishedHeader.addEventListener('click', () => { + finishedHeader.onclick = () => { finishedContainer.classList.toggle('expanded'); finishedHeader.classList.toggle('expanded'); @@ -10432,24 +10490,24 @@ class CleanTalkWidgetDoboard { } } }, 350); - }); + }; } } this.savedIssuesQuantityOnPage = issuesQuantityOnPage; this.savedIssuesQuantityAll = tasks.length; const finishedSpotsListHeader = document.getElementById('finishedTasksHeader'); - if (finishedSpotsListHeader?.classList?.contains('expanded')) { - spotFixHighlightElements(spotsToBeHighlighted, this); - } else { - spotFixRemoveHighlights(); - spotFixHighlightElements(spotsToBeHighlighted.filter(item => !item.isFixed), this); - } + if (finishedSpotsListHeader?.classList?.contains('expanded')) { + spotFixHighlightElements(spotsToBeHighlighted, this); + } else { + spotFixRemoveHighlights(); + spotFixHighlightElements(spotsToBeHighlighted.filter(item => !item.isFixed), this); + } const headerSpan = document.querySelector('.doboard_task_widget-header span'); if (headerSpan) { - headerSpan.innerHTML = ksesFilter('All spots ' + getIssuesCounterString(this.savedIssuesQuantityOnPage, this.savedIssuesQuantityAll)); + headerSpan.innerHTML = ksesFilter('All spots ' + getIssuesCounterString(this.savedIssuesQuantityOnPage, this.savedIssuesQuantityAll)); } - } + } if (tasks.length === 0) { document.querySelector(".doboard_task_widget-all_issues-container").innerHTML = @@ -10458,15 +10516,21 @@ class CleanTalkWidgetDoboard { if (activeTasks?.length === 0 && finishedTasks?.length !== 0) { const container = document.querySelector(".doboard_task_widget-all_issues-container"); - if (container) { const messageHtml = ksesFilter(''); - container.insertAdjacentHTML('afterbegin', messageHtml); } } - // Bind the click event to the task elements for scrolling to the selected text and Go to concrete issue interface by click issue-item row + + // Save the rendered issues list HTML, highlight data, and cache timestamp. + const finalContainer = document.querySelector(".doboard_task_widget-all_issues-container"); + if (finalContainer) { + this.cachedHTML = finalContainer.innerHTML; + this.cachedSpotsToBeHighlighted = spotsToBeHighlighted; + this.htmlCacheTimestamp = Date.now(); + } + this.bindIssuesClick(); hideContainersSpinner(false); break; @@ -10526,7 +10590,43 @@ class CleanTalkWidgetDoboard { break; case 'spot_menu': - if(!this.nonRequesting) await getReleaseVersion(); + if (!this.spotMenuCache) { + this.spotMenuCache = {}; + } + + const nowSM = Date.now(); + const currentTaskIdSM = this.currentActiveTaskId; + const taskCacheSM = this.spotMenuCache[currentTaskIdSM]; + + const isCacheValidSM = taskCacheSM && (nowSM - taskCacheSM.timestamp < 60000) && !this.nonRequesting; + + if (isCacheValidSM) { + widgetContainer.innerHTML = taskCacheSM.widgetHTML; + if (!document.body.contains(widgetContainer)) { + document.body.appendChild(widgetContainer); + } + + const currentUserId = localStorage.getItem('spotfix_user_id') || 0; + const unsubscribeElem = document.getElementById('unsubscribe_from_spot'); + const highlightElem = document.getElementById('highlight_the_spot'); + + if (unsubscribeElem && taskCacheSM.isViewer) { + unsubscribeElem.checked = true; + } + if (highlightElem && currentUserId) { + const highlightStatuses = JSON.parse(localStorage.getItem('spotfix_highlight_statuses') || '{}'); + highlightElem.checked = highlightStatuses[currentUserId]?.[currentTaskIdSM] ?? true; + } + if (!localStorage.getItem('spotfix_session_id')) { + if (unsubscribeElem) unsubscribeElem.disabled = true; + if (highlightElem) highlightElem.disabled = true; + } + + break; + } + + if (!this.nonRequesting) await getReleaseVersion(); + let spotfixVersion = ''; const spotMenuVersion = localStorage.getItem('spotfix_app_version') || SPOTFIX_VERSION; spotfixVersion = spotMenuVersion ? `Spotfix version ${spotMenuVersion}.` : ''; @@ -10534,7 +10634,7 @@ class CleanTalkWidgetDoboard { let allTasks = this.allTasksData; - if(this.nonRequesting){ + if (this.nonRequesting) { allTasks = await spotfixIndexedDB.getAll(SPOTFIX_TABLE_TASKS); this.allTasksData = allTasks; } @@ -10543,10 +10643,8 @@ class CleanTalkWidgetDoboard { templateVariables.taskName = currentTask.taskTitle; templateVariables.taskType = currentTask.task_type === 'PUBLIC' ? this.srcVariables.iconPublicDark : this.srcVariables.iconLockDark; - templateVariables.doboardLink = - `https://app.doboard.com/${localStorage.getItem('spotfix_company_id')}/task/${currentTask.taskId}?token=${currentTask.taskToken}`; - templateVariables.doboardLinkShort = - `https://app.doboard.com/${localStorage.getItem('spotfix_company_id')}/task/${currentTask.taskId}`; + templateVariables.doboardLink = `https://app.doboard.com/${localStorage.getItem('spotfix_company_id')}/task/${currentTask.taskId}?token=${currentTask.taskToken}`; + templateVariables.doboardLinkShort = `https://app.doboard.com/${localStorage.getItem('spotfix_company_id')}/task/${currentTask.taskId}`; const currentUserId = localStorage.getItem('spotfix_user_id') || 0; @@ -10555,45 +10653,138 @@ class CleanTalkWidgetDoboard { templateVariables.viewersCount = `${usersFiltered.length || 0} members`; - if(usersFiltered.length) { + if (usersFiltered.length) { templateVariables.viewers = usersFiltered.map(user => { return `` - }).join('') +