From ef7496ff60565545826ede5cc63b71f5ffc7c226 Mon Sep 17 00:00:00 2001 From: msramalho <19508417+msramalho@users.noreply.github.com> Date: Fri, 18 Aug 2023 16:21:41 +0100 Subject: [PATCH] filter by archive date --- source/js/background.js | 23 ++++++++++++++++++++--- source/vue/Popup.vue | 14 ++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/source/js/background.js b/source/js/background.js index 8ba6a54..80f5d9b 100644 --- a/source/js/background.js +++ b/source/js/background.js @@ -40,7 +40,7 @@ function processMessages(request, sender) { break; } case 'search': { - search(resolve, reject, request.query); + search(resolve, reject, request.query, request.archivedAfter, request.archivedBefore); break; } case 'status': { @@ -215,14 +215,21 @@ function checkTaskStatus(resolve, reject, task) { }); } -function search(resolve, reject, url) { +function search(resolve, reject, url, archivedAfter, archivedBefore) { console.log('API: SEARCH'); chrome.identity.getAuthToken({ interactive: false }, async accessToken => { if (accessToken == undefined) { reject(new Error(LOGIN_FAILED)); return; } - fetch(`${API_ENDPOINT_TASKS}/search-url?` + new URLSearchParams({ url }), { + let searchParams = { url }; + // convert date strings to python-readable or exclude if not set + archivedAfter = dateStrToIso(archivedAfter); + archivedBefore = dateStrToIso(archivedBefore); + if (archivedAfter) { searchParams = { ...searchParams, archived_after: archivedAfter } } + if (archivedBefore) { searchParams = { ...searchParams, archived_before: archivedBefore } } + + fetch(`${API_ENDPOINT_TASKS}/search-url?` + new URLSearchParams(searchParams), { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -235,6 +242,16 @@ function search(resolve, reject, url) { }); } +function dateStrToIso(dateStr) { + if (dateStr) { + const date = new Date(dateStr); + if (!isNaN(date)) { + return date.toISOString(); + } + } + return undefined; +} + async function syncLocalTasks(resolve, reject) { console.log('API: SYNC'); chrome.identity.getAuthToken({ interactive: false }, async accessToken => { diff --git a/source/vue/Popup.vue b/source/vue/Popup.vue index c9b22fb..f7e774b 100644 --- a/source/vue/Popup.vue +++ b/source/vue/Popup.vue @@ -59,6 +59,14 @@ +
+
+ Archived after +
+
+ Archived before +
+
search @@ -70,7 +78,7 @@ URL Result - Date + Archive date @@ -113,6 +121,8 @@ export default { isSearchingOnline: false, search: '', errorMessage: '', + archivedAfter: '', + archivedBefore: '', _public: true, tagsChips: null, groupVisibility: "-1", @@ -237,7 +247,7 @@ export default { (async () => { this.isSearchingOnline = true; try { - const onlineTasks = await this.callBackground({ action: "search", query: this.search }); + const onlineTasks = await this.callBackground({ action: "search", query: this.search, archivedAfter: this.archivedAfter, archivedBefore: this.archivedBefore }); if (!onlineTasks) return; this.onlineTasks = (onlineTasks || []).filter(task => !Object.keys(this.tasks).includes(task.id)) } finally {