Skip to content

Commit

Permalink
fix seasons option routings
Browse files Browse the repository at this point in the history
  • Loading branch information
perfectsquare123 committed Feb 1, 2024
1 parent bc65761 commit 250c711
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/web/pages/challenges/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
-webkit-text-fill-color: transparent;
font-weight: 550;
font-size: 70px;
}
}
10 changes: 7 additions & 3 deletions apps/web/pages/challenges/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ type SeasonData = {
const seasonData: SeasonData[] = [
{
uuid: 1001,
seasonName: "season 1",
seasonName: "season1",
seasonDescription:
"this is the first ever chanllenge held by SCSE, problems vary from easy to hard mode. Everyone is welcome to join!",
},
{
uuid: 1002,
seasonName: "season 2",
seasonName: "season2",
seasonDescription:
"2nd season of challenge!! We added a few interesting problems. Come join the challenge to find out more!",
},
Expand All @@ -48,7 +48,11 @@ const Challenges = () => {

// TODO: jump to the selected season
const handleJoinClick = (seasonName: string) => {
router.push("/challenges/problems");
console.log(seasonName);
router.push({
pathname: "/challenges/problems",
query: { season: seasonName },
});
};

return (
Expand Down
14 changes: 12 additions & 2 deletions apps/web/pages/challenges/problems/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as React from "react";
import { createColumnHelper } from "@tanstack/react-table";
import { ProblemListTable } from "@/features/challenges/components/ProblemListingTable";
import Link from "next/link";
import { useState, SetStateAction } from "react";
import { useState, SetStateAction, useEffect } from "react";
import { useRouter } from "next/router";

type ProblemListData = {
uuid: number;
Expand Down Expand Up @@ -84,11 +85,19 @@ const columns = [

const Problems = () => {
const [option, setOption] = useState("");
const router = useRouter();

useEffect(() => {
const { season } = router.query;
if (season) setOption(season as string);
}, [router.query]);

const handleOptionChange = (event: {
target: { value: SetStateAction<string> };
}) => {
setOption(event.target.value);
const selectedOption = event.target.value;
setOption(selectedOption);
router.push(`/challenges/problems?season=${selectedOption}`);
};

const selectedSeasonData = seasonsData[option] || [];
Expand All @@ -107,6 +116,7 @@ const Problems = () => {
my={4}
bg="#CBD5F0"
onChange={handleOptionChange}
value={option}
>
{Object.keys(seasonsData).map((season) => (
<option key={season} value={season}>
Expand Down

0 comments on commit 250c711

Please sign in to comment.