From 914ee65ded8ab68c49385ff28db1fed9b04a1ed9 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Wed, 20 Jan 2021 20:07:52 -0800 Subject: [PATCH] Don't use a persisted setting when switching users; ref #3021 --- .../scripts/components/dashboard/DashboardContainer.tsx | 5 +++-- resources/scripts/plugins/usePersistedState.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/resources/scripts/components/dashboard/DashboardContainer.tsx b/resources/scripts/components/dashboard/DashboardContainer.tsx index b4cb4c290..2edc06056 100644 --- a/resources/scripts/components/dashboard/DashboardContainer.tsx +++ b/resources/scripts/components/dashboard/DashboardContainer.tsx @@ -16,8 +16,9 @@ import Pagination from '@/components/elements/Pagination'; export default () => { const { clearFlashes, clearAndAddHttpError } = useFlash(); const [ page, setPage ] = useState(1); - const { rootAdmin } = useStoreState(state => state.user.data!); - const [ showOnlyAdmin, setShowOnlyAdmin ] = usePersistedState('show_all_servers', false); + const uuid = useStoreState(state => state.user.data!.uuid); + const rootAdmin = useStoreState(state => state.user.data!.rootAdmin); + const [ showOnlyAdmin, setShowOnlyAdmin ] = usePersistedState(`${uuid}:show_all_servers`, false); const { data: servers, error } = useSWR>( [ '/api/client/servers', showOnlyAdmin, page ], diff --git a/resources/scripts/plugins/usePersistedState.ts b/resources/scripts/plugins/usePersistedState.ts index f31985558..007e3fcde 100644 --- a/resources/scripts/plugins/usePersistedState.ts +++ b/resources/scripts/plugins/usePersistedState.ts @@ -1,6 +1,6 @@ import { Dispatch, SetStateAction, useEffect, useState } from 'react'; -export function usePersistedState (key: string, defaultValue: S): [S | undefined, Dispatch>] { +export function usePersistedState (key: string, defaultValue: S): [ S | undefined, Dispatch> ] { const [ state, setState ] = useState( () => { try { @@ -12,7 +12,7 @@ export function usePersistedState (key: string, defaultValue: S): return defaultValue; } - } + }, ); useEffect(() => {