Reusable page style for lectures

This commit is contained in:
Ibitoye Rotimi Best
2021-07-01 09:31:26 +03:00
parent e14c84a1bf
commit b76d1c9647
12 changed files with 290 additions and 203 deletions
@@ -0,0 +1,6 @@
<script>
import PageNav from "../../../../PageNav/index.svelte";
</script>
<PageNav title="Attendance" />
All attendance will be here with table
@@ -2,7 +2,11 @@
import { stores, goto } from "@sapper/app";
import Expandable from "../../Expandable/index.svelte";
import PageNav from "../../PageNav/index.svelte";
import { getNavItemRoute, getLectureRoute, getLectureNo } from "../function";
// export let lectureId;
export let courseId;
const { page } = stores();
function handleMainGroupClick(href) {
@@ -11,84 +15,92 @@
};
}
const lectures = [
const navItems = [
{
title: "Вводный урок. Soft skills",
link: "/courses/1/lecture/1",
label: "Overview",
to: getNavItemRoute(courseId),
hideSortIcon: true,
},
{
title: "Введение в ReactJS",
link: "/courses/1/lecture/2",
label: "Lectures",
to: getLectureRoute(courseId),
hideSortIcon: false,
items: [
{
id: 1,
title: "Вводный урок. Soft skills",
to: getLectureRoute(courseId, 1),
},
{
id: 2,
title: "Введение в ReactJS",
to: getLectureRoute(courseId, 2),
},
{
id: 3,
title: "Компоненты",
to: getLectureRoute(courseId, 3),
},
{
id: 4,
title: "Состояние компонентов и пропсы",
to: getLectureRoute(courseId, 4),
},
{
id: 5,
title: "Жизненный цикл",
to: getLectureRoute(courseId, 5),
},
],
},
{
title: "Компоненты",
link: "/courses/1/lecture/3",
label: "People",
to: getNavItemRoute(courseId, "people"),
hideSortIcon: true,
},
{
title: "Состояние компонентов и пропсы",
link: "/courses/1/lecture/4",
label: "Timetable",
to: getNavItemRoute(courseId, "timetable"),
hideSortIcon: true,
},
{
title: "Жизненный цикл",
link: "/courses/1/lecture/5",
label: "Scoreboard",
to: getNavItemRoute(courseId, "scoreboard"),
hideSortIcon: true,
},
{
label: "Hometasks",
to: getNavItemRoute(courseId, "hometasks"),
hideSortIcon: true,
},
];
function getLectureNo(index) {
if (index < 9) {
return `00${index}`;
}
return `0${index}`;
}
</script>
<div class="root">
<PageNav title="React.JS" />
<div>
<Expandable
label="Overview"
handleClick={handleMainGroupClick("/courses/1")}
isGroupActive={$page.path === "/courses/1"}
hideSortIcon
/>
<Expandable label="Lectures">
{#each lectures as lecture, index}
<a
class="item {(lecture.link === $page.path ||
!$page.path.length > 3) &&
'active'} pl-7 py-2"
href={lecture.link}
>
<span class="course-counter"> {getLectureNo(index + 1)} </span>
<span>{lecture.title}</span>
</a>
{/each}
</Expandable>
<Expandable
label="People"
handleClick={handleMainGroupClick("/courses/1/people")}
isGroupActive={$page.path === "/courses/1/people"}
hideSortIcon
/>
<Expandable
label="Timetable"
handleClick={handleMainGroupClick("/courses/1/timetable")}
isGroupActive={$page.path === "/courses/1/timetable"}
hideSortIcon
/>
<Expandable
label="Scoreboard"
handleClick={handleMainGroupClick("/courses/1/score")}
isGroupActive={$page.path === "/courses/1/score"}
hideSortIcon
/>
<Expandable
label="Home tasks"
handleClick={handleMainGroupClick("/courses/1/hometasks")}
isGroupActive={$page.path === "/courses/1/hometasks"}
hideSortIcon
/>
{#each navItems as navItem}
<Expandable
label={navItem.label}
handleClick={handleMainGroupClick(navItem.to)}
isGroupActive={$page.path === navItem.to}
hideSortIcon={navItem.hideSortIcon}
>
{#if Array.isArray(navItem.items)}
{#each navItem.items as item, index}
<a
class="item flex items-center {(item.to === $page.path ||
!$page.path.length > 3) &&
'active'} pl-7 py-2"
href={item.to}
>
<span class="course-counter"> {getLectureNo(index + 1)} </span>
<span>{item.title}</span>
</a>
{/each}
{/if}
</Expandable>
{/each}
</div>
</div>
@@ -0,0 +1,8 @@
<script>
import PageNav from "../../../../PageNav/index.svelte";
import PageBody from "../../../../PageBody/index.svelte";
</script>
<PageNav title="Lectures" />
<PageBody>All lecture will be here</PageBody>
@@ -35,6 +35,8 @@
variant={VARIANTS.OUTLINED}
onClick={handleAddQuestion}
label="Add Question"
mnb
v
/>
</div>
@@ -1,6 +1,6 @@
<script>
import { questionnaire } from "./store/index";
import RadioQuestion from "../../../../Question/RadioQuestion/index.svelte";
// import RadioQuestion from "../../../../Question/RadioQuestion/index.svelte";
import CheckboxQuestion from "../../../../Question/CheckboxQuestion/index.svelte";
import PrimaryButton from "../../../../PrimaryButton/index.svelte";
@@ -1,13 +1,25 @@
<script>
import MODES from "../../../../../utils/constants/mode.js";
import PrimaryContainedButton from "../../../../PrimaryContainedButton/index.svelte";
import PageBody from "../../../../PageBody/index.svelte";
import EditMode from "./EditMode.svelte";
import ViewMode from "./ViewMode.svelte";
import MODES from "../../../../../utils/constants/mode.js";
export let mode = "";
let mode = MODES.view;
</script>
{#if mode === MODES.edit}
<EditMode />
{:else}
<ViewMode />
{/if}
<PageBody>
<svelte:fragment slot="header">
<h3>Lesson 2 home exercises</h3>
<PrimaryContainedButton
label={mode === MODES.edit ? "Save" : "Edit"}
handleClick={() => (mode = mode === MODES.edit ? MODES.view : MODES.edit)}
/>
</svelte:fragment>
{#if mode === MODES.edit}
<EditMode />
{:else}
<ViewMode />
{/if}
</PageBody>
@@ -1,64 +1,55 @@
<script>
import { onMount } from "svelte";
import PageNav from "../../../PageNav/index.svelte";
import Classwork from "./Classwork.svelte";
import Homework from "./Homework/index.svelte";
import Readme from "./Readme/index.svelte";
import PrimaryContainedButton from "../../../PrimaryContainedButton/index.svelte";
import MODES from "../../../../utils/constants/mode.js";
import Home from "./Home/index.svelte";
export let path;
export let tab;
export let mode;
export let showLectureHome;
let modeLabel = "Edit";
$: modeLabel = mode === MODES.edit ? "Save" : "Edit";
function handleModeChange(e) {
e.preventDefault();
mode = mode === MODES.edit ? MODES.view : MODES.edit;
}
onMount(() => {
console.log("mounted");
});
</script>
<div>
<PageNav
navItems={[
{
label: "README.md",
isActive: tab === "lectures",
href: `${path}?tab=lectures`,
},
{
label: "Class work",
isActive: tab === "classwork",
href: `${path}?tab=classwork`,
},
{
label: "Hometasks",
isActive: tab === "hometasks",
href: `${path}?tab=hometasks`,
},
]}
>
<div slot="widget">
<PrimaryContainedButton
label={modeLabel}
handleClick={handleModeChange}
/>
</div>
</PageNav>
{#if showLectureHome}
<Home />
{:else}
<div>
<PageNav
navItems={[
{
label: "README.md",
isActive: tab === "lectures",
href: `${path}?tab=lectures`,
},
{
label: "Class work",
isActive: tab === "classwork",
href: `${path}?tab=classwork`,
},
{
label: "Hometasks",
isActive: tab === "hometasks",
href: `${path}?tab=hometasks`,
},
]}
/>
<div class="course relative">
{#if tab === "lectures"}
<Readme {mode} />
{:else if tab === "classwork"}
<Classwork />
{:else if tab === "hometasks"}
<Homework {mode} />
{/if}
<div class="course relative">
{#if tab === "lectures"}
<Readme />
{:else if tab === "classwork"}
<Classwork />
{:else if tab === "hometasks"}
<Homework />
{/if}
</div>
</div>
</div>
{/if}
<style>
.course {
@@ -0,0 +1,2 @@
import { writable } from "svelte/store";
+32
View File
@@ -0,0 +1,32 @@
const ROUTES = {
COURSES: "courses",
LECTURES: "lecture",
};
export function getNavItemRoute(courseId, routeId) {
const path = `/${ROUTES.COURSES}/${courseId}`;
if (!routeId) {
return path;
}
return `${path}/${routeId}`;
}
export function getLectureRoute(courseId, lectureId) {
const path = getNavItemRoute(courseId, ROUTES.LECTURES);
if (!lectureId) {
return path;
}
return `${path}/${lectureId}`;
}
export function getLectureNo(index) {
if (index < 9) {
return `00${index}`;
}
return `0${index}`;
}
+21 -19
View File
@@ -14,6 +14,27 @@
}
</script>
<div>
<div
class="item relative flex items-center {isGroupActive && 'active'}"
role="button"
tabindex="0"
on:click={onClick}
>
{#if !hideSortIcon}
<CaretSortDown20
class="carbon-icon-sort {isExpanded ? '' : 'carbon-icon-minimize'}"
/>
{/if}
<span class="font-bold">{label}</span>
</div>
{#if isExpanded}
<div class="flex flex-col">
<slot />
</div>
{/if}
</div>
<style>
:global(svg.carbon-icon-sort) {
position: absolute;
@@ -43,22 +64,3 @@
background-color: #cae2f9;
}
</style>
<div>
<div
class="item relative flex items-center {isGroupActive && 'active'}"
role="button"
tabindex="0"
on:click={onClick}>
{#if !hideSortIcon}
<CaretSortDown20
class="carbon-icon-sort {isExpanded ? '' : 'carbon-icon-minimize'}" />
{/if}
<span class="font-bold">{label}</span>
</div>
{#if isExpanded}
<div class="flex flex-col">
<slot />
</div>
{/if}
</div>
+22
View File
@@ -0,0 +1,22 @@
<script>
// import
</script>
<div class="m-3">
{#if $$slots.header}
<div
class="head flex bg-white items-center justify-between sticky right-0 w-full"
>
<slot name="header" />
</div>
{/if}
<slot />
</div>
<style>
.head {
top: 63px;
z-index: 2;
}
</style>
+64 -66
View File
@@ -1,68 +1,66 @@
<script context="module">
export async function preload({ params }) {
let [slug, courseNavItem, lectureId] = params.id;
return { slug, courseNavItem, lectureId };
}
</script>
<script>
import { stores } from "@sapper/app";
import Lecture from "../../../components/Course/components/Lecture/index.svelte";
import HomeTask from "../../../components/Course/components/HomeTask.svelte";
import Overview from "../../../components/Course/index.svelte";
import People from "../../../components/Course/components/People.svelte";
import Scoreboard from "../../../components/Course/components/Scoreboard.svelte";
import TimeTable from "../../../components/Course/components/TimeTable.svelte";
import CourseNav from "../../../components/Course/components/CourseNav.svelte";
import Apps from "../../../components/Apps/index.svelte";
// export let slug;
export let courseNavItem;
// export let lectureId;
const { page } = stores();
let tab = "";
let mode = "";
$: tab = $page.query.tab || "lectures";
$: mode = $page.query.mode;
</script>
<style>
.root {
display: flex;
border-right: 1px solid var(--border-color);
width: 100%;
}
.rightBar {
width: 80%;
}
</style>
<svelte:head>
<title>ReactJS</title>
</svelte:head>
<div class="root">
<CourseNav />
<div class="rightBar">
{#if !courseNavItem}
<Overview />
{:else if courseNavItem === 'score'}
<Scoreboard />
{:else if courseNavItem === 'timetable'}
<TimeTable />
{:else if courseNavItem === 'hometasks'}
<HomeTask />
{:else if courseNavItem === 'lecture'}
<Lecture path={$page.path} {tab} {mode} />
{:else if courseNavItem === 'people'}
<People />
{/if}
</div>
<Apps />
export async function preload({ params }) {
let [courseId, courseNavItem, lectureId] = params.id;
return { courseId, courseNavItem, lectureId };
}
</script>
<script>
import { stores } from "@sapper/app";
import Lecture from "../../../components/Course/components/Lecture/index.svelte";
import HomeTask from "../../../components/Course/components/HomeTask.svelte";
import Overview from "../../../components/Course/index.svelte";
import People from "../../../components/Course/components/People.svelte";
import Scoreboard from "../../../components/Course/components/Scoreboard.svelte";
import TimeTable from "../../../components/Course/components/TimeTable.svelte";
import CourseNav from "../../../components/Course/components/CourseNav.svelte";
import Apps from "../../../components/Apps/index.svelte";
export let courseId;
export let courseNavItem;
export let lectureId;
const { page } = stores();
let tab = "";
let mode = "";
$: tab = $page.query.tab || "lectures";
</script>
<svelte:head>
<title>ReactJS</title>
</svelte:head>
<div class="root">
<CourseNav {courseId} />
<div class="rightBar">
{#if !courseNavItem}
<Overview />
{:else if courseNavItem === "score"}
<Scoreboard />
{:else if courseNavItem === "timetable"}
<TimeTable />
{:else if courseNavItem === "hometasks"}
<HomeTask />
{:else if courseNavItem === "lecture"}
<Lecture path={$page.path} {tab} showLectureHome={!lectureId} />
{:else if courseNavItem === "people"}
<People />
{/if}
</div>
<Apps />
</div>
<style>
.root {
display: flex;
border-right: 1px solid var(--border-color);
width: 100%;
}
.rightBar {
width: 80%;
}
</style>