fix: prevent duplicate comment channel subscriptions and improve translation check
This commit is contained in:
+17
-11
@@ -1,6 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Avatar from '$lib/components/Avatar/index.svelte';
|
import Avatar from '$lib/components/Avatar/index.svelte';
|
||||||
import { lesson } from '$lib/components/Course/components/Lesson/store/lessons';
|
import {
|
||||||
|
lesson,
|
||||||
|
lessonCommentsChannel
|
||||||
|
} from '$lib/components/Course/components/Lesson/store/lessons';
|
||||||
import { group } from '$lib/components/Course/store';
|
import { group } from '$lib/components/Course/store';
|
||||||
import TextArea from '$lib/components/Form/TextArea.svelte';
|
import TextArea from '$lib/components/Form/TextArea.svelte';
|
||||||
import DeleteModal from '$lib/components/Modal/DeleteModal.svelte';
|
import DeleteModal from '$lib/components/Modal/DeleteModal.svelte';
|
||||||
@@ -26,7 +29,6 @@
|
|||||||
export let lessonId = '';
|
export let lessonId = '';
|
||||||
|
|
||||||
let comment = '';
|
let comment = '';
|
||||||
let lessonCommentChannel: RealtimeChannel;
|
|
||||||
let comments: LessonComment[] = [];
|
let comments: LessonComment[] = [];
|
||||||
let groupmember: GroupPerson | undefined;
|
let groupmember: GroupPerson | undefined;
|
||||||
let isSaving: boolean = false;
|
let isSaving: boolean = false;
|
||||||
@@ -243,18 +245,22 @@
|
|||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
fetchComments($group.people);
|
fetchComments($group.people);
|
||||||
|
|
||||||
lessonCommentChannel = supabase
|
if (!$lessonCommentsChannel) {
|
||||||
.channel('any')
|
lessonCommentsChannel.set(
|
||||||
.on(
|
supabase
|
||||||
'postgres_changes',
|
.channel('any')
|
||||||
{ event: 'INSERT', schema: 'public', table: 'lesson_comment' },
|
.on(
|
||||||
handleInsert
|
'postgres_changes',
|
||||||
)
|
{ event: 'INSERT', schema: 'public', table: 'lesson_comment' },
|
||||||
.subscribe();
|
handleInsert
|
||||||
|
)
|
||||||
|
.subscribe()
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
supabase.removeChannel(lessonCommentChannel);
|
supabase.removeChannel($lessonCommentsChannel);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
+5
-3
@@ -16,7 +16,9 @@
|
|||||||
$lesson.locale
|
$lesson.locale
|
||||||
);
|
);
|
||||||
$: hasAtLeastOneTranslation = Object.values($lessonByTranslation[lessonId] || {}).some(
|
$: hasAtLeastOneTranslation = Object.values($lessonByTranslation[lessonId] || {}).some(
|
||||||
(c) => !!c.length
|
(content) => {
|
||||||
|
return content && !!content.length;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -29,8 +31,8 @@
|
|||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
</HtmlRender>
|
</HtmlRender>
|
||||||
{:else if hasAtLeastOneTranslation}
|
{:else if hasAtLeastOneTranslation}
|
||||||
<div class="flex items-center justify-center flex-col text-center">
|
<div class="flex flex-col items-center justify-center text-center">
|
||||||
<h3 class="text-lg font-normal italic dark:text-white py-2">
|
<h3 class="py-2 text-lg font-normal italic dark:text-white">
|
||||||
{$t('course.navItem.lessons.materials.no_translation')}
|
{$t('course.navItem.lessons.materials.no_translation')}
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
} from '$lib/utils/services/courses';
|
} from '$lib/utils/services/courses';
|
||||||
|
|
||||||
import { LOCALE } from '$lib/utils/types';
|
import { LOCALE } from '$lib/utils/types';
|
||||||
|
import type { RealtimeChannel } from '@supabase/supabase-js';
|
||||||
import { lessonValidation } from '$lib/utils/functions/validator';
|
import { lessonValidation } from '$lib/utils/functions/validator';
|
||||||
import { snackbar } from '$lib/components/Snackbar/store';
|
import { snackbar } from '$lib/components/Snackbar/store';
|
||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
@@ -23,6 +24,8 @@ export const lessons: Writable<Lesson[]> = writable([]);
|
|||||||
|
|
||||||
export const lessonSections: Writable<LessonSection[]> = writable([]);
|
export const lessonSections: Writable<LessonSection[]> = writable([]);
|
||||||
|
|
||||||
|
export const lessonCommentsChannel: Writable<RealtimeChannel> = writable();
|
||||||
|
|
||||||
export const lesson = writable<LessonPage>({
|
export const lesson = writable<LessonPage>({
|
||||||
id: null,
|
id: null,
|
||||||
locale: LOCALE.EN,
|
locale: LOCALE.EN,
|
||||||
|
|||||||
Reference in New Issue
Block a user