Files
classroomio/apps/dashboard/src/lib/components/Org/Quiz/QuizCard.svelte
T

101 lines
2.8 KiB
Svelte
Raw Normal View History

2025-11-01 15:49:29 +01:00
<script lang="ts">
2023-06-17 19:11:29 +00:00
import pluralize from 'pluralize';
2025-11-01 15:49:29 +01:00
import EllipsisIcon from '@lucide/svelte/icons/ellipsis';
import { currentOrgPath } from '$lib/utils/store/org';
import { t } from '$lib/utils/functions/translations';
import { themeImages } from '$lib/utils/constants/quiz';
import { calDateDiff } from '$lib/utils/functions/date';
import { onRename, onDelete } from '$lib/utils/services/org/quiz';
import { VARIANTS } from '$lib/components/PrimaryButton/constants';
import ImageRenderer from '../ImageRenderer.svelte';
import Dropdown from '$lib/components/Dropdown/index.svelte';
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
2023-06-17 19:11:29 +00:00
2025-11-01 15:49:29 +01:00
let { quiz, totalQuestions } = $props();
2023-06-17 19:11:29 +00:00
function getOptions() {
return [
// {
// label: 'Edit',
// onClick: onEdit(quiz),
// },
// {
// label: 'Share',
// onClick: onShare(quiz),
// },
// {
// label: 'Report',
// onClick: onReport(quiz),
// },
{
2024-04-19 05:45:48 +01:00
label: $t('components.quiz.rename'),
2023-06-17 19:11:29 +00:00
onClick() {
onRename(quiz);
2023-08-11 00:19:53 +01:00
}
2023-06-17 19:11:29 +00:00
},
// {
// label: 'Make a copy',
// onClick() {
// onMakeCopy(quiz);
// },
// },
{
2024-04-19 05:45:48 +01:00
label: $t('components.quiz.delete'),
2023-06-17 19:11:29 +00:00
onClick() {
onDelete(quiz);
2023-08-11 00:19:53 +01:00
}
}
2023-06-17 19:11:29 +00:00
];
}
function startQuiz() {}
</script>
{#if quiz}
<div
2025-11-01 15:49:29 +01:00
class="root relative mb-5 flex w-full flex-col rounded-lg border bg-gray-100 p-3 transition ease-in-out hover:shadow-2xl lg:flex-row dark:bg-black"
2023-06-17 19:11:29 +00:00
>
<ImageRenderer
2023-06-17 19:11:29 +00:00
src={themeImages[quiz.theme]?.card || themeImages.standard.card}
alt="quiz-card"
className="max-w-[300px] min-w-[200px]"
2023-06-17 19:11:29 +00:00
/>
2025-11-01 15:49:29 +01:00
<div class="flex w-full flex-col justify-between p-2 md:p-5">
2023-06-17 19:11:29 +00:00
<div class="flex justify-between">
<h4 class="title text-md capitalize dark:text-white">
2023-06-17 19:11:29 +00:00
<a href="{$currentOrgPath}/quiz/{quiz.id}">{quiz.title}</a>
</h4>
2023-08-11 00:19:53 +01:00
<Dropdown options={getOptions()} classNames="absolute top-4 right-4" isIcon={true}>
2025-11-01 15:49:29 +01:00
<div class="rounded-full bg-gray-200 p-1 dark:bg-gray-600">
<EllipsisIcon size={16} />
2023-06-17 19:11:29 +00:00
</div>
</Dropdown>
</div>
2025-11-01 15:49:29 +01:00
<div class="flex flex-col justify-between md:flex-row">
2023-06-17 19:11:29 +00:00
<div>
<p class="mb-2">{pluralize('question', totalQuestions, true)}</p>
2024-04-19 05:45:48 +01:00
<p class="mb-2 md:mb-0">{$t('components.quiz.updated')} {calDateDiff(quiz.updated_at)}</p>
2023-06-17 19:11:29 +00:00
</div>
<PrimaryButton
className="px-6 py-3"
variant={VARIANTS.OUTLINED}
2024-04-19 05:45:48 +01:00
label={$t('components.quiz.start')}
2023-06-17 19:11:29 +00:00
onClick={startQuiz}
/>
</div>
</div>
</div>
{/if}
<style>
.root {
min-height: 180px;
2023-06-17 19:11:29 +00:00
}
</style>