Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix review context filter preference #2029

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/js/Content/Features/Store/App/FSaveReviewFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ export default class FSaveReviewFilters extends Feature<CApp> {

override async apply(): Promise<void> {

document.addEventListener("filtersChanged", async () => {
const context = document.querySelector<HTMLInputElement>("#review_context")!.value;
const language = document.querySelector<HTMLInputElement>("input[name=review_language]:checked")!.id;
document.addEventListener("as_filtersChanged", async () => {
const context = document.querySelector<HTMLInputElement>("input[name=review_context]:checked")?.id;
const language = document.querySelector<HTMLInputElement>("input[name=review_language]:checked")?.id;
const minPlaytime = document.querySelector<HTMLInputElement>("#app_reviews_playtime_range_min")?.value;
const maxPlaytime = document.querySelector<HTMLInputElement>("#app_reviews_playtime_range_max")?.value;

const value: Record<string, string> = (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",
Expand Down
4 changes: 2 additions & 2 deletions src/js/Core/Storage/LocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 12 additions & 6 deletions src/scriptlets/Store/App/saveReviewFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down