From 27e6534d94d09673337d8b110784c4625eb36b7b Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Mon, 3 Oct 2022 08:15:27 -0600 Subject: [PATCH] Persist preferred comment sort order by contract --- web/components/contract/contract-tabs.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/web/components/contract/contract-tabs.tsx b/web/components/contract/contract-tabs.tsx index bf18fdbe..0b3585ca 100644 --- a/web/components/contract/contract-tabs.tsx +++ b/web/components/contract/contract-tabs.tsx @@ -31,6 +31,11 @@ import { useUser } from 'web/hooks/use-user' import { Tooltip } from 'web/components/tooltip' import { BountiedContractSmallBadge } from 'web/components/contract/bountied-contract-badge' import { Row } from '../layout/row' +import { + storageStore, + usePersistentState, +} from 'web/hooks/use-persistent-state' +import { safeLocalStorage } from 'web/lib/util/local' export function ContractTabs(props: { contract: Contract @@ -75,7 +80,10 @@ const CommentsTabContent = memo(function CommentsTabContent(props: { const { contract } = props const tips = useTipTxns({ contractId: contract.id }) const comments = useComments(contract.id) ?? props.comments - const [sort, setSort] = useState<'Newest' | 'Best'>('Newest') + const [sort, setSort] = usePersistentState<'Newest' | 'Best'>('Newest', { + key: `contract-${contract.id}-comments-sort`, + store: storageStore(safeLocalStorage()), + }) const me = useUser() if (comments == null) { return