diff --git a/src/api/ApiController.ts b/src/api/ApiController.ts index e536b3f..709a1bd 100644 --- a/src/api/ApiController.ts +++ b/src/api/ApiController.ts @@ -6,14 +6,11 @@ import { isLoginStorage } from 'utils/loginStorage'; import { logout, refresh } from './etc'; -export const PROXY_URL = window.location.hostname === 'localhost' ? '/api' : '/proxy'; axios.defaults.withCredentials = true; const JwtInterceptors = () => { const [token, setToken] = useRecoilState(tokenState); - const instance = axios.create({ - baseURL: `${PROXY_URL}`, - }); + const instance = axios.create(); //액세스토큰 유효성 검사 const isAccessTokenValid = async () => { diff --git a/src/api/etc.ts b/src/api/etc.ts index 946db59..035bbb1 100644 --- a/src/api/etc.ts +++ b/src/api/etc.ts @@ -3,12 +3,10 @@ import axios from 'axios'; import type { ClientRefresh } from 'types/user'; import { removeStorage } from 'utils/loginStorage'; -import { PROXY_URL } from './ApiController'; - // 전공 선택 의존성때문에 따로 빼놓은 것 export const type = async (Authorization: string) => { try { - const { data } = await axios.get(`${PROXY_URL}/suwiki/majorType`, { + const { data } = await axios.get(`suwiki/majorType`, { headers: { Authorization }, }); @@ -21,7 +19,7 @@ export const type = async (Authorization: string) => { export const searchFavorite = async (Authorization: string) => { try { - const { data } = await axios.get(`${PROXY_URL}/user/favorite-major`, { + const { data } = await axios.get(`user/favorite-major`, { headers: { Authorization }, }); @@ -35,7 +33,7 @@ export const searchFavorite = async (Authorization: string) => { // 로그아웃 export const logout = async () => { try { - const { data } = await axios.post(`${PROXY_URL}/user/client-logout`); + const { data } = await axios.post(`user/client-logout`); if (data.Success) { removeStorage('login'); window.location.href = '/'; @@ -49,7 +47,7 @@ export const logout = async () => { // 리프레시 export const refresh = () => { try { - const res = axios.post(`${PROXY_URL}/user/client-refresh`); + const res = axios.post(`user/client-refresh`); return res; } catch (error) { diff --git a/src/components/Lecture/IsTestInfo.tsx b/src/components/Lecture/IsTestInfo.tsx index 94aed34..241ab7f 100644 --- a/src/components/Lecture/IsTestInfo.tsx +++ b/src/components/Lecture/IsTestInfo.tsx @@ -11,9 +11,9 @@ interface IsTestInfoProps { } const IsTestInfo = ({ selectId, setWritten }: IsTestInfoProps) => { - const { TestInfo } = useLectureQuery(); + const { testInfo } = useLectureQuery(); const isLogin = isLoginStorage(); - const { data, isLoading, isFetchingNextPage, ref } = TestInfo(selectId, setWritten); + const { data, isLoading, isFetchingNextPage, ref } = testInfo(selectId, setWritten); if (!isLogin) { return ; diff --git a/src/components/Lecture/LectureDetail.tsx b/src/components/Lecture/LectureDetail.tsx index d33a92f..aa73ab0 100644 --- a/src/components/Lecture/LectureDetail.tsx +++ b/src/components/Lecture/LectureDetail.tsx @@ -3,8 +3,8 @@ import { fakeLectureInfo } from 'constants/placeholderData'; import useLectureQuery from 'hooks/useLectureQuery'; const LectureDetail = () => { - const { Detail } = useLectureQuery(); - const { data, isLogin } = Detail(); + const { detail } = useLectureQuery(); + const { data, isLogin } = detail(); return ; }; diff --git a/src/components/List/EvaluationList.tsx b/src/components/List/EvaluationList.tsx index 34e04d3..6d931e0 100644 --- a/src/components/List/EvaluationList.tsx +++ b/src/components/List/EvaluationList.tsx @@ -9,8 +9,8 @@ import { floatFix } from 'utils/floatFix'; import { subStr } from 'utils/subString'; const EvaluationList = () => { - const { EvaluationList } = useUserQuery(); - const { data, isLoading, isFetchingNextPage, ref } = EvaluationList(); + const { evaluationList } = useUserQuery(); + const { data, isLoading, isFetchingNextPage, ref } = evaluationList(); if (isLoading) return ; const isExistData = data?.pages[0]?.data.length === 0; diff --git a/src/components/List/LectureList.tsx b/src/components/List/LectureList.tsx index aaf7b80..28d7d27 100644 --- a/src/components/List/LectureList.tsx +++ b/src/components/List/LectureList.tsx @@ -19,8 +19,8 @@ interface LectureListProps { } const LectureList = ({ count, pages }: LectureListProps) => { - const { Search } = useLectureQuery(); - const { nextLoading, value, ref } = Search(); + const { search } = useLectureQuery(); + const { nextLoading, value, ref } = search(); return count ? ( <> diff --git a/src/components/List/SearchEvaluationList.tsx b/src/components/List/SearchEvaluationList.tsx index 45e44c4..f34f59c 100644 --- a/src/components/List/SearchEvaluationList.tsx +++ b/src/components/List/SearchEvaluationList.tsx @@ -27,8 +27,8 @@ interface SearchEvaluationListProps { } const SearchEvaluationList = ({ selectId, setWritten, isLogin }: SearchEvaluationListProps) => { - const { Evaluation } = useLectureQuery(); - const { data, isLoading, isFetchingNextPage, ref } = Evaluation(selectId, setWritten); + const { evaluation } = useLectureQuery(); + const { data, isLoading, isFetchingNextPage, ref } = evaluation(selectId, setWritten); if (isLoading) return ; diff --git a/src/components/List/TestInfoList.tsx b/src/components/List/TestInfoList.tsx index 97432c8..7df1e75 100644 --- a/src/components/List/TestInfoList.tsx +++ b/src/components/List/TestInfoList.tsx @@ -9,8 +9,8 @@ import { subStr } from 'utils/subString'; import type { ExamDiff } from './SearchTestInfoList'; const TestInfoList = () => { - const { TestInfoList } = useUserQuery(); - const { data, isLoading, isFetchingNextPage, ref } = TestInfoList(); + const { testInfoList } = useUserQuery(); + const { data, isLoading, isFetchingNextPage, ref } = testInfoList(); const isExistData = data?.pages[0]?.data.length === 0; if (isLoading || !data) return ; diff --git a/src/components/Write/WriteTestInfo.tsx b/src/components/Write/WriteTestInfo.tsx index 4baa441..5b176ef 100644 --- a/src/components/Write/WriteTestInfo.tsx +++ b/src/components/Write/WriteTestInfo.tsx @@ -23,6 +23,7 @@ const WriteTestInfo = ({ setModalIsOpen, row, type }: WriteTestInfoProps) => { examInfo: row.examInfo.split(', '), examDifficulty: row.examDifficulty, }); //시험내용 옵션 + const handleChange = (e: React.FormEvent) => { const { name, value, checked } = e.currentTarget; const { examInfo } = examOptions; diff --git a/src/hooks/useFavoriteMajor.ts b/src/hooks/useFavoriteMajor.ts index 6bc6980..9a5f4d0 100644 --- a/src/hooks/useFavoriteMajor.ts +++ b/src/hooks/useFavoriteMajor.ts @@ -22,21 +22,21 @@ const useFavoriteMajor = (setModalIsOpen: React.Dispatch { + const onFavoriteMajor = (e: React.MouseEvent) => { if (!isLoginStorage()) { alert('로그인 후 이용해주세요'); navigate('/login'); return; } - if (!favoriteDb.includes(e.target.alt)) { - setFavoriteDb(favoriteDb.concat([e.target.alt])); - favoriting(e.target.alt); + if (!favoriteDb.includes(e.currentTarget.alt)) { + setFavoriteDb(favoriteDb.concat([e.currentTarget.alt])); + favoriting(e.currentTarget.alt); } else { - setFavoriteDb(favoriteDb.filter((v) => v !== e.target.alt)); - unfavoriting(e.target.alt); + setFavoriteDb(favoriteDb.filter((v) => v !== e.currentTarget.alt)); + unfavoriting(e.currentTarget.alt); } - setSelectedMajor(e.target.alt); + setSelectedMajor(e.currentTarget.alt); }; // 확인 버튼 클릭 이벤트 @@ -50,6 +50,7 @@ const useFavoriteMajor = (setModalIsOpen: React.Dispatch setSelectedMajor(e.target.value); // 즐겨찾기 리스트 불러오기 diff --git a/src/hooks/useLectureQuery.ts b/src/hooks/useLectureQuery.ts index dd4c0aa..e064780 100644 --- a/src/hooks/useLectureQuery.ts +++ b/src/hooks/useLectureQuery.ts @@ -30,7 +30,7 @@ const useLectureQuery = () => { ); // 검색 쿼리(key: 검색어,정렬,전공) - const Search = () => { + const search = () => { const { ref, inView } = useInView(); const { data, @@ -59,7 +59,7 @@ const useLectureQuery = () => { }; // 강의 상세 쿼리(key: 강의id) - const Detail = () => { + const detail = () => { const { data, isLoading } = useQuery( ['lecture', 'detail', selectId], () => lecture.detail(selectId), @@ -95,7 +95,7 @@ const useLectureQuery = () => { }; // 강의평가 쿼리(key: 강의id) - const Evaluation = (id: string, setWritten: React.Dispatch>) => { + const evaluation = (id: string, setWritten: React.Dispatch>) => { const { ref, inView } = useInView(); const { data, isFetchingNextPage, isLoading, fetchNextPage } = useInfiniteQuery( ['lecture', 'evaluationList', id], @@ -122,7 +122,7 @@ const useLectureQuery = () => { }; // 시험정보 쿼리(key: 강의id) - const TestInfo = (id: string, setWritten: React.Dispatch>) => { + const testInfo = (id: string, setWritten: React.Dispatch>) => { const { ref, inView } = useInView(); const { data, isFetchingNextPage, isLoading, fetchNextPage } = useInfiniteQuery( ['lecture', 'examList', id], @@ -148,7 +148,7 @@ const useLectureQuery = () => { return { data, isFetchingNextPage, isLoading, ref }; }; - return { getMainLecture, Search, Detail, Evaluation, TestInfo }; + return { getMainLecture, search, detail, evaluation, testInfo }; }; export default useLectureQuery; diff --git a/src/hooks/useUserQuery.ts b/src/hooks/useUserQuery.ts index 88fe8bd..0698c16 100644 --- a/src/hooks/useUserQuery.ts +++ b/src/hooks/useUserQuery.ts @@ -8,7 +8,7 @@ import { isLoginStorage } from 'utils/loginStorage'; const useUserQuery = () => { const user = User(); // 내가 작성한 평가 - const EvaluationList = () => { + const evaluationList = () => { const { ref, inView } = useInView(); const { data, isLoading, fetchNextPage, isFetchingNextPage } = useInfiniteQuery( ['myInfo', 'myEvaluation'], @@ -22,7 +22,7 @@ const useUserQuery = () => { enabled: isLoginStorage(), cacheTime: CACHE_TIME.MINUTE_30, staleTime: CACHE_TIME.MINUTE_30, - } + }, ); useEffect(() => { if (inView) { @@ -34,7 +34,7 @@ const useUserQuery = () => { }; // 내가 작성한 시험정보 - const TestInfoList = () => { + const testInfoList = () => { const { ref, inView } = useInView(); const { data, isLoading, fetchNextPage, isFetchingNextPage } = useInfiniteQuery( ['myInfo', 'myExamInfo'], @@ -48,7 +48,7 @@ const useUserQuery = () => { enabled: isLoginStorage(), cacheTime: CACHE_TIME.MINUTE_30, staleTime: CACHE_TIME.MINUTE_30, - } + }, ); useEffect(() => { if (inView) { @@ -59,6 +59,6 @@ const useUserQuery = () => { return { data, isLoading, isFetchingNextPage, ref }; }; - return { EvaluationList, TestInfoList }; + return { evaluationList, testInfoList }; }; export default useUserQuery; diff --git a/src/main.tsx b/src/main.tsx index db9f93b..0970e7c 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -12,6 +12,7 @@ import { ReactQueryDevtools } from 'react-query/devtools'; import { RecoilRoot } from 'recoil'; import App from './App'; + initialize('G-KG7KQ8K3GP'); export const queryClient = new QueryClient({ @@ -23,7 +24,7 @@ export const queryClient = new QueryClient({ }, }, }); -const PROXY_URL = window.location.hostname === 'localhost' ? '' : '/proxy'; +const PROXY_URL = window.location.hostname === 'localhost' ? '/api' : '/proxy'; axios.defaults.baseURL = PROXY_URL; axios.defaults.withCredentials = true; @@ -38,5 +39,5 @@ ReactDOM.createRoot(document.getElementById('root')!).render( - + , ); diff --git a/src/pages/Search.tsx b/src/pages/Search.tsx index f30c047..304dc4a 100644 --- a/src/pages/Search.tsx +++ b/src/pages/Search.tsx @@ -4,8 +4,8 @@ import { sortOptions } from 'constants/placeholderData'; import useLectureQuery from 'hooks/useLectureQuery'; const Search = () => { - const { Search } = useLectureQuery(); - const { data } = Search(); + const { search } = useLectureQuery(); + const { data } = search(); const count = data?.pages[0]?.data.count ?? 0;