Skip to content

Commit

Permalink
Merge pull request #913 from tutors-sdk/development
Browse files Browse the repository at this point in the history
rune reorg + persistence of cardStyle and layout
  • Loading branch information
edeleastar authored Jan 3, 2025
2 parents c858980 + 19ab522 commit 6d230d1
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 184 deletions.
6 changes: 4 additions & 2 deletions src/lib/runes.ts
Original file line number Diff line number Diff line change
@@ -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<Lo | null>(null);
export const currentCourse = rune<Course | null>(null);
export const currentCourse = rune<Course | null>(null);

export const tutorsId = rune<TutorsId | null>(null);
30 changes: 14 additions & 16 deletions src/lib/services/connect.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,8 +27,6 @@ if (PUBLIC_ANON_MODE === "TRUE") {
}

export const tutorsConnectService: TutorsConnectService = {
/** Current user's Tutors identity */
tutorsId: rune<TutorsId | null>(null),
/** Active user profile implementation */
profile: localStorageProfile,
/** Timer ID for analytics updates */
Expand All @@ -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");
Expand All @@ -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";
}
}
},
Expand All @@ -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`);
}
Expand Down Expand Up @@ -146,10 +144,10 @@ export const tutorsConnectService: TutorsConnectService = {
*/
learningEvent(params: Record<string, string>): 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);
}
}
},
Expand All @@ -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);
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/models/markdown-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 2 additions & 1 deletion src/lib/services/presence.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions src/lib/services/profiles/supabaseProfile.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand All @@ -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[];
}
Expand All @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion src/lib/services/themes.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 1 addition & 3 deletions src/lib/services/types.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -130,7 +128,7 @@ export interface TutorsConnectService {
disconnect(redirectStr: string): void;
toggleShare(): void;

courseVisit(course: Course, user: TutorsId): void;
courseVisit(course: Course): void;
deleteCourseVisit(courseId: string): void;
getCourseVisits(): Promise<CourseVisit[]>;
favouriteCourse(courseId: string): void;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ui/components/Card.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
{/snippet}

{#snippet landscape(cardDetails: CardDetails)}
<div class="w-1/3">
<div class="flex h-full w-1/3 items-center">
{@render figure(cardDetails)}
</div>
<div class="w-2/3">
Expand Down
106 changes: 0 additions & 106 deletions src/lib/ui/components/LandscapeCard.svelte

This file was deleted.

5 changes: 3 additions & 2 deletions src/lib/ui/components/Menu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
<nav class="card-body list-nav card w-56 space-y-4 bg-gray-100 p-4 shadow-lg dark:bg-gray-800">
<nav class="card-body list-nav card w-56 space-y-2 bg-gray-100 p-2 shadow-lg dark:bg-gray-800">
{@render menuContent()}
</nav>
{/snippet}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ui/navigators/MainNavigator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import ConnectedProfile from "./tutors-connect/ConnectedProfile.svelte";
import TutorsTitle from "./titles/TutorsTitle.svelte";
import CalendarButton from "./buttons/CalendarButton.svelte";
import { currentCourse } from "$lib/runes";
import { currentCourse, tutorsId } from "$lib/runes";
</script>

<AppBar
Expand Down Expand Up @@ -46,7 +46,7 @@
<span class="mx-2 h-10 w-[1px] bg-gray-400 dark:bg-gray-200"></span>
{#if !currentCourse?.value?.isPrivate}
<div class="relative">
{#if !tutorsConnectService.tutorsId.value?.login}
{#if !tutorsId.value?.login}
<AnonProfile redirect="/{currentCourse?.value?.courseId}" />
{:else}
<ConnectedProfile />
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ui/navigators/SecondaryNavigator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{#if !currentCourse?.value?.isPortfolio}
<div in:fly={slideFromLeft.in} out:fly={slideFromLeft.out}>
<div
class="border-primary-100 bg-primary-50 dark:border-primary-800 {themeClasses.firstDiv} z-10 flex h-12 border-b-[1px]"
class="z-10 border-primary-100 bg-primary-50 dark:border-primary-800 {themeClasses.firstDiv} flex h-12 border-b-[1px]"
>
<Breadcrumbs />
{#if currentCourse?.value}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ui/navigators/buttons/Breadcrumbs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
});
</script>

<div class="mx-8 my-2 overflow-hidden p-1">
<ol class="flex items-center gap-4">
<div class="mx-8 my-2 overflow-hidden p-1 flex items-center">
<ol class="flex items-center gap-4 w-full">
<li>
<a class="hover:underline" href="/{currentCourse?.value?.properties?.parent}">
<Icon type="programHome" tip={`Go to Course Home`} /></a
Expand Down
11 changes: 3 additions & 8 deletions src/lib/ui/navigators/footers/TutorsMessage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@
let contentHtml = "";
onMount(async () => {
try {
const response = await fetch("https://msg.tutors.dev/msg.json");
const data = await response.json();
contentHtml = convertMdToHtml(data.footerMessage, "monokai");
} catch (error) {
console.error("Failed to fetch message:", error);
contentHtml = convertMdToHtml("An [Open Learning Web Toolkit](/course/tutors-reference-manual)");
}
contentHtml = convertMdToHtml(
"An [Open Learning Web Toolkit](/course/tutors-reference-manual): Check out the new Card Styles in the layout menu"
);
});
</script>

Expand Down
Loading

0 comments on commit 6d230d1

Please sign in to comment.