feat(web): preserve sort order on Filters list (#772)

* preserve filter sortOrder in localStorage

* refactor to use SettingsContext
This commit is contained in:
soup 2023-03-30 22:14:14 +02:00 committed by GitHub
parent 86725d804e
commit 30cf9c55f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 17 deletions

View file

@ -19,8 +19,11 @@ export const InitializeGlobalContext = () => {
)
}));
}
const filterList_ctx = localStorage.getItem("filterList");
if (filterList_ctx) {
FilterListContext.set(JSON.parse(filterList_ctx));
}
};
interface AuthInfo {
username: string;
isLoggedIn: boolean;
@ -78,3 +81,27 @@ export const SettingsContext = newRidgeState<SettingsType>(
}
}
);
export type FilterListState = {
indexerFilter: string[],
sortOrder: string;
status: string;
};
export const FilterListContext = newRidgeState<FilterListState>(
{
indexerFilter: [],
sortOrder: "",
status: ""
},
{
onSet: (new_state) => {
try {
localStorage.setItem("filterList", JSON.stringify(new_state));
} catch (e) {
console.log("An error occurred while trying to modify the local filter list context state.");
console.log("Error:", e);
}
}
}
);