From bea974976fc5391840e9580559c7c6fb9caed2b4 Mon Sep 17 00:00:00 2001 From: Devansh Sehgal Date: Thu, 9 Oct 2025 04:47:56 +0530 Subject: [PATCH 1/3] Hide internal topics by default when no preference exists (closes #1073) --- .../src/components/Topics/List/ListPage.tsx | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/Topics/List/ListPage.tsx b/frontend/src/components/Topics/List/ListPage.tsx index d8508175c..00390e0ca 100644 --- a/frontend/src/components/Topics/List/ListPage.tsx +++ b/frontend/src/components/Topics/List/ListPage.tsx @@ -22,19 +22,27 @@ const ListPage: React.FC = () => { if (!searchParams.has('perPage')) { searchParams.set('perPage', String(PER_PAGE)); } - if ( - !!localStorage.getItem('hideInternalTopics') && - !searchParams.has('hideInternal') - ) { - searchParams.set('hideInternal', 'true'); + // If URL doesn't specify it, derive from localStorage (default = true when missing) + if (!searchParams.has('hideInternal')) { + const stored = localStorage.getItem('hideInternalTopics'); + const shouldHide = stored === null ? true : stored === 'true'; + searchParams.set('hideInternal', String(shouldHide)); + // persist the default so it sticks across pages + if (stored === null) localStorage.setItem('hideInternalTopics', 'true'); + } else { + // sync localStorage if URL has it set + const raw = searchParams.get('hideInternal'); + const norm = raw === 'true' || raw === 'false' ? raw : 'true'; // default to true if malformed + localStorage.setItem('hideInternalTopics', norm); + if (norm !== raw) searchParams.set('hideInternal', norm); // sync URL if malformed } setSearchParams(searchParams); }, []); const handleSwitch = () => { - if (searchParams.has('hideInternal')) { - localStorage.removeItem('hideInternalTopics'); - searchParams.delete('hideInternal'); + if (searchParams.get('hideInternal') === 'true') { + localStorage.setItem('hideInternalTopics', 'false'); + searchParams.set('hideInternal', 'false'); } else { localStorage.setItem('hideInternalTopics', 'true'); searchParams.set('hideInternal', 'true'); @@ -66,7 +74,7 @@ const ListPage: React.FC = () => {