mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
fix: keep timetable sharing available when avatar loading fails
This commit is contained in:
1 parent
0b6d01feaa
commit
0eeb10a057
5 files changed
+76
-16
No files matched your search
@@ -5,9 +5,11 @@
|
|||||||
import { loadSession } from "./rosterStore";
|
import { loadSession } from "./rosterStore";
|
||||||
import { openTimetableClassmatesOptInPopup } from "./openTimetableClassmatesPopup";
|
import { openTimetableClassmatesOptInPopup } from "./openTimetableClassmatesPopup";
|
||||||
import { runTimetableClassmatesSync } from "./syncOrchestrator";
|
import { runTimetableClassmatesSync } from "./syncOrchestrator";
|
||||||
|
import { accountsAvailability } from "./accountsAvailability";
|
||||||
|
|
||||||
let rootEl = $state<HTMLDivElement | null>(null);
|
let rootEl = $state<HTMLDivElement | null>(null);
|
||||||
let busy = $state(false);
|
let busy = $state(false);
|
||||||
|
let error = $state("");
|
||||||
|
|
||||||
function syncTheme() {
|
function syncTheme() {
|
||||||
const host = rootEl?.closest(".bsplus-friends-sync-mount");
|
const host = rootEl?.closest(".bsplus-friends-sync-mount");
|
||||||
@@ -15,16 +17,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handleClick() {
|
async function handleClick() {
|
||||||
if (busy) return;
|
if (busy || !$accountsAvailability.available) return;
|
||||||
const session = await loadSession();
|
error = "";
|
||||||
if (!session.syncOptIn) {
|
|
||||||
openTimetableClassmatesOptInPopup({ onAccepted: () => {} });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
busy = true;
|
busy = true;
|
||||||
try {
|
try {
|
||||||
await runTimetableClassmatesSync();
|
const session = await loadSession();
|
||||||
|
if (!session.syncOptIn) {
|
||||||
|
openTimetableClassmatesOptInPopup({ onAccepted: () => {} });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const result = await runTimetableClassmatesSync();
|
||||||
|
if (!result.ok) error = result.error ?? "Sync failed";
|
||||||
|
} catch (err) {
|
||||||
|
error = err instanceof Error ? err.message : "Sync failed";
|
||||||
} finally {
|
} finally {
|
||||||
busy = false;
|
busy = false;
|
||||||
}
|
}
|
||||||
@@ -59,14 +64,17 @@
|
|||||||
type="button"
|
type="button"
|
||||||
class="uiButton bsplus-cal-trigger"
|
class="uiButton bsplus-cal-trigger"
|
||||||
class:bsplus-cal-trigger--busy={busy}
|
class:bsplus-cal-trigger--busy={busy}
|
||||||
disabled={busy}
|
disabled={busy || !$accountsAvailability.available}
|
||||||
aria-busy={busy}
|
aria-busy={busy}
|
||||||
aria-label="Sync with Friends"
|
aria-label={error || $accountsAvailability.message || "Sync with Friends"}
|
||||||
|
title={error || $accountsAvailability.message || "Sync with Friends"}
|
||||||
onclick={() => void handleClick()}
|
onclick={() => void handleClick()}
|
||||||
>
|
>
|
||||||
<span class="bsplus-cal-trigger-content">
|
<span class="bsplus-cal-trigger-content">
|
||||||
<span class="bsplus-cal-trigger-icon iconFamily" aria-hidden="true"></span>
|
<span class="bsplus-cal-trigger-icon iconFamily" aria-hidden="true"></span>
|
||||||
<span class="bsplus-cal-trigger-text">Sync with Friends</span>
|
<span class="bsplus-cal-trigger-text">
|
||||||
|
{busy ? "Syncing…" : error ? "Sync failed" : "Sync with Friends"}
|
||||||
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
import { ACCOUNTS_BASE } from "./constants";
|
import { ACCOUNTS_BASE } from "./constants";
|
||||||
import { markResumeOptInAfterCloudLogin } from "./optInResume";
|
import { markResumeOptInAfterCloudLogin } from "./optInResume";
|
||||||
import { registerOptIn } from "./syncOrchestrator";
|
import { registerOptIn } from "./syncOrchestrator";
|
||||||
|
import { accountsAvailability } from "./accountsAvailability";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onAccepted: () => void | Promise<void>;
|
onAccepted: () => void | Promise<void>;
|
||||||
@@ -48,7 +49,7 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const canSubmit = $derived(agreeShare && agreeJoin && cloudLoggedIn && !busy);
|
const canSubmit = $derived(agreeShare && agreeJoin && cloudLoggedIn && !busy && $accountsAvailability.available);
|
||||||
const checksDisabled = $derived(busy || !cloudLoggedIn);
|
const checksDisabled = $derived(busy || !cloudLoggedIn);
|
||||||
|
|
||||||
async function signInWithCloud() {
|
async function signInWithCloud() {
|
||||||
@@ -113,7 +114,7 @@
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="bsplus-cal-btn bsplus-cal-btn--primary bsplus-tc-cloud-signin"
|
class="bsplus-cal-btn bsplus-cal-btn--primary bsplus-tc-cloud-signin"
|
||||||
disabled={busy}
|
disabled={busy || !$accountsAvailability.available}
|
||||||
onclick={() => void signInWithCloud()}
|
onclick={() => void signInWithCloud()}
|
||||||
>
|
>
|
||||||
Sign in with Cloud
|
Sign in with Cloud
|
||||||
@@ -154,6 +155,10 @@
|
|||||||
<p class="bsplus-tc-error">{error}</p>
|
<p class="bsplus-tc-error">{error}</p>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if $accountsAvailability.message}
|
||||||
|
<p class="bsplus-tc-error" role="status">{$accountsAvailability.message}</p>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class="bsplus-tc-actions">
|
<div class="bsplus-tc-actions">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
import { runTimetableClassmatesSync } from "./syncOrchestrator";
|
import { runTimetableClassmatesSync } from "./syncOrchestrator";
|
||||||
import { loadSession, resolveClassmatesScope } from "./rosterStore";
|
import { loadSession, resolveClassmatesScope } from "./rosterStore";
|
||||||
import { pluginSettingsStore } from "@/interface/pages/settings/pluginSettingsState.svelte";
|
import { pluginSettingsStore } from "@/interface/pages/settings/pluginSettingsState.svelte";
|
||||||
|
import { accountsAvailability } from "./accountsAvailability";
|
||||||
import {
|
import {
|
||||||
openTimetableClassmatesOptInPopup,
|
openTimetableClassmatesOptInPopup,
|
||||||
openTimetableClassmatesOptOutPopup,
|
openTimetableClassmatesOptOutPopup,
|
||||||
@@ -92,11 +93,17 @@
|
|||||||
|
|
||||||
{#if syncOptIn}
|
{#if syncOptIn}
|
||||||
<div class="flex flex-wrap gap-2 justify-end">
|
<div class="flex flex-wrap gap-2 justify-end">
|
||||||
<Button text="Sync now" onClick={() => void syncNow()} disabled={busy} />
|
<Button text="Sync now" onClick={() => void syncNow()} disabled={busy || !$accountsAvailability.available} />
|
||||||
<Button variant="ghost" class="text-red-600 dark:text-red-400" text="Opt out…" onClick={startOptOut} disabled={busy} />
|
<Button variant="ghost" class="text-red-600 dark:text-red-400" text="Opt out…" onClick={startOptOut} disabled={busy} />
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<Button text="Opt in…" onClick={startOptIn} disabled={busy} />
|
<Button text="Opt in…" onClick={startOptIn} disabled={busy || !$accountsAvailability.available} />
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if $accountsAvailability.message}
|
||||||
|
<p class="text-xs text-right text-zinc-500 dark:text-zinc-400" role="status">
|
||||||
|
{$accountsAvailability.message}
|
||||||
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if error}
|
{#if error}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { readable } from "svelte/store";
|
||||||
|
import { ACCOUNTS_BASE } from "./constants";
|
||||||
|
|
||||||
|
export const accountsAvailability = readable(
|
||||||
|
{ available: false, message: "Checking BetterSEQTA Cloud…" },
|
||||||
|
(set) => {
|
||||||
|
let checking = false;
|
||||||
|
let stopped = false;
|
||||||
|
async function check() {
|
||||||
|
if (checking) return;
|
||||||
|
checking = true;
|
||||||
|
let available = false;
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${ACCOUNTS_BASE}/api/health`, {
|
||||||
|
cache: "no-store",
|
||||||
|
credentials: "omit",
|
||||||
|
signal: AbortSignal.timeout(5_000),
|
||||||
|
});
|
||||||
|
const health = await response.json();
|
||||||
|
available = response.ok && health?.ok === true && health?.service === "accounts";
|
||||||
|
} catch {
|
||||||
|
/* Network errors and timeouts leave the service unavailable. */
|
||||||
|
}
|
||||||
|
checking = false;
|
||||||
|
if (stopped) return;
|
||||||
|
set({
|
||||||
|
available,
|
||||||
|
message: available ? "" : "BetterSEQTA Cloud is unavailable. Retrying automatically.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void check();
|
||||||
|
const timer = window.setInterval(check, 60_000);
|
||||||
|
window.addEventListener("online", check);
|
||||||
|
return () => {
|
||||||
|
stopped = true;
|
||||||
|
window.clearInterval(timer);
|
||||||
|
window.removeEventListener("online", check);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
);
|
||||||
@@ -139,7 +139,6 @@ const timetableClassmatesPlugin: Plugin<typeof timetableClassmatesSettings> = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
schedulePaint();
|
schedulePaint();
|
||||||
await paintTimetable();
|
|
||||||
void mountClassmatesToolbarChip();
|
void mountClassmatesToolbarChip();
|
||||||
|
|
||||||
if (page && !gridObserver) {
|
if (page && !gridObserver) {
|
||||||
|
|||||||
Reference in new issue
Block a user