remember toggle state in local storage

This commit is contained in:
smolgrrr 2023-12-12 22:36:53 +11:00
parent b6596d349e
commit 3394695dc5
2 changed files with 14 additions and 5 deletions

View File

@ -47,7 +47,8 @@ const NewNoteCard = ({
if (refEvent && tagType && unsigned.tags.length === 0) { if (refEvent && tagType && unsigned.tags.length === 0) {
const tags = tagMapping[tagType]; const tags = tagMapping[tagType];
if (tags) { 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') { if (tagType === 'Quote') {
setComment(comment + '\nnostr:' + nip19.noteEncode(refEvent.id)); setComment(comment + '\nnostr:' + nip19.noteEncode(refEvent.id));

View File

@ -29,8 +29,8 @@ const useUniqEvents = () => {
const Home = () => { const Home = () => {
const filterDifficulty = localStorage.getItem("filterDifficulty") || DEFAULT_DIFFICULTY; const filterDifficulty = localStorage.getItem("filterDifficulty") || DEFAULT_DIFFICULTY;
const [sortByTime, setSortByTime] = useState(true); const [sortByTime, setSortByTime] = useState<boolean>(localStorage.getItem('sortBy') !== 'false');
const [setAnon, setSetAnon] = useState(true); const [setAnon, setSetAnon] = useState<boolean>(localStorage.getItem('anonMode') !== 'false');
const { noteEvents, metadataEvents } = useUniqEvents(); const { noteEvents, metadataEvents } = useUniqEvents();
const postEvents = noteEvents const postEvents = noteEvents
@ -49,11 +49,19 @@ const Home = () => {
); );
const toggleSort = useCallback(() => { const toggleSort = useCallback(() => {
setSortByTime(prev => !prev); setSortByTime(prev => {
const newValue = !prev;
localStorage.setItem('sortBy', String(newValue));
return newValue;
});
}, []); }, []);
const toggleAnon = useCallback(() => { const toggleAnon = useCallback(() => {
setSetAnon(prev => !prev); setSetAnon(prev => {
const newValue = !prev;
localStorage.setItem('anonMode', String(newValue));
return newValue;
});
}, []); }, []);
const countReplies = (event: Event) => { const countReplies = (event: Event) => {