From c206e38ee257d7479182b05e8d544923c39ea136 Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Wed, 7 May 2025 21:03:46 +1000 Subject: [PATCH] fix: change shortcuts to rely on links list --- src/background.ts | 36 ------------------- src/interface/pages/settings/shortcuts.svelte | 31 ++++++++-------- src/seqta/utils/listeners/StorageChanges.ts | 11 +++--- 3 files changed, 21 insertions(+), 57 deletions(-) diff --git a/src/background.ts b/src/background.ts index 7821e531..2bc7f515 100644 --- a/src/background.ts +++ b/src/background.ts @@ -100,10 +100,6 @@ const DefaultValues: SettingsState = { assessmentsAverage: true, defaultPage: "home", shortcuts: [ - { - name: "YouTube", - enabled: false, - }, { name: "Outlook", enabled: true, @@ -112,42 +108,10 @@ const DefaultValues: SettingsState = { name: "Office", enabled: true, }, - { - name: "Spotify", - enabled: false, - }, { name: "Google", enabled: true, }, - { - name: "DuckDuckGo", - enabled: false, - }, - { - name: "Cool Math Games", - enabled: false, - }, - { - name: "SACE", - enabled: false, - }, - { - name: "Google Scholar", - enabled: false, - }, - { - name: "Gmail", - enabled: false, - }, - { - name: "Netflix", - enabled: false, - }, - { - name: "Education Perfect", - enabled: false, - }, ], customshortcuts: [], lettergrade: false, diff --git a/src/interface/pages/settings/shortcuts.svelte b/src/interface/pages/settings/shortcuts.svelte index 1d155857..b9b4f637 100644 --- a/src/interface/pages/settings/shortcuts.svelte +++ b/src/interface/pages/settings/shortcuts.svelte @@ -3,6 +3,7 @@ import { settingsState } from "@/seqta/utils/listeners/SettingsState.ts" import Switch from "@/interface/components/Switch.svelte" import { onMount } from 'svelte'; + import Shortcuts from "@/seqta/content/links.json" let isLoaded = $state(false); @@ -21,10 +22,14 @@ }); }); - const switchChange = (index: number) => { - const updatedShortcuts = [...settingsState.shortcuts]; - updatedShortcuts[index].enabled = !updatedShortcuts[index].enabled; - settingsState.shortcuts = updatedShortcuts; + const switchChange = (shortcut: any) => { + const value = $settingsState.shortcuts.find(s => s.name === shortcut); + if (value) { + value.enabled = !value.enabled; + settingsState.shortcuts = settingsState.shortcuts; + } else { + settingsState.shortcuts = [...settingsState.shortcuts, { name: shortcut, enabled: true }]; + } } let isFormVisible = $state(false); @@ -65,15 +70,6 @@ }; -{#snippet Shortcuts([index, Shortcut]: [string, { name: string, enabled: boolean }]) } -
-
-

{Shortcut.name}

-
- switchChange(parseInt(index))} /> -
-{/snippet} -
{#if isLoaded}
@@ -136,8 +132,13 @@
- {#each Object.entries($settingsState.shortcuts) as shortcut} - {@render Shortcuts(shortcut)} + {#each Object.entries(Shortcuts) as shortcut} +
+
+

{shortcut[0]}

+
+ s.name === shortcut[0])?.enabled ?? false} onChange={() => switchChange(shortcut[0])} /> +
{/each} diff --git a/src/seqta/utils/listeners/StorageChanges.ts b/src/seqta/utils/listeners/StorageChanges.ts index a7bd8f76..cf363b42 100644 --- a/src/seqta/utils/listeners/StorageChanges.ts +++ b/src/seqta/utils/listeners/StorageChanges.ts @@ -70,14 +70,13 @@ export class StorageChangeHandler { oldValue: { enabled: boolean; name: string }[], ) { const addedShortcuts = newValue.filter((newItem: any) => { - const isAdded = oldValue.some((oldItem: any) => { - const match = oldItem.name === newItem.name; - const wasDisabled = !oldItem.enabled; - const isEnabled = newItem.enabled; - return match && wasDisabled && isEnabled; + const wasDisabledAndNowEnabled = oldValue.some((oldItem: any) => { + return oldItem.name === newItem.name && !oldItem.enabled && newItem.enabled; }); - return isAdded; + const isNewShortcut = !oldValue.some((oldItem: any) => oldItem.name === newItem.name); + + return (wasDisabledAndNowEnabled || isNewShortcut) && newItem.enabled; }); const removedShortcuts = newValue.filter((newItem: any) => {