Merge pull request #1 from BetterSEQTA/main

Merge changes for testing PR
This commit is contained in:
StroepWafel
2025-05-07 20:40:54 +09:30
committed by GitHub
6 changed files with 32 additions and 69 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,
+1 -1
View File
@@ -50,6 +50,6 @@
} }
.dark .switch[data-ison="true"] { .dark .switch[data-ison="true"] {
@apply from-[#30D259]/50 to-[#30D259]; @apply from-[#30D259]/40 to-[#30D259];
} }
</style> </style>
+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 -->
@@ -1,10 +1,10 @@
import type { Job } from "./types"; import type { Job } from "./types";
import { messagesJob } from "./jobs/messages"; import { messagesJob } from "./jobs/messages";
import { assessmentsJob } from "./jobs/assessments"; import { notificationsJob } from "./jobs/notifications";
import { forumsJob } from "./jobs/forums"; import { forumsJob } from "./jobs/forums";
export const jobs: Record<string, Job> = { export const jobs: Record<string, Job> = {
messages: messagesJob, messages: messagesJob,
assessments: assessmentsJob, notifications: notificationsJob,
forums: forumsJob, forums: forumsJob,
}; };
@@ -27,8 +27,7 @@ interface AssessmentNotification {
type Notification = MessageNotification | AssessmentNotification; type Notification = MessageNotification | AssessmentNotification;
/* ------------- Progress model ------------- */ interface NotificationsProgress {
interface AssessmentsProgress {
lastTs: number; // ms since epoch of last processed notification lastTs: number; // ms since epoch of last processed notification
} }
@@ -108,14 +107,14 @@ const fetchAssessmentName = async (
}; };
/* ------------- Job ------------- */ /* ------------- Job ------------- */
export const assessmentsJob: Job = { export const notificationsJob: Job = {
id: "assessments", id: "notifications",
label: "Assessments", label: "Notifications",
renderComponentId: "assessment", renderComponentId: "notifications",
frequency: { type: "expiry", afterMs: 15 * 60 * 1000 }, frequency: { type: "expiry", afterMs: 15 * 60 * 1000 },
run: async (ctx) => { run: async (ctx) => {
const progress = (await ctx.getProgress<AssessmentsProgress>()) ?? { const progress = (await ctx.getProgress<NotificationsProgress>()) ?? {
lastTs: 0, lastTs: 0,
}; };
@@ -123,14 +122,14 @@ export const assessmentsJob: Job = {
try { try {
notifications = await fetchNotifications(); notifications = await fetchNotifications();
} catch (e) { } catch (e) {
console.error("[Assessments job] fetch failed:", e); console.error("[Notifications job] fetch failed:", e);
return []; return [];
} }
const notificationIsIndexed = async (id: string): Promise<boolean> => { const notificationIsIndexed = async (id: string): Promise<boolean> => {
const [inAssessments, inMessages] = await Promise.all([ const [inAssessments, inMessages] = await Promise.all([
ctx ctx
.getStoredItems("assessments") .getStoredItems("notifications")
.then((items) => items.some((i) => i.id === id)), .then((items) => items.some((i) => i.id === id)),
ctx ctx
.getStoredItems("messages") .getStoredItems("messages")
+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) => {