@@ -2,10 +2,62 @@ import React, { useEffect, useState } from "react";
22import { Button , Container } from "react-bootstrap" ;
33import { useNavigate } from "react-router-dom" ;
44
5+ import styles from "../App.module.css" ;
6+
7+ import PuzzleBox from "../components/PuzzleBox" ;
8+
59import { BACKEND_URI } from "src/config" ;
610
11+ export interface puzzle {
12+ name : string ;
13+ dayNum : number ;
14+ pixelArtLine : string ;
15+ partsInfo : part [ ] ;
16+ }
17+
18+ export interface part {
19+ partNum : number ,
20+ description : string ,
21+ solved : boolean ,
22+ answer : string
23+ }
24+
25+ // puzzle: {
26+ // n_parts: integer,
27+ // name: string,
28+ // dayNum: integer,
29+ // pixelArtLine: string
30+ // }
31+
732const Calendar : React . FC < { } > = ( ) => {
33+ const defaultProblems : puzzle [ ] = [
34+ {
35+ name : 'Manav is a very cool ice cube' ,
36+ dayNum : 1 ,
37+ pixelArtLine : '...____..._____..._______...' ,
38+ partsInfo : [ ] ,
39+ } ,
40+ {
41+ name : 'Jason is a very cool ice cube' ,
42+ dayNum : 2 ,
43+ pixelArtLine : '...____..._____..._______...' ,
44+ partsInfo : [ ] ,
45+ } ,
46+ {
47+ name : 'Hanh is a very cool ice cube' ,
48+ dayNum : 3 ,
49+ pixelArtLine : '...____..._____..._______...' ,
50+ partsInfo : [ ] ,
51+ } ,
52+ {
53+ name : 'Hanyuan is a very cool ice cube' ,
54+ dayNum : 4 ,
55+ pixelArtLine : '...____..._____..._______...' ,
56+ partsInfo : [ ] ,
57+ }
58+ ] ;
859 const [ times , setTimes ] = useState ( 0 ) ;
60+ const [ showPuzzles , setShowPuzzles ] = useState ( defaultProblems ) ;
961
1062 useEffect ( ( ) => {
1163 const verifyToken = async ( ) => {
@@ -15,12 +67,47 @@ const Calendar: React.FC<{}> = () => {
1567 verifyToken ( ) ;
1668 } , [ ] ) ;
1769
70+ useEffect ( ( ) => {
71+ const getProblems = async ( ) => {
72+ const init = {
73+ method : 'GET' ,
74+ headers : {
75+ 'Content-type' : 'application/json' ,
76+ Authorization : 'insertTokenhere' ,
77+ } ,
78+ body : undefined
79+ }
80+ try {
81+ // Note, probably need to get all questions and then delete this one manually
82+ // i.e. get all questions via get and then do another post request to update
83+ const response = await fetch ( `${ BACKEND_URI } /puzzle/all` , init ) ;
84+ const body = await response . json ( ) ;
85+ if ( body . error ) {
86+ alert ( body . error ) ;
87+ } else {
88+ const puzzleList = body . puzzles ;
89+ setShowPuzzles ( puzzleList ) ;
90+ // fetchDelete(quizId, questionsList, body, setAlteredQuestion);
91+ }
92+ } catch ( e ) {
93+ alert ( e ) ;
94+ }
95+ }
96+
97+ getProblems ( ) ;
98+
99+ } , [ ] ) ;
100+
18101 return (
19102 < >
20- < Container className = "justify-content-center text-center" >
21- < p > You have clicked this button { times } times.</ p >
22- < Button onClick = { ( ) => setTimes ( times + 1 ) } > Calendar Page</ Button >
23- </ Container >
103+ < div className = { styles . quizRightPanel } >
104+ { showPuzzles . map ( ( puzzle , i ) =>
105+ < div key = { 'puzzle_' + i } className = { styles . puzzleBox } >
106+ < h2 > { 'Question ' + ( i + 1 ) } </ h2 >
107+ < PuzzleBox name = { puzzle . name } dayNum = { puzzle . dayNum } pixelArtLine = { puzzle . pixelArtLine } partsInfo = { puzzle . partsInfo } />
108+ < br />
109+ </ div > ) }
110+ </ div >
24111 </ >
25112 )
26113} ;
0 commit comments