From 15602a92978dff27ce69f9072b65a6ca9eb5783f Mon Sep 17 00:00:00 2001 From: happycastle <41810556+happycastle114@users.noreply.github.com> Date: Fri, 1 Dec 2023 02:52:47 +0900 Subject: [PATCH 1/5] Add: URL Parameters --- src/components/molecules/LocalSelector.tsx | 10 +++++++--- src/components/organisms/LocalCouncilReport.tsx | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/components/molecules/LocalSelector.tsx b/src/components/molecules/LocalSelector.tsx index aac9b6b..9ed9f93 100644 --- a/src/components/molecules/LocalSelector.tsx +++ b/src/components/molecules/LocalSelector.tsx @@ -3,6 +3,7 @@ import { type ReactNode, useEffect, useState } from "react"; import { css } from "@emotion/react"; import { axios, hexToRgb, majorBlend, rgbToHex } from "@/utils"; import { Flex, Switch } from "antd"; +import { useSearchParams } from "react-router-dom"; interface Props { selected: MetroID; @@ -16,7 +17,8 @@ const LocalSelector = ({ selected, idMap, onClick = () => {} }: Props) => { const partyColorMap = new Map(); const [coloring, setColoring] = useState<"none" | "party">("party"); const [localPartyColor, setLocalPartyColor] = useState>(); - + const [searchParams] = useSearchParams(); + const sgYear = searchParams.get("year") || "2022"; const fetchPartyColor = async () => { await axios .get("localCouncil/partyInfo") @@ -35,7 +37,9 @@ const LocalSelector = ({ selected, idMap, onClick = () => {} }: Props) => { const fetchPartyData = () => { idMap.get(selected)?.forEach((value, key) => { axios - .get(`localCouncil/chart-data/${value[0]}/${value[1]}?factor=party`) + .get( + `localCouncil/chart-data/${value[0]}/${value[1]}?factor=party&year=${sgYear}`, + ) .then(response => { setLocalPartyColor(prev => { const data = response.data.data as { @@ -73,7 +77,7 @@ const LocalSelector = ({ selected, idMap, onClick = () => {} }: Props) => { }; useEffect(() => { fetchPartyColor().then(fetchPartyData); - }, []); + }, [searchParams.get("year")]); return ( (); const [sgType, setSgType] = useState<"elected" | "candidate">("elected"); - const [sgYear, setSgYear] = useState(2022); + const [searchParams, setSearchParams] = useSearchParams(); + const sgYear = searchParams.get("year") || 2022; + const navigate = useNavigate(); const [genderPieChartData, setGenderPieChartData] = useState(); @@ -312,7 +315,8 @@ const LocalCouncilReport = ({ )} onClick={key => { // key: "YYYY년 (제NN대)" - setSgYear(parseInt(key.split("년")[0])); + searchParams.set("year", key.split("년")[0]); + setSearchParams(searchParams); }} /> Date: Fri, 1 Dec 2023 10:09:52 +0900 Subject: [PATCH 2/5] Add: Validator --- src/components/pages/MainPage.tsx | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/components/pages/MainPage.tsx b/src/components/pages/MainPage.tsx index 6eb2e3c..7569cd2 100644 --- a/src/components/pages/MainPage.tsx +++ b/src/components/pages/MainPage.tsx @@ -1,4 +1,4 @@ -import { useParams } from "react-router-dom"; +import { useNavigate, useParams } from "react-router-dom"; import { Divider } from "antd"; import { Layout } from "@/components/templates"; import { Card } from "@/components/atoms"; @@ -10,8 +10,30 @@ import { TabSelector, } from "@/components/organisms"; +const BANNED_METRO = ["제주특별자치도", "세종특별자치시"]; + +const BANNED_LOCAL = ["군위군"]; + +const vaildateLocalAndMetroName = ( + reportType: string, + metroName: string, + localName: string, +) => { + if ( + reportType === "localCouncil" && + (BANNED_LOCAL.includes(localName) || BANNED_METRO.includes(metroName)) + ) { + return false; + } + + return true; +}; const MainPage = () => { - const { reportType = "" } = useParams(); + const { reportType = "", metroName = "", localName = "" } = useParams(); + const navigate = useNavigate(); + if (!vaildateLocalAndMetroName(reportType, metroName, localName)) { + navigate("/localCouncil", { replace: true }); + } return ( From 0177e1af49e7b30193e3e632587e9932de19c514 Mon Sep 17 00:00:00 2001 From: happycastle <41810556+happycastle114@users.noreply.github.com> Date: Fri, 1 Dec 2023 10:19:54 +0900 Subject: [PATCH 3/5] Add: year filter --- src/components/organisms/LocalCouncilReport.tsx | 6 +++--- src/components/organisms/MetroCouncilReport.tsx | 6 +++--- src/components/organisms/NationalCouncilReport.tsx | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/organisms/LocalCouncilReport.tsx b/src/components/organisms/LocalCouncilReport.tsx index 9fd6f92..a8d342d 100644 --- a/src/components/organisms/LocalCouncilReport.tsx +++ b/src/components/organisms/LocalCouncilReport.tsx @@ -310,9 +310,9 @@ const LocalCouncilReport = ({ > `${election.year}년 (제${election.ordinal}대)`, - )} + options={localElectionYears + .filter(election => election.year !== 2010) + .map(election => `${election.year}년 (제${election.ordinal}대)`)} onClick={key => { // key: "YYYY년 (제NN대)" searchParams.set("year", key.split("년")[0]); diff --git a/src/components/organisms/MetroCouncilReport.tsx b/src/components/organisms/MetroCouncilReport.tsx index 8ae9d1e..68999ff 100644 --- a/src/components/organisms/MetroCouncilReport.tsx +++ b/src/components/organisms/MetroCouncilReport.tsx @@ -288,9 +288,9 @@ const MetroCouncilReport = ({ metroName, metroMap, onLoaded }: Props) => { > `${election.year}년 (제${election.ordinal}대)`, - )} + options={localElectionYears + .filter(election => election.year !== 2010) + .map(election => `${election.year}년 (제${election.ordinal}대)`)} onClick={key => { // key: "YYYY년 (제NN대)" setSgYear(parseInt(key.split("년")[0])); diff --git a/src/components/organisms/NationalCouncilReport.tsx b/src/components/organisms/NationalCouncilReport.tsx index 61c2b2c..b66204a 100644 --- a/src/components/organisms/NationalCouncilReport.tsx +++ b/src/components/organisms/NationalCouncilReport.tsx @@ -288,9 +288,9 @@ const NationalCouncilReport = ({ > `${election.year}년 (제${election.ordinal}대)`, - )} + options={nationalElectionYears + .filter(election => election.year !== 2008) + .map(election => `${election.year}년 (제${election.ordinal}대)`)} onClick={key => { // key: "YYYY년 (제NN대)" setSgYear(parseInt(key.split("년")[0])); From a4815acbf7f7832e829701fb5314113c0cfcf1af Mon Sep 17 00:00:00 2001 From: happycastle <41810556+happycastle114@users.noreply.github.com> Date: Fri, 1 Dec 2023 10:26:26 +0900 Subject: [PATCH 4/5] Sorry lint --- src/components/organisms/LocalCouncilReport.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/organisms/LocalCouncilReport.tsx b/src/components/organisms/LocalCouncilReport.tsx index a8d342d..61be8aa 100644 --- a/src/components/organisms/LocalCouncilReport.tsx +++ b/src/components/organisms/LocalCouncilReport.tsx @@ -25,7 +25,7 @@ import { useLocalElectionYears, type ElectionYears, } from "@/utils"; -import { useNavigate, useSearchParams } from "react-router-dom"; +import { useSearchParams } from "react-router-dom"; const { Title } = Typography; @@ -80,7 +80,6 @@ const LocalCouncilReport = ({ const [sgType, setSgType] = useState<"elected" | "candidate">("elected"); const [searchParams, setSearchParams] = useSearchParams(); const sgYear = searchParams.get("year") || 2022; - const navigate = useNavigate(); const [genderPieChartData, setGenderPieChartData] = useState(); From 81b06d449474242ae295bf0d1d6da039d9d7aa93 Mon Sep 17 00:00:00 2001 From: happycastle <41810556+happycastle114@users.noreply.github.com> Date: Fri, 1 Dec 2023 10:46:44 +0900 Subject: [PATCH 5/5] Metro Validate --- src/components/pages/MainPage.tsx | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/components/pages/MainPage.tsx b/src/components/pages/MainPage.tsx index 7569cd2..fb919c3 100644 --- a/src/components/pages/MainPage.tsx +++ b/src/components/pages/MainPage.tsx @@ -1,4 +1,4 @@ -import { useNavigate, useParams } from "react-router-dom"; +import { Navigate, useParams } from "react-router-dom"; import { Divider } from "antd"; import { Layout } from "@/components/templates"; import { Card } from "@/components/atoms"; @@ -14,6 +14,27 @@ const BANNED_METRO = ["제주특별자치도", "세종특별자치시"]; const BANNED_LOCAL = ["군위군"]; +const METRO_NAMES: string[] = [ + "제주특별자치도", + "경상남도", + "경상북도", + "전라남도", + "전라북도", + "충청남도", + "충청북도", + "강원도", + "경기도", + "세종특별자치시", + "울산광역시", + "대전광역시", + "광주광역시", + "대구광역시", + "부산광역시", + "인천광역시", + "서울특별시", + "", +]; + const vaildateLocalAndMetroName = ( reportType: string, metroName: string, @@ -25,14 +46,17 @@ const vaildateLocalAndMetroName = ( ) { return false; } + if (!METRO_NAMES.includes(metroName)) { + return false; + } return true; }; + const MainPage = () => { const { reportType = "", metroName = "", localName = "" } = useParams(); - const navigate = useNavigate(); if (!vaildateLocalAndMetroName(reportType, metroName, localName)) { - navigate("/localCouncil", { replace: true }); + return ; } return (