mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
feat: optimise recent changes
This commit is contained in:
1 parent
1ba5f1ef49
commit
242e4f3ff8
18 files changed
+187
-439
No files matched your search
@@ -18,8 +18,6 @@
|
|||||||
type SidebarStyleId,
|
type SidebarStyleId,
|
||||||
} from "@/seqta/ui/sidebar/sidebarStyles";
|
} from "@/seqta/ui/sidebar/sidebarStyles";
|
||||||
|
|
||||||
let { showStylePreview = true }: { showStylePreview?: boolean } = $props();
|
|
||||||
|
|
||||||
const PREVIEW_ITEMS = [
|
const PREVIEW_ITEMS = [
|
||||||
{ label: "Home", active: true },
|
{ label: "Home", active: true },
|
||||||
{ label: "Timetable", active: false },
|
{ label: "Timetable", active: false },
|
||||||
@@ -69,22 +67,20 @@
|
|||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="picker-body" class:picker-body-no-preview={!showStylePreview}>
|
<div class="picker-body">
|
||||||
{#if showStylePreview}
|
<div class="preview-pane" aria-hidden="true">
|
||||||
<div class="preview-pane" aria-hidden="true">
|
<div class={`preview style-${selectedId}`}>
|
||||||
<div class={`preview style-${selectedId}`}>
|
<div class="preview-chrome">
|
||||||
<div class="preview-chrome">
|
<div class="preview-logo"></div>
|
||||||
<div class="preview-logo"></div>
|
{#each PREVIEW_ITEMS as item (item.label)}
|
||||||
{#each PREVIEW_ITEMS as item (item.label)}
|
<div class="preview-item" class:active={item.active}>
|
||||||
<div class="preview-item" class:active={item.active}>
|
<span class="preview-dot"></span>
|
||||||
<span class="preview-dot"></span>
|
<span class="preview-label">{item.label}</span>
|
||||||
<span class="preview-label">{item.label}</span>
|
</div>
|
||||||
</div>
|
{/each}
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="options"
|
class="options"
|
||||||
@@ -323,10 +319,6 @@
|
|||||||
padding: 0.5rem 1rem 1rem;
|
padding: 0.5rem 1rem 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.picker-body-no-preview {
|
|
||||||
grid-template-columns: 1fr;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 720px) {
|
@media (max-width: 720px) {
|
||||||
.picker-body {
|
.picker-body {
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
|
|||||||
@@ -7,16 +7,6 @@
|
|||||||
let { communityState, searchTerm }: { communityState: CommunityThemesState; searchTerm: string } =
|
let { communityState, searchTerm }: { communityState: CommunityThemesState; searchTerm: string } =
|
||||||
$props();
|
$props();
|
||||||
|
|
||||||
const themes = $derived(
|
|
||||||
communityState.browseThemes.filter((theme) => {
|
|
||||||
const q = searchTerm.toLowerCase();
|
|
||||||
if (!q) return true;
|
|
||||||
return (
|
|
||||||
(theme.name ?? "").toLowerCase().includes(q) ||
|
|
||||||
(theme.description ?? "").toLowerCase().includes(q)
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if communityState.browseLoading}
|
{#if communityState.browseLoading}
|
||||||
@@ -39,7 +29,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<ThemeGrid
|
<ThemeGrid
|
||||||
{themes}
|
themes={communityState.browseThemes}
|
||||||
{searchTerm}
|
{searchTerm}
|
||||||
setDisplayTheme={(theme) => (communityState.displayTheme = theme)}
|
setDisplayTheme={(theme) => (communityState.displayTheme = theme)}
|
||||||
toggleFavorite={() => {}}
|
toggleFavorite={() => {}}
|
||||||
@@ -50,7 +40,7 @@
|
|||||||
{#if communityState.displayTheme}
|
{#if communityState.displayTheme}
|
||||||
<ThemeModal
|
<ThemeModal
|
||||||
currentThemes={communityState.currentThemes}
|
currentThemes={communityState.currentThemes}
|
||||||
allThemes={themes}
|
allThemes={communityState.browseThemes}
|
||||||
theme={communityState.displayTheme}
|
theme={communityState.displayTheme}
|
||||||
displayTheme={communityState.displayTheme}
|
displayTheme={communityState.displayTheme}
|
||||||
setDisplayTheme={(t) => (communityState.displayTheme = t)}
|
setDisplayTheme={(t) => (communityState.displayTheme = t)}
|
||||||
|
|||||||
@@ -33,13 +33,6 @@
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
const isCommunity = $derived(variant === 'community');
|
const isCommunity = $derived(variant === 'community');
|
||||||
const hasSearchQuery = $derived(searchTerm.trim().length > 0);
|
|
||||||
|
|
||||||
function openCommunityThemeBuilder() {
|
|
||||||
void import('@/seqta/utils/launchPageThemeBuilder').then(({ launchPageThemeBuilder }) =>
|
|
||||||
launchPageThemeBuilder(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
@@ -59,30 +52,15 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{:else if isCommunity}
|
{:else if isCommunity}
|
||||||
<div class="mx-auto flex max-w-lg flex-col items-center justify-center py-24 text-center">
|
<div class="mx-auto max-w-md py-24 text-center text-zinc-500 dark:text-zinc-400">
|
||||||
{#if hasSearchQuery}
|
<p class="text-lg font-medium text-zinc-900 dark:text-white">
|
||||||
<h2 class="text-xl font-semibold text-zinc-900 dark:text-white" style="text-wrap: balance">
|
{searchTerm.trim() ? "No themes match your search" : "No community themes yet"}
|
||||||
No themes match your search
|
</p>
|
||||||
</h2>
|
<p class="mt-2 text-sm">
|
||||||
<p class="mt-2 text-base text-zinc-500 dark:text-zinc-400" style="text-wrap: pretty">
|
{searchTerm.trim()
|
||||||
Try another name or keyword, or clear the search box to browse all approved community themes.
|
? "Try a different search or clear the box."
|
||||||
</p>
|
: "Approved submissions show up here. Use Create & submit above to share yours."}
|
||||||
{:else}
|
</p>
|
||||||
<h2 class="text-xl font-semibold text-zinc-900 dark:text-white" style="text-wrap: balance">
|
|
||||||
No community themes yet
|
|
||||||
</h2>
|
|
||||||
<p class="mt-2 text-base text-zinc-500 dark:text-zinc-400" style="text-wrap: pretty">
|
|
||||||
Approved themes from other users will appear here. Create your own and submit it for review to
|
|
||||||
share it with the community.
|
|
||||||
</p>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="mt-6 rounded-lg bg-zinc-900 px-4 py-2.5 text-sm font-medium text-white transition-all duration-200 hover:bg-zinc-700 focus:outline-none focus:ring-2 focus:ring-zinc-500 focus:ring-offset-2 active:scale-95 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-white"
|
|
||||||
onclick={openCommunityThemeBuilder}
|
|
||||||
>
|
|
||||||
Create & submit a theme
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="absolute top-0 flex h-96 w-full flex-col items-center justify-center text-center">
|
<div class="absolute top-0 flex h-96 w-full flex-col items-center justify-center text-center">
|
||||||
|
|||||||
@@ -633,7 +633,7 @@
|
|||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
<div class="theme-creator-sidebar -mx-2">
|
<div class="theme-creator-sidebar -mx-2">
|
||||||
<SidebarAppearance showStylePreview={false} />
|
<SidebarAppearance />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Divider />
|
<Divider />
|
||||||
@@ -721,4 +721,13 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.theme-creator-sidebar :global(.preview-pane) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.theme-creator-sidebar :global(.picker-body) {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -152,7 +152,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
{:else}
|
{:else}
|
||||||
<p class="bsplus-analytics-class-groups-empty">
|
<p class="bsplus-analytics-class-groups-empty">
|
||||||
Combine the same subject across years (e.g. English 2024 + English 2025) into one grade trend.
|
Combine the same subject across years into one grade trend.
|
||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
@@ -181,8 +181,7 @@
|
|||||||
{editingId ? "Edit combined classes" : "Combine classes"}
|
{editingId ? "Edit combined classes" : "Combine classes"}
|
||||||
</h2>
|
</h2>
|
||||||
<p class="bsplus-analytics-class-groups-dialog-desc">
|
<p class="bsplus-analytics-class-groups-dialog-desc">
|
||||||
Pick two or more classes from any year — useful when your school splits a subject by
|
Pick classes from any year (same list as Courses).
|
||||||
year. Same class list as Courses.
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "@jest/globals";
|
||||||
import { DEFAULT_ANALYTICS_GRADE_INFERENCE } from "./gradeInferenceSettings";
|
import { DEFAULT_ANALYTICS_GRADE_INFERENCE } from "./gradeInferenceSettings";
|
||||||
import {
|
import {
|
||||||
resolveGradeFromAssessmentPayload,
|
resolveGradeFromAssessmentPayload,
|
||||||
|
|||||||
@@ -600,10 +600,7 @@
|
|||||||
>
|
>
|
||||||
<div class="bsplus-cal-menu-header">
|
<div class="bsplus-cal-menu-header">
|
||||||
<span class="bsplus-cal-menu-title">Calendar sync</span>
|
<span class="bsplus-cal-menu-title">Calendar sync</span>
|
||||||
<span class="bsplus-cal-menu-sub"
|
<span class="bsplus-cal-menu-sub">Sync classes and optional assessment due dates to Google or Outlook</span>
|
||||||
>Copy your SEQTA classes, appointments, and optional assessment due dates to Google or
|
|
||||||
Outlook</span
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{@render providerPanel(
|
{@render providerPanel(
|
||||||
@@ -658,10 +655,7 @@
|
|||||||
<label class="bsplus-cal-setting bsplus-cal-setting--toggle">
|
<label class="bsplus-cal-setting bsplus-cal-setting--toggle">
|
||||||
<div class="bsplus-cal-setting-copy">
|
<div class="bsplus-cal-setting-copy">
|
||||||
<span class="bsplus-cal-setting-label">Sync assessment due dates</span>
|
<span class="bsplus-cal-setting-label">Sync assessment due dates</span>
|
||||||
<span class="bsplus-cal-setting-desc">
|
<span class="bsplus-cal-setting-desc">Uses the same weeks window. Update calendar once after enabling.</span>
|
||||||
Add upcoming assessment due dates from SEQTA using the same weeks window. Run Update
|
|
||||||
calendar after enabling to backfill.
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
buildLessonSyncResult,
|
buildLessonSyncResult,
|
||||||
collectOriginDeleteEntries,
|
collectOriginDeleteEntries,
|
||||||
assessmentEntriesToRemove,
|
|
||||||
entriesToPrune,
|
entriesToPrune,
|
||||||
formatLessonSyncResultMessage,
|
formatLessonSyncResultMessage,
|
||||||
mapPool,
|
mapPool,
|
||||||
@@ -121,30 +120,12 @@ describe("entriesToPrune", () => {
|
|||||||
"full",
|
"full",
|
||||||
weeksAhead,
|
weeksAhead,
|
||||||
new Set(),
|
new Set(),
|
||||||
{ syncAssessmentDueDates: false },
|
false,
|
||||||
);
|
);
|
||||||
expect(pruned).toEqual([]);
|
expect(pruned).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("assessmentEntriesToRemove", () => {
|
|
||||||
const origin = "https://school.seqta.com.au";
|
|
||||||
|
|
||||||
it("lists all assessment map entries for the origin", () => {
|
|
||||||
const lessonKey = `${origin}::${origin}:cal:1`;
|
|
||||||
const assessmentKey = `${origin}::${origin}:assessment:3`;
|
|
||||||
expect(
|
|
||||||
assessmentEntriesToRemove(
|
|
||||||
{
|
|
||||||
[lessonKey]: { id: "evt-1", date: "2026-01-01" },
|
|
||||||
[assessmentKey]: { id: "evt-a", date: "2026-02-01" },
|
|
||||||
},
|
|
||||||
origin,
|
|
||||||
),
|
|
||||||
).toEqual([[assessmentKey, "evt-a"]]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("mergeRemoteEventsIntoMap", () => {
|
describe("mergeRemoteEventsIntoMap", () => {
|
||||||
const origin = "https://school.seqta.com.au";
|
const origin = "https://school.seqta.com.au";
|
||||||
const mapKey = (o: string, seqtaKey: string) => `${o}::${seqtaKey}`;
|
const mapKey = (o: string, seqtaKey: string) => `${o}::${seqtaKey}`;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
} from "@/seqta/utils/calendarSync/eventMap";
|
} from "@/seqta/utils/calendarSync/eventMap";
|
||||||
import { eventFingerprint } from "@/seqta/utils/calendarSync/eventFingerprint";
|
import { eventFingerprint } from "@/seqta/utils/calendarSync/eventFingerprint";
|
||||||
import type { RemoteSyncedEvent } from "@/seqta/utils/calendarSync/remoteEvents";
|
import type { RemoteSyncedEvent } from "@/seqta/utils/calendarSync/remoteEvents";
|
||||||
import { isAssessmentSeqtaKey } from "@/seqta/utils/googleCalendar/assessmentEventMapper";
|
|
||||||
import {
|
import {
|
||||||
isDateInRange,
|
isDateInRange,
|
||||||
syncWindowRange,
|
syncWindowRange,
|
||||||
@@ -86,31 +85,24 @@ export function originEventMapEntries(
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EntriesToPruneOptions = {
|
|
||||||
/** When false, assessment events are not pruned here (use assessmentEntriesToRemove). */
|
|
||||||
syncAssessmentDueDates?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function entriesToPrune(
|
export function entriesToPrune(
|
||||||
eventMap: EventMapRecord,
|
eventMap: EventMapRecord,
|
||||||
origin: string,
|
origin: string,
|
||||||
mode: "full" | "incremental",
|
mode: "full" | "incremental",
|
||||||
weeksAhead: number,
|
weeksAhead: number,
|
||||||
currentMapKeys: Set<string>,
|
currentMapKeys: Set<string>,
|
||||||
options: EntriesToPruneOptions = {},
|
syncAssessmentDueDates = false,
|
||||||
): Array<[string, string]> {
|
): Array<[string, string]> {
|
||||||
if (mode === "incremental") return [];
|
if (mode === "incremental") return [];
|
||||||
|
|
||||||
const syncAssessments = options.syncAssessmentDueDates === true;
|
const syncAssessments = syncAssessmentDueDates;
|
||||||
const window = syncWindowRange(weeksAhead);
|
const window = syncWindowRange(weeksAhead);
|
||||||
const prefix = `${origin}::`;
|
const prefix = `${origin}::`;
|
||||||
const entries: Array<[string, string]> = [];
|
const entries: Array<[string, string]> = [];
|
||||||
|
|
||||||
for (const [mapKey, raw] of Object.entries(eventMap)) {
|
for (const [mapKey, raw] of Object.entries(eventMap)) {
|
||||||
if (!mapKey.startsWith(prefix)) continue;
|
if (!mapKey.startsWith(prefix)) continue;
|
||||||
const seqtaKey = mapKey.slice(prefix.length);
|
if (!syncAssessments && mapKey.includes(":assessment:")) continue;
|
||||||
const isAssessment = isAssessmentSeqtaKey(seqtaKey);
|
|
||||||
if (isAssessment && !syncAssessments) continue;
|
|
||||||
|
|
||||||
const entry = normalizeEventMapEntry(raw);
|
const entry = normalizeEventMapEntry(raw);
|
||||||
if (!entry) continue;
|
if (!entry) continue;
|
||||||
@@ -124,26 +116,6 @@ export function entriesToPrune(
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove all tracked assessment events when due-date sync is turned off. */
|
|
||||||
export function assessmentEntriesToRemove(
|
|
||||||
eventMap: EventMapRecord,
|
|
||||||
origin: string,
|
|
||||||
): Array<[string, string]> {
|
|
||||||
const prefix = `${origin}::`;
|
|
||||||
const entries: Array<[string, string]> = [];
|
|
||||||
|
|
||||||
for (const [mapKey, raw] of Object.entries(eventMap)) {
|
|
||||||
if (!mapKey.startsWith(prefix)) continue;
|
|
||||||
const seqtaKey = mapKey.slice(prefix.length);
|
|
||||||
if (!isAssessmentSeqtaKey(seqtaKey)) continue;
|
|
||||||
const entry = normalizeEventMapEntry(raw);
|
|
||||||
if (!entry) continue;
|
|
||||||
entries.push([mapKey, entry.id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Merge remote BS+ events into the local eventMap (origin-scoped keys). */
|
/** Merge remote BS+ events into the local eventMap (origin-scoped keys). */
|
||||||
export function mergeRemoteEventsIntoMap(
|
export function mergeRemoteEventsIntoMap(
|
||||||
eventMap: EventMapRecord,
|
eventMap: EventMapRecord,
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import { isGoogleCalendarConfigured } from "@/config/googleCalendar";
|
import { isGoogleCalendarConfigured } from "@/config/googleCalendar";
|
||||||
import { isOutlookCalendarConfigured } from "@/config/outlookCalendar";
|
import { isOutlookCalendarConfigured } from "@/config/outlookCalendar";
|
||||||
import { getSyncWeeksAhead } from "@/seqta/utils/calendarSync/settings";
|
import { getSyncWeeksAhead } from "@/seqta/utils/calendarSync/settings";
|
||||||
import { eventMapKey } from "@/seqta/utils/calendarSync/eventMap";
|
import { eventMapKey, normalizeEventMapEntry } from "@/seqta/utils/calendarSync/eventMap";
|
||||||
import type { EventMapRecord } from "@/seqta/utils/calendarSync/eventMap";
|
import type { EventMapRecord } from "@/seqta/utils/calendarSync/eventMap";
|
||||||
import {
|
import {
|
||||||
assessmentEntriesToRemove,
|
|
||||||
buildDeleteSyncResult,
|
buildDeleteSyncResult,
|
||||||
buildLessonSyncResult,
|
buildLessonSyncResult,
|
||||||
clearOriginEventMapEntries,
|
clearOriginEventMapEntries,
|
||||||
@@ -19,7 +18,7 @@ import {
|
|||||||
reportSyncProgress,
|
reportSyncProgress,
|
||||||
upsertLessonEvents,
|
upsertLessonEvents,
|
||||||
} from "@/seqta/utils/calendarSync/lessonSyncShared";
|
} from "@/seqta/utils/calendarSync/lessonSyncShared";
|
||||||
import { mapAssessmentsToGoogleEvents } from "@/seqta/utils/googleCalendar/assessmentEventMapper";
|
import { mapAssessmentsToGoogleEvents } from "@/seqta/utils/googleCalendar/eventMapper";
|
||||||
import {
|
import {
|
||||||
deleteGoogleCalendarEvent,
|
deleteGoogleCalendarEvent,
|
||||||
deleteOutlookCalendarEvent,
|
deleteOutlookCalendarEvent,
|
||||||
@@ -219,10 +218,15 @@ export async function syncLessonsToCalendar(
|
|||||||
mode,
|
mode,
|
||||||
weeksAhead,
|
weeksAhead,
|
||||||
currentMapKeys,
|
currentMapKeys,
|
||||||
{ syncAssessmentDueDates },
|
syncAssessmentDueDates,
|
||||||
);
|
);
|
||||||
if (!syncAssessmentDueDates && mode === "full") {
|
if (!syncAssessmentDueDates && mode === "full") {
|
||||||
staleEntries = [...staleEntries, ...assessmentEntriesToRemove(eventMap, request.origin)];
|
const prefix = `${request.origin}::`;
|
||||||
|
for (const [mapKey, raw] of Object.entries(eventMap)) {
|
||||||
|
if (!mapKey.startsWith(prefix) || !mapKey.includes(":assessment:")) continue;
|
||||||
|
const entry = normalizeEventMapEntry(raw);
|
||||||
|
if (entry) staleEntries.push([mapKey, entry.id]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const totalSteps = Math.max(staleEntries.length + events.length, 1);
|
const totalSteps = Math.max(staleEntries.length + events.length, 1);
|
||||||
const lastSyncAt = Date.now();
|
const lastSyncAt = Date.now();
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import browser from "webextension-polyfill";
|
import browser from "webextension-polyfill";
|
||||||
import { fetchTimetableForSync, fetchTimetableLessons } from "@/seqta/utils/googleCalendar/fetchTimetable";
|
import {
|
||||||
|
fetchAssessmentsForCalendarSync,
|
||||||
|
fetchTimetableForSync,
|
||||||
|
fetchTimetableLessons,
|
||||||
|
} from "@/seqta/utils/googleCalendar/fetchTimetable";
|
||||||
import { syncWindowRange, trailingWeekRange } from "@/seqta/utils/googleCalendar/syncDateRange";
|
import { syncWindowRange, trailingWeekRange } from "@/seqta/utils/googleCalendar/syncDateRange";
|
||||||
import {
|
import {
|
||||||
googleLessonSyncProvider,
|
googleLessonSyncProvider,
|
||||||
@@ -19,7 +23,6 @@ import {
|
|||||||
getSyncWeeksAhead,
|
getSyncWeeksAhead,
|
||||||
readResumableCalendarSync,
|
readResumableCalendarSync,
|
||||||
} from "@/seqta/utils/calendarSync/settings";
|
} from "@/seqta/utils/calendarSync/settings";
|
||||||
import { fetchAssessmentsForCalendarSync } from "@/seqta/utils/googleCalendar/fetchAssessmentsForCalendarSync";
|
|
||||||
import type {
|
import type {
|
||||||
GoogleCalendarStatus,
|
GoogleCalendarStatus,
|
||||||
GoogleCalendarSyncProgress,
|
GoogleCalendarSyncProgress,
|
||||||
|
|||||||
@@ -1,83 +0,0 @@
|
|||||||
import { describe, expect, it } from "@jest/globals";
|
|
||||||
import {
|
|
||||||
assessmentToGoogleEvent,
|
|
||||||
mapAssessmentsToGoogleEvents,
|
|
||||||
seqtaAssessmentKey,
|
|
||||||
shouldSyncAssessment,
|
|
||||||
} from "./assessmentEventMapper";
|
|
||||||
|
|
||||||
const ORIGIN = "https://school.seqta.com.au";
|
|
||||||
|
|
||||||
describe("shouldSyncAssessment", () => {
|
|
||||||
it("accepts upcoming assessments with due dates", () => {
|
|
||||||
expect(
|
|
||||||
shouldSyncAssessment({
|
|
||||||
id: 1,
|
|
||||||
title: "Essay",
|
|
||||||
subject: "English",
|
|
||||||
code: "10ENG",
|
|
||||||
due: "2026-06-27",
|
|
||||||
}),
|
|
||||||
).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("rejects released marks", () => {
|
|
||||||
expect(
|
|
||||||
shouldSyncAssessment({
|
|
||||||
id: 2,
|
|
||||||
title: "Test",
|
|
||||||
subject: "Math",
|
|
||||||
code: "10MAT",
|
|
||||||
due: "2026-06-27",
|
|
||||||
status: "MARKS_RELEASED",
|
|
||||||
}),
|
|
||||||
).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("assessmentToGoogleEvent", () => {
|
|
||||||
it("maps date-only due dates to all-day events", () => {
|
|
||||||
const event = assessmentToGoogleEvent(
|
|
||||||
ORIGIN,
|
|
||||||
{
|
|
||||||
id: 42,
|
|
||||||
title: "Project",
|
|
||||||
subject: "Science",
|
|
||||||
code: "10SCI",
|
|
||||||
due: "2026-06-27",
|
|
||||||
},
|
|
||||||
"Australia/Perth",
|
|
||||||
);
|
|
||||||
expect(event).toMatchObject({
|
|
||||||
seqtaKey: seqtaAssessmentKey(ORIGIN, 42),
|
|
||||||
allDay: true,
|
|
||||||
startDate: "2026-06-27",
|
|
||||||
endDate: "2026-06-28",
|
|
||||||
summary: "Due: Project (Science)",
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("dedupes by assessment id", () => {
|
|
||||||
const events = mapAssessmentsToGoogleEvents(
|
|
||||||
ORIGIN,
|
|
||||||
[
|
|
||||||
{
|
|
||||||
id: 5,
|
|
||||||
title: "A",
|
|
||||||
subject: "X",
|
|
||||||
code: "X",
|
|
||||||
due: "2026-07-01",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 5,
|
|
||||||
title: "A duplicate",
|
|
||||||
subject: "X",
|
|
||||||
code: "X",
|
|
||||||
due: "2026-07-01",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"UTC",
|
|
||||||
);
|
|
||||||
expect(events).toHaveLength(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
import { toISODate } from "@/seqta/utils/Loaders/engageParentTimetable";
|
|
||||||
import type { GoogleCalendarEventInput } from "./types";
|
|
||||||
|
|
||||||
export interface CalendarSyncAssessment {
|
|
||||||
id: number;
|
|
||||||
title: string;
|
|
||||||
subject: string;
|
|
||||||
code: string;
|
|
||||||
due: string;
|
|
||||||
status?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const SKIP_STATUSES = new Set(["MARKS_RELEASED", "CANCELLED"]);
|
|
||||||
|
|
||||||
export function isAssessmentSeqtaKey(seqtaKey: string): boolean {
|
|
||||||
return seqtaKey.includes(":assessment:");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function seqtaAssessmentKey(origin: string, assessmentId: number): string {
|
|
||||||
return `${origin}:assessment:${assessmentId}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function dueDateOnly(due: string): string | null {
|
|
||||||
const trimmed = due.trim();
|
|
||||||
if (/^\d{4}-\d{2}-\d{2}$/.test(trimmed)) return trimmed;
|
|
||||||
const parsed = new Date(trimmed);
|
|
||||||
if (Number.isNaN(parsed.getTime())) return null;
|
|
||||||
return toISODate(parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
function addDays(isoDate: string, days: number): string {
|
|
||||||
const d = new Date(`${isoDate}T12:00:00`);
|
|
||||||
d.setDate(d.getDate() + days);
|
|
||||||
return toISODate(d);
|
|
||||||
}
|
|
||||||
|
|
||||||
function hasTimeComponent(due: string): boolean {
|
|
||||||
const trimmed = due.trim();
|
|
||||||
if (/^\d{4}-\d{2}-\d{2}$/.test(trimmed)) return false;
|
|
||||||
return /T\d{2}:\d{2}/.test(trimmed) || /\d{1,2}:\d{2}/.test(trimmed);
|
|
||||||
}
|
|
||||||
|
|
||||||
function timedDueBounds(due: string, timeZone: string): { start: string; end: string } | null {
|
|
||||||
const parsed = new Date(due.trim());
|
|
||||||
if (Number.isNaN(parsed.getTime())) return null;
|
|
||||||
const datePart = toISODate(parsed);
|
|
||||||
const pad = (n: number) => String(n).padStart(2, "0");
|
|
||||||
const hours = parsed.getHours();
|
|
||||||
const minutes = parsed.getMinutes();
|
|
||||||
const start = `${datePart}T${pad(hours)}:${pad(minutes)}:00`;
|
|
||||||
const endDate = new Date(parsed);
|
|
||||||
endDate.setMinutes(endDate.getMinutes() + 30);
|
|
||||||
const endDatePart = toISODate(endDate);
|
|
||||||
const end = `${endDatePart}T${pad(endDate.getHours())}:${pad(endDate.getMinutes())}:00`;
|
|
||||||
void timeZone;
|
|
||||||
return { start, end };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function shouldSyncAssessment(assessment: CalendarSyncAssessment): boolean {
|
|
||||||
if (!assessment.id || !assessment.title.trim()) return false;
|
|
||||||
if (assessment.status && SKIP_STATUSES.has(assessment.status)) return false;
|
|
||||||
return dueDateOnly(assessment.due) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function assessmentToGoogleEvent(
|
|
||||||
origin: string,
|
|
||||||
assessment: CalendarSyncAssessment,
|
|
||||||
timeZone: string,
|
|
||||||
): GoogleCalendarEventInput | null {
|
|
||||||
if (!shouldSyncAssessment(assessment)) return null;
|
|
||||||
|
|
||||||
const dateOnly = dueDateOnly(assessment.due)!;
|
|
||||||
const subjectLabel = (assessment.subject || assessment.code || "Assessment").trim();
|
|
||||||
const summary = `Due: ${assessment.title.trim()} (${subjectLabel})`;
|
|
||||||
|
|
||||||
const descriptionLines = ["Synced by BetterSEQTA+", "Type: Assessment due date"];
|
|
||||||
if (assessment.code) descriptionLines.push(`Code: ${assessment.code}`);
|
|
||||||
|
|
||||||
const seqtaKey = seqtaAssessmentKey(origin, assessment.id);
|
|
||||||
|
|
||||||
if (hasTimeComponent(assessment.due)) {
|
|
||||||
const bounds = timedDueBounds(assessment.due, timeZone);
|
|
||||||
if (!bounds) return null;
|
|
||||||
return {
|
|
||||||
seqtaKey,
|
|
||||||
summary,
|
|
||||||
description: descriptionLines.join("\n"),
|
|
||||||
startDateTime: bounds.start,
|
|
||||||
endDateTime: bounds.end,
|
|
||||||
timeZone,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
seqtaKey,
|
|
||||||
summary,
|
|
||||||
description: descriptionLines.join("\n"),
|
|
||||||
allDay: true,
|
|
||||||
startDate: dateOnly,
|
|
||||||
endDate: addDays(dateOnly, 1),
|
|
||||||
startDateTime: `${dateOnly}T00:00:00`,
|
|
||||||
endDateTime: `${dateOnly}T23:59:00`,
|
|
||||||
timeZone,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function mapAssessmentsToGoogleEvents(
|
|
||||||
origin: string,
|
|
||||||
assessments: CalendarSyncAssessment[],
|
|
||||||
timeZone: string,
|
|
||||||
): GoogleCalendarEventInput[] {
|
|
||||||
const out: GoogleCalendarEventInput[] = [];
|
|
||||||
const seen = new Set<string>();
|
|
||||||
for (const assessment of assessments) {
|
|
||||||
const mapped = assessmentToGoogleEvent(origin, assessment, timeZone);
|
|
||||||
if (!mapped || seen.has(mapped.seqtaKey)) continue;
|
|
||||||
seen.add(mapped.seqtaKey);
|
|
||||||
out.push(mapped);
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@ import { describe, expect, it } from "@jest/globals";
|
|||||||
import {
|
import {
|
||||||
googleApiEventBody,
|
googleApiEventBody,
|
||||||
lessonToGoogleEvent,
|
lessonToGoogleEvent,
|
||||||
|
mapAssessmentsToGoogleEvents,
|
||||||
mapLessonsToGoogleEvents,
|
mapLessonsToGoogleEvents,
|
||||||
outlookGraphEventBody,
|
outlookGraphEventBody,
|
||||||
seqtaLessonKey,
|
seqtaLessonKey,
|
||||||
@@ -111,6 +112,21 @@ describe("mapLessonsToGoogleEvents", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("mapAssessmentsToGoogleEvents", () => {
|
||||||
|
it("maps due dates to all-day events", () => {
|
||||||
|
const [event] = mapAssessmentsToGoogleEvents(
|
||||||
|
ORIGIN,
|
||||||
|
[{ id: 42, title: "Essay", subject: "English", code: "10ENG", due: "2026-06-27" }],
|
||||||
|
"Australia/Perth",
|
||||||
|
);
|
||||||
|
expect(event).toMatchObject({
|
||||||
|
seqtaKey: `${ORIGIN}:assessment:42`,
|
||||||
|
allDay: true,
|
||||||
|
startDate: "2026-06-27",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("outlookGraphEventBody", () => {
|
describe("outlookGraphEventBody", () => {
|
||||||
it("embeds Key: seqtaKey in the body for remote reconcile", () => {
|
it("embeds Key: seqtaKey in the body for remote reconcile", () => {
|
||||||
const event = lessonToGoogleEvent(ORIGIN, baseLesson, "Australia/Perth");
|
const event = lessonToGoogleEvent(ORIGIN, baseLesson, "Australia/Perth");
|
||||||
|
|||||||
@@ -1,9 +1,21 @@
|
|||||||
import { BSPLUS_GOOGLE_CALENDAR_EVENT_PROP } from "@/config/googleCalendar";
|
import { BSPLUS_GOOGLE_CALENDAR_EVENT_PROP } from "@/config/googleCalendar";
|
||||||
import { BSPLUS_OUTLOOK_CALENDAR_EVENT_CATEGORY } from "@/config/outlookCalendar";
|
import { BSPLUS_OUTLOOK_CALENDAR_EVENT_CATEGORY } from "@/config/outlookCalendar";
|
||||||
import { outlookDescriptionWithKey } from "@/seqta/utils/calendarSync/eventFingerprint";
|
import { outlookDescriptionWithKey } from "@/seqta/utils/calendarSync/eventFingerprint";
|
||||||
|
import { toISODate } from "@/seqta/utils/Loaders/engageParentTimetable";
|
||||||
import { nearestGoogleEventColorId } from "./eventColor";
|
import { nearestGoogleEventColorId } from "./eventColor";
|
||||||
import type { GoogleCalendarEventInput, SeqtaTimetableLesson } from "./types";
|
import type { GoogleCalendarEventInput, SeqtaTimetableLesson } from "./types";
|
||||||
|
|
||||||
|
export type CalendarSyncAssessment = {
|
||||||
|
id: number;
|
||||||
|
title: string;
|
||||||
|
subject: string;
|
||||||
|
code: string;
|
||||||
|
due: string;
|
||||||
|
status?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const SKIP_ASSESSMENT_STATUSES = new Set(["MARKS_RELEASED", "CANCELLED"]);
|
||||||
|
|
||||||
const SKIP_TYPES = new Set(["note", "holiday", "assembly-note"]);
|
const SKIP_TYPES = new Set(["note", "holiday", "assembly-note"]);
|
||||||
|
|
||||||
function normalizeTime(value: string): string {
|
function normalizeTime(value: string): string {
|
||||||
@@ -93,6 +105,49 @@ export function mapLessonsToGoogleEvents(
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function assessmentDueDate(due: string): string | null {
|
||||||
|
const trimmed = due.trim();
|
||||||
|
if (/^\d{4}-\d{2}-\d{2}$/.test(trimmed)) return trimmed;
|
||||||
|
const parsed = new Date(trimmed);
|
||||||
|
return Number.isNaN(parsed.getTime()) ? null : toISODate(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function mapAssessmentsToGoogleEvents(
|
||||||
|
origin: string,
|
||||||
|
assessments: CalendarSyncAssessment[],
|
||||||
|
timeZone: string,
|
||||||
|
): GoogleCalendarEventInput[] {
|
||||||
|
const out: GoogleCalendarEventInput[] = [];
|
||||||
|
const seen = new Set<string>();
|
||||||
|
for (const row of assessments) {
|
||||||
|
if (!row.id || !row.title.trim()) continue;
|
||||||
|
if (row.status && SKIP_ASSESSMENT_STATUSES.has(row.status)) continue;
|
||||||
|
const dateOnly = assessmentDueDate(row.due);
|
||||||
|
if (!dateOnly) continue;
|
||||||
|
|
||||||
|
const seqtaKey = `${origin}:assessment:${row.id}`;
|
||||||
|
if (seen.has(seqtaKey)) continue;
|
||||||
|
seen.add(seqtaKey);
|
||||||
|
|
||||||
|
const subject = (row.subject || row.code || "Assessment").trim();
|
||||||
|
const end = new Date(`${dateOnly}T12:00:00`);
|
||||||
|
end.setDate(end.getDate() + 1);
|
||||||
|
|
||||||
|
out.push({
|
||||||
|
seqtaKey,
|
||||||
|
summary: `Due: ${row.title.trim()} (${subject})`,
|
||||||
|
description: ["Synced by BetterSEQTA+", "Type: Assessment due date"].join("\n"),
|
||||||
|
allDay: true,
|
||||||
|
startDate: dateOnly,
|
||||||
|
endDate: toISODate(end),
|
||||||
|
startDateTime: `${dateOnly}T00:00:00`,
|
||||||
|
endDateTime: `${dateOnly}T23:59:00`,
|
||||||
|
timeZone,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
export function googleApiEventBody(event: GoogleCalendarEventInput): Record<string, unknown> {
|
export function googleApiEventBody(event: GoogleCalendarEventInput): Record<string, unknown> {
|
||||||
const start =
|
const start =
|
||||||
event.allDay && event.startDate
|
event.allDay && event.startDate
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
import {
|
|
||||||
shouldSyncAssessment,
|
|
||||||
type CalendarSyncAssessment,
|
|
||||||
} from "@/seqta/utils/googleCalendar/assessmentEventMapper";
|
|
||||||
import { resolveStudentId } from "@/seqta/utils/googleCalendar/fetchTimetable";
|
|
||||||
import { isDateInRange, type SyncDateRange } from "@/seqta/utils/googleCalendar/syncDateRange";
|
|
||||||
import { toISODate } from "@/seqta/utils/Loaders/engageParentTimetable";
|
|
||||||
|
|
||||||
async function postSeqtaJson<T>(path: string, body: Record<string, unknown>): Promise<T> {
|
|
||||||
const res = await fetch(`${location.origin}${path}`, {
|
|
||||||
method: "POST",
|
|
||||||
credentials: "include",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json; charset=utf-8",
|
|
||||||
"X-Requested-With": "XMLHttpRequest",
|
|
||||||
Accept: "text/javascript, text/html, application/xml, text/xml, */*",
|
|
||||||
},
|
|
||||||
body: JSON.stringify(body),
|
|
||||||
});
|
|
||||||
if (!res.ok) {
|
|
||||||
throw new Error(`SEQTA request failed (${res.status})`);
|
|
||||||
}
|
|
||||||
return (await res.json()) as T;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isEngageParentContext(): boolean {
|
|
||||||
return (
|
|
||||||
location.pathname.includes("/parent/") ||
|
|
||||||
location.hash.includes("/parent/") ||
|
|
||||||
document.body.classList.contains("parent")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeDue(raw: Record<string, unknown>): string {
|
|
||||||
const due = raw.due ?? raw.date ?? raw.dueDate;
|
|
||||||
return typeof due === "string" ? due : String(due ?? "");
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseAssessmentRow(raw: unknown): CalendarSyncAssessment | null {
|
|
||||||
if (!raw || typeof raw !== "object") return null;
|
|
||||||
const row = raw as Record<string, unknown>;
|
|
||||||
const id = Number(row.id);
|
|
||||||
const title = String(row.title ?? "").trim();
|
|
||||||
const due = normalizeDue(row);
|
|
||||||
if (!id || !title || !due) return null;
|
|
||||||
|
|
||||||
return {
|
|
||||||
id,
|
|
||||||
title,
|
|
||||||
subject: String(row.subject ?? row.code ?? "").trim(),
|
|
||||||
code: String(row.code ?? row.subject ?? "").trim(),
|
|
||||||
due,
|
|
||||||
status: row.status != null ? String(row.status) : undefined,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function dueDateInRange(due: string, range: SyncDateRange): boolean {
|
|
||||||
const trimmed = due.trim();
|
|
||||||
let datePart = trimmed;
|
|
||||||
if (!/^\d{4}-\d{2}-\d{2}$/.test(trimmed)) {
|
|
||||||
const parsed = new Date(trimmed);
|
|
||||||
if (Number.isNaN(parsed.getTime())) return false;
|
|
||||||
datePart = toISODate(parsed);
|
|
||||||
}
|
|
||||||
return isDateInRange(datePart, range);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchUpcomingAssessments(studentId: number): Promise<CalendarSyncAssessment[]> {
|
|
||||||
const path = isEngageParentContext()
|
|
||||||
? "/seqta/parent/assessment/list/upcoming?"
|
|
||||||
: "/seqta/student/assessment/list/upcoming?";
|
|
||||||
const data = await postSeqtaJson<{ payload?: unknown[] }>(path, { student: studentId });
|
|
||||||
const payload = Array.isArray(data.payload) ? data.payload : [];
|
|
||||||
const out: CalendarSyncAssessment[] = [];
|
|
||||||
for (const raw of payload) {
|
|
||||||
const parsed = parseAssessmentRow(raw);
|
|
||||||
if (parsed) out.push(parsed);
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Upcoming assessments with due dates inside the sync window. */
|
|
||||||
export async function fetchAssessmentsForCalendarSync(
|
|
||||||
range: SyncDateRange,
|
|
||||||
): Promise<CalendarSyncAssessment[]> {
|
|
||||||
try {
|
|
||||||
const studentId = await resolveStudentId();
|
|
||||||
if (studentId == null) return [];
|
|
||||||
|
|
||||||
const upcoming = await fetchUpcomingAssessments(studentId);
|
|
||||||
return upcoming.filter(
|
|
||||||
(a) => shouldSyncAssessment(a) && dueDateInRange(a.due, range),
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
console.warn("[BetterSEQTA+] Assessment calendar fetch failed:", err);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import { toISODate } from "@/seqta/utils/Loaders/engageParentTimetable";
|
||||||
|
import type { CalendarSyncAssessment } from "./eventMapper";
|
||||||
import type { SyncDateRange } from "./syncDateRange";
|
import type { SyncDateRange } from "./syncDateRange";
|
||||||
import { syncWindowRange } from "./syncDateRange";
|
import { isDateInRange, syncWindowRange } from "./syncDateRange";
|
||||||
import type { SeqtaTimetableLesson } from "./types";
|
import type { SeqtaTimetableLesson } from "./types";
|
||||||
|
|
||||||
type PrefItem = { name?: string; value?: string };
|
type PrefItem = { name?: string; value?: string };
|
||||||
@@ -228,3 +230,58 @@ export async function fetchTimetableLessons(
|
|||||||
export async function fetchTimetableForSync(weeksAhead?: number): Promise<SeqtaTimetableLesson[]> {
|
export async function fetchTimetableForSync(weeksAhead?: number): Promise<SeqtaTimetableLesson[]> {
|
||||||
return fetchTimetableLessons(syncWindowRange(weeksAhead));
|
return fetchTimetableLessons(syncWindowRange(weeksAhead));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseAssessmentDue(raw: Record<string, unknown>): string {
|
||||||
|
const due = raw.due ?? raw.date ?? raw.dueDate;
|
||||||
|
return typeof due === "string" ? due : String(due ?? "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function assessmentDueInRange(due: string, range: SyncDateRange): boolean {
|
||||||
|
const trimmed = due.trim();
|
||||||
|
let datePart = trimmed;
|
||||||
|
if (!/^\d{4}-\d{2}-\d{2}$/.test(trimmed)) {
|
||||||
|
const parsed = new Date(trimmed);
|
||||||
|
if (Number.isNaN(parsed.getTime())) return false;
|
||||||
|
datePart = toISODate(parsed);
|
||||||
|
}
|
||||||
|
return isDateInRange(datePart, range);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Upcoming assessments with due dates inside the sync window. */
|
||||||
|
export async function fetchAssessmentsForCalendarSync(
|
||||||
|
range: SyncDateRange,
|
||||||
|
): Promise<CalendarSyncAssessment[]> {
|
||||||
|
try {
|
||||||
|
const studentId = await resolveStudentId();
|
||||||
|
if (studentId == null) return [];
|
||||||
|
|
||||||
|
const path = isEngageParentContext()
|
||||||
|
? "/seqta/parent/assessment/list/upcoming?"
|
||||||
|
: "/seqta/student/assessment/list/upcoming?";
|
||||||
|
const data = await postSeqtaJson<{ payload?: unknown[] }>(path, { student: studentId });
|
||||||
|
const payload = Array.isArray(data.payload) ? data.payload : [];
|
||||||
|
|
||||||
|
const out: CalendarSyncAssessment[] = [];
|
||||||
|
for (const raw of payload) {
|
||||||
|
if (!raw || typeof raw !== "object") continue;
|
||||||
|
const row = raw as Record<string, unknown>;
|
||||||
|
const id = Number(row.id);
|
||||||
|
const title = String(row.title ?? "").trim();
|
||||||
|
const due = parseAssessmentDue(row);
|
||||||
|
if (!id || !title || !due || !assessmentDueInRange(due, range)) continue;
|
||||||
|
if (row.status === "MARKS_RELEASED" || row.status === "CANCELLED") continue;
|
||||||
|
out.push({
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
subject: String(row.subject ?? row.code ?? "").trim(),
|
||||||
|
code: String(row.code ?? row.subject ?? "").trim(),
|
||||||
|
due,
|
||||||
|
status: row.status != null ? String(row.status) : undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("[BetterSEQTA+] Assessment calendar fetch failed:", err);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { CalendarSyncAssessment } from "./assessmentEventMapper";
|
import type { CalendarSyncAssessment } from "./eventMapper";
|
||||||
|
|
||||||
export interface SeqtaTimetableLesson {
|
export interface SeqtaTimetableLesson {
|
||||||
date: string;
|
date: string;
|
||||||
|
|||||||
Reference in new issue
Block a user