Skip to content

Commit

Permalink
fix: presence
Browse files Browse the repository at this point in the history
  • Loading branch information
jouwdan committed Aug 9, 2023
1 parent ae5969d commit 0c5c536
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 36 deletions.
15 changes: 5 additions & 10 deletions apps/web/src/lib/ui/navigators/NavUser.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
timeUrl = `${timeApp}/time/${course?.url}/${user.userId}`;
}
let currentStatus: boolean;
onlineStatus.subscribe((value) => {
currentStatus = value;
});
currentUser.subscribe(async (newUser: User) => {
if (newUser) {
user = newUser;
Expand All @@ -42,7 +37,7 @@
});
function handleClick() {
onlineStatus.set(currentStatus);
onlineStatus.set(!$onlineStatus);
// analyticsService.setOnlineStatus(status, session);
}
Expand All @@ -62,10 +57,10 @@
>
{/if}
<span class="badge-icon absolute -bottom-2 -right-2 z-10 text-white">
{#if currentStatus}
{#if $onlineStatus}
<Icon type="online" />
{/if}
{#if !currentStatus}
{#if !onlineStatus}
<Icon type="offline" />
{/if}</span
>
Expand All @@ -90,7 +85,7 @@
<div class="ml-2">Share Presence</div>
</a>
</li>
{#if currentStatus}
{#if $onlineStatus}
<li>
<!-- svelte-ignore a11y-missing-attribute -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
Expand All @@ -105,7 +100,7 @@
</ul>
<hr />
<ul>
{#if currentStatus}
{#if $onlineStatus}
<li>
<a href={liveUrl} target="_blank" rel="noreferrer">
<Icon type="listOnline" />
Expand Down
70 changes: 44 additions & 26 deletions apps/web/src/routes/(course-reader)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
}
}
let presenceSetup: boolean = false;
onMount(() => {
setInitialClassState();
initServices(data.session);
setInterval(updatePageCount, 30 * 1000);
});
let presenceSetup: boolean = false;
function setupPresenceLocally() {
setupPresence(supabase, $page.params.courseid);
setTimeout(() => {
Expand All @@ -59,27 +59,22 @@
presenceSetup = false;
}
$: !presenceSetup && data.session && $onlineStatus && setupPresenceLocally();
$: $currentLo &&
data.session &&
$onlineStatus &&
presenceSetup &&
updatePresence({
studentName: session.user.user_metadata.full_name,
studentEmail: session.user.user_metadata.email,
studentImg: session.user.user_metadata.avatar_url,
courseTitle: get(currentLo).parentLo ? get(currentLo).parentLo.title : get(currentLo).title,
loTitle: get(currentLo).title,
loImage: get(currentLo).img,
loRoute: get(currentLo).route,
loIcon: get(currentLo).icon
});
$: {
if (!presenceSetup && data.session && $onlineStatus) {
setupPresenceLocally();
} else if (!$onlineStatus && presenceSetup) {
unsubscribePresenceLocally();
}
}
$: $onlineStatus &&
data.session &&
subscribePresence(
{
$: {
if (
$currentLo &&
data.session &&
presenceSetup &&
($onlineStatus || $onlineStatus === undefined)
) {
updatePresence({
studentName: session.user.user_metadata.full_name,
studentEmail: session.user.user_metadata.email,
studentImg: session.user.user_metadata.avatar_url,
Expand All @@ -88,11 +83,34 @@
loImage: get(currentLo).img,
loRoute: get(currentLo).route,
loIcon: get(currentLo).icon
},
$page.params.courseid
);
});
}
}
$: !$onlineStatus && data.session && presenceSetup && unsubscribePresenceLocally();
$: {
if (
$onlineStatus &&
data.session &&
presenceSetup &&
($onlineStatus || $onlineStatus === undefined)
) {
subscribePresence(
{
studentName: session.user.user_metadata.full_name,
studentEmail: session.user.user_metadata.email,
studentImg: session.user.user_metadata.avatar_url,
courseTitle: get(currentLo).parentLo
? get(currentLo).parentLo.title
: get(currentLo).title,
loTitle: get(currentLo).title,
loImage: get(currentLo).img,
loRoute: get(currentLo).route,
loIcon: get(currentLo).icon
},
$page.params.courseid
);
}
}
page.subscribe((path) => {
if (path.route.id) {
Expand Down

0 comments on commit 0c5c536

Please sign in to comment.