From 7935b78ce458dfba2f0145e9f08d0e4d88ddd4bc Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Fri, 1 Dec 2023 05:35:55 -0500 Subject: [PATCH] [O] Use course data --- frontend/src/index.sass | 4 +++- frontend/src/logic/sdk.ts | 31 ++++++++++++++++++++++++++++--- frontend/src/pages/Course.tsx | 28 ++++++++++++++-------------- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/frontend/src/index.sass b/frontend/src/index.sass index 982985d..50acb6b 100644 --- a/frontend/src/index.sass +++ b/frontend/src/index.sass @@ -128,6 +128,8 @@ h2 gap: 1em width: 100% + margin-bottom: 60px + &.non-center justify-content: flex-start @@ -256,4 +258,4 @@ h2 color: white display: flex align-items: center - justify-content: center \ No newline at end of file + justify-content: center diff --git a/frontend/src/logic/sdk.ts b/frontend/src/logic/sdk.ts index 7aa6a38..ca69b1b 100644 --- a/frontend/src/logic/sdk.ts +++ b/frontend/src/logic/sdk.ts @@ -2,6 +2,7 @@ import MandarinChinese from '../assets/img/lang/zh.svg' import Japanese from '../assets/img/lang/ja.svg' import English from '../assets/img/lang/en.svg' +import {Chapter, chapters_jp} from "./CourseData"; // db.users: Signup table map // db.user: Current logged-in user @@ -13,12 +14,13 @@ export interface Lang { name: string code: string icon: string + data: Chapter[] } export const possibleLangs: Lang[] = [ - {name: 'Mandarin Chinese', code: 'zh', icon: MandarinChinese}, - {name: 'Japanese', code: 'ja', icon: Japanese}, - {name: 'English', code: 'en', icon: English}, + // {name: 'Mandarin Chinese', code: 'zh', icon: MandarinChinese, data: []}, + {name: 'Japanese', code: 'ja', icon: Japanese, data: chapters_jp}, + // {name: 'English', code: 'en', icon: English, data: []}, ] export function signup(username: string, password: string, language: string) @@ -58,6 +60,29 @@ export function getUsername() return db.user } +export function getXp() +{ + if (!db.completed) return 0 + const completed = JSON.parse(db.completed) + return completed.length * 20 +} + +export function isStepCompleted(chapter: string, step: number) +{ + if (!db.completed) return false + const completed = JSON.parse(db.completed) + return completed.includes(`${chapter}-${step}`) +} + +export function setStepCompleted(chapter: string, step: number) +{ + if (!db.completed) + db.completed = JSON.stringify([]) + const completed = JSON.parse(db.completed) + completed.push(`${chapter}-${step}`) + db.completed = JSON.stringify(completed) +} + export function getLanguage(): Lang { const users = JSON.parse(db.users) diff --git a/frontend/src/pages/Course.tsx b/frontend/src/pages/Course.tsx index 1b346c9..85f4d5c 100644 --- a/frontend/src/pages/Course.tsx +++ b/frontend/src/pages/Course.tsx @@ -1,6 +1,6 @@ import NavBar from "../components/NavBar" import {Icon} from "@iconify/react"; -import {getLanguage, isLoggedIn} from "../logic/sdk"; +import {getLanguage, isLoggedIn, isStepCompleted} from "../logic/sdk"; import React from "react"; import "./Course.sass" @@ -45,21 +45,21 @@ export default function Course() 1 -
-
Chapter 1, Section 1
-
Say hello and goodbye, use numbers
-
-
- - - - - - -
+ {lang.data.map((chapter, i) => <> +
+
Chapter 1, Section 1
+
{chapter.name}
+
- +
+ {chapter.steps.map((step, i) => + )} +
+ + + )} )