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,
|
||||
} from "@/seqta/ui/sidebar/sidebarStyles";
|
||||
|
||||
let { showStylePreview = true }: { showStylePreview?: boolean } = $props();
|
||||
|
||||
const PREVIEW_ITEMS = [
|
||||
{ label: "Home", active: true },
|
||||
{ label: "Timetable", active: false },
|
||||
@@ -69,22 +67,20 @@
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="picker-body" class:picker-body-no-preview={!showStylePreview}>
|
||||
{#if showStylePreview}
|
||||
<div class="preview-pane" aria-hidden="true">
|
||||
<div class={`preview style-${selectedId}`}>
|
||||
<div class="preview-chrome">
|
||||
<div class="preview-logo"></div>
|
||||
{#each PREVIEW_ITEMS as item (item.label)}
|
||||
<div class="preview-item" class:active={item.active}>
|
||||
<span class="preview-dot"></span>
|
||||
<span class="preview-label">{item.label}</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
<div class="picker-body">
|
||||
<div class="preview-pane" aria-hidden="true">
|
||||
<div class={`preview style-${selectedId}`}>
|
||||
<div class="preview-chrome">
|
||||
<div class="preview-logo"></div>
|
||||
{#each PREVIEW_ITEMS as item (item.label)}
|
||||
<div class="preview-item" class:active={item.active}>
|
||||
<span class="preview-dot"></span>
|
||||
<span class="preview-label">{item.label}</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="options"
|
||||
@@ -323,10 +319,6 @@
|
||||
padding: 0.5rem 1rem 1rem;
|
||||
}
|
||||
|
||||
.picker-body-no-preview {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.picker-body {
|
||||
grid-template-columns: 1fr;
|
||||
|
||||
@@ -7,16 +7,6 @@
|
||||
let { communityState, searchTerm }: { communityState: CommunityThemesState; searchTerm: string } =
|
||||
$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>
|
||||
|
||||
{#if communityState.browseLoading}
|
||||
@@ -39,7 +29,7 @@
|
||||
</div>
|
||||
{:else}
|
||||
<ThemeGrid
|
||||
{themes}
|
||||
themes={communityState.browseThemes}
|
||||
{searchTerm}
|
||||
setDisplayTheme={(theme) => (communityState.displayTheme = theme)}
|
||||
toggleFavorite={() => {}}
|
||||
@@ -50,7 +40,7 @@
|
||||
{#if communityState.displayTheme}
|
||||
<ThemeModal
|
||||
currentThemes={communityState.currentThemes}
|
||||
allThemes={themes}
|
||||
allThemes={communityState.browseThemes}
|
||||
theme={communityState.displayTheme}
|
||||
displayTheme={communityState.displayTheme}
|
||||
setDisplayTheme={(t) => (communityState.displayTheme = t)}
|
||||
|
||||
@@ -33,13 +33,6 @@
|
||||
}));
|
||||
|
||||
const isCommunity = $derived(variant === 'community');
|
||||
const hasSearchQuery = $derived(searchTerm.trim().length > 0);
|
||||
|
||||
function openCommunityThemeBuilder() {
|
||||
void import('@/seqta/utils/launchPageThemeBuilder').then(({ launchPageThemeBuilder }) =>
|
||||
launchPageThemeBuilder(),
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="relative">
|
||||
@@ -59,30 +52,15 @@
|
||||
{/each}
|
||||
</div>
|
||||
{:else if isCommunity}
|
||||
<div class="mx-auto flex max-w-lg flex-col items-center justify-center py-24 text-center">
|
||||
{#if hasSearchQuery}
|
||||
<h2 class="text-xl font-semibold text-zinc-900 dark:text-white" style="text-wrap: balance">
|
||||
No themes match your search
|
||||
</h2>
|
||||
<p class="mt-2 text-base text-zinc-500 dark:text-zinc-400" style="text-wrap: pretty">
|
||||
Try another name or keyword, or clear the search box to browse all approved community themes.
|
||||
</p>
|
||||
{:else}
|
||||
<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 class="mx-auto max-w-md py-24 text-center text-zinc-500 dark:text-zinc-400">
|
||||
<p class="text-lg font-medium text-zinc-900 dark:text-white">
|
||||
{searchTerm.trim() ? "No themes match your search" : "No community themes yet"}
|
||||
</p>
|
||||
<p class="mt-2 text-sm">
|
||||
{searchTerm.trim()
|
||||
? "Try a different search or clear the box."
|
||||
: "Approved submissions show up here. Use Create & submit above to share yours."}
|
||||
</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="absolute top-0 flex h-96 w-full flex-col items-center justify-center text-center">
|
||||
|
||||
@@ -633,7 +633,7 @@
|
||||
<Divider />
|
||||
|
||||
<div class="theme-creator-sidebar -mx-2">
|
||||
<SidebarAppearance showStylePreview={false} />
|
||||
<SidebarAppearance />
|
||||
</div>
|
||||
|
||||
<Divider />
|
||||
@@ -721,4 +721,13 @@
|
||||
{/if}
|
||||
</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>
|
||||
{:else}
|
||||
<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>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -181,8 +181,7 @@
|
||||
{editingId ? "Edit combined classes" : "Combine classes"}
|
||||
</h2>
|
||||
<p class="bsplus-analytics-class-groups-dialog-desc">
|
||||
Pick two or more classes from any year — useful when your school splits a subject by
|
||||
year. Same class list as Courses.
|
||||
Pick classes from any year (same list as Courses).
|
||||
</p>
|
||||
</div>
|
||||
<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 {
|
||||
resolveGradeFromAssessmentPayload,
|
||||
|
||||
@@ -600,10 +600,7 @@
|
||||
>
|
||||
<div class="bsplus-cal-menu-header">
|
||||
<span class="bsplus-cal-menu-title">Calendar sync</span>
|
||||
<span class="bsplus-cal-menu-sub"
|
||||
>Copy your SEQTA classes, appointments, and optional assessment due dates to Google or
|
||||
Outlook</span
|
||||
>
|
||||
<span class="bsplus-cal-menu-sub">Sync classes and optional assessment due dates to Google or Outlook</span>
|
||||
</div>
|
||||
|
||||
{@render providerPanel(
|
||||
@@ -658,10 +655,7 @@
|
||||
<label class="bsplus-cal-setting bsplus-cal-setting--toggle">
|
||||
<div class="bsplus-cal-setting-copy">
|
||||
<span class="bsplus-cal-setting-label">Sync assessment due dates</span>
|
||||
<span class="bsplus-cal-setting-desc">
|
||||
Add upcoming assessment due dates from SEQTA using the same weeks window. Run Update
|
||||
calendar after enabling to backfill.
|
||||
</span>
|
||||
<span class="bsplus-cal-setting-desc">Uses the same weeks window. Update calendar once after enabling.</span>
|
||||
</div>
|
||||
<input
|
||||
type="checkbox"
|
||||
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
import {
|
||||
buildLessonSyncResult,
|
||||
collectOriginDeleteEntries,
|
||||
assessmentEntriesToRemove,
|
||||
entriesToPrune,
|
||||
formatLessonSyncResultMessage,
|
||||
mapPool,
|
||||
@@ -121,30 +120,12 @@ describe("entriesToPrune", () => {
|
||||
"full",
|
||||
weeksAhead,
|
||||
new Set(),
|
||||
{ syncAssessmentDueDates: false },
|
||||
false,
|
||||
);
|
||||
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", () => {
|
||||
const origin = "https://school.seqta.com.au";
|
||||
const mapKey = (o: string, seqtaKey: string) => `${o}::${seqtaKey}`;
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
} from "@/seqta/utils/calendarSync/eventMap";
|
||||
import { eventFingerprint } from "@/seqta/utils/calendarSync/eventFingerprint";
|
||||
import type { RemoteSyncedEvent } from "@/seqta/utils/calendarSync/remoteEvents";
|
||||
import { isAssessmentSeqtaKey } from "@/seqta/utils/googleCalendar/assessmentEventMapper";
|
||||
import {
|
||||
isDateInRange,
|
||||
syncWindowRange,
|
||||
@@ -86,31 +85,24 @@ export function originEventMapEntries(
|
||||
return entries;
|
||||
}
|
||||
|
||||
export type EntriesToPruneOptions = {
|
||||
/** When false, assessment events are not pruned here (use assessmentEntriesToRemove). */
|
||||
syncAssessmentDueDates?: boolean;
|
||||
};
|
||||
|
||||
export function entriesToPrune(
|
||||
eventMap: EventMapRecord,
|
||||
origin: string,
|
||||
mode: "full" | "incremental",
|
||||
weeksAhead: number,
|
||||
currentMapKeys: Set<string>,
|
||||
options: EntriesToPruneOptions = {},
|
||||
syncAssessmentDueDates = false,
|
||||
): Array<[string, string]> {
|
||||
if (mode === "incremental") return [];
|
||||
|
||||
const syncAssessments = options.syncAssessmentDueDates === true;
|
||||
const syncAssessments = syncAssessmentDueDates;
|
||||
const window = syncWindowRange(weeksAhead);
|
||||
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);
|
||||
const isAssessment = isAssessmentSeqtaKey(seqtaKey);
|
||||
if (isAssessment && !syncAssessments) continue;
|
||||
if (!syncAssessments && mapKey.includes(":assessment:")) continue;
|
||||
|
||||
const entry = normalizeEventMapEntry(raw);
|
||||
if (!entry) continue;
|
||||
@@ -124,26 +116,6 @@ export function entriesToPrune(
|
||||
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). */
|
||||
export function mergeRemoteEventsIntoMap(
|
||||
eventMap: EventMapRecord,
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { isGoogleCalendarConfigured } from "@/config/googleCalendar";
|
||||
import { isOutlookCalendarConfigured } from "@/config/outlookCalendar";
|
||||
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 {
|
||||
assessmentEntriesToRemove,
|
||||
buildDeleteSyncResult,
|
||||
buildLessonSyncResult,
|
||||
clearOriginEventMapEntries,
|
||||
@@ -19,7 +18,7 @@ import {
|
||||
reportSyncProgress,
|
||||
upsertLessonEvents,
|
||||
} from "@/seqta/utils/calendarSync/lessonSyncShared";
|
||||
import { mapAssessmentsToGoogleEvents } from "@/seqta/utils/googleCalendar/assessmentEventMapper";
|
||||
import { mapAssessmentsToGoogleEvents } from "@/seqta/utils/googleCalendar/eventMapper";
|
||||
import {
|
||||
deleteGoogleCalendarEvent,
|
||||
deleteOutlookCalendarEvent,
|
||||
@@ -219,10 +218,15 @@ export async function syncLessonsToCalendar(
|
||||
mode,
|
||||
weeksAhead,
|
||||
currentMapKeys,
|
||||
{ syncAssessmentDueDates },
|
||||
syncAssessmentDueDates,
|
||||
);
|
||||
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 lastSyncAt = Date.now();
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
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 {
|
||||
googleLessonSyncProvider,
|
||||
@@ -19,7 +23,6 @@ import {
|
||||
getSyncWeeksAhead,
|
||||
readResumableCalendarSync,
|
||||
} from "@/seqta/utils/calendarSync/settings";
|
||||
import { fetchAssessmentsForCalendarSync } from "@/seqta/utils/googleCalendar/fetchAssessmentsForCalendarSync";
|
||||
import type {
|
||||
GoogleCalendarStatus,
|
||||
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 {
|
||||
googleApiEventBody,
|
||||
lessonToGoogleEvent,
|
||||
mapAssessmentsToGoogleEvents,
|
||||
mapLessonsToGoogleEvents,
|
||||
outlookGraphEventBody,
|
||||
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", () => {
|
||||
it("embeds Key: seqtaKey in the body for remote reconcile", () => {
|
||||
const event = lessonToGoogleEvent(ORIGIN, baseLesson, "Australia/Perth");
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
import { BSPLUS_GOOGLE_CALENDAR_EVENT_PROP } from "@/config/googleCalendar";
|
||||
import { BSPLUS_OUTLOOK_CALENDAR_EVENT_CATEGORY } from "@/config/outlookCalendar";
|
||||
import { outlookDescriptionWithKey } from "@/seqta/utils/calendarSync/eventFingerprint";
|
||||
import { toISODate } from "@/seqta/utils/Loaders/engageParentTimetable";
|
||||
import { nearestGoogleEventColorId } from "./eventColor";
|
||||
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"]);
|
||||
|
||||
function normalizeTime(value: string): string {
|
||||
@@ -93,6 +105,49 @@ export function mapLessonsToGoogleEvents(
|
||||
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> {
|
||||
const start =
|
||||
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 { syncWindowRange } from "./syncDateRange";
|
||||
import { isDateInRange, syncWindowRange } from "./syncDateRange";
|
||||
import type { SeqtaTimetableLesson } from "./types";
|
||||
|
||||
type PrefItem = { name?: string; value?: string };
|
||||
@@ -228,3 +230,58 @@ export async function fetchTimetableLessons(
|
||||
export async function fetchTimetableForSync(weeksAhead?: number): Promise<SeqtaTimetableLesson[]> {
|
||||
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 {
|
||||
date: string;
|
||||
|
||||
Reference in new issue
Block a user