2021-05-08 11:47:18 +03:00
|
|
|
<script>
|
2021-08-18 19:47:02 +03:00
|
|
|
import marked from 'marked';
|
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 '../../utils/constants/mode';
|
|
|
|
|
import PrimaryButton from '../PrimaryButton/index.svelte';
|
2021-08-24 10:45:43 +03:00
|
|
|
import PageBody from '../PageBody/index.svelte';
|
2021-08-18 19:47:02 +03:00
|
|
|
import EditContent from '../EditContent/index.svelte';
|
2022-12-30 13:08:54 +01:00
|
|
|
import { course } from './store';
|
2021-08-18 19:47:02 +03:00
|
|
|
import { updateCourse } from '../../utils/services/courses';
|
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">
|
2021-09-11 21:52:46 +03:00
|
|
|
<RoleBasedSecurity allowedRoles="[1,2]">
|
|
|
|
|
<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}
|
|
|
|
|
<EditContent
|
|
|
|
|
writeLabel="Note"
|
|
|
|
|
bind:value={$course.overview}
|
|
|
|
|
placeholder="Start typing your lesson"
|
|
|
|
|
onInputChange={() => {
|
|
|
|
|
isDirty = true;
|
|
|
|
|
console.log('input change');
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
{:else}
|
2021-08-26 13:35:56 +03:00
|
|
|
<article class="preview prose prose-sm sm:prose p-2">
|
|
|
|
|
{@html marked($course.overview || '')}
|
|
|
|
|
</article>
|
2021-08-18 19:47:02 +03:00
|
|
|
{/if}
|
2021-08-24 10:45:43 +03:00
|
|
|
</PageBody>
|