Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions frontend/src/components/Topics/List/ListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -66,7 +74,7 @@ const ListPage: React.FC = () => {
<label>
<Switch
name="ShowInternalTopics"
checked={!searchParams.has('hideInternal')}
checked={searchParams.get('hideInternal') === 'false'}
onChange={handleSwitch}
/>
Show Internal Topics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
const switchInput = screen.getByLabelText('Show Internal Topics');
expect(switchInput).toBeInTheDocument();

expect(global.localStorage.getItem('hideInternalTopics')).toBeNull();
await userEvent.click(switchInput);
expect(global.localStorage.getItem('hideInternalTopics')).toBeTruthy();
await userEvent.click(switchInput);
expect(global.localStorage.getItem('hideInternalTopics')).toBeNull();
expect(global.localStorage.getItem('hideInternalTopics')).toBeFalsy();

Check failure on line 41 in frontend/src/components/Topics/List/__tests__/ListPage.spec.tsx

View workflow job for this annotation

GitHub Actions / build-and-test / tests

ListPage Component › Component Render › handles switch of Internal Topics visibility

expect(received).toBeFalsy() Received: "false" at Object.toBeFalsy (src/components/Topics/List/__tests__/ListPage.spec.tsx:41:65)
await userEvent.click(switchInput);
expect(global.localStorage.getItem('hideInternalTopics')).toBeTruthy();
});

it('renders the TopicsTable', () => {
Expand Down
Loading