fix: change shortcuts to rely on links list

This commit is contained in:
SethBurkart123
2025-05-07 21:03:46 +10:00
parent 87bf526dc6
commit c206e38ee2
3 changed files with 21 additions and 57 deletions
-36
View File
@@ -100,10 +100,6 @@ const DefaultValues: SettingsState = {
assessmentsAverage: true, assessmentsAverage: true,
defaultPage: "home", defaultPage: "home",
shortcuts: [ shortcuts: [
{
name: "YouTube",
enabled: false,
},
{ {
name: "Outlook", name: "Outlook",
enabled: true, enabled: true,
@@ -112,42 +108,10 @@ const DefaultValues: SettingsState = {
name: "Office", name: "Office",
enabled: true, enabled: true,
}, },
{
name: "Spotify",
enabled: false,
},
{ {
name: "Google", name: "Google",
enabled: true, 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: [], customshortcuts: [],
lettergrade: false, lettergrade: false,
+16 -15
View File
@@ -3,6 +3,7 @@
import { settingsState } from "@/seqta/utils/listeners/SettingsState.ts" import { settingsState } from "@/seqta/utils/listeners/SettingsState.ts"
import Switch from "@/interface/components/Switch.svelte" import Switch from "@/interface/components/Switch.svelte"
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import Shortcuts from "@/seqta/content/links.json"
let isLoaded = $state(false); let isLoaded = $state(false);
@@ -21,10 +22,14 @@
}); });
}); });
const switchChange = (index: number) => { const switchChange = (shortcut: any) => {
const updatedShortcuts = [...settingsState.shortcuts]; const value = $settingsState.shortcuts.find(s => s.name === shortcut);
updatedShortcuts[index].enabled = !updatedShortcuts[index].enabled; if (value) {
settingsState.shortcuts = updatedShortcuts; value.enabled = !value.enabled;
settingsState.shortcuts = settingsState.shortcuts;
} else {
settingsState.shortcuts = [...settingsState.shortcuts, { name: shortcut, enabled: true }];
}
} }
let isFormVisible = $state(false); let isFormVisible = $state(false);
@@ -65,15 +70,6 @@
}; };
</script> </script>
{#snippet Shortcuts([index, Shortcut]: [string, { name: string, enabled: boolean }]) }
<div class="flex justify-between items-center px-4 py-3">
<div class="pr-4">
<h2 class="text-sm">{Shortcut.name}</h2>
</div>
<Switch state={Shortcut.enabled} onChange={() => switchChange(parseInt(index))} />
</div>
{/snippet}
<div class="flex flex-col pt-4 divide-y divide-zinc-100 dark:divide-zinc-700"> <div class="flex flex-col pt-4 divide-y divide-zinc-100 dark:divide-zinc-700">
{#if isLoaded} {#if isLoaded}
<div> <div>
@@ -136,8 +132,13 @@
</MotionDiv> </MotionDiv>
</div> </div>
{#each Object.entries($settingsState.shortcuts) as shortcut} {#each Object.entries(Shortcuts) as shortcut}
{@render Shortcuts(shortcut)} <div class="flex justify-between items-center px-4 py-3">
<div class="pr-4">
<h2 class="text-sm">{shortcut[0]}</h2>
</div>
<Switch state={$settingsState.shortcuts.find(s => s.name === shortcut[0])?.enabled ?? false} onChange={() => switchChange(shortcut[0])} />
</div>
{/each} {/each}
<!-- Custom Shortcuts Section --> <!-- Custom Shortcuts Section -->
+5 -6
View File
@@ -70,14 +70,13 @@ export class StorageChangeHandler {
oldValue: { enabled: boolean; name: string }[], oldValue: { enabled: boolean; name: string }[],
) { ) {
const addedShortcuts = newValue.filter((newItem: any) => { const addedShortcuts = newValue.filter((newItem: any) => {
const isAdded = oldValue.some((oldItem: any) => { const wasDisabledAndNowEnabled = oldValue.some((oldItem: any) => {
const match = oldItem.name === newItem.name; return oldItem.name === newItem.name && !oldItem.enabled && newItem.enabled;
const wasDisabled = !oldItem.enabled;
const isEnabled = newItem.enabled;
return match && wasDisabled && isEnabled;
}); });
return isAdded; const isNewShortcut = !oldValue.some((oldItem: any) => oldItem.name === newItem.name);
return (wasDisabledAndNowEnabled || isNewShortcut) && newItem.enabled;
}); });
const removedShortcuts = newValue.filter((newItem: any) => { const removedShortcuts = newValue.filter((newItem: any) => {