Skip to content

Commit 29bdcba

Browse files
Added markdown preview. Added round selection. Fixed homepage layout. (#13)
* md preview * added markdown preview to create question. Changed to md preview from blocknote in update question. Fixed update question. * Fixed incorrect padding * Fixed initial markdown * added round enable functionality * put up same fonts in edit and update page * commented out navigation section on dashboard
1 parent 47ba2d9 commit 29bdcba

File tree

11 files changed

+714
-83
lines changed

11 files changed

+714
-83
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"react-hook-form": "^7.53.0",
3939
"react-hot-toast": "^2.4.1",
4040
"react-icons": "^5.3.0",
41+
"react-markdown": "^9.0.1",
4142
"tailwind-merge": "^2.5.2",
4243
"tailwindcss-animate": "^1.0.7",
4344
"zod": "^3.23.8"

pnpm-lock.yaml

Lines changed: 517 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api/round.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { handleAPIError } from "@/lib/error";
2+
import api from ".";
3+
4+
export interface RoundParams{
5+
round_id: number;
6+
}
7+
8+
9+
export async function RoundEnable(data: RoundParams) {
10+
try {
11+
console.log(data)
12+
const response = await api.post<{message:string}>("/round/enable", data);
13+
return response.data;
14+
} catch (e) {
15+
16+
console.log(e)
17+
throw handleAPIError(e);
18+
}
19+
}

src/app/dashboard/page.tsx

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,43 @@
11
"use client";
2+
import Round from "@/components/round";
23
import { Button } from "@/components/ui/button";
34
import { useRouter } from "next/navigation";
45
function Dashboard() {
56
const router = useRouter();
67
return (
7-
<div>
8-
<div className="flex h-screen w-full items-center justify-around gap-20">
9-
<Button
10-
onClick={() => {
11-
router.push("/question");
12-
}}
13-
className="p-15 m-10 h-80 flex-grow border-2 border-orange-500 text-6xl"
14-
>
15-
QUESTIONS
16-
</Button>
17-
<Button
18-
onClick={() => {
19-
router.push("/users");
20-
}}
21-
className="p-15 m-10 h-80 flex-grow border-2 border-orange-500 text-6xl"
22-
>
23-
USERS
24-
</Button>
8+
<div className="h-screen">
9+
<div>
10+
{/* <div className="border-gray-300-4 relative m-10 w-full rounded-md border shadow-md">
11+
<span className="absolute -top-3 left-4 bg-black px-2 text-lg font-semibold text-white">
12+
Navigate
13+
</span>
14+
15+
<div className="mt-2 flex justify-center">
16+
<Button
17+
onClick={() => {
18+
router.push("/question");
19+
}}
20+
className="p-15 m-10 border-2 border-orange-500 p-5"
21+
>
22+
QUESTIONS
23+
</Button>
24+
<Button
25+
onClick={() => {
26+
router.push("/users");
27+
}}
28+
className="p-15 m-10 border-2 border-orange-500 p-5"
29+
>
30+
USERS
31+
</Button>
32+
</div>
33+
</div> */}
34+
<div className="border-gray-300-4 relative m-10 w-full rounded-md border shadow-md p-10">
35+
<span className="absolute -top-3 left-4 bg-black px-2 text-lg font-semibold text-white">
36+
Round Select
37+
</span>
38+
39+
<Round />
40+
</div>
2541
</div>
2642
</div>
2743
);

src/app/question/ModalUpdate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const ModalUpdate = ({id, children}: {id:string, children: React.ReactNode;}) =
55
{
66
const router = useRouter()
77
console.log(id)
8-
return(<Button className="bg-white flex justify-start p-0 text-black pl-1 hover:bg-orange-200 w-full text-left" onClick={()=>{router.push(`/question/create/${id}`)}}>{children}</Button>)
8+
return(<div className=" cursor-pointer text-sm flex justify-start p-1 rounded-md text-white bg-gray-500 pl-1 hover:bg-gray-400 w-full text-left" onClick={()=>{router.push(`/question/create/${id}`)}}>{children}</div>)
99

1010
}
1111

src/app/question/create/[qid]/page.tsx

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,26 @@ import { Input } from "@/components/ui/input";
1212
import { Label } from "@/components/ui/label";
1313
import { Textarea } from "@/components/ui/textarea";
1414
import { useMutation, useQueryClient } from "@tanstack/react-query";
15-
import dynamic from "next/dynamic";
1615

1716
import { type ApiError } from "next/dist/server/api-utils";
1817
import { useForm } from "react-hook-form";
1918
import toast from "react-hot-toast";
2019

21-
const Editor = dynamic(() => import("../editor"), { ssr: false });
2220
import { useRouter } from "next/navigation";
2321
import { useEffect, useState } from "react";
24-
import { changeData } from "../editor";
22+
import Markdown from "react-markdown";
2523

2624
const CreateButton = () => {
2725
const params = useParams<{ qid: string }>();
2826

2927
const router = useRouter();
3028
const [question, setQuestion] = useState<QuestionResponse>();
29+
const [description, setDescription] = useState<string>("teri-mummy");
3130
const queryClient = useQueryClient();
3231
useEffect(() => {
3332
void toast.promise(
3433
GetQuestionById(params.qid).then(async (q) => {
3534
setQuestion(q);
36-
37-
38-
void changeData(q)
3935
}),
4036
{
4137
loading: "Getting Question",
@@ -44,18 +40,13 @@ const CreateButton = () => {
4440
},
4541
);
4642
}, [params.qid]);
47-
const {
48-
register,
49-
handleSubmit,
50-
reset,
51-
} = useForm<UpdateQuestionParams>();
43+
const { register, handleSubmit, reset } = useForm<UpdateQuestionParams>();
5244
const createQuestion = useMutation({
5345
mutationFn: (data: UpdateQuestionParams) => {
5446
data.id = params.qid;
5547
data.input_format = data.input_format?.[0]?.split("\n") ?? [];
5648
data.points = +data.points;
5749
data.round = +data.round;
58-
5950
data.constraints = data.constraints?.[0]?.split("\n") ?? [];
6051
data.output_format = data.output_format?.[0]?.split("\n") ?? [];
6152
data.sample_test_input = data.sample_test_input?.[0]?.split("\n") ?? [];
@@ -88,7 +79,7 @@ const CreateButton = () => {
8879
<div className="grid grid-cols-4 items-center gap-4">
8980
<Label
9081
htmlFor="title"
91-
className="text-right text-lg font-bold text-primary"
82+
className="text-right text-lg font-bold text-white"
9283
>
9384
Title
9485
</Label>
@@ -103,16 +94,29 @@ const CreateButton = () => {
10394
<div className="grid grid-cols-4 items-center gap-4">
10495
<Label
10596
htmlFor="description"
106-
className="col-span-1 text-right text-lg font-bold text-primary"
97+
className="col-span-1 text-right text-lg font-bold text-white"
10798
>
10899
Description
109100
</Label>
110-
<Editor />
101+
<div className="col-span-3 flex gap-2">
102+
{/* <Editor /> */}
103+
<Textarea
104+
id="description"
105+
defaultValue={description}
106+
className="w-full"
107+
{...register("description")}
108+
onChange={(e) => setDescription(e.target.value)}
109+
rows={10}
110+
></Textarea>
111+
<Markdown className="markdown w-full border p-2">
112+
{description}
113+
</Markdown>
114+
</div>
111115
</div>
112116
<div className="grid grid-cols-4 items-center gap-4">
113117
<Label
114118
htmlFor="input_format"
115-
className="text-right text-lg font-bold text-primary"
119+
className="text-right text-lg font-bold text-white"
116120
>
117121
Input Format
118122
</Label>
@@ -127,7 +131,7 @@ const CreateButton = () => {
127131
<div className="grid grid-cols-4 items-center gap-4">
128132
<Label
129133
htmlFor="points"
130-
className="text-right text-lg font-bold text-primary"
134+
className="text-right text-lg font-bold text-white"
131135
>
132136
Points
133137
</Label>
@@ -143,7 +147,7 @@ const CreateButton = () => {
143147
<div className="grid grid-cols-4 items-center gap-4">
144148
<Label
145149
htmlFor="round"
146-
className="text-right text-lg font-bold text-primary"
150+
className="text-right text-lg font-bold text-white"
147151
>
148152
Round
149153
</Label>
@@ -161,7 +165,7 @@ const CreateButton = () => {
161165
<div className="grid grid-cols-4 items-center gap-4">
162166
<Label
163167
htmlFor="constraints"
164-
className="text-right text-lg font-bold text-primary"
168+
className="text-right text-lg font-bold text-white"
165169
>
166170
Constraints
167171
</Label>
@@ -176,7 +180,7 @@ const CreateButton = () => {
176180
<div className="grid grid-cols-4 items-center gap-4">
177181
<Label
178182
htmlFor="output_format"
179-
className="text-right text-lg font-bold text-primary"
183+
className="text-right text-lg font-bold text-white"
180184
>
181185
Output Format
182186
</Label>
@@ -191,7 +195,7 @@ const CreateButton = () => {
191195
<div className="grid grid-cols-4 items-center gap-4">
192196
<Label
193197
htmlFor="sample_test_input"
194-
className="text-right text-lg font-bold text-primary"
198+
className="text-right text-lg font-bold text-white"
195199
>
196200
Sample Test Input
197201
</Label>
@@ -206,7 +210,7 @@ const CreateButton = () => {
206210
<div className="grid grid-cols-4 items-center gap-4">
207211
<Label
208212
htmlFor="sample_test_output"
209-
className="text-right text-lg font-bold text-primary"
213+
className="text-right text-lg font-bold text-white"
210214
>
211215
Sample Test Output
212216
</Label>
@@ -221,7 +225,7 @@ const CreateButton = () => {
221225
<div className="grid grid-cols-4 items-center gap-4">
222226
<Label
223227
htmlFor="explanation"
224-
className="text-right text-lg font-bold text-primary"
228+
className="text-right text-lg font-bold text-white"
225229
>
226230
Explanation
227231
</Label>

0 commit comments

Comments
 (0)