[O] Use course data
This commit is contained in:
@@ -128,6 +128,8 @@ h2
|
|||||||
gap: 1em
|
gap: 1em
|
||||||
width: 100%
|
width: 100%
|
||||||
|
|
||||||
|
margin-bottom: 60px
|
||||||
|
|
||||||
&.non-center
|
&.non-center
|
||||||
justify-content: flex-start
|
justify-content: flex-start
|
||||||
|
|
||||||
@@ -256,4 +258,4 @@ h2
|
|||||||
color: white
|
color: white
|
||||||
display: flex
|
display: flex
|
||||||
align-items: center
|
align-items: center
|
||||||
justify-content: center
|
justify-content: center
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import MandarinChinese from '../assets/img/lang/zh.svg'
|
import MandarinChinese from '../assets/img/lang/zh.svg'
|
||||||
import Japanese from '../assets/img/lang/ja.svg'
|
import Japanese from '../assets/img/lang/ja.svg'
|
||||||
import English from '../assets/img/lang/en.svg'
|
import English from '../assets/img/lang/en.svg'
|
||||||
|
import {Chapter, chapters_jp} from "./CourseData";
|
||||||
|
|
||||||
// db.users: Signup table map<username, password>
|
// db.users: Signup table map<username, password>
|
||||||
// db.user: Current logged-in user
|
// db.user: Current logged-in user
|
||||||
@@ -13,12 +14,13 @@ export interface Lang {
|
|||||||
name: string
|
name: string
|
||||||
code: string
|
code: string
|
||||||
icon: string
|
icon: string
|
||||||
|
data: Chapter[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const possibleLangs: Lang[] = [
|
export const possibleLangs: Lang[] = [
|
||||||
{name: 'Mandarin Chinese', code: 'zh', icon: MandarinChinese},
|
// {name: 'Mandarin Chinese', code: 'zh', icon: MandarinChinese, data: []},
|
||||||
{name: 'Japanese', code: 'ja', icon: Japanese},
|
{name: 'Japanese', code: 'ja', icon: Japanese, data: chapters_jp},
|
||||||
{name: 'English', code: 'en', icon: English},
|
// {name: 'English', code: 'en', icon: English, data: []},
|
||||||
]
|
]
|
||||||
|
|
||||||
export function signup(username: string, password: string, language: string)
|
export function signup(username: string, password: string, language: string)
|
||||||
@@ -58,6 +60,29 @@ export function getUsername()
|
|||||||
return db.user
|
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
|
export function getLanguage(): Lang
|
||||||
{
|
{
|
||||||
const users = JSON.parse(db.users)
|
const users = JSON.parse(db.users)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import NavBar from "../components/NavBar"
|
import NavBar from "../components/NavBar"
|
||||||
import {Icon} from "@iconify/react";
|
import {Icon} from "@iconify/react";
|
||||||
import {getLanguage, isLoggedIn} from "../logic/sdk";
|
import {getLanguage, isLoggedIn, isStepCompleted} from "../logic/sdk";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import "./Course.sass"
|
import "./Course.sass"
|
||||||
|
|
||||||
@@ -45,21 +45,21 @@ export default function Course()
|
|||||||
<span>1</span>
|
<span>1</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="box green">
|
|
||||||
<div>Chapter 1, Section 1</div>
|
|
||||||
<div className="font-bold">Say hello and goodbye, use numbers</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="v-layout non-center items-center gap2">
|
{lang.data.map((chapter, i) => <>
|
||||||
<CourseButton state={'completed'} index={0}/>
|
<div className="box green">
|
||||||
<CourseButton state={'active'} index={1}/>
|
<div>Chapter 1, Section 1</div>
|
||||||
<CourseButton state={'locked'} index={2}/>
|
<div className="font-bold">{chapter.name}</div>
|
||||||
<CourseButton state={'locked'} index={3}/>
|
</div>
|
||||||
<CourseButton state={'locked'} index={4}/>
|
|
||||||
<CourseButton state={'locked'} index={5}/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<NavBar/>
|
<div className="v-layout non-center items-center gap2">
|
||||||
|
{chapter.steps.map((step, i) =>
|
||||||
|
<CourseButton state={isStepCompleted(chapter.name, i) ? 'completed' : i == 0 || isStepCompleted(chapter.name, i - 1) ? 'active' : 'locked'}
|
||||||
|
index={i} key={i}/>)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<NavBar/>
|
||||||
|
</>)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user