2023-05-20 23:53:28 +00:00
|
|
|
<script>
|
2023-08-02 19:35:27 +01:00
|
|
|
import { goto } from '$app/navigation';
|
2023-05-20 23:53:28 +00:00
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
2023-08-02 19:35:27 +01:00
|
|
|
import AddCommentIcon from 'carbon-icons-svelte/lib/AddComment.svelte';
|
2023-09-05 10:23:42 +00:00
|
|
|
import CommunityLoader from './Loader.svelte';
|
2023-08-02 19:35:27 +01:00
|
|
|
import Vote from '$lib/components/Vote/index.svelte';
|
|
|
|
|
import Box from '$lib/components/Box/index.svelte';
|
|
|
|
|
import CoursesEmptyIcon from '$lib/components/Icons/CoursesEmptyIcon.svelte';
|
|
|
|
|
import Space from '$lib/components/Space/index.svelte';
|
|
|
|
|
import { currentOrgPath, currentOrg } from '$lib/utils/store/org';
|
|
|
|
|
import { supabase } from '$lib/utils/functions/supabase';
|
2023-05-20 23:53:28 +00:00
|
|
|
|
2023-08-17 14:05:01 +01:00
|
|
|
export let isLMS = false;
|
|
|
|
|
|
2023-09-05 10:23:42 +00:00
|
|
|
let isLoading = false;
|
2023-05-20 23:53:28 +00:00
|
|
|
let discussions = [];
|
|
|
|
|
|
|
|
|
|
dayjs.extend(relativeTime);
|
|
|
|
|
|
|
|
|
|
async function fetchCommunityQuestions(orgId) {
|
|
|
|
|
if (!orgId) return;
|
2023-09-05 10:23:42 +00:00
|
|
|
isLoading = true;
|
2023-05-20 23:53:28 +00:00
|
|
|
|
|
|
|
|
const { data, error } = await supabase
|
|
|
|
|
.from('community_question')
|
|
|
|
|
.select(
|
|
|
|
|
`
|
|
|
|
|
organization_id,
|
|
|
|
|
title,
|
|
|
|
|
votes,
|
|
|
|
|
created_at,
|
|
|
|
|
slug,
|
|
|
|
|
comments:community_answer(count),
|
|
|
|
|
author:organizationmember!community_question_author_id_fkey!inner(
|
|
|
|
|
profile!inner(fullname)
|
|
|
|
|
)
|
|
|
|
|
`
|
|
|
|
|
)
|
|
|
|
|
.eq('organization_id', orgId);
|
|
|
|
|
console.log('data', data);
|
|
|
|
|
console.log('error', error);
|
2023-09-05 10:23:42 +00:00
|
|
|
isLoading = false;
|
2023-05-20 23:53:28 +00:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
console.error('Error loading community', error);
|
2023-08-17 14:05:01 +01:00
|
|
|
return goto(isLMS ? '/lms' : $currentOrgPath);
|
2023-05-20 23:53:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
discussions =
|
|
|
|
|
data?.map((discussion) => ({
|
|
|
|
|
title: discussion.title,
|
|
|
|
|
slug: discussion.slug,
|
|
|
|
|
author: discussion?.author?.profile?.fullname,
|
|
|
|
|
comments: discussion.comments?.[0]?.count || 0,
|
|
|
|
|
votes: discussion.votes,
|
2023-08-17 14:05:01 +01:00
|
|
|
createdAt: dayjs(discussion.created_at).fromNow(true)
|
2023-05-20 23:53:28 +00:00
|
|
|
})) || [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$: fetchCommunityQuestions($currentOrg.id);
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div
|
2023-09-16 22:44:20 +01:00
|
|
|
class="flex items-center justify-center lg:justify-start flex-wrap my-4 m-auto border-c rounded bg-gray-100 dark:bg-neutral-800"
|
2023-05-20 23:53:28 +00:00
|
|
|
>
|
2023-09-05 10:23:42 +00:00
|
|
|
{#if isLoading}
|
|
|
|
|
<CommunityLoader />
|
|
|
|
|
<CommunityLoader />
|
|
|
|
|
<CommunityLoader />
|
|
|
|
|
<CommunityLoader />
|
2023-05-20 23:53:28 +00:00
|
|
|
{:else}
|
2023-09-05 10:23:42 +00:00
|
|
|
{#each discussions as discussion}
|
|
|
|
|
<div class="w-full flex border-bottom-c p-5">
|
|
|
|
|
<Vote value={discussion.votes} />
|
|
|
|
|
<div class="discussion-topic-author">
|
|
|
|
|
<h4>
|
|
|
|
|
<a
|
|
|
|
|
class="text-black dark:text-white"
|
|
|
|
|
href="{isLMS ? '/lms' : $currentOrgPath}/community/{discussion.slug}"
|
|
|
|
|
>
|
|
|
|
|
{discussion.title}
|
|
|
|
|
</a>
|
|
|
|
|
</h4>
|
|
|
|
|
<span class="text-gray-600 dark:text-white">
|
|
|
|
|
{discussion.author} asked {discussion.createdAt}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<Space />
|
|
|
|
|
<div class="flex items-center">
|
|
|
|
|
<AddCommentIcon size={20} />
|
|
|
|
|
<span class="ml-1">{discussion.comments}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{:else}
|
2023-09-08 09:17:05 +00:00
|
|
|
<Box className="w-screen">
|
2023-09-05 10:23:42 +00:00
|
|
|
<CoursesEmptyIcon />
|
|
|
|
|
<h3 class="dark:text-white text-2xl my-5">No Questions asked</h3>
|
|
|
|
|
<p class="dark:text-white w-1/3 text-center">Ask a question to the community</p>
|
|
|
|
|
</Box>
|
|
|
|
|
{/each}
|
|
|
|
|
{/if}
|
2023-05-20 23:53:28 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
h4 {
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
font-weight: 900;
|
|
|
|
|
word-break: break-word;
|
|
|
|
|
overflow-wrap: break-word;
|
|
|
|
|
margin: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.discussion-topic-author {
|
|
|
|
|
margin-right: 20px;
|
|
|
|
|
}
|
|
|
|
|
.discussion-topic-author span {
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|