Skip to content

feat: make workspace search bar remember text #9759

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

Merged
merged 17 commits into from
Sep 20, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: add localStorage to useWorkspacesFilter
  • Loading branch information
Parkreiner committed Sep 18, 2023
commit 553ce890f7c38080fae044263cdabeac99eef310
17 changes: 15 additions & 2 deletions site/src/pages/WorkspacesPage/WorkspacesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,27 @@ type UseWorkspacesFilterOptions = {
pagination: ReturnType<typeof usePagination>;
};

const filterPreferencesKey = "WorkspacesPage/filterPreferences";

const useWorkspacesFilter = ({
searchParamsResult,
pagination,
}: UseWorkspacesFilterOptions) => {
const filter = useFilter({
initialValue: `owner:me`,
searchParamsResult,
onUpdate: () => {
initialValue: () => {
const fallbackValue = "owner:me";

// Have to include check because initialValue will be called during the
// render itself; future-proofing for SSR, if we ever need that
if (typeof window === "undefined") {
return fallbackValue;
}

return window.localStorage.getItem(filterPreferencesKey) ?? fallbackValue;
},
onUpdate: (newValues) => {
window.localStorage.setItem(filterPreferencesKey, newValues);
pagination.goToPage(1);
},
});
Expand Down