From 3394695dc5816fd2e64250454916345c6d1ddbad Mon Sep 17 00:00:00 2001 From: smolgrrr Date: Tue, 12 Dec 2023 22:36:53 +1100 Subject: [PATCH] remember toggle state in local storage --- client/src/components/Forms/PostFormCard.tsx | 3 ++- client/src/components/Home.tsx | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/client/src/components/Forms/PostFormCard.tsx b/client/src/components/Forms/PostFormCard.tsx index 344f116..e978d83 100644 --- a/client/src/components/Forms/PostFormCard.tsx +++ b/client/src/components/Forms/PostFormCard.tsx @@ -47,7 +47,8 @@ const NewNoteCard = ({ if (refEvent && tagType && unsigned.tags.length === 0) { const tags = tagMapping[tagType]; if (tags) { - tags.forEach(tag => unsigned.tags.push([tag, refEvent[tag === 'p' ? 'pubkey' : 'id']])); + tags.forEach(tag => unsigned.tags.push([tag, refEvent[tag === 'p' ? 'pubkey' : 'id']])); + // Ref event should be the latest event they're replying to, and their event should include prev replies } if (tagType === 'Quote') { setComment(comment + '\nnostr:' + nip19.noteEncode(refEvent.id)); diff --git a/client/src/components/Home.tsx b/client/src/components/Home.tsx index 56732cd..188bc04 100644 --- a/client/src/components/Home.tsx +++ b/client/src/components/Home.tsx @@ -29,8 +29,8 @@ const useUniqEvents = () => { const Home = () => { const filterDifficulty = localStorage.getItem("filterDifficulty") || DEFAULT_DIFFICULTY; - const [sortByTime, setSortByTime] = useState(true); - const [setAnon, setSetAnon] = useState(true); + const [sortByTime, setSortByTime] = useState(localStorage.getItem('sortBy') !== 'false'); + const [setAnon, setSetAnon] = useState(localStorage.getItem('anonMode') !== 'false'); const { noteEvents, metadataEvents } = useUniqEvents(); const postEvents = noteEvents @@ -49,11 +49,19 @@ const Home = () => { ); const toggleSort = useCallback(() => { - setSortByTime(prev => !prev); + setSortByTime(prev => { + const newValue = !prev; + localStorage.setItem('sortBy', String(newValue)); + return newValue; + }); }, []); const toggleAnon = useCallback(() => { - setSetAnon(prev => !prev); + setSetAnon(prev => { + const newValue = !prev; + localStorage.setItem('anonMode', String(newValue)); + return newValue; + }); }, []); const countReplies = (event: Event) => {