From 05aa8132c845f43f47da800ec9a7ec2d88a93e88 Mon Sep 17 00:00:00 2001 From: Eamonn de Leastar Date: Fri, 3 Jan 2025 17:47:52 +0000 Subject: [PATCH 1/3] move tutors-id rune into runes... + menu layout adjustments --- src/lib/runes.ts | 6 ++-- src/lib/services/connect.svelte.ts | 30 ++++++++--------- src/lib/services/models/markdown-utils.ts | 2 +- src/lib/services/presence.svelte.ts | 3 +- .../profiles/supabaseProfile.svelte.ts | 9 +++--- src/lib/services/themes.svelte.ts | 1 - src/lib/services/types.svelte.ts | 2 -- src/lib/ui/components/Menu.svelte | 5 +-- src/lib/ui/navigators/MainNavigator.svelte | 4 +-- .../ui/navigators/SecondaryNavigator.svelte | 2 +- .../ui/navigators/buttons/Breadcrumbs.svelte | 4 +-- .../navigators/footers/TutorsMessage.svelte | 11 ++----- .../tutors-connect/ConnectedProfile.svelte | 23 ++++++------- src/lib/ui/themes/LayoutMenu.svelte | 32 +++++++++++-------- src/routes/(home)/Welcome.svelte | 8 ++--- tailwind.config.ts | 3 +- 16 files changed, 70 insertions(+), 75 deletions(-) diff --git a/src/lib/runes.ts b/src/lib/runes.ts index f74202f3..fc1cc6a3 100644 --- a/src/lib/runes.ts +++ b/src/lib/runes.ts @@ -1,10 +1,12 @@ import type { Course, Lo } from "./services/models/lo-types"; +import type { TutorsId } from "./services/types.svelte"; import { rune } from "./services/utils/runes.svelte"; export const currentLabStepIndex = rune(0); export const adobeLoaded = rune(false); export const animationDelay = rune(200); - export const currentLo = rune(null); -export const currentCourse = rune(null); \ No newline at end of file +export const currentCourse = rune(null); + +export const tutorsId = rune(null); \ No newline at end of file diff --git a/src/lib/services/connect.svelte.ts b/src/lib/services/connect.svelte.ts index bfd01ab1..be1fa20d 100644 --- a/src/lib/services/connect.svelte.ts +++ b/src/lib/services/connect.svelte.ts @@ -17,7 +17,7 @@ import { analyticsService } from "./analytics.svelte"; import { presenceService } from "./presence.svelte"; import { PUBLIC_ANON_MODE } from "$env/static/public"; import { updateCourseList } from "./profiles/allCourseAccess"; -import { currentCourse, currentLo } from "$lib/runes"; +import { currentCourse, currentLo, tutorsId } from "$lib/runes"; /** Global anonymous mode flag, controlled by environment variable */ let anonMode = false; @@ -27,8 +27,6 @@ if (PUBLIC_ANON_MODE === "TRUE") { } export const tutorsConnectService: TutorsConnectService = { - /** Current user's Tutors identity */ - tutorsId: rune(null), /** Active user profile implementation */ profile: localStorageProfile, /** Timer ID for analytics updates */ @@ -54,13 +52,13 @@ export const tutorsConnectService: TutorsConnectService = { if (anonMode) return; presenceService.connectToAllCourseAccess(); if (user) { - this.tutorsId.value = user; + tutorsId.value = user; this.profile = supabaseProfile; if (browser) { if (!localStorage.share) { localStorage.share = true; } - this.tutorsId.value.share = localStorage.share; + tutorsId.value.share = localStorage.share; if (localStorage.loginCourse) { const courseId = localStorage.loginCourse; localStorage.removeItem("loginCourse"); @@ -83,11 +81,11 @@ export const tutorsConnectService: TutorsConnectService = { * Updates both local storage and current session */ toggleShare() { - if (this.tutorsId.value && browser) { - if (this.tutorsId.value.share === "true") { - localStorage.share = this.tutorsId.value.share = "false"; + if (tutorsId.value && browser) { + if (tutorsId.value.share === "true") { + localStorage.share = tutorsId.value.share = "false"; } else { - localStorage.share = this.tutorsId.value.share = "true"; + localStorage.share = tutorsId.value.share = "true"; } } }, @@ -102,7 +100,7 @@ export const tutorsConnectService: TutorsConnectService = { updateCourseList(course); this.profile.logCourseVisit(course); presenceService.startPresenceListener(course.courseId); - if (course.authLevel! > 0 && !this.tutorsId.value?.login) { + if (course.authLevel! > 0 && !tutorsId.value?.login) { localStorage.loginCourse = course.courseId; goto(`/auth`); } @@ -146,10 +144,10 @@ export const tutorsConnectService: TutorsConnectService = { */ learningEvent(params: Record): void { if (anonMode) return; - if (currentCourse.value && currentLo.value && this.tutorsId.value) { - analyticsService.learningEvent(currentCourse.value, params, currentLo.value, this.tutorsId.value); - if (this.tutorsId.value.share === "true" && !currentCourse.value.isPrivate) { - presenceService.sendLoEvent(currentCourse.value, currentLo.value, this.tutorsId.value); + if (currentCourse.value && currentLo.value && tutorsId.value) { + analyticsService.learningEvent(currentCourse.value, params, currentLo.value, tutorsId.value); + if (tutorsId.value.share === "true" && !currentCourse.value.isPrivate) { + presenceService.sendLoEvent(currentCourse.value, currentLo.value, tutorsId.value); } } }, @@ -161,8 +159,8 @@ export const tutorsConnectService: TutorsConnectService = { startTimer() { if (anonMode) return; this.intervalId = setInterval(() => { - if (!document.hidden && currentCourse.value && currentLo.value && this.tutorsId.value) { - analyticsService.updatePageCount(currentCourse.value, currentLo.value, this.tutorsId.value); + if (!document.hidden && currentCourse.value && currentLo.value && tutorsId.value) { + analyticsService.updatePageCount(currentCourse.value, currentLo.value, tutorsId.value); } }, 30 * 1000); }, diff --git a/src/lib/services/models/markdown-utils.ts b/src/lib/services/models/markdown-utils.ts index 01bd0e8b..9612a8d4 100644 --- a/src/lib/services/models/markdown-utils.ts +++ b/src/lib/services/models/markdown-utils.ts @@ -96,7 +96,7 @@ markdownIt.renderer.rules.link_open = function (tokens: any, idx: any, options: return defaultRender(tokens, idx, options, env, self); }; -export function convertMdToHtml(md: string, codeTheme: string): string { +export function convertMdToHtml(md: string, codeTheme: string = "ayu-dark"): string { currentTheme = codeTheme; return markdownIt.render(md); } diff --git a/src/lib/services/presence.svelte.ts b/src/lib/services/presence.svelte.ts index 661aa0a0..52c7c538 100644 --- a/src/lib/services/presence.svelte.ts +++ b/src/lib/services/presence.svelte.ts @@ -9,6 +9,7 @@ import { rune } from "./utils/runes.svelte"; import { LoRecord, type LoUser, type PresenceService, type TutorsId } from "./types.svelte"; import type { Course, Lo } from "./models/lo-types"; import { tutorsConnectService } from "./connect.svelte"; +import { tutorsId } from "$lib/runes"; /** PartyKit server URL from environment */ const partyKitServer = PUBLIC_party_kit_main_room; @@ -34,7 +35,7 @@ export const presenceService: PresenceService = { const nextCourseEvent = JSON.parse(event.data); if ( nextCourseEvent.courseId === this.listeningTo && - nextCourseEvent.user.id !== tutorsConnectService.tutorsId.value.login + nextCourseEvent.user.id !== tutorsId.value?.login ) { const studentEvent = this.studentEventMap.get(nextCourseEvent.user.id); if (!studentEvent) { diff --git a/src/lib/services/profiles/supabaseProfile.svelte.ts b/src/lib/services/profiles/supabaseProfile.svelte.ts index c5257d51..b137b4e3 100644 --- a/src/lib/services/profiles/supabaseProfile.svelte.ts +++ b/src/lib/services/profiles/supabaseProfile.svelte.ts @@ -9,6 +9,7 @@ import type { Course, IconType } from "../models/lo-types"; import { tutorsConnectService } from "$lib/services/connect.svelte.js"; import type { CourseVisit, ProfileStore } from "../types.svelte"; import { supabase } from "./supabase-client"; +import { tutorsId } from "$lib/runes"; export const supabaseProfile: ProfileStore = { courseVisits: [] as CourseVisit[], @@ -19,11 +20,11 @@ export const supabaseProfile: ProfileStore = { * @async */ async reload() { - if (tutorsConnectService.tutorsId.value?.login) { + if (tutorsId.value?.login) { const { data: profile } = await supabase .from("tutors-connect-profiles") .select("profile") - .eq("tutorId", tutorsConnectService.tutorsId.value?.login); + .eq("tutorId", tutorsId.value?.login); if (profile.length > 0) { this.courseVisits = profile[0].profile as unknown as CourseVisit[]; } @@ -36,11 +37,11 @@ export const supabaseProfile: ProfileStore = { * @async */ async save() { - const id = tutorsConnectService.tutorsId.value?.login; + const id = tutorsId.value?.login; if (id) { const { error } = await supabase .from("tutors-connect-profiles") - .upsert({ tutorId: tutorsConnectService.tutorsId.value?.login, profile: this.courseVisits }); + .upsert({ tutorId: tutorsId.value?.login, profile: this.courseVisits }); if (error) { console.log(error); } diff --git a/src/lib/services/themes.svelte.ts b/src/lib/services/themes.svelte.ts index 9dbb175f..804b2641 100644 --- a/src/lib/services/themes.svelte.ts +++ b/src/lib/services/themes.svelte.ts @@ -22,7 +22,6 @@ export const themeService: ThemeService = { { name: "tutors", icons: FluentIconLib }, { name: "classic", icons: FluentIconLib }, { name: "dyslexia", icons: FluentIconLib }, - { name: "festive", icons: FestiveIcons }, { name: "nouveau", icons: FluentIconLib }, { name: "rose", icons: FluentIconLib }, { name: "cerberus", icons: FluentIconLib } diff --git a/src/lib/services/types.svelte.ts b/src/lib/services/types.svelte.ts index 698898e3..2d48e987 100644 --- a/src/lib/services/types.svelte.ts +++ b/src/lib/services/types.svelte.ts @@ -119,8 +119,6 @@ export interface ProfileStore { * Service for managing user authentication and course access */ export interface TutorsConnectService { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - tutorsId: any; profile: ProfileStore; intervalId: any; anonMode: boolean; diff --git a/src/lib/ui/components/Menu.svelte b/src/lib/ui/components/Menu.svelte index da37d955..b7ebe92f 100644 --- a/src/lib/ui/components/Menu.svelte +++ b/src/lib/ui/components/Menu.svelte @@ -10,13 +10,14 @@ bind:open={openState} positioning={{ placement: "top" }} triggerBase="btn" - contentBase="card bg-surface-50 m-4 space-y-4 max-w-[320px] z-[100]" + class="z-[9999]" + contentBase="card bg-surface-50 m-4 space-y-4 max-w-[320px] z-[9999]" > {#snippet trigger()} {@render menuSelector()} {/snippet} {#snippet content()} -