From 66c7651834f866a873a93e12c01dd3d40f8f7622 Mon Sep 17 00:00:00 2001 From: 2NNS-V Date: Tue, 10 Sep 2024 16:15:49 +0900 Subject: [PATCH 1/5] =?UTF-8?q?refactor:=20renderData=20=ED=8C=8C=EB=9D=BC?= =?UTF-8?q?=EB=AF=B8=ED=84=B0=EC=97=90=20=ED=83=80=EC=9E=85=20=EC=A7=80?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/AnalyticsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/AnalyticsPage.tsx b/src/pages/AnalyticsPage.tsx index 3a4b7be..267ea7d 100644 --- a/src/pages/AnalyticsPage.tsx +++ b/src/pages/AnalyticsPage.tsx @@ -30,7 +30,7 @@ export interface top10Response { top: [string, number][]; } -const renderData = (data: top10Response | null, isPending: boolean, isError: any) => { +const renderData = (data: top10Response | null, isPending: boolean, isError: boolean) => { if (isPending) return 로딩중...; if (isError) return 오류가 발생했습니다.; if (!data) { From ebe8efa3cf6f7ec1f359c1cf6f49464b3ff57b22 Mon Sep 17 00:00:00 2001 From: 2NNS-V Date: Tue, 10 Sep 2024 16:16:28 +0900 Subject: [PATCH 2/5] =?UTF-8?q?remove:=20useAxios=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useAxios.tsx | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 src/hooks/useAxios.tsx diff --git a/src/hooks/useAxios.tsx b/src/hooks/useAxios.tsx deleted file mode 100644 index 4760bd6..0000000 --- a/src/hooks/useAxios.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import React from "react"; - -import axios, { AxiosRequestConfig } from "axios"; - -const instance = axios.create({ - baseURL: "https://api.dongbti.com", - withCredentials: true, -}); - -export default function useAxios(config: AxiosRequestConfig, dependencies: ReadonlyArray = []) { - const [data, setData] = React.useState(null); - const [loading, setLoading] = React.useState(false); - const [error, setError] = React.useState(null); - - React.useEffect(() => { - const fetchData = async () => { - setLoading(true); - try { - const response = await instance(config); - setData(response.data); - console.log(response.data); - } catch (err: any) { - if (axios.isAxiosError(err)) { - setError(err.message || "Something went wrong"); - } else { - setError("Something went wrong"); - } - } finally { - setLoading(false); - } - }; - fetchData(); - }, dependencies); - - return { data, loading, error }; -} From 2c6413cdd58bbbd6b9fb6ec1602e77d16e2aae95 Mon Sep 17 00:00:00 2001 From: 2NNS-V Date: Wed, 11 Sep 2024 10:48:27 +0900 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20major=20->=20deparment=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useSubmitResult.tsx | 4 ++-- src/pages/HomePage.tsx | 12 ++++++------ src/store/store.ts | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/hooks/useSubmitResult.tsx b/src/hooks/useSubmitResult.tsx index bc9bb71..e2820fc 100644 --- a/src/hooks/useSubmitResult.tsx +++ b/src/hooks/useSubmitResult.tsx @@ -6,7 +6,7 @@ import { useUserInfo } from "@/store/store"; export const useSubmitResult = () => { const [isPending, setIsPending] = useState(false); - const major = useUserInfo((state) => state.major); + const department = useUserInfo((state) => state.department); const navigate = useNavigate(); const [searchParams] = useSearchParams(); @@ -15,7 +15,7 @@ export const useSubmitResult = () => { const mbti = searchParams.get("type"); console.log(searchParams); - api.post("/stats", { department: major, mbti }) + api.post("/stats", { department: department, mbti }) .then(() => { navigate(`/result?type=${mbti}`); }) diff --git a/src/pages/HomePage.tsx b/src/pages/HomePage.tsx index 00f06da..4c308be 100644 --- a/src/pages/HomePage.tsx +++ b/src/pages/HomePage.tsx @@ -33,7 +33,7 @@ export default function HomePage() { const userInfo = useUserInfo((state) => state); const [isOpen, setIsOpen] = useState(false); - const [selectedMajor, setSelectedMajor] = useState(""); + const [selectedDepartment, setSelectedDepartment] = useState(""); const handleSideBar = () => { setIsOpen(!isOpen); @@ -44,7 +44,7 @@ export default function HomePage() { toast.error("이름을 입력해주세용"); return; } - if (!userInfo.major) { + if (!userInfo.department) { toast.error("단과대학을 입력해주세용"); return; } @@ -52,8 +52,8 @@ export default function HomePage() { }; useEffect(() => { - userInfo.setMajor(selectedMajor); - }, [selectedMajor, userInfo.setMajor]); + userInfo.setDepartment(selectedDepartment); + }, [selectedDepartment, userInfo.setDepartment]); return ( @@ -103,8 +103,8 @@ export default function HomePage() { color="primary" width="242px" height="30px" - selectedDepartment={selectedMajor} - setSelectedDepartment={setSelectedMajor} + selectedDepartment={selectedDepartment} + setSelectedDepartment={setSelectedDepartment} /> 개인정보는 외부에 공유되지 않으니 안심하세용 diff --git a/src/store/store.ts b/src/store/store.ts index 562f30d..2409a76 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -2,17 +2,17 @@ import { create } from "zustand"; type UserProps = { name: string; - major: string; + department: string; }; type UserAction = { setName: (name: UserProps["name"]) => void; - setMajor: (major: UserProps["major"]) => void; + setDepartment: (department: UserProps["department"]) => void; }; export const useUserInfo = create()((set) => ({ name: "", - major: "", + department: "", setName: (name) => set(() => ({ name: name })), - setMajor: (major) => set(() => ({ major: major })), + setDepartment: (department) => set(() => ({ department: department })), })); From d39e121bffe709d2f95690de21751e992f76e8c2 Mon Sep 17 00:00:00 2001 From: 2NNS-V Date: Wed, 11 Sep 2024 10:50:12 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20zustand-persist=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/store.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/store/store.ts b/src/store/store.ts index 2409a76..18aabdc 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -1,5 +1,7 @@ import { create } from "zustand"; +import { persist } from "zustand/middleware"; + type UserProps = { name: string; department: string; @@ -10,9 +12,17 @@ type UserAction = { setDepartment: (department: UserProps["department"]) => void; }; -export const useUserInfo = create()((set) => ({ - name: "", - department: "", - setName: (name) => set(() => ({ name: name })), - setDepartment: (department) => set(() => ({ department: department })), -})); +export const useUserInfo = create()( + persist( + (set) => ({ + name: "", + department: "", + setName: (name) => set(() => ({ name: name })), + setDepartment: (department) => set(() => ({ department: department })), + }), + { + name: "user-storage", + getStorage: () => localStorage, + }, + ), +); From cb069b800cf89eca0b5aec111ab3de3f04224579 Mon Sep 17 00:00:00 2001 From: 2NNS-V Date: Wed, 11 Sep 2024 11:08:33 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20=EB=A1=9C=EC=BB=AC=EC=8A=A4?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=EC=A7=80=EC=97=90=20=EA=B0=92=EC=9D=B4=20?= =?UTF-8?q?=EC=9E=88=EB=8B=A4=EB=A9=B4=20name,=20department=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/HomePage.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/HomePage.tsx b/src/pages/HomePage.tsx index 9a492d8..91aac7e 100644 --- a/src/pages/HomePage.tsx +++ b/src/pages/HomePage.tsx @@ -33,7 +33,7 @@ export default function HomePage() { const userInfo = useUserInfo((state) => state); const [isOpen, setIsOpen] = useState(false); - const [selectedDepartment, setSelectedDepartment] = useState(""); + const [selectedDepartment, setSelectedDepartment] = useState(userInfo.department); const handleSideBar = () => { setIsOpen(!isOpen); @@ -98,6 +98,7 @@ export default function HomePage() { height="45px" placeholder="이름을 입력하세용" onChange={(e) => userInfo.setName(e.currentTarget.value)} + defaultValue={userInfo.name} />