2023-12-13 14:03:02 +01:00
|
|
|
<script lang="ts">
|
2025-11-01 15:49:29 +01:00
|
|
|
import { untrack } from 'svelte';
|
2025-12-22 19:57:27 +01:00
|
|
|
import * as Page from '@cio/ui/base/page';
|
2025-11-21 12:18:04 +01:00
|
|
|
import * as Select from '@cio/ui/base/select';
|
2025-12-22 19:57:27 +01:00
|
|
|
import { Empty } from '@cio/ui/custom/empty';
|
|
|
|
|
import * as Item from '@cio/ui/base/item';
|
2025-12-02 09:54:38 +01:00
|
|
|
import { Search } from '@cio/ui/custom/search';
|
2025-12-22 19:57:27 +01:00
|
|
|
import MessageSquareMoreIcon from '@lucide/svelte/icons/message-square-more';
|
2025-11-01 15:49:29 +01:00
|
|
|
import MessageCirclePlusIcon from '@lucide/svelte/icons/message-circle-plus';
|
|
|
|
|
|
2025-11-21 12:18:04 +01:00
|
|
|
import { profile } from '$lib/utils/store/user';
|
|
|
|
|
import { t } from '$lib/utils/functions/translations';
|
2025-12-22 19:57:27 +01:00
|
|
|
import { communityApi } from '../api/community.svelte';
|
2025-11-21 12:18:04 +01:00
|
|
|
import { calDateDiff } from '$lib/utils/functions/date';
|
|
|
|
|
import { currentOrg, currentOrgPath } from '$lib/utils/store/org';
|
2025-12-02 09:54:38 +01:00
|
|
|
|
|
|
|
|
import { AskCommunityButton } from '../components';
|
2025-12-22 19:57:27 +01:00
|
|
|
import { CommunityListLoader } from '../components';
|
|
|
|
|
import { Vote } from '$features/ui';
|
|
|
|
|
import type { CommunityQuestionData } from '../utils/types';
|
2023-05-20 23:53:28 +00:00
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
interface Props {
|
|
|
|
|
isLMS?: boolean;
|
|
|
|
|
}
|
2023-08-17 14:05:01 +01:00
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
let { isLMS = false }: Props = $props();
|
2023-05-20 23:53:28 +00:00
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
let searchValue = $state('');
|
|
|
|
|
let selectedId = $state('');
|
|
|
|
|
|
|
|
|
|
function fetchCommunityQuestions(orgId?: string, profileId?: string) {
|
2024-02-13 22:17:15 +01:00
|
|
|
if (!orgId || !profileId) return;
|
|
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
untrack(async () => {
|
2025-12-22 19:57:27 +01:00
|
|
|
// Fetch courses - API class handles this
|
|
|
|
|
await communityApi.fetchCoursesForOrg(profileId, orgId);
|
|
|
|
|
// Call API - API class handles loading, errors, navigation
|
|
|
|
|
await communityApi.fetchCommunityQuestions({ orgId, isLMS });
|
2025-11-01 15:49:29 +01:00
|
|
|
});
|
2023-05-20 23:53:28 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
$effect(() => {
|
|
|
|
|
fetchCommunityQuestions($currentOrg.id, $profile.id);
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-22 19:57:27 +01:00
|
|
|
let filteredQuestions = $derived(
|
|
|
|
|
communityApi.questions.filter(
|
|
|
|
|
(question: CommunityQuestionData[number]) =>
|
|
|
|
|
question.title.toLowerCase().includes(searchValue.toLowerCase()) &&
|
|
|
|
|
(!selectedId || question.courseId === selectedId)
|
2025-11-01 15:49:29 +01:00
|
|
|
)
|
2024-02-13 22:17:15 +01:00
|
|
|
);
|
2023-05-20 23:53:28 +00:00
|
|
|
</script>
|
|
|
|
|
|
2025-12-02 09:54:38 +01:00
|
|
|
<Page.BodyHeader>
|
|
|
|
|
<Search placeholder={$t('community.find_question')} bind:value={searchValue} />
|
|
|
|
|
|
|
|
|
|
<Select.Root type="single" bind:value={selectedId}>
|
|
|
|
|
<Select.Trigger class="w-full bg-gray-100 dark:bg-neutral-800">
|
|
|
|
|
<p class="truncate">
|
2025-12-22 19:57:27 +01:00
|
|
|
{selectedId
|
|
|
|
|
? communityApi.courses.find((course) => course.id === selectedId)?.title || $t('community.all')
|
|
|
|
|
: $t('community.all')}
|
2025-12-02 09:54:38 +01:00
|
|
|
</p>
|
|
|
|
|
</Select.Trigger>
|
|
|
|
|
<Select.Content>
|
|
|
|
|
<Select.Item value="">{$t('community.all')}</Select.Item>
|
2025-12-22 19:57:27 +01:00
|
|
|
{#each communityApi.courses as course}
|
|
|
|
|
{#if course.id}
|
|
|
|
|
<Select.Item value={course.id}>{course.title}</Select.Item>
|
|
|
|
|
{/if}
|
2025-12-02 09:54:38 +01:00
|
|
|
{/each}
|
|
|
|
|
</Select.Content>
|
|
|
|
|
</Select.Root>
|
|
|
|
|
</Page.BodyHeader>
|
|
|
|
|
|
2025-12-22 19:57:27 +01:00
|
|
|
{#if communityApi.isLoading}
|
2025-12-02 09:54:38 +01:00
|
|
|
<CommunityListLoader />
|
|
|
|
|
<CommunityListLoader />
|
|
|
|
|
<CommunityListLoader />
|
|
|
|
|
<CommunityListLoader />
|
|
|
|
|
{:else}
|
2025-12-22 19:57:27 +01:00
|
|
|
{#each filteredQuestions as question}
|
2025-12-22 02:36:48 +01:00
|
|
|
<Item.Root variant="outline">
|
|
|
|
|
{#snippet child({ props })}
|
2025-12-22 19:57:27 +01:00
|
|
|
<a href="{isLMS ? '/lms' : $currentOrgPath}/community/{question.slug}" {...props}>
|
|
|
|
|
<Vote value={question.votes} />
|
2025-12-22 02:36:48 +01:00
|
|
|
<Item.Content class="gap-y-0.5">
|
|
|
|
|
<Item.Title class="mt-0">
|
2025-12-22 19:57:27 +01:00
|
|
|
{question.title}
|
2025-12-22 02:36:48 +01:00
|
|
|
</Item.Title>
|
|
|
|
|
<Item.Description>
|
2025-12-22 19:57:27 +01:00
|
|
|
{question.authorFullname} asked {calDateDiff(question.createdAt)}
|
2025-12-22 02:36:48 +01:00
|
|
|
</Item.Description>
|
2025-12-22 19:57:27 +01:00
|
|
|
<a class="m-0" href="/courses/{question.courseId}" onclick={(e) => e.stopPropagation()}>
|
2025-12-22 02:36:48 +01:00
|
|
|
<span class="text-muted-foreground p-0 text-xs">
|
2025-12-22 19:57:27 +01:00
|
|
|
#{question.courseTitle}
|
2025-12-22 02:36:48 +01:00
|
|
|
</span>
|
2023-09-05 10:23:42 +00:00
|
|
|
</a>
|
2025-12-22 02:36:48 +01:00
|
|
|
</Item.Content>
|
|
|
|
|
<Item.Actions>
|
|
|
|
|
<div class="flex items-center">
|
|
|
|
|
<MessageCirclePlusIcon size={16} />
|
2025-12-22 19:57:27 +01:00
|
|
|
<span class="ml-1">{question.comments}</span>
|
2025-12-22 02:36:48 +01:00
|
|
|
</div>
|
|
|
|
|
</Item.Actions>
|
|
|
|
|
</a>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</Item.Root>
|
2025-12-02 09:54:38 +01:00
|
|
|
{:else}
|
|
|
|
|
<Empty
|
|
|
|
|
title={$t('community.no_question')}
|
|
|
|
|
description={$t('community.ask_a_question')}
|
|
|
|
|
icon={MessageSquareMoreIcon}
|
|
|
|
|
variant="page"
|
|
|
|
|
>
|
|
|
|
|
<AskCommunityButton />
|
|
|
|
|
</Empty>
|
|
|
|
|
{/each}
|
|
|
|
|
{/if}
|