Skip to content
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

fix: 타입 애러 #96

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ export default [
},
rules: {
...commonRules,
//TODO: 추후 제거 예정 (변경 시 현재 동작에 영향이 가는 것을 고려해야함)
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/consistent-type-imports': [
'error',
{
Expand Down
5 changes: 1 addition & 4 deletions src/api/ApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
18 changes: 10 additions & 8 deletions src/api/Lecture.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AxiosError } from 'axios';
import type { Review } from 'types/evaluate';
import type { ReviewResponse } from 'types/evaluate';
import type { ExamPostsResponse } from 'types/exam';
import type { LectureDetailItem, MainLecture } from 'types/lecture';

Expand All @@ -12,7 +12,7 @@ const Lecture = () => {
const main = async (lecture = 'modifiedDate', page = 1, majorType = '') => {
try {
const data: MainLecture = await instance.get(
`/lecture/all/?option=${lecture}&page=${page}&majorType=${majorType}`
`/lecture/all/?option=${lecture}&page=${page}&majorType=${majorType}`,
);

return data;
Expand All @@ -28,11 +28,11 @@ const Lecture = () => {
searchValue = '{교수이름or과목이름}',
pageParam = 1,
option = 'modifiedDate',
major: string
major: string,
) => {
try {
const data: MainLecture = await instance.get(
`/lecture/search/?searchValue=${searchValue}&option=${option}&page=${pageParam}&majorType=${major}`
`/lecture/search/?searchValue=${searchValue}&option=${option}&page=${pageParam}&majorType=${major}`,
);

return {
Expand All @@ -59,12 +59,13 @@ const Lecture = () => {
// 검색 결과 자세히보기 (Evaluation)
const evaluation = async (selectId: string, pageParam = 1) => {
try {
const { data } = await instance.get<Review[]>(
`/evaluate-posts/?lectureId=${selectId}&page=${pageParam}`
const { data, written }: ReviewResponse = await instance.get(
`/evaluate-posts/?lectureId=${selectId}&page=${pageParam}`,
);

return {
data,
data: data,
written: written,
isLast: data.length < 10,
nextPage: pageParam + 1,
};
Expand All @@ -78,11 +79,12 @@ const Lecture = () => {
const examInfo = async (selectId: string, pageParam = 1) => {
try {
const data: ExamPostsResponse = await instance.get(
`/exam-posts/?lectureId=${selectId}&page=${pageParam}`
`/exam-posts/?lectureId=${selectId}&page=${pageParam}`,
);

return {
data,
written: data.written,
isLast: data.data.length < 10,
nextPage: pageParam + 1,
};
Expand Down
10 changes: 4 additions & 6 deletions src/api/etc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
});

Expand All @@ -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 },
});

Expand All @@ -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 = '/';
Expand All @@ -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) {
Expand Down
13 changes: 6 additions & 7 deletions src/components/ErrorFrame.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import styled from '@emotion/styled';
import { useNavigate } from 'react-router-dom';
import { AuthWrapper, Button, Container, Img } from 'styles/common';
import { AuthWrapper, Container, Img } from 'styles/common';

interface ErrorFrameProps {
status?: string;
Expand All @@ -9,17 +8,13 @@ interface ErrorFrameProps {
}

const ErrorFrame = ({ mainMsg, subMsg }: ErrorFrameProps) => {
const navigate = useNavigate();

return (
<Container>
<Img src="images/signup.svg" width={400} />
<AuthWrapper>
<StyledText id="top">{mainMsg}</StyledText>
<StyledText>{subMsg}</StyledText>
<Button background="#336af8" onClick={() => navigate('/')}>
홈으로 돌아가기
</Button>
<StyleLink href="/">홈으로 돌아가기</StyleLink>
</AuthWrapper>
</Container>
);
Expand All @@ -37,3 +32,7 @@ const StyledText = styled.div`
padding-top: 2rem;
}
`;

const StyleLink = styled.a`
text-align: center;
`;
12 changes: 6 additions & 6 deletions src/components/Lecture/IsTestInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import styled from '@emotion/styled';
import { User } from 'api';
import { Button, SearchTestInfoList,Spinner } from 'components';
import { Button, SearchTestInfoList, Spinner } from 'components';
import { fakeEvaluationList } from 'constants/placeholderData';
import useLectureQuery from 'hooks/useLectureQuery';
import { isLoginStorage } from 'utils/loginStorage';

interface IsTestInfoProps {
selectId: string;
setWritten: (value: boolean) => void;
setWritten: React.Dispatch<React.SetStateAction<boolean>>;
}

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} />;
Expand All @@ -22,10 +22,10 @@ const IsTestInfo = ({ selectId, setWritten }: IsTestInfoProps) => {
if (isLoading || !data || !data.pages[0]) return <Spinner />;

const listLength = data.pages[0].data.data.length;
const isExamDataExists = data?.pages[0].data.isExamDataExists;
const written = data?.pages[0].data.written;

if (listLength === 0) {
return isExamDataExists ? <NotUsePoint selectId={selectId} /> : <NoTestInfo />;
return written ? <NotUsePoint selectId={selectId} /> : <NoTestInfo />;
}

return (
Expand Down
4 changes: 2 additions & 2 deletions src/components/Lecture/LectureDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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} />;
};
Expand Down
14 changes: 6 additions & 8 deletions src/components/List/EvaluationList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from '@emotion/styled';
import { User } from 'api';
import { EvaluationDetail, Modal,Spinner, WriteEvaluation } from 'components';
import { EvaluationDetail, Modal, Spinner, WriteEvaluation } from 'components';
import useUserQuery from 'hooks/useUserQuery';
import { useState } from 'react';
import StarRatings from 'react-star-ratings';
Expand All @@ -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;

Expand All @@ -19,12 +19,10 @@ const EvaluationList = () => {
{isExistData ? (
<NoEvaluation>아직 평가한 강의가 없어요.</NoEvaluation>
) : (
data?.pages.map((page) => {
data?.pages.map((page, index) => {
return (
<Wrapper key={page?.nextPage}>
{page?.data.map((row) => (
<EvaluationCard key={row.id} row={row} />
))}
<Wrapper key={index}>
{page?.data.map((row) => <EvaluationCard key={row.id} row={row} />)}
</Wrapper>
);
})
Expand Down
8 changes: 3 additions & 5 deletions src/components/List/LectureList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ 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 ? (
<>
{pages?.map((page) => (
<LectureContainer key={page?.nextPage} data={page?.data.data} />
))}
{pages?.map((page, index) => <LectureContainer key={index} data={page?.data.data} />)}
<div ref={ref} style={{ marginBottom: '10px' }}>
{nextLoading ? <LectureContainer data={fakeLectureList} /> : null}
</div>
Expand Down
14 changes: 6 additions & 8 deletions src/components/List/SearchEvaluationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { User } from 'api';
import { EvaluationDetail, Spinner } from 'components';
import { fakeEvaluationList } from 'constants/placeholderData';
import useLectureQuery from 'hooks/useLectureQuery';
import { Fragment,useState } from 'react';
import { Fragment, useState } from 'react';
import StarRatings from 'react-star-ratings';
import type { Review } from 'types/evaluate';
import { floatFix } from 'utils/floatFix';
Expand All @@ -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" />;

Expand All @@ -49,11 +49,9 @@ const SearchEvaluationList = ({ selectId, setWritten, isLogin }: SearchEvaluatio
return (
<Wrapper>
<div style={{ filter: !isLogin ? 'blur(10px)' : undefined }}>
{data?.pages?.map((page) => (
<Fragment key={page?.nextPage}>
{page?.data.map((lecture) => (
<Subject key={lecture.id} lecture={lecture} />
))}
{data?.pages?.map((page, index) => (
<Fragment key={index}>
{page?.data.map((lecture) => <Subject key={lecture.id} lecture={lecture} />)}
</Fragment>
))}
<div ref={ref} style={{ marginBottom: '10px' }}>
Expand Down
8 changes: 4 additions & 4 deletions src/components/List/TestInfoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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" />;
Expand All @@ -20,9 +20,9 @@ const TestInfoList = () => {
{isExistData ? (
<NoEvaluation>아직 평가한 강의가 없어요.</NoEvaluation>
) : (
data.pages.map((page) => {
data.pages.map((page, index) => {
return (
<Wrapper key={page?.nextPage}>
<Wrapper key={index}>
{page?.data.map((row) => <TestInfoCard key={row.id} row={row} />)}
</Wrapper>
);
Expand Down
Loading
Loading