Skip to content
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
chore: clean up WorkspacesPage
  • Loading branch information
Parkreiner committed Sep 19, 2023
commit ae5b3592f5539e036bf50e5f6447ee3fb9e13220
12 changes: 6 additions & 6 deletions site/src/pages/WorkspacesPage/WorkspacesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import { useEffectEvent } from "hooks/hookPolyfills";
function useSafeSearchParams() {
// Have to wrap setSearchParams because React Router doesn't make sure that
// the function's memory reference stays stable on each render, even though
// its logic never changes, and it even has function update support
// its logic never changes, and even though it has function update support
const [searchParams, setSearchParams] = useSearchParams();
const stableSetSearchParams = useEffectEvent(setSearchParams);

// Need this to be a tuple type, but can't use "as const", because that would
// make the whole array readonly and cause type mismatches
// make the whole array readonly and cause type mismatches downstream
return [searchParams, stableSetSearchParams] as ReturnType<
typeof useSearchParams
>;
Expand All @@ -46,7 +46,7 @@ const WorkspacesPage: FC = () => {
const pagination = usePagination({ searchParamsResult });
const filterProps = useWorkspacesFilter({
searchParamsResult,
onPageChange: () => pagination.goToPage(1),
onFilterChange: () => pagination.goToPage(1),
});

const { data, error, queryKey, refetch } = useWorkspacesData({
Expand Down Expand Up @@ -165,12 +165,12 @@ function subscribeToFilterChanges(notifyReact: () => void) {

type UseWorkspacesFilterOptions = {
searchParamsResult: ReturnType<typeof useSearchParams>;
onPageChange: () => void;
onFilterChange: () => void;
};

const useWorkspacesFilter = ({
searchParamsResult,
onPageChange,
onFilterChange,
}: UseWorkspacesFilterOptions) => {
// Using useSyncExternalStore store to safely access localStorage from the
// first render; both snapshot callbacks return primitives, so no special
Expand All @@ -194,7 +194,7 @@ const useWorkspacesFilter = ({
searchParamsResult,
onUpdate: (newValues) => {
window.localStorage.setItem(workspaceFilterKey, newValues);
onPageChange();
onFilterChange();
},
});

Expand Down