Skip to content

Commit

Permalink
Merge pull request #42 from LikeLion-KNU/feature/ratio
Browse files Browse the repository at this point in the history
Feature/ratio
  • Loading branch information
toothlessdev authored Sep 9, 2024
2 parents 54c1fed + da61290 commit 97d25bd
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 11 deletions.
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.26.1",
"react-toastify": "^10.0.5",
"react-transition-group": "^4.4.5",
"zustand": "^4.5.5"
},
Expand Down
15 changes: 15 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { BrowserRouter } from "react-router-dom";
import { Bounce, ToastContainer } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";

import { FontsStyle } from "@/styles/fonts";
import { GlobalStyle } from "@/styles/global";
Expand All @@ -9,6 +11,19 @@ import { Global } from "@emotion/react";
export default function App() {
return (
<BrowserRouter>
<ToastContainer
position="top-center"
autoClose={3000}
hideProgressBar={false}
newestOnTop={false}
closeOnClick
rtl={false}
pauseOnFocusLoss
draggable
pauseOnHover
theme="light"
transition={Bounce}
/>
<Global styles={[FontsStyle, GlobalStyle]} />
<Router />
</BrowserRouter>
Expand Down
32 changes: 32 additions & 0 deletions src/hooks/useRatioResult.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useEffect, useState } from "react";
import { useSearchParams } from "react-router-dom";

import { api } from "@/config/axios";

interface RatioResultResponse {
status: number;
count: number;
total_count: number;
}

export const useRatioResult = () => {
const [searchParams] = useSearchParams();

const [isPending, setIsPending] = useState<boolean>(false);
const [totalCount, setTotalCount] = useState<number>(0);
const [mbtiCount, setMbtiCount] = useState<number>(0);

useEffect(() => {
setIsPending(true);
api.get<RatioResultResponse>(`/stats?type=${searchParams.get("type")}`)
.then((data) => {
setMbtiCount(data.data.count);
setTotalCount(data.data.total_count);
})
.finally(() => {
setIsPending(false);
});
}, []);

return { isPending, totalCount, mbtiCount };
};
7 changes: 7 additions & 0 deletions src/pages/AnalyticsPage.style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import styled from "@emotion/styled";

export const AnalyticsPageWrapper = styled.div`
width: 100%;
height: 100%;
margin-top: 60px;
`;

export const TitleContainer = styled.div`
display: flex;
flex-direction: column;
Expand Down
27 changes: 23 additions & 4 deletions src/pages/AnalyticsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useNavigate } from "react-router-dom";
import Footer from "@/components/display/Footer";
import DropDown from "@/components/form/DropDown";
import TopBar from "@/components/layout/TopBar";
import { TopBarContainer, TopBarWrapper } from "@/components/layout/TopBar.styled";
import { Text } from "@/components/typography";

import { useTop10 } from "@/hooks/useTop10";
Expand All @@ -13,7 +14,17 @@ import backIcon from "@/assets/back.svg";

import { results } from "@/constants/results";

import { TitleContainer, TitleTop, Main, MiddleSection, TableContainer, Card, Rank, Type } from "./AnalyticsPage.style";
import {
TitleContainer,
TitleTop,
Main,
MiddleSection,
TableContainer,
Card,
Rank,
Type,
AnalyticsPageWrapper,
} from "./AnalyticsPage.style";

export interface top10Response {
top: [string, number][];
Expand Down Expand Up @@ -67,10 +78,18 @@ export default function AnalyticsPage() {
}, [selectedDepartment]);

return (
<>
<img src={backIcon} onClick={handleGoBack} />
<AnalyticsPageWrapper>
<TopBar title="전체 통계" />

<TopBarWrapper>
<TopBarContainer>
<img src={backIcon} onClick={handleGoBack} />
<Text size="m" weight="extrabold">
전체 통계
</Text>
</TopBarContainer>
</TopBarWrapper>

<TitleContainer>
<Text size="m" weight="bold">
어떤 유형이 가장 많을까요?
Expand Down Expand Up @@ -103,6 +122,6 @@ export default function AnalyticsPage() {
{selectedDepartment && renderData(top10ByDepartment, top10ByDepartmentLoading, top10ByDepartmentError)}
</Main>
<Footer />
</>
</AnalyticsPageWrapper>
);
}
24 changes: 18 additions & 6 deletions src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { toast } from "react-toastify";

import Footer from "@/components/display/Footer";
import { Button } from "@/components/form/Button";
Expand Down Expand Up @@ -29,8 +30,7 @@ export default function HomePage() {
const { isPending, isError, totalCount } = useTotalCount();
const navigate = useNavigate();

const setName = useUserInfo((state) => state.setName);
const setMajor = useUserInfo((state) => state.setMajor);
const userInfo = useUserInfo((state) => state);

const [isOpen, setIsOpen] = useState<boolean>(false);
const [selectedMajor, setSelectedMajor] = useState<string>("");
Expand All @@ -39,9 +39,21 @@ export default function HomePage() {
setIsOpen(!isOpen);
};

const handleStart = () => {
if (!userInfo.name) {
toast.error("이름을 입력해주세용");
return;
}
if (!userInfo.major) {
toast.error("단과대학을 입력해주세용");
return;
}
navigate("/select");
};

useEffect(() => {
setMajor(selectedMajor);
}, [selectedMajor, setMajor]);
userInfo.setMajor(selectedMajor);
}, [selectedMajor, userInfo.setMajor]);

return (
<HomePageWrapper>
Expand Down Expand Up @@ -85,7 +97,7 @@ export default function HomePage() {
width="242px"
height="40px"
placeholder="이름을 입력하세용"
onChange={(e) => setName(e.currentTarget.value)}
onChange={(e) => userInfo.setName(e.currentTarget.value)}
/>
<DropDown
color="primary"
Expand All @@ -105,7 +117,7 @@ export default function HomePage() {
width="242px"
height="55px"
children="테스트 시작하기"
onClick={() => navigate("/select")}
onClick={handleStart}
/>
</ButtonContainer>

Expand Down
9 changes: 8 additions & 1 deletion src/pages/ResultPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Button } from "@/components/form/Button";
import TopBar from "@/components/layout/TopBar";
import { Text } from "@/components/typography";

import { useRatioResult } from "@/hooks/useRatioResult";
import { useResult } from "@/hooks/useResult";

import clubs from "@/constants/clubs";
Expand All @@ -24,6 +25,8 @@ import { css } from "@emotion/react";
export default function ResultPage() {
const { name, mbti, result, navigate } = useResult();

const { isPending, totalCount, mbtiCount } = useRatioResult();

return (
<>
<TopBar title="결과 보기" />
Expand Down Expand Up @@ -78,7 +81,11 @@ export default function ResultPage() {
</ClubItems>

<Text size="xs" weight="light">
<b>3,800명</b>의 참가자 중 <b>38명</b>이 이 유형이 나왔어요!
{!isPending && (
<>
<b>{totalCount}</b>의 참가자 중 <b>{mbtiCount}</b>이 이 유형이 나왔어요!
</>
)}
</Text>
</ResultContainer>

Expand Down

0 comments on commit 97d25bd

Please sign in to comment.