Skip to content

Commit bea9749

Browse files
committed
Hide internal topics by default when no preference exists (closes #1073)
1 parent 46e1536 commit bea9749

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

frontend/src/components/Topics/List/ListPage.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,27 @@ const ListPage: React.FC = () => {
2222
if (!searchParams.has('perPage')) {
2323
searchParams.set('perPage', String(PER_PAGE));
2424
}
25-
if (
26-
!!localStorage.getItem('hideInternalTopics') &&
27-
!searchParams.has('hideInternal')
28-
) {
29-
searchParams.set('hideInternal', 'true');
25+
// If URL doesn't specify it, derive from localStorage (default = true when missing)
26+
if (!searchParams.has('hideInternal')) {
27+
const stored = localStorage.getItem('hideInternalTopics');
28+
const shouldHide = stored === null ? true : stored === 'true';
29+
searchParams.set('hideInternal', String(shouldHide));
30+
// persist the default so it sticks across pages
31+
if (stored === null) localStorage.setItem('hideInternalTopics', 'true');
32+
} else {
33+
// sync localStorage if URL has it set
34+
const raw = searchParams.get('hideInternal');
35+
const norm = raw === 'true' || raw === 'false' ? raw : 'true'; // default to true if malformed
36+
localStorage.setItem('hideInternalTopics', norm);
37+
if (norm !== raw) searchParams.set('hideInternal', norm); // sync URL if malformed
3038
}
3139
setSearchParams(searchParams);
3240
}, []);
3341

3442
const handleSwitch = () => {
35-
if (searchParams.has('hideInternal')) {
36-
localStorage.removeItem('hideInternalTopics');
37-
searchParams.delete('hideInternal');
43+
if (searchParams.get('hideInternal') === 'true') {
44+
localStorage.setItem('hideInternalTopics', 'false');
45+
searchParams.set('hideInternal', 'false');
3846
} else {
3947
localStorage.setItem('hideInternalTopics', 'true');
4048
searchParams.set('hideInternal', 'true');
@@ -66,7 +74,7 @@ const ListPage: React.FC = () => {
6674
<label>
6775
<Switch
6876
name="ShowInternalTopics"
69-
checked={!searchParams.has('hideInternal')}
77+
checked={searchParams.get('hideInternal') === 'false'}
7078
onChange={handleSwitch}
7179
/>
7280
Show Internal Topics

0 commit comments

Comments
 (0)