Skip to content

fix: axios 컴포넌트와 함수의 대소문자 명명 규칙 일관성 유지 #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/api/ApiController.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
10 changes: 4 additions & 6 deletions src/api/etc.ts
Original file line number Diff line number Diff line change
@@ -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<ClientRefresh>(`${PROXY_URL}/user/client-refresh`);
const res = axios.post<ClientRefresh>(`user/client-refresh`);

return res;
} catch (error) {
4 changes: 2 additions & 2 deletions src/components/Lecture/IsTestInfo.tsx
Original file line number Diff line number Diff line change
@@ -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 <SearchTestInfoList page={fakeEvaluationList} isLogin={false} />;
4 changes: 2 additions & 2 deletions src/components/Lecture/LectureDetail.tsx
Original file line number Diff line number Diff line change
@@ -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 <LectureInfoBox isLogin={isLogin} current={data?.data ? data.data : fakeLectureInfo} />;
};
4 changes: 2 additions & 2 deletions src/components/List/EvaluationList.tsx
Original file line number Diff line number Diff line change
@@ -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 <Spinner id="myInfo" />;
const isExistData = data?.pages[0]?.data.length === 0;

4 changes: 2 additions & 2 deletions src/components/List/LectureList.tsx
Original file line number Diff line number Diff line change
@@ -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 ? (
<>
4 changes: 2 additions & 2 deletions src/components/List/SearchEvaluationList.tsx
Original file line number Diff line number Diff line change
@@ -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 <Spinner id="nextPage" />;

4 changes: 2 additions & 2 deletions src/components/List/TestInfoList.tsx
Original file line number Diff line number Diff line change
@@ -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 <Spinner id="myInfo" />;
1 change: 1 addition & 0 deletions src/components/Write/WriteTestInfo.tsx
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ const WriteTestInfo = ({ setModalIsOpen, row, type }: WriteTestInfoProps) => {
examInfo: row.examInfo.split(', '),
examDifficulty: row.examDifficulty,
}); //시험내용 옵션

const handleChange = (e: React.FormEvent<HTMLFormElement>) => {
const { name, value, checked } = e.currentTarget;
const { examInfo } = examOptions;
15 changes: 8 additions & 7 deletions src/hooks/useFavoriteMajor.ts
Original file line number Diff line number Diff line change
@@ -22,21 +22,21 @@ const useFavoriteMajor = (setModalIsOpen: React.Dispatch<React.SetStateAction<bo
const token = useRecoilValue(tokenState);

// 즐겨찾기 추가/삭제
const onFavoriteMajor = (e: any) => {
const onFavoriteMajor = (e: React.MouseEvent<HTMLImageElement>) => {
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<React.SetStateAction<bo
};

// 전공 선택 변경
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const majorChange = (e: any) => setSelectedMajor(e.target.value);

// 즐겨찾기 리스트 불러오기
10 changes: 5 additions & 5 deletions src/hooks/useLectureQuery.ts
Original file line number Diff line number Diff line change
@@ -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<React.SetStateAction<boolean>>) => {
const evaluation = (id: string, setWritten: React.Dispatch<React.SetStateAction<boolean>>) => {
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<React.SetStateAction<boolean>>) => {
const testInfo = (id: string, setWritten: React.Dispatch<React.SetStateAction<boolean>>) => {
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;
10 changes: 5 additions & 5 deletions src/hooks/useUserQuery.ts
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 3 additions & 2 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -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(
</RecoilRoot>
</QueryClientProvider>
</AsyncBoundary>
</React.StrictMode>
</React.StrictMode>,
);
4 changes: 2 additions & 2 deletions src/pages/Search.tsx
Original file line number Diff line number Diff line change
@@ -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;

Loading