mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
feat: improve and add timetable pill to sync with friends
This commit is contained in:
1 parent
b3b3763fc8
commit
9e16eaa543
11 files changed
+511
-34
No files matched your search
@@ -0,0 +1,72 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
|
||||||
|
import { syncCalendarSyncTheme } from "@/plugins/built-in/timetable/calendarSyncUi";
|
||||||
|
import { loadSession } from "./rosterStore";
|
||||||
|
import { openTimetableClassmatesOptInPopup } from "./openTimetableClassmatesPopup";
|
||||||
|
import { runTimetableClassmatesSync } from "./syncOrchestrator";
|
||||||
|
|
||||||
|
let rootEl = $state<HTMLDivElement | null>(null);
|
||||||
|
let busy = $state(false);
|
||||||
|
|
||||||
|
function syncTheme() {
|
||||||
|
const host = rootEl?.closest(".bsplus-friends-sync-mount");
|
||||||
|
if (host instanceof HTMLElement) syncCalendarSyncTheme(host);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleClick() {
|
||||||
|
if (busy) return;
|
||||||
|
const session = await loadSession();
|
||||||
|
if (!session.syncOptIn) {
|
||||||
|
openTimetableClassmatesOptInPopup({ onAccepted: () => {} });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
busy = true;
|
||||||
|
try {
|
||||||
|
await runTimetableClassmatesSync();
|
||||||
|
} finally {
|
||||||
|
busy = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
const themeKeys = ["selectedColor", "selectedFont", "DarkMode", "adaptiveThemeColour"] as const;
|
||||||
|
const onThemeChange = () => syncTheme();
|
||||||
|
for (const key of themeKeys) {
|
||||||
|
settingsState.register(key, onThemeChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
const themeObserver = new MutationObserver(onThemeChange);
|
||||||
|
themeObserver.observe(document.documentElement, {
|
||||||
|
attributes: true,
|
||||||
|
attributeFilter: ["style", "class"],
|
||||||
|
});
|
||||||
|
|
||||||
|
syncTheme();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
for (const key of themeKeys) {
|
||||||
|
settingsState.unregister(key, onThemeChange);
|
||||||
|
}
|
||||||
|
themeObserver.disconnect();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="bsplus-friends-sync" bind:this={rootEl}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="uiButton bsplus-cal-trigger"
|
||||||
|
class:bsplus-cal-trigger--busy={busy}
|
||||||
|
disabled={busy}
|
||||||
|
aria-busy={busy}
|
||||||
|
aria-label="Sync with Friends"
|
||||||
|
onclick={() => void handleClick()}
|
||||||
|
>
|
||||||
|
<span class="bsplus-cal-trigger-content">
|
||||||
|
<span class="bsplus-cal-trigger-icon iconFamily" aria-hidden="true"></span>
|
||||||
|
<span class="bsplus-cal-trigger-text">Sync with Friends</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { cloudAuth } from "@/seqta/utils/CloudAuth";
|
import CloudPfpAvatar from "@/interface/components/CloudPfpAvatar.svelte";
|
||||||
|
import { cloudAuth, type CloudUser } from "@/seqta/utils/CloudAuth";
|
||||||
import { ACCOUNTS_BASE } from "./constants";
|
import { ACCOUNTS_BASE } from "./constants";
|
||||||
|
import { markResumeOptInAfterCloudLogin } from "./optInResume";
|
||||||
import { registerOptIn } from "./syncOrchestrator";
|
import { registerOptIn } from "./syncOrchestrator";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -17,17 +19,35 @@
|
|||||||
let busy = $state(false);
|
let busy = $state(false);
|
||||||
let error = $state("");
|
let error = $state("");
|
||||||
let cloudLoggedIn = $state(cloudAuth.state.isLoggedIn);
|
let cloudLoggedIn = $state(cloudAuth.state.isLoggedIn);
|
||||||
let cloudName = $state(
|
let cloudUser = $state<CloudUser | null>(cloudAuth.state.user);
|
||||||
cloudAuth.state.user?.displayName ?? cloudAuth.state.user?.username ?? "",
|
|
||||||
);
|
|
||||||
|
|
||||||
onMount(() =>
|
onMount(() =>
|
||||||
cloudAuth.subscribe((s) => {
|
cloudAuth.subscribe((s) => {
|
||||||
cloudLoggedIn = s.isLoggedIn;
|
cloudLoggedIn = s.isLoggedIn;
|
||||||
cloudName = s.user?.displayName ?? s.user?.username ?? "";
|
cloudUser = s.user;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function cloudInitials(user: CloudUser | null | undefined): string {
|
||||||
|
if (!user) return "?";
|
||||||
|
if (user.displayName) return user.displayName.slice(0, 2).toUpperCase();
|
||||||
|
if (user.username) return user.username.slice(0, 2).toUpperCase();
|
||||||
|
if (user.email) return user.email.slice(0, 2).toUpperCase();
|
||||||
|
return "?";
|
||||||
|
}
|
||||||
|
|
||||||
|
function cloudDisplayName(user: CloudUser | null | undefined): string {
|
||||||
|
if (!user) return "Cloud account";
|
||||||
|
return user.displayName || user.username || user.email || "Cloud account";
|
||||||
|
}
|
||||||
|
|
||||||
|
function cloudSubtitle(user: CloudUser | null | undefined): string | null {
|
||||||
|
if (!user) return null;
|
||||||
|
if (user.username) return `@${user.username}`;
|
||||||
|
if (user.email) return user.email;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const canSubmit = $derived(agreeShare && agreeJoin && cloudLoggedIn && !busy);
|
const canSubmit = $derived(agreeShare && agreeJoin && cloudLoggedIn && !busy);
|
||||||
const checksDisabled = $derived(busy || !cloudLoggedIn);
|
const checksDisabled = $derived(busy || !cloudLoggedIn);
|
||||||
|
|
||||||
@@ -36,7 +56,11 @@
|
|||||||
error = "";
|
error = "";
|
||||||
try {
|
try {
|
||||||
const res = await cloudAuth.startLogin();
|
const res = await cloudAuth.startLogin();
|
||||||
if (!res.success) error = res.error ?? "Could not open sign-in.";
|
if (!res.success) {
|
||||||
|
error = res.error ?? "Could not open sign-in.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
markResumeOptInAfterCloudLogin();
|
||||||
} finally {
|
} finally {
|
||||||
busy = false;
|
busy = false;
|
||||||
}
|
}
|
||||||
@@ -66,21 +90,33 @@
|
|||||||
<div class="bsplus-tc-popup">
|
<div class="bsplus-tc-popup">
|
||||||
<section class="bsplus-tc-card bsplus-tc-cloud" aria-labelledby="bsplus-tc-cloud-heading">
|
<section class="bsplus-tc-card bsplus-tc-cloud" aria-labelledby="bsplus-tc-cloud-heading">
|
||||||
<h2 id="bsplus-tc-cloud-heading">BetterSEQTA Cloud</h2>
|
<h2 id="bsplus-tc-cloud-heading">BetterSEQTA Cloud</h2>
|
||||||
{#if cloudLoggedIn}
|
|
||||||
<p class="bsplus-tc-cloud-ok">
|
{#if cloudLoggedIn && cloudUser}
|
||||||
Signed in{cloudName ? ` as ${cloudName}` : ""}. We link this account to your SEQTA student id
|
<div class="bsplus-tc-cloud-user" role="status">
|
||||||
on this site.
|
<div class="bsplus-tc-cloud-avatar" aria-hidden="true">
|
||||||
</p>
|
<span class="bsplus-tc-cloud-avatar-fallback">{cloudInitials(cloudUser)}</span>
|
||||||
|
<CloudPfpAvatar user={cloudUser} class="bsplus-tc-cloud-avatar-img" />
|
||||||
|
</div>
|
||||||
|
<div class="bsplus-tc-cloud-user-meta">
|
||||||
|
<span class="bsplus-tc-cloud-user-name">{cloudDisplayName(cloudUser)}</span>
|
||||||
|
{#if cloudSubtitle(cloudUser)}
|
||||||
|
<span class="bsplus-tc-cloud-user-sub">{cloudSubtitle(cloudUser)}</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<span class="bsplus-tc-cloud-check iconFamily" aria-hidden="true"></span>
|
||||||
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<p class="bsplus-tc-muted">Sign in with a free cloud account to join your school phonebook.</p>
|
<p class="bsplus-tc-cloud-lead">
|
||||||
|
Sign in with your free cloud account to join your school's classmate phonebook.
|
||||||
|
</p>
|
||||||
<div class="bsplus-tc-cloud-actions">
|
<div class="bsplus-tc-cloud-actions">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="bsplus-cal-btn bsplus-cal-btn--primary"
|
class="bsplus-cal-btn bsplus-cal-btn--primary bsplus-tc-cloud-signin"
|
||||||
disabled={busy}
|
disabled={busy}
|
||||||
onclick={() => void signInWithCloud()}
|
onclick={() => void signInWithCloud()}
|
||||||
>
|
>
|
||||||
Sign in
|
Sign in with Cloud
|
||||||
</button>
|
</button>
|
||||||
<a
|
<a
|
||||||
class="bsplus-tc-link"
|
class="bsplus-tc-link"
|
||||||
@@ -88,7 +124,7 @@
|
|||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
>
|
>
|
||||||
Create account
|
Create free account
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
.timetable-classmates-controls {
|
||||||
|
position: relative;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-friends-sync-mount {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-friends-sync {
|
||||||
|
position: relative;
|
||||||
|
display: inline-flex;
|
||||||
|
font-family: var(--bsplus-cal-font-family, var(--betterseqta-font-family, Rubik), sans-serif);
|
||||||
|
color: var(--bsplus-cal-text, var(--text-primary, #111));
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-friends-sync .bsplus-cal-trigger {
|
||||||
|
position: relative;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 6px;
|
||||||
|
min-width: auto;
|
||||||
|
height: auto;
|
||||||
|
padding: 0 10px;
|
||||||
|
margin: 0;
|
||||||
|
border-radius: 16px !important;
|
||||||
|
font-family: inherit;
|
||||||
|
background: var(--bsplus-cal-surface, var(--background-primary, #232323)) !important;
|
||||||
|
transition:
|
||||||
|
transform 0.2s ease,
|
||||||
|
opacity 0.2s ease,
|
||||||
|
background-color 0.2s ease;
|
||||||
|
overflow: hidden;
|
||||||
|
isolation: isolate;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-friends-sync .bsplus-cal-trigger-content {
|
||||||
|
position: relative;
|
||||||
|
z-index: 1;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-friends-sync .bsplus-cal-trigger-icon {
|
||||||
|
font-family: "IconFamily" !important;
|
||||||
|
font-size: 16px;
|
||||||
|
line-height: 1;
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-friends-sync .bsplus-cal-trigger-text {
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-friends-sync .bsplus-cal-trigger:hover:not(:disabled) {
|
||||||
|
transform: scale(1.03);
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-friends-sync .bsplus-cal-trigger:active:not(:disabled) {
|
||||||
|
transform: scale(0.97);
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-friends-sync .bsplus-cal-trigger--busy {
|
||||||
|
opacity: 0.95;
|
||||||
|
cursor: wait;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-friends-sync .bsplus-cal-trigger--busy:hover,
|
||||||
|
.bsplus-friends-sync .bsplus-cal-trigger--busy:active {
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { mount, unmount } from "svelte";
|
||||||
|
import { syncCalendarSyncTheme } from "@/plugins/built-in/timetable/calendarSyncUi";
|
||||||
|
import chipStyles from "./classmatesToolbarChip.css?inline";
|
||||||
|
|
||||||
|
const CONTROLS_CLASS = "timetable-classmates-controls";
|
||||||
|
const HOST_STYLE_ID = "bsplus-timetable-classmates-chip-styles";
|
||||||
|
|
||||||
|
let currentApp: ReturnType<typeof mount> | null = null;
|
||||||
|
|
||||||
|
function ensureHostStyles() {
|
||||||
|
if (document.getElementById(HOST_STYLE_ID)) return;
|
||||||
|
const style = document.createElement("style");
|
||||||
|
style.id = HOST_STYLE_ID;
|
||||||
|
style.textContent = chipStyles;
|
||||||
|
document.head.appendChild(style);
|
||||||
|
}
|
||||||
|
|
||||||
|
function teardown() {
|
||||||
|
if (currentApp) {
|
||||||
|
unmount(currentApp);
|
||||||
|
currentApp = null;
|
||||||
|
}
|
||||||
|
document.querySelector(`.${CONTROLS_CLASS}`)?.remove();
|
||||||
|
document.getElementById(HOST_STYLE_ID)?.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertControls(toolbar: HTMLElement, controls: HTMLElement) {
|
||||||
|
const calendar = toolbar.querySelector(".timetable-calendar-controls");
|
||||||
|
const zoomControls = toolbar.querySelector(".timetable-zoom-controls");
|
||||||
|
if (calendar?.nextSibling) {
|
||||||
|
toolbar.insertBefore(controls, calendar.nextSibling);
|
||||||
|
} else if (zoomControls) {
|
||||||
|
toolbar.insertBefore(controls, zoomControls);
|
||||||
|
} else {
|
||||||
|
toolbar.appendChild(controls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function mountClassmatesToolbarChip(): Promise<void> {
|
||||||
|
if (document.querySelector(`.${CONTROLS_CLASS}`)) return;
|
||||||
|
|
||||||
|
const toolbar = document.getElementById("toolbar");
|
||||||
|
if (!toolbar) return;
|
||||||
|
|
||||||
|
ensureHostStyles();
|
||||||
|
|
||||||
|
const controls = document.createElement("div");
|
||||||
|
controls.className = CONTROLS_CLASS;
|
||||||
|
insertControls(toolbar, controls);
|
||||||
|
|
||||||
|
const mountRoot = document.createElement("div");
|
||||||
|
mountRoot.className = "bsplus-friends-sync-mount";
|
||||||
|
syncCalendarSyncTheme(mountRoot);
|
||||||
|
controls.appendChild(mountRoot);
|
||||||
|
|
||||||
|
const { default: ClassmatesToolbarChip } = await import("./ClassmatesToolbarChip.svelte");
|
||||||
|
currentApp = mount(ClassmatesToolbarChip, { target: mountRoot });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function unmountClassmatesToolbarChip(): void {
|
||||||
|
teardown();
|
||||||
|
}
|
||||||
@@ -28,36 +28,124 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.bsplus-tc-cloud {
|
.bsplus-tc-cloud {
|
||||||
border-color: color-mix(in srgb, var(--tc-accent) 40%, transparent);
|
border-color: color-mix(in srgb, var(--tc-accent) 35%, transparent);
|
||||||
background: color-mix(in srgb, var(--tc-accent) 10%, transparent);
|
background: linear-gradient(
|
||||||
|
145deg,
|
||||||
|
color-mix(in srgb, var(--tc-accent) 14%, transparent),
|
||||||
|
color-mix(in srgb, var(--tc-accent) 5%, transparent)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
.bsplus-tc-cloud h2 {
|
.bsplus-tc-cloud h2 {
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
margin: 0 0 0.35rem;
|
margin: 0 0 0.65rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bsplus-tc-cloud p {
|
.bsplus-tc-cloud p {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bsplus-tc-cloud-ok {
|
.bsplus-tc-cloud-user {
|
||||||
color: color-mix(in srgb, #4ade80 88%, currentColor);
|
display: flex;
|
||||||
font-weight: 500;
|
align-items: center;
|
||||||
|
gap: 0.75rem;
|
||||||
|
padding: 0.65rem 0.75rem;
|
||||||
|
border-radius: 0.65rem;
|
||||||
|
background: color-mix(in srgb, currentColor 5%, transparent);
|
||||||
|
border: 1px solid var(--tc-edge);
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-tc-cloud-avatar {
|
||||||
|
position: relative;
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 2.75rem;
|
||||||
|
height: 2.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-tc-cloud-avatar-fallback,
|
||||||
|
.bsplus-tc-cloud-avatar-img {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 50%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-tc-cloud-avatar-fallback {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.03em;
|
||||||
|
color: color-mix(in srgb, var(--tc-accent) 70%, currentColor);
|
||||||
|
background: color-mix(in srgb, var(--tc-accent) 22%, transparent);
|
||||||
|
border: 1px solid color-mix(in srgb, var(--tc-accent) 35%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-tc-cloud-user-meta {
|
||||||
|
min-width: 0;
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-tc-cloud-user-name {
|
||||||
|
font-size: 0.95rem;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.25;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-tc-cloud-user-sub {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
opacity: 0.72;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-tc-cloud-check {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: 1.35rem;
|
||||||
|
line-height: 1;
|
||||||
|
color: color-mix(in srgb, #4ade80 90%, currentColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-tc-cloud-lead {
|
||||||
|
margin: 0 0 0.75rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
line-height: 1.45;
|
||||||
|
opacity: 0.88;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bsplus-tc-cloud-actions {
|
.bsplus-tc-cloud-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: stretch;
|
||||||
gap: 0.65rem;
|
gap: 0.55rem;
|
||||||
margin-top: 0.5rem;
|
}
|
||||||
|
|
||||||
|
.bsplus-tc-cloud-signin {
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bsplus-tc-link {
|
.bsplus-tc-link {
|
||||||
font-size: 0.9rem;
|
font-size: 0.88rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
text-align: center;
|
||||||
|
text-decoration: none;
|
||||||
|
opacity: 0.85;
|
||||||
|
transition: opacity 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-tc-link:hover {
|
||||||
|
opacity: 1;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
text-underline-offset: 2px;
|
text-underline-offset: 2px;
|
||||||
}
|
}
|
||||||
@@ -123,6 +211,36 @@
|
|||||||
|
|
||||||
.bsplus-timetable-classmates-popup-host .bsplus-cal-btn {
|
.bsplus-timetable-classmates-popup-host .bsplus-cal-btn {
|
||||||
min-width: 7.5rem;
|
min-width: 7.5rem;
|
||||||
|
padding: 0.5rem 0.9rem;
|
||||||
|
border: none;
|
||||||
|
border-radius: 0.55rem;
|
||||||
|
font-size: 0.88rem;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-timetable-classmates-popup-host .bsplus-cal-btn:disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-timetable-classmates-popup-host .bsplus-cal-btn--primary {
|
||||||
|
background: var(--tc-accent);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-timetable-classmates-popup-host .bsplus-cal-btn--primary:hover:not(:disabled) {
|
||||||
|
filter: brightness(1.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-timetable-classmates-popup-host .bsplus-cal-btn--ghost {
|
||||||
|
background: color-mix(in srgb, currentColor 8%, transparent);
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bsplus-timetable-classmates-popup-host .bsplus-cal-btn--ghost:hover:not(:disabled) {
|
||||||
|
background: color-mix(in srgb, currentColor 14%, transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.bsplus-timetable-classmates-popup-host .bsplus-cal-btn--danger {
|
.bsplus-timetable-classmates-popup-host .bsplus-cal-btn--danger {
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ import { peerCloudIdsForPaint } from "./accountsClient";
|
|||||||
import { fetchSchoolYearEnrollmentSnapshot } from "./timetableYearSnapshot";
|
import { fetchSchoolYearEnrollmentSnapshot } from "./timetableYearSnapshot";
|
||||||
import { CLASSMATES_TIMETABLE_POLL_MS } from "./constants";
|
import { CLASSMATES_TIMETABLE_POLL_MS } from "./constants";
|
||||||
import { scheduleClassmatesSyncIfNeeded } from "./syncOrchestrator";
|
import { scheduleClassmatesSyncIfNeeded } from "./syncOrchestrator";
|
||||||
|
import {
|
||||||
|
mountClassmatesToolbarChip,
|
||||||
|
unmountClassmatesToolbarChip,
|
||||||
|
} from "./classmatesToolbarUi";
|
||||||
|
import { maybeResumeTimetableClassmatesOptInPopup } from "./openTimetableClassmatesPopup";
|
||||||
|
|
||||||
const timetableClassmatesPlugin: Plugin<typeof timetableClassmatesSettings> = {
|
const timetableClassmatesPlugin: Plugin<typeof timetableClassmatesSettings> = {
|
||||||
id: "timetable-classmates",
|
id: "timetable-classmates",
|
||||||
@@ -38,6 +43,7 @@ const timetableClassmatesPlugin: Plugin<typeof timetableClassmatesSettings> = {
|
|||||||
run: async (api) => {
|
run: async (api) => {
|
||||||
if (isPluginBlockedByPerformanceMode("timetable-classmates")) return () => {};
|
if (isPluginBlockedByPerformanceMode("timetable-classmates")) return () => {};
|
||||||
await Promise.all([api.storage.loaded, api.settings.loaded]);
|
await Promise.all([api.storage.loaded, api.settings.loaded]);
|
||||||
|
void maybeResumeTimetableClassmatesOptInPopup();
|
||||||
|
|
||||||
const onSyncMessage = (request: { type?: string }) => {
|
const onSyncMessage = (request: { type?: string }) => {
|
||||||
if (request?.type === "timetableClassmatesSync") scheduleClassmatesSyncIfNeeded();
|
if (request?.type === "timetableClassmatesSync") scheduleClassmatesSyncIfNeeded();
|
||||||
@@ -134,6 +140,7 @@ const timetableClassmatesPlugin: Plugin<typeof timetableClassmatesSettings> = {
|
|||||||
|
|
||||||
schedulePaint();
|
schedulePaint();
|
||||||
await paintTimetable();
|
await paintTimetable();
|
||||||
|
void mountClassmatesToolbarChip();
|
||||||
|
|
||||||
if (page && !gridObserver) {
|
if (page && !gridObserver) {
|
||||||
gridObserver = new MutationObserver((mutations) => {
|
gridObserver = new MutationObserver((mutations) => {
|
||||||
@@ -171,6 +178,7 @@ const timetableClassmatesPlugin: Plugin<typeof timetableClassmatesSettings> = {
|
|||||||
document.removeEventListener("click", onClassEntryClick, true);
|
document.removeEventListener("click", onClassEntryClick, true);
|
||||||
unregisterEnabled();
|
unregisterEnabled();
|
||||||
removeClassmateStacks();
|
removeClassmateStacks();
|
||||||
|
unmountClassmatesToolbarChip();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,12 @@ import { mount, unmount } from "svelte";
|
|||||||
import TimetableClassmatesOptInPopup from "./TimetableClassmatesOptInPopup.svelte";
|
import TimetableClassmatesOptInPopup from "./TimetableClassmatesOptInPopup.svelte";
|
||||||
import TimetableClassmatesOptOutPopup from "./TimetableClassmatesOptOutPopup.svelte";
|
import TimetableClassmatesOptOutPopup from "./TimetableClassmatesOptOutPopup.svelte";
|
||||||
import popupStyles from "./consentPopup.css?inline";
|
import popupStyles from "./consentPopup.css?inline";
|
||||||
|
import { cloudAuth } from "@/seqta/utils/CloudAuth";
|
||||||
|
import { loadSession } from "./rosterStore";
|
||||||
|
import {
|
||||||
|
clearResumeOptInAfterCloudLogin,
|
||||||
|
shouldResumeOptInAfterCloudLogin,
|
||||||
|
} from "./optInResume";
|
||||||
|
|
||||||
const STYLE_ID = "bsplus-timetable-classmates-popup-styles";
|
const STYLE_ID = "bsplus-timetable-classmates-popup-styles";
|
||||||
const CLASSMATES_VIDEO_URL =
|
const CLASSMATES_VIDEO_URL =
|
||||||
@@ -82,11 +88,54 @@ export function openTimetableClassmatesOptInPopup(options: {
|
|||||||
"Timetable classmates",
|
"Timetable classmates",
|
||||||
"Share class lists with opted-in students at your school",
|
"Share class lists with opted-in students at your school",
|
||||||
TimetableClassmatesOptInPopup,
|
TimetableClassmatesOptInPopup,
|
||||||
{ onAccepted: options.onAccepted },
|
{
|
||||||
{ onDismiss: options.onDismiss, heroVideo: true },
|
onAccepted: async () => {
|
||||||
|
clearResumeOptInAfterCloudLogin();
|
||||||
|
await options.onAccepted();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onDismiss: () => {
|
||||||
|
clearResumeOptInAfterCloudLogin();
|
||||||
|
options.onDismiss?.();
|
||||||
|
},
|
||||||
|
heroVideo: true,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function openResumeOptInIfNeeded(): Promise<void> {
|
||||||
|
if (!shouldResumeOptInAfterCloudLogin()) return;
|
||||||
|
if (document.getElementById("whatsnewbk")) return;
|
||||||
|
|
||||||
|
const token = await cloudAuth.getStoredToken();
|
||||||
|
if (!token) return;
|
||||||
|
|
||||||
|
const session = await loadSession();
|
||||||
|
if (session.syncOptIn) {
|
||||||
|
clearResumeOptInAfterCloudLogin();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
openTimetableClassmatesOptInPopup({ onAccepted: () => {} });
|
||||||
|
}
|
||||||
|
|
||||||
|
/** After cloud OAuth refreshes the page, reopen opt-in if the user started sign-in from this flow. */
|
||||||
|
export async function maybeResumeTimetableClassmatesOptInPopup(): Promise<void> {
|
||||||
|
if (!shouldResumeOptInAfterCloudLogin()) return;
|
||||||
|
|
||||||
|
if (await cloudAuth.getStoredToken()) {
|
||||||
|
await openResumeOptInIfNeeded();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const unsub = cloudAuth.subscribe((state) => {
|
||||||
|
if (!state.isLoggedIn) return;
|
||||||
|
unsub();
|
||||||
|
void openResumeOptInIfNeeded();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function openTimetableClassmatesOptOutPopup(options: {
|
export function openTimetableClassmatesOptOutPopup(options: {
|
||||||
onConfirmed: () => void | Promise<void>;
|
onConfirmed: () => void | Promise<void>;
|
||||||
onDismiss?: () => void;
|
onDismiss?: () => void;
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
const SESSION_KEY = "bsplus-tc-resume-opt-in-after-cloud-login";
|
||||||
|
|
||||||
|
export function markResumeOptInAfterCloudLogin(): void {
|
||||||
|
try {
|
||||||
|
sessionStorage.setItem(SESSION_KEY, "1");
|
||||||
|
} catch {
|
||||||
|
/* private mode */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clearResumeOptInAfterCloudLogin(): void {
|
||||||
|
try {
|
||||||
|
sessionStorage.removeItem(SESSION_KEY);
|
||||||
|
} catch {
|
||||||
|
/* private mode */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function shouldResumeOptInAfterCloudLogin(): boolean {
|
||||||
|
try {
|
||||||
|
return sessionStorage.getItem(SESSION_KEY) === "1";
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
@@ -124,10 +124,34 @@ export function applySidebarStyleClass(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let bodyPositionListenerAttached = false;
|
||||||
|
|
||||||
|
function deferSidebarPositionUntilBody() {
|
||||||
|
if (bodyPositionListenerAttached) return;
|
||||||
|
bodyPositionListenerAttached = true;
|
||||||
|
const apply = () => {
|
||||||
|
bodyPositionListenerAttached = false;
|
||||||
|
const body = document.body;
|
||||||
|
if (!body) return;
|
||||||
|
const position = normalizeSidebarPosition(settingsState.sidebarPosition);
|
||||||
|
body.classList.toggle("bsplus-sidebar-right", position === "right");
|
||||||
|
};
|
||||||
|
if (document.readyState === "loading") {
|
||||||
|
document.addEventListener("DOMContentLoaded", apply, { once: true });
|
||||||
|
} else {
|
||||||
|
queueMicrotask(apply);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Apply left/right placement on `body` and drill slide direction vars. */
|
/** Apply left/right placement on `body` and drill slide direction vars. */
|
||||||
export function applySidebarPosition() {
|
export function applySidebarPosition() {
|
||||||
const position = normalizeSidebarPosition(settingsState.sidebarPosition);
|
const position = normalizeSidebarPosition(settingsState.sidebarPosition);
|
||||||
document.body.classList.toggle("bsplus-sidebar-right", position === "right");
|
const body = document.body;
|
||||||
|
if (body) {
|
||||||
|
body.classList.toggle("bsplus-sidebar-right", position === "right");
|
||||||
|
} else {
|
||||||
|
deferSidebarPositionUntilBody();
|
||||||
|
}
|
||||||
const root = document.documentElement;
|
const root = document.documentElement;
|
||||||
root.style.setProperty("--bsplus-slide-off", position === "right" ? "320px" : "-320px");
|
root.style.setProperty("--bsplus-slide-off", position === "right" ? "320px" : "-320px");
|
||||||
root.style.setProperty("--bsplus-slide-off-compact", position === "right" ? "70px" : "-70px");
|
root.style.setProperty("--bsplus-slide-off-compact", position === "right" ? "70px" : "-70px");
|
||||||
@@ -149,16 +173,17 @@ export function applySidebarLook(
|
|||||||
|
|
||||||
applySidebarPosition();
|
applySidebarPosition();
|
||||||
|
|
||||||
const lookKey = `${density}|${indicator}|${width}|${radius}|${blur}|${normalizeSidebarPosition(settingsState.sidebarPosition)}`;
|
|
||||||
if (lookKey === lastSidebarLookKey) return;
|
|
||||||
lastSidebarLookKey = lookKey;
|
|
||||||
|
|
||||||
const root = document.documentElement;
|
const root = document.documentElement;
|
||||||
root.style.setProperty("--bsplus-sidebar-width", `${SIDEBAR_WIDTH_PX[width]}px`);
|
root.style.setProperty("--bsplus-sidebar-width", `${SIDEBAR_WIDTH_PX[width]}px`);
|
||||||
root.style.setProperty("--bsplus-sidebar-radius", `${radius}px`);
|
root.style.setProperty("--bsplus-sidebar-radius", `${radius}px`);
|
||||||
root.style.setProperty("--bsplus-sidebar-blur", `${blur}px`);
|
root.style.setProperty("--bsplus-sidebar-blur", `${blur}px`);
|
||||||
|
|
||||||
if (!menu) return;
|
if (!menu) return;
|
||||||
|
|
||||||
|
const lookKey = `${density}|${indicator}|${width}|${radius}|${blur}|${normalizeSidebarPosition(settingsState.sidebarPosition)}`;
|
||||||
|
if (lookKey === lastSidebarLookKey) return;
|
||||||
|
lastSidebarLookKey = lookKey;
|
||||||
|
|
||||||
setExclusiveClass(menu, DENSITY_CLASS_PREFIX, density, DEFAULT_SIDEBAR_DENSITY);
|
setExclusiveClass(menu, DENSITY_CLASS_PREFIX, density, DEFAULT_SIDEBAR_DENSITY);
|
||||||
setExclusiveClass(
|
setExclusiveClass(
|
||||||
menu,
|
menu,
|
||||||
@@ -169,13 +194,14 @@ export function applySidebarLook(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function clearSidebarAppearance(menu: HTMLElement | null | undefined) {
|
export function clearSidebarAppearance(menu: HTMLElement | null | undefined) {
|
||||||
|
lastSidebarLookKey = "";
|
||||||
const root = document.documentElement;
|
const root = document.documentElement;
|
||||||
root.style.removeProperty("--bsplus-sidebar-width");
|
root.style.removeProperty("--bsplus-sidebar-width");
|
||||||
root.style.removeProperty("--bsplus-sidebar-radius");
|
root.style.removeProperty("--bsplus-sidebar-radius");
|
||||||
root.style.removeProperty("--bsplus-sidebar-blur");
|
root.style.removeProperty("--bsplus-sidebar-blur");
|
||||||
root.style.removeProperty("--bsplus-slide-off");
|
root.style.removeProperty("--bsplus-slide-off");
|
||||||
root.style.removeProperty("--bsplus-slide-off-compact");
|
root.style.removeProperty("--bsplus-slide-off-compact");
|
||||||
document.body.classList.remove("bsplus-sidebar-right");
|
document.body?.classList.remove("bsplus-sidebar-right");
|
||||||
if (!menu) return;
|
if (!menu) return;
|
||||||
clearPrefixed(menu, STYLE_CLASS_PREFIX);
|
clearPrefixed(menu, STYLE_CLASS_PREFIX);
|
||||||
clearPrefixed(menu, DENSITY_CLASS_PREFIX);
|
clearPrefixed(menu, DENSITY_CLASS_PREFIX);
|
||||||
|
|||||||
Reference in new issue
Block a user