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';
|
2023-08-02 19:35:27 +01:00
|
|
|
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';
|
2022-12-30 13:08:54 +01:00
|
|
|
import { course } from './store';
|
2023-08-02 19:35:27 +01:00
|
|
|
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">
|
2023-08-02 19:35:27 +01:00
|
|
|
<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-05-08 22:03:44 +03:00
|
|
|
|
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}
|
2023-08-22 11:01:09 +00:00
|
|
|
<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>
|