From 6a21716ec689d4bd3076d55dccba7c2d9768623d Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Thu, 30 Nov 2023 17:03:39 -0500 Subject: [PATCH] [+] Course page --- frontend/src/index.sass | 19 ++++++++- frontend/src/logic/sdk.ts | 32 +++++++++++----- frontend/src/pages/Course.sass | 29 ++++++++++++++ frontend/src/pages/Course.tsx | 70 +++++++++++++++++++++++++++++----- frontend/src/pages/Profile.tsx | 4 +- frontend/src/pages/Review.tsx | 2 +- 6 files changed, 133 insertions(+), 23 deletions(-) create mode 100644 frontend/src/pages/Course.sass diff --git a/frontend/src/index.sass b/frontend/src/index.sass index 0b8b389..65b42ec 100644 --- a/frontend/src/index.sass +++ b/frontend/src/index.sass @@ -10,7 +10,13 @@ $c-green: rgb(88, 204, 2) $c-green-shadow: rgb(88, 167, 0) $c-red: rgb(255, 69, 58) $c-red-shadow: darken($c-red, 10%) +$c-gold: rgb(255, 200, 0) +$c-gold-flare: rgb(251, 233, 2) +$c-gold-shadow: rgb(221, 164, 11) +$c-gold-text: rgb(195, 126, 11) $c-white-shadow: rgb(222, 222, 222) +$c-gray: rgb(229, 229, 229) +$c-gray-shadow: rgb(175, 175, 175) $border-radius: 16px $shadow-width: 0 4px 0 @@ -78,6 +84,12 @@ button.white &.no-shadow border-width: 2px +.box.green + border: none + background-color: $c-green + box-shadow: $shadow-width $c-green-shadow + color: white + input @extend .box transition: all 0.2s ease-in-out @@ -109,13 +121,16 @@ h2 gap: 1em width: 100% - height: 100% &.non-center justify-content: flex-start + &.gap2 + gap: 2em + .page-pad padding: 2em 1em + height: 100% .navbar position: fixed @@ -201,4 +216,4 @@ h2 .message.other align-self: flex-start background-color: $c-green - border-radius: 0 20px 20px 20px \ No newline at end of file + border-radius: 0 20px 20px 20px diff --git a/frontend/src/logic/sdk.ts b/frontend/src/logic/sdk.ts index 92e18b0..26cbfdb 100644 --- a/frontend/src/logic/sdk.ts +++ b/frontend/src/logic/sdk.ts @@ -15,7 +15,7 @@ export interface Lang { icon: string } -export const possibleLangs = [ +export const possibleLangs: Lang[] = [ {name: 'Mandarin Chinese', code: 'zh', icon: MandarinChinese}, {name: 'Japanese', code: 'ja', icon: Japanese}, {name: 'English', code: 'en', icon: English}, @@ -53,17 +53,31 @@ export function isLoggedIn() return !!db.user } -export function getLanguage(username: string) -{ - const users = JSON.parse(db.users) - return users[username].language -} - export function getUsername() { return db.user } +export function getLanguage(): Lang +{ + const users = JSON.parse(db.users) + const lang = users[getUsername()].language + if (!lang) + { + alert('No language set, logging out') + logout() + window.location.href = '/' + } + const lang_obj = possibleLangs.find(l => l.name === lang)! + if (!lang_obj) + { + alert(`Invalid language set: ${lang}, logging out`) + logout() + window.location.href = '/' + } + return lang_obj +} + export interface CharacterChatCreationRequest { character: string; @@ -78,12 +92,12 @@ export interface CharacterChatCreationResponse export async function startFictionalChat(character: string): Promise { const currUser = getUsername(); - const language = getLanguage(currUser); + const language = getLanguage(); const request: CharacterChatCreationRequest = { character: character, user_name: currUser, - language: language + language: language.name }; const response = await fetch(`${backendUrl}/character-chat`, { diff --git a/frontend/src/pages/Course.sass b/frontend/src/pages/Course.sass new file mode 100644 index 0000000..6c32851 --- /dev/null +++ b/frontend/src/pages/Course.sass @@ -0,0 +1,29 @@ +@import "../index" + +.course-button + @extend button + @extend .green + + box-shadow: 0 8px 0 $c-green-shadow + + width: 70px + height: 60px + border-radius: 50% + + display: flex + justify-content: center + align-items: center + font-size: 5em + overflow: hidden + + &.gray + background: $c-gray + color: $c-gray-shadow + box-shadow: 0 8px 0 $c-gray-shadow + + &.gold + background: $c-gold + color: $c-gold-text + box-shadow: 0 8px 0 $c-gold-shadow + + diff --git a/frontend/src/pages/Course.tsx b/frontend/src/pages/Course.tsx index 5935c7b..1b346c9 100644 --- a/frontend/src/pages/Course.tsx +++ b/frontend/src/pages/Course.tsx @@ -1,14 +1,66 @@ import NavBar from "../components/NavBar" +import {Icon} from "@iconify/react"; +import {getLanguage, isLoggedIn} from "../logic/sdk"; +import React from "react"; +import "./Course.sass" -export default function Course() { +function CourseButton(props: {state: 'active' | 'locked' | 'completed', index: number}) +{ + let cs = 'course-button ' + {active: 'green', locked: 'gray', completed: 'gold'}[props.state]; - return ( -
-
-

Course Page

-
- + const icon = {active: 'solar:star-bold', locked: 'solar:lock-bold', completed: 'mingcute:check-fill'}[props.state]; + + // Parameters for the sin wave + const amplitude = 50; // Change this value to adjust the wave's height + const frequency = 1; // Change this value to adjust the wave's frequency + + // Calculate the horizontal translation + const translateXValue = amplitude * Math.sin(props.index * frequency); + + return ( +
+ +
+ ) +} + + +export default function Course() +{ + if (!isLoggedIn()) + { + window.location.href = '/login'; + return
; + } + + // Get language + const lang = getLanguage(); + + return ( +
+
+ {lang.name} +
+ + 1
- ) +
+
+
Chapter 1, Section 1
+
Say hello and goodbye, use numbers
+
-} \ No newline at end of file +
+ + + + + + +
+ + +
+ ) + +} diff --git a/frontend/src/pages/Profile.tsx b/frontend/src/pages/Profile.tsx index 41fdb8c..04597cb 100644 --- a/frontend/src/pages/Profile.tsx +++ b/frontend/src/pages/Profile.tsx @@ -18,11 +18,11 @@ export default function Profile() {

Profile

Username: {username}

-

Currently Learning: {getLanguage(username)}

+

Currently Learning: {getLanguage().name}

) -} \ No newline at end of file +} diff --git a/frontend/src/pages/Review.tsx b/frontend/src/pages/Review.tsx index 62b9258..fd7f972 100644 --- a/frontend/src/pages/Review.tsx +++ b/frontend/src/pages/Review.tsx @@ -7,7 +7,7 @@ export default function Review() { const writtenReview = ["Questions", "Vocabulary"]; const verbalReview = ["Questions", "Pronunciation"]; - const language = getLanguage(getUsername()); + const language = getLanguage().name; const handleReviewLessonClick = (reviewType: string, lesson: string) => { type Question = { question: string, wordBank: string[], expected: string, type: string, exercise: string };