Skip to content

Commit

Permalink
Merge pull request #58 from NewWays-TechForImpactKAIST/aju-nice
Browse files Browse the repository at this point in the history
URL 필터링 / 각종 문제 해결
  • Loading branch information
happycastle114 authored Dec 1, 2023
2 parents 1c1a2a8 + 81b06d4 commit 41aaed9
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 16 deletions.
10 changes: 7 additions & 3 deletions src/components/molecules/LocalSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,7 +17,8 @@ const LocalSelector = ({ selected, idMap, onClick = () => {} }: Props) => {
const partyColorMap = new Map<string, Color>();
const [coloring, setColoring] = useState<"none" | "party">("party");
const [localPartyColor, setLocalPartyColor] = useState<Map<string, string>>();

const [searchParams] = useSearchParams();
const sgYear = searchParams.get("year") || "2022";
const fetchPartyColor = async () => {
await axios
.get("localCouncil/partyInfo")
Expand All @@ -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 {
Expand Down Expand Up @@ -73,7 +77,7 @@ const LocalSelector = ({ selected, idMap, onClick = () => {} }: Props) => {
};
useEffect(() => {
fetchPartyColor().then(fetchPartyData);
}, []);
}, [searchParams.get("year")]);
return (
<Flex
vertical
Expand Down
13 changes: 8 additions & 5 deletions src/components/organisms/LocalCouncilReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
useLocalElectionYears,
type ElectionYears,
} from "@/utils";
import { useSearchParams } from "react-router-dom";

const { Title } = Typography;

Expand Down Expand Up @@ -77,7 +78,8 @@ const LocalCouncilReport = ({

const [genderTextData, setGenderTextData] = useState<GenderTextData>();
const [sgType, setSgType] = useState<"elected" | "candidate">("elected");
const [sgYear, setSgYear] = useState<number>(2022);
const [searchParams, setSearchParams] = useSearchParams();
const sgYear = searchParams.get("year") || 2022;

const [genderPieChartData, setGenderPieChartData] =
useState<PieChartData[]>();
Expand Down Expand Up @@ -307,12 +309,13 @@ const LocalCouncilReport = ({
>
<DropdownSelector
innerText="연도를 선택해주세요."
options={localElectionYears.map(
election => `${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]));
searchParams.set("year", key.split("년")[0]);
setSearchParams(searchParams);
}}
/>
<Switch
Expand Down
6 changes: 3 additions & 3 deletions src/components/organisms/MetroCouncilReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ const MetroCouncilReport = ({ metroName, metroMap, onLoaded }: Props) => {
>
<DropdownSelector
innerText="연도를 선택해주세요."
options={localElectionYears.map(
election => `${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]));
Expand Down
6 changes: 3 additions & 3 deletions src/components/organisms/NationalCouncilReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ const NationalCouncilReport = ({
>
<DropdownSelector
innerText="연도를 선택해주세요."
options={nationalElectionYears.map(
election => `${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]));
Expand Down
50 changes: 48 additions & 2 deletions src/components/pages/MainPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { 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";
Expand All @@ -10,8 +10,54 @@ import {
TabSelector,
} from "@/components/organisms";

const BANNED_METRO = ["제주특별자치도", "세종특별자치시"];

const BANNED_LOCAL = ["군위군"];

const METRO_NAMES: string[] = [
"제주특별자치도",
"경상남도",
"경상북도",
"전라남도",
"전라북도",
"충청남도",
"충청북도",
"강원도",
"경기도",
"세종특별자치시",
"울산광역시",
"대전광역시",
"광주광역시",
"대구광역시",
"부산광역시",
"인천광역시",
"서울특별시",
"",
];

const vaildateLocalAndMetroName = (
reportType: string,
metroName: string,
localName: string,
) => {
if (
reportType === "localCouncil" &&
(BANNED_LOCAL.includes(localName) || BANNED_METRO.includes(metroName))
) {
return false;
}
if (!METRO_NAMES.includes(metroName)) {
return false;
}

return true;
};

const MainPage = () => {
const { reportType = "" } = useParams();
const { reportType = "", metroName = "", localName = "" } = useParams();
if (!vaildateLocalAndMetroName(reportType, metroName, localName)) {
return <Navigate to="/localCouncil" replace />;
}

return (
<Layout>
Expand Down

0 comments on commit 41aaed9

Please sign in to comment.