diff options
| author | Fuwn <[email protected]> | 2024-05-27 18:41:20 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-05-27 18:41:20 -0700 |
| commit | 1cc227354ff7caf8f6c5ad61170636208bc1542b (patch) | |
| tree | 2c73e27b18faad47464d406bfa85870f3dbc82dc /src/routes | |
| parent | feat(badges): click counter for badges (diff) | |
| download | due.moe-1cc227354ff7caf8f6c5ad61170636208bc1542b.tar.xz due.moe-1cc227354ff7caf8f6c5ad61170636208bc1542b.zip | |
refactor(badges): move category toggle to script
Diffstat (limited to 'src/routes')
| -rw-r--r-- | src/routes/user/[user]/+page.svelte | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/routes/user/[user]/+page.svelte b/src/routes/user/[user]/+page.svelte index 4152c9f4..5cff3ca8 100644 --- a/src/routes/user/[user]/+page.svelte +++ b/src/routes/user/[user]/+page.svelte @@ -146,6 +146,19 @@ .then((rawPreferences) => rawPreferences.json()) .then((JSONpreferences) => (preferences = JSONpreferences)); + const toggleCategory = () => { + if (!userData) return; + + const categoryElement = document.getElementById('category') as HTMLInputElement; + const category = categoryElement.value; + + fetch(root(`/api/preferences?id=${userData.id}&toggleCategory=${category}`), { + method: 'PUT' + }).then(refreshPreferences); + + categoryElement.value = ''; + }; + // 8.5827814569536423841e0 </script> @@ -352,20 +365,7 @@ <input type="text" id="category" placeholder="Category" style="width: 10em;" /> </span> - <button - class="button-lined" - on:click={() => { - if (userData) { - const category = document.getElementById('category').value; - - fetch(root(`/api/preferences?id=${userData.id}&toggleCategory=${category}`), { - method: 'PUT' - }).then(refreshPreferences); - - document.getElementById('category').value = ''; - } - }}>Add</button - > + <button class="button-lined" on:click={toggleCategory}>Add</button> </span> </div> |