-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): store accordion state in search params (#6435)
* keep admin settings accordion state in search params * refactor: sync implementation * fix: avoid mutating svelte's internal search params * add query parameter to enum --------- Co-authored-by: Jason Rasmussen <[email protected]>
- Loading branch information
1 parent
6e78655
commit a9e6657
Showing
9 changed files
with
132 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 16 additions & 2 deletions
18
web/src/lib/components/admin-page/settings/setting-accordion.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { goto } from '$app/navigation'; | ||
import { page } from '$app/stores'; | ||
import { get } from 'svelte/store'; | ||
|
||
interface UpdateParamAction { | ||
param: string; | ||
value: string; | ||
add: boolean; | ||
} | ||
|
||
const getParamValues = (param: string) => | ||
new Set((get(page).url.searchParams.get(param) || '').split(' ').filter((x) => x !== '')); | ||
|
||
export const hasParamValue = (param: string, value: string) => getParamValues(param).has(value); | ||
|
||
export const updateParamList = async ({ param, value, add }: UpdateParamAction) => { | ||
const values = getParamValues(param); | ||
|
||
if (add) { | ||
values.add(value); | ||
} else { | ||
values.delete(value); | ||
} | ||
|
||
const searchParams = new URLSearchParams(get(page).url.searchParams); | ||
searchParams.set(param, [...values.values()].join(' ')); | ||
|
||
if (values.size === 0) { | ||
searchParams.delete(param); | ||
} | ||
|
||
await goto(`?${searchParams.toString()}`, { replaceState: true, noScroll: true, keepFocus: true }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters