From 250f32963d554a1305f225f4eb406bea83a74f45 Mon Sep 17 00:00:00 2001 From: candela97 <54083835+candela97@users.noreply.github.com> Date: Sun, 25 Aug 2024 22:32:54 +0800 Subject: [PATCH] Fix review context filter preference --- .../Features/Store/App/FSaveReviewFilters.ts | 21 +++++++++---------- src/js/Core/Storage/LocalStorage.ts | 4 ++-- src/scriptlets/Store/App/saveReviewFilters.js | 18 ++++++++++------ 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/js/Content/Features/Store/App/FSaveReviewFilters.ts b/src/js/Content/Features/Store/App/FSaveReviewFilters.ts index b00cf2415..6ba8c64e0 100644 --- a/src/js/Content/Features/Store/App/FSaveReviewFilters.ts +++ b/src/js/Content/Features/Store/App/FSaveReviewFilters.ts @@ -11,20 +11,19 @@ export default class FSaveReviewFilters extends Feature { override async apply(): Promise { - document.addEventListener("filtersChanged", async () => { - const context = document.querySelector("#review_context")!.value; - const language = document.querySelector("input[name=review_language]:checked")!.id; + document.addEventListener("as_filtersChanged", async () => { + const context = document.querySelector("input[name=review_context]:checked")?.id; + const language = document.querySelector("input[name=review_language]:checked")?.id; const minPlaytime = document.querySelector("#app_reviews_playtime_range_min")?.value; const maxPlaytime = document.querySelector("#app_reviews_playtime_range_max")?.value; - const value: Record = (await LocalStorage.get("review_filters")) ?? {}; - value.context = context; - value.language = language; - if (minPlaytime) { value.minPlaytime = minPlaytime; } - if (maxPlaytime) { value.maxPlaytime = maxPlaytime; } - - // @ts-ignore - LocalStorage.set("review_filters", value); + LocalStorage.set("review_filters", { + ...((await LocalStorage.get("review_filters")) ?? {}), + context, + language, + ...(minPlaytime && {minPlaytime}), + ...(maxPlaytime && {maxPlaytime}) + }); }); DOMHelper.insertScript("scriptlets/Store/App/saveReviewFilters.js", diff --git a/src/js/Core/Storage/LocalStorage.ts b/src/js/Core/Storage/LocalStorage.ts index 7c375a072..6cd853c75 100644 --- a/src/js/Core/Storage/LocalStorage.ts +++ b/src/js/Core/Storage/LocalStorage.ts @@ -41,8 +41,8 @@ interface LocalStorageSchema extends StorageSchema { expiry: number }, review_filters: { - context: string, - language: string, + context: string|undefined, + language: string|undefined, minPlaytime?: string, maxPlaytime?: string } diff --git a/src/scriptlets/Store/App/saveReviewFilters.js b/src/scriptlets/Store/App/saveReviewFilters.js index 611278bfd..99c0dfc8a 100644 --- a/src/scriptlets/Store/App/saveReviewFilters.js +++ b/src/scriptlets/Store/App/saveReviewFilters.js @@ -6,19 +6,25 @@ window.ShowFilteredReviews = function() { oldShowFilteredReviews(); - document.dispatchEvent(new CustomEvent("filtersChanged")); + document.dispatchEvent(new CustomEvent("as_filtersChanged")); }; let filtersChanged = false; - if (context && context !== "summary") { - filtersChanged = true; - document.querySelector("#review_context").value = context; + if (context && context !== "review_context_summary") { + const input = document.querySelector(`#${context}`); + if (input) { + filtersChanged = true; + input.checked = true; + } } if (language && language !== "review_language_mine") { - filtersChanged = true; - document.querySelector(`#${language}`).checked = true; + const input = document.querySelector(`#${language}`); + if (input) { + filtersChanged = true; + input.checked = true; + } } // Playtime filters may not be available on apps with too few reviews