aboutsummaryrefslogtreecommitdiff
path: root/src/routes
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-05-27 18:41:20 -0700
committerFuwn <[email protected]>2024-05-27 18:41:20 -0700
commit1cc227354ff7caf8f6c5ad61170636208bc1542b (patch)
tree2c73e27b18faad47464d406bfa85870f3dbc82dc /src/routes
parentfeat(badges): click counter for badges (diff)
downloaddue.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.svelte28
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>