Skip to content

Commit bbadb5f

Browse files
authored
Calendar frontend (#56)
* set up backend framework for calendar displaying * basic skeleton done * frontend almost complete, no backend though
1 parent bcceddb commit bbadb5f

File tree

4 files changed

+138
-4
lines changed

4 files changed

+138
-4
lines changed

database/setup.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ CREATE TABLE Questions (
1313
cid FOREIGN KEY references Competitions(cid),
1414
numParts INTEGER NOT NULL,
1515
name TEXT NOT NULL,
16+
pixelArtLine TEXT NOT NULL,
1617
dayNum INTEGER UNIQUE NOT NULL
1718
);
1819

frontend/src/App.module.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ body {
7878
padding: 20px;
7979
}
8080

81+
/* --------------------------------------------------------- CALENDAR PAGE STYLES ---------------------------------------------------------*/
82+
83+
.puzzleBox {
84+
padding: 20px;
85+
8186
/* --------------------------------------------------------- LEADERBOARD PAGE STYLES ---------------------------------------------------*/
8287

8388
.leaderboardPage {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
3+
import PropTypes from 'prop-types';
4+
5+
import { useNavigate } from 'react-router-dom';
6+
import styles from '../nav.module.css';
7+
8+
import {puzzle, part} from '../pages/Calendar';
9+
10+
function PuzzleBox (puzzleInfo : puzzle) {
11+
const navigate = useNavigate();
12+
13+
let numStars : number = 0;
14+
for (let p of puzzleInfo.partsInfo) {
15+
numStars += p.solved ? 1 : 0;
16+
}
17+
18+
return (
19+
<>
20+
<div className={styles.puzzleBox}>
21+
<span>
22+
{puzzleInfo.pixelArtLine}
23+
</span>
24+
<span>
25+
{puzzleInfo.dayNum}
26+
</span>
27+
<span>
28+
{numStars} {' Stars'}
29+
</span>
30+
31+
32+
</div>
33+
</>
34+
);
35+
}
36+
37+
PuzzleBox.propTypes = {
38+
session: PropTypes.number,
39+
}
40+
41+
export default PuzzleBox;

frontend/src/pages/Calendar.tsx

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,62 @@ import React, { useEffect, useState } from "react";
22
import { Button, Container } from "react-bootstrap";
33
import { useNavigate } from "react-router-dom";
44

5+
import styles from "../App.module.css";
6+
7+
import PuzzleBox from "../components/PuzzleBox";
8+
59
import { 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+
732
const 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

Comments
 (0)