Files
classroomio/apps/dashboard/src/lib/components/Course/index.svelte
T

57 lines
1.6 KiB
Svelte
Raw Normal View History

2021-05-08 11:47:18 +03:00
<script>
2021-09-11 21:52:46 +03:00
import RoleBasedSecurity from '../RoleBasedSecurity/index.svelte';
2021-08-18 19:47:02 +03:00
import PageNav from '../PageNav/index.svelte';
import MODES from '$lib/utils/constants/mode';
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
2021-08-24 10:45:43 +03:00
import PageBody from '../PageBody/index.svelte';
import { course } from './store';
import { updateCourse } from '$lib/utils/services/courses';
2023-09-05 13:21:44 +00:00
import TextEditor from '$lib/components/TextEditor/index.svelte';
2023-09-24 12:24:28 +01:00
import HtmlRender from '$lib/components/HTMLRender/HTMLRender.svelte';
2021-05-08 11:47:18 +03:00
2021-08-18 19:47:02 +03:00
let mode = MODES.view;
let isDirty = false;
2021-05-08 11:47:18 +03:00
2021-08-18 19:47:02 +03:00
async function handleModeChange() {
if (mode === MODES.edit) {
mode = MODES.view;
if (isDirty) {
const { overview, id } = $course;
2023-07-05 08:51:11 +00:00
await updateCourse(id, undefined, { overview });
2021-08-18 19:47:02 +03:00
}
} else {
mode = MODES.edit;
}
}
2021-05-08 11:47:18 +03:00
</script>
2021-08-18 19:47:02 +03:00
<PageNav title="Overview" disableSticky={true}>
<svelte:fragment slot="widget">
<RoleBasedSecurity allowedRoles={[1, 2]}>
2021-09-11 21:52:46 +03:00
<div class="flex items-center">
<PrimaryButton
className="mr-2"
label={mode === MODES.edit ? 'Save' : 'Edit'}
onClick={handleModeChange}
/>
</div>
</RoleBasedSecurity>
2021-08-18 19:47:02 +03:00
</svelte:fragment>
</PageNav>
2021-08-26 13:35:56 +03:00
<PageBody width="max-w-3xl px-3">
2021-08-18 19:47:02 +03:00
{#if mode === MODES.edit}
<TextEditor
2023-09-05 13:21:44 +00:00
value={$course.overview}
onChange={(html) => {
2021-08-18 19:47:02 +03:00
isDirty = true;
2023-09-05 13:21:44 +00:00
$course.overview = html;
2021-08-18 19:47:02 +03:00
}}
2023-09-05 13:21:44 +00:00
placeholder="Write your overview here"
2023-11-01 09:45:40 +00:00
height={700}
2021-08-18 19:47:02 +03:00
/>
{:else}
2023-09-24 12:24:28 +01:00
<HtmlRender className="p-2" content={$course.overview || ''} />
2021-08-18 19:47:02 +03:00
{/if}
2021-08-24 10:45:43 +03:00
</PageBody>