-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #915 from tutors-sdk/development
reintegrate tutors live
- Loading branch information
Showing
21 changed files
with
445 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { supabase } from "./profiles/supabase-client"; | ||
import type { CatalogueEntry, CatalogueService } from "./types.svelte"; | ||
|
||
export const catalogueService: CatalogueService = { | ||
async getCatalogue() { | ||
try { | ||
const { data, error } = await supabase | ||
.from("tutors-connect-courses") | ||
.select("*") | ||
.order("visited_at", { ascending: false }); | ||
|
||
if (error) { | ||
throw error; | ||
} | ||
|
||
const catalogue = data as Array<CatalogueEntry>; | ||
return catalogue; | ||
} catch (error) { | ||
console.error("Error fetching courses:", error); | ||
return []; | ||
} | ||
}, | ||
|
||
async getCatalogueCount() { | ||
try { | ||
const { count, error } = await supabase | ||
.from("tutors-connect-courses") | ||
.select("*", { count: "exact", head: true }); | ||
|
||
if (error) { | ||
throw error; | ||
} | ||
|
||
return count || 0; | ||
} catch (error) { | ||
console.error("Error fetching course count:", error); | ||
return 0; | ||
} | ||
}, | ||
|
||
async getStudentCount() { | ||
try { | ||
const { count, error } = await supabase | ||
.from("tutors-connect-profiles") | ||
.select("*", { count: "exact", head: true }); | ||
|
||
if (error) { | ||
throw error; | ||
} | ||
|
||
return count || 0; | ||
} catch (error) { | ||
console.error("Error fetching course count:", error); | ||
return 0; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import PartySocket from "partysocket"; | ||
|
||
import { PUBLIC_party_kit_main_room } from "$env/static/public"; | ||
import { rune } from "./utils/runes.svelte"; | ||
import { LoRecord } from "./types.svelte"; | ||
import { refreshLoRecord } from "./presence.svelte"; | ||
|
||
/** PartyKit server URL from environment */ | ||
const partyKitServer = PUBLIC_party_kit_main_room; | ||
|
||
let partyKitAll = <PartySocket>{}; | ||
|
||
if (PUBLIC_party_kit_main_room !== "XXX") { | ||
partyKitAll = new PartySocket({ | ||
host: partyKitServer, | ||
room: "tutors-all-course-access" | ||
}); | ||
} | ||
|
||
export const liveService = { | ||
listeningForCourse: rune<string>(""), | ||
coursesOnline: rune<LoRecord[]>([]), | ||
studentsOnline: rune<LoRecord[]>([]), | ||
studentsOnlineByCourse: rune<LoRecord[][]>([]), | ||
|
||
studentEventMap: new Map<string, LoRecord>(), | ||
courseEventMap: new Map<string, LoRecord>(), | ||
|
||
partyKitCourse: <PartySocket>{}, | ||
listeningAll: false, | ||
|
||
groupedStudentListener(event: any) { | ||
const courseArray = this.studentsOnlineByCourse.value.find((lo: LoRecord[]) => lo[0].courseId === event.courseId); | ||
if (!courseArray) { | ||
const studentArray = new Array<LoRecord>(); | ||
studentArray.push(new LoRecord(event)); | ||
this.studentsOnlineByCourse.value.push(studentArray); | ||
} else { | ||
const loStudent = courseArray.find((lo: LoRecord) => lo.user?.id === event.user.id); | ||
if (!loStudent) { | ||
courseArray.push(new LoRecord(event)); | ||
} else { | ||
refreshLoRecord(loStudent, event); | ||
} | ||
} | ||
}, | ||
|
||
studentListener(event: any) { | ||
const studentEvent = this.studentEventMap.get(event.user.id); | ||
if (!studentEvent) { | ||
const latestLo = new LoRecord(event); | ||
this.studentsOnline.value.push(latestLo); | ||
this.studentEventMap.set(event.user.id, latestLo); | ||
} else { | ||
refreshLoRecord(studentEvent, event); | ||
} | ||
}, | ||
|
||
courseListener(event: any) { | ||
const courseEvent = this.courseEventMap.get(event.courseId); | ||
if (!courseEvent) { | ||
const latestLo = new LoRecord(event); | ||
this.coursesOnline.value.push(latestLo); | ||
this.courseEventMap.set(event.courseId, latestLo); | ||
} else { | ||
refreshLoRecord(courseEvent, event); | ||
} | ||
}, | ||
partyKitListener(event: any) { | ||
try { | ||
const nextCourseEvent = JSON.parse(event.data); | ||
this.courseListener(nextCourseEvent); | ||
this.studentListener(nextCourseEvent); | ||
this.groupedStudentListener(nextCourseEvent); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}, | ||
|
||
startGlobalPresenceService() { | ||
if (!this.listeningAll) { | ||
this.listeningAll = true; | ||
partyKitAll.addEventListener("message", (event) => { | ||
this.partyKitListener(event); | ||
}); | ||
} | ||
}, | ||
|
||
startCoursePresenceListener(courseId: string) { | ||
const partyKitCourse = new PartySocket({ | ||
host: partyKitServer, | ||
room: courseId | ||
}); | ||
partyKitCourse.addEventListener("message", (event) => { | ||
try { | ||
const nextCourseEvent = JSON.parse(event.data); | ||
this.listeningForCourse.value = nextCourseEvent.courseTitle; | ||
this.groupedStudentListener(nextCourseEvent); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<script lang="ts"> | ||
import type { CourseVisit } from "$lib/services/types.svelte"; | ||
import Card from "../components/Card.svelte"; | ||
interface Props { | ||
courseRecords: CourseVisit[]; | ||
} | ||
let { courseRecords = [] }: Props = $props(); | ||
// tabSet.value = 4; | ||
</script> | ||
|
||
<div class="flex flex-wrap justify-center"> | ||
{#each courseRecords as courseRecord} | ||
<Card | ||
cardDetails={{ | ||
route: `/course/${courseRecord?.id}`, | ||
title: courseRecord?.title, | ||
type: "course", | ||
summary: courseRecord?.credits, | ||
img: courseRecord?.img, | ||
icon: courseRecord?.icon | ||
}} | ||
/> | ||
{/each} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script lang="ts"> | ||
import { presenceService } from "$lib/services/presence.svelte"; | ||
import Card from "../components/Card.svelte"; | ||
</script> | ||
|
||
<div class="flex flex-wrap justify-center"> | ||
{#each presenceService.studentsOnline.value as lo} | ||
<Card | ||
cardDetails={{ | ||
route: lo.loRoute, | ||
title: lo.courseTitle, | ||
type: lo.type, | ||
summary: lo.title, | ||
summaryEx: "(" + lo.type + ")", | ||
img: lo.img, | ||
icon: lo.icon | ||
}} | ||
/> | ||
{/each} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<script lang="ts"> | ||
import { LoRecord } from "$lib/services/types.svelte"; | ||
import Card from "../components/Card.svelte"; | ||
export let los: LoRecord[]; | ||
</script> | ||
|
||
<div | ||
class="bg-surface-100-800-token border-surface-200-700-token mx-auto mb-2 w-full place-items-center overflow-hidden rounded-xl border-[1px] p-4" | ||
> | ||
<div class="flex w-full justify-between pb-2"> | ||
<h2 class="p-2"> | ||
{los[0].courseTitle} | ||
</h2> | ||
</div> | ||
<div class="flex flex-wrap justify-center"> | ||
{#each los as lo} | ||
<Card | ||
cardDetails={{ | ||
route: lo?.loRoute, | ||
student: lo?.user, | ||
title: lo?.courseTitle, | ||
type: lo?.type, | ||
summary: lo?.title, | ||
img: lo?.img, | ||
icon: lo?.icon | ||
}} | ||
/> | ||
{/each} | ||
</div> | ||
</div> |
Oops, something went wrong.