2023-08-02 19:35:27 +01:00
|
|
|
<script>
|
|
|
|
|
import { onMount } from 'svelte';
|
|
|
|
|
import { page } from '$app/stores';
|
|
|
|
|
import { profile } from '$lib/utils/store/user';
|
|
|
|
|
import { fetchCourses } from '$lib/components/Courses/api';
|
|
|
|
|
import Courses from '$lib/components/Courses/index.svelte';
|
|
|
|
|
import NewCourseModal from '$lib/components/Courses/components/NewCourseModal/index.svelte';
|
|
|
|
|
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
|
2023-08-07 06:18:30 +00:00
|
|
|
import { courses, createCourseModal, courseMetaDeta } from '$lib/components/Courses/store';
|
2023-08-02 19:35:27 +01:00
|
|
|
import { setProfileIdOfGroupMember } from '$lib/utils/services/courses';
|
2023-09-01 15:28:47 +01:00
|
|
|
import { currentOrg } from '$lib/utils/store/org';
|
2023-08-02 19:35:27 +01:00
|
|
|
|
|
|
|
|
export let data;
|
|
|
|
|
let { allCourses, cantFetch } = data;
|
|
|
|
|
|
|
|
|
|
const urlParams = new URLSearchParams($page.url.search);
|
|
|
|
|
|
|
|
|
|
if (urlParams.get('create') === 'true') {
|
|
|
|
|
$createCourseModal.open = true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-07 06:18:30 +00:00
|
|
|
async function getCourses(userId, orgId) {
|
|
|
|
|
if (cantFetch && typeof cantFetch === 'boolean' && !allCourses.length && orgId) {
|
2023-08-02 19:35:27 +01:00
|
|
|
$courseMetaDeta.isLoading = true;
|
|
|
|
|
|
2023-08-07 06:18:30 +00:00
|
|
|
const updatedProfile = await setProfileIdOfGroupMember($profile.email, userId);
|
2023-08-02 19:35:27 +01:00
|
|
|
console.log(`updatedProfile`, updatedProfile);
|
2023-08-07 06:18:30 +00:00
|
|
|
const coursesResult = await fetchCourses(userId, orgId);
|
2023-08-02 19:35:27 +01:00
|
|
|
console.log(`coursesResult`, coursesResult);
|
|
|
|
|
|
|
|
|
|
$courseMetaDeta.isLoading = false;
|
|
|
|
|
if (!coursesResult) return;
|
|
|
|
|
|
|
|
|
|
// organizationId = coursesResult.organizationId;
|
|
|
|
|
courses.set(coursesResult.allCourses);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
courses.set(allCourses);
|
|
|
|
|
});
|
|
|
|
|
|
2023-08-07 06:18:30 +00:00
|
|
|
$: getCourses($profile.id, $currentOrg.id);
|
2023-08-02 19:35:27 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<svelte:head>
|
|
|
|
|
<title>Courses - ClassroomIO</title>
|
|
|
|
|
</svelte:head>
|
|
|
|
|
|
|
|
|
|
<section class="w-full max-w-6xl mx-auto">
|
|
|
|
|
<div class="py-10 px-5">
|
|
|
|
|
<div class="flex items-center justify-between mb-10">
|
|
|
|
|
<h1 class="dark:text-white text-3xl font-bold">Courses</h1>
|
2023-08-07 06:18:30 +00:00
|
|
|
<PrimaryButton label="Create Course" onClick={() => ($createCourseModal.open = true)} />
|
2023-08-02 19:35:27 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<NewCourseModal />
|
|
|
|
|
|
|
|
|
|
<Courses />
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|