Skip to content

Commit

Permalink
Allow deselecting topic filters (#7791)
Browse files Browse the repository at this point in the history
* Use URLSearchParams to remove filter params as well as add them

* Add comment back in
  • Loading branch information
sophie-macmillan committed May 26, 2023
1 parent f1b2126 commit cf78326
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions dotcom-rendering/src/web/components/TopicFilterBank.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,10 @@ const topicStyles = css`
`;

const getTopicLink = (isActive: boolean, topics: string, id: Props['id']) => {
const urlParams = isActive
? // if active, the button links to the the page without the params
''
: // we only add the link if the topic is *inactive*
'?' +
new URLSearchParams({
topics,
}).toString();

return `${urlParams}#${id}`;
// If active, remove the search params. Otherwise use them.
const urlParams = new URLSearchParams(isActive ? {} : { topics });
return `?${urlParams.toString()}#${id}`;
};

const getKeyEventLink = (filterKeyEvents: boolean, id: Props['id']) => {
const urlParams = new URLSearchParams({
filterKeyEvents: filterKeyEvents ? 'false' : 'true',
Expand Down

0 comments on commit cf78326

Please sign in to comment.