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

[FE] Refactor/#642: 북마크 및 전체보기 페이지 API 로직 수정 및 React-Query 적용 #644

Merged
merged 21 commits into from
Jan 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3717ebd
feat: Axios http 정의 및 get 메서드 구현
semnil5202 Jan 13, 2024
9ab2f36
refactor: Bookmarks 페이지 TopicCardList 분리 코드 합병
semnil5202 Jan 13, 2024
ab32302
design: Skeleton 컴포넌트 스타일 변경 및 적용
semnil5202 Jan 13, 2024
6f12bb4
refactor: SkeletonBox 공통 컴포넌트 구현 및 convertCSS 유틸 함수 구현
semnil5202 Jan 13, 2024
971a3b6
refactor: Skeleton 컴포넌트 Bookmark 페이지에 적용
semnil5202 Jan 13, 2024
76b4ae7
refactor: http api 수정 및 useGetBookmark isLoading 상태 사용
semnil5202 Jan 13, 2024
5ca854e
refactor: SeeAllNearTopics 페이지 TopicCardList 분리 및 코드 합병
semnil5202 Jan 13, 2024
89c5256
refactor: API 로직 반환값 타입 지정
semnil5202 Jan 13, 2024
7dd724a
refactor: Bookmark 스켈레톤 수정
semnil5202 Jan 13, 2024
6038f39
refactor: SeeAllLatestTopics 페이지 TopicCardList 분리 및 코드 합병
semnil5202 Jan 13, 2024
0efd169
refactor: SeeAllPopularTopics 페이지 TopicCardList 분리 및 코드 합병
semnil5202 Jan 13, 2024
fb7234b
refactor: AllTopics Query key 수정 및 시맨틱 태그 수정
semnil5202 Jan 13, 2024
10e9713
rename: API 명세와 페이지 이름 통일화
semnil5202 Jan 13, 2024
5c97955
refactor: 전체보기 페이지 명칭 수정 router 적용
semnil5202 Jan 13, 2024
e9a8463
feat: 리프레쉬 토큰 요청 기능 추가
semnil5202 Jan 16, 2024
a53b435
feat: query default option 설정
semnil5202 Jan 16, 2024
8db43f2
refactor: useSuspenseQuery 를 통한 선언적으로 로딩상태 처리
semnil5202 Jan 16, 2024
4b3e0f9
fix: token 없을 때 Authorization 빈 객체로 세팅하여 비로그인 오류 해결
semnil5202 Jan 16, 2024
f2fca6e
refactor: withCredentials 옵션 잠시 보류
semnil5202 Jan 17, 2024
645fbf2
refactor: 01.17 회의를 통한 변경
semnil5202 Jan 17, 2024
1e1a7a3
Merge branch 'develop-FE' into refactor/#642
jiwonh423 Jan 21, 2024
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
Prev Previous commit
Next Next commit
refactor: useSuspenseQuery 를 통한 선언적으로 로딩상태 처리
  • Loading branch information
semnil5202 committed Jan 16, 2024
commit 8db43f2f4373933ac3ce17b112823671dc893712
6 changes: 3 additions & 3 deletions frontend/src/apiHooks/new/useGetAllTopics.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useQuery } from '@tanstack/react-query';
import { useSuspenseQuery } from '@tanstack/react-query';

import { getAllTopics } from '../../apis/new';

const useGetAllTopics = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useQuery를 useSuspenseQuery로 바꾸면 SeeAllTopics.tsx에서 isloading 상태를 신경안쓰고 Suspense fallback으로 관리하면 될꺼같은데 카톡에서 말한 내용이 이부분인가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뎃츠롸잇~ 제가 푸쉬를 안했군요

const { isLoading, data: allTopics } = useQuery({
const { data: allTopics } = useSuspenseQuery({
queryKey: ['GetAllTopics'],
queryFn: getAllTopics,
});

return { isLoading, allTopics };
return { allTopics };
};

export default useGetAllTopics;
6 changes: 3 additions & 3 deletions frontend/src/apiHooks/new/useGetBestTopics.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useQuery } from '@tanstack/react-query';
import { useSuspenseQuery } from '@tanstack/react-query';

import { getBestTopics } from '../../apis/new';

const useGetBestTopics = () => {
const { isLoading, data: bestTopics } = useQuery({
const { data: bestTopics } = useSuspenseQuery({
queryKey: ['GetBestTopics'],
queryFn: getBestTopics,
});

return { isLoading, bestTopics };
return { bestTopics };
};

export default useGetBestTopics;
6 changes: 3 additions & 3 deletions frontend/src/apiHooks/new/useGetBookmarks.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useQuery } from '@tanstack/react-query';
import { useSuspenseQuery } from '@tanstack/react-query';

import { getBookmarks } from '../../apis/new';

const useGetBookmarks = () => {
const { isLoading, data: bookmarks } = useQuery({
const { data: bookmarks } = useSuspenseQuery({
queryKey: ['GetBookmarks'],
queryFn: getBookmarks,
});

return { isLoading, bookmarks };
return { bookmarks };
};

export default useGetBookmarks;
6 changes: 3 additions & 3 deletions frontend/src/apiHooks/new/useGetNewestTopics.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useQuery } from '@tanstack/react-query';
import { useSuspenseQuery } from '@tanstack/react-query';

import { getNewestTopics } from '../../apis/new';

const useGetNewestTopics = () => {
const { isLoading, data: newestTopics } = useQuery({
const { data: newestTopics } = useSuspenseQuery({
queryKey: ['GetNewestTopics'],
queryFn: getNewestTopics,
});

return { isLoading, newestTopics };
return { newestTopics };
};

export default useGetNewestTopics;
20 changes: 18 additions & 2 deletions frontend/src/components/Skeletons/TopicListSkeleton.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스켈레톤 변경 좋습네다~! 😄

Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { styled } from 'styled-components';

import Box from '../common/Box';
import Space from '../common/Space';
import SkeletonBox from './common/SkeletonBox';
import TopicCardSkeleton from './TopicCardSkeleton';

function TopicListSkeleton() {
return (
<>
<Wrapper>
<Space size={5} />
<SkeletonBox width={160} height={32} />
<Space size={4} />
<Space size={5} />
<TopicCardWrapper>
<TopicCardSkeleton />
<TopicCardSkeleton />
@@ -21,10 +27,20 @@ function TopicListSkeleton() {
<TopicCardSkeleton />
<TopicCardSkeleton />
</TopicCardWrapper>
</>
</Wrapper>
);
}

const Wrapper = styled(Box)`
width: 1140px;
margin: 0 auto;
position: relative;

@media (max-width: 1180px) {
width: 100%;
}
`;

const TopicCardWrapper = styled.section`
display: flex;
flex-wrap: wrap;
19 changes: 1 addition & 18 deletions frontend/src/pages/Bookmark.tsx
Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@ import Space from '../components/common/Space';
import MediaSpace from '../components/common/Space/MediaSpace';
import Text from '../components/common/Text';
import MediaText from '../components/common/Text/MediaText';
import SkeletonBox from '../components/Skeletons/common/SkeletonBox';
import TopicListSkeleton from '../components/Skeletons/TopicListSkeleton';
import TopicCard from '../components/TopicCard';
import { ARIA_FOCUS, FULLSCREEN } from '../constants';
import useNavigator from '../hooks/useNavigator';
@@ -24,22 +22,7 @@ function Bookmark() {
useSetNavbarHighlight('favorite');

const { routingHandlers } = useNavigator();
const { isLoading, bookmarks: topics } = useGetBookmarks();

if (isLoading)
return (
<>
<Wrapper>
<Space size={5} />
<SkeletonBox width={160} height={32} />
<Space size={0} />
<SkeletonBox width={230} height={16} />

<Space size={5} />
<TopicListSkeleton />
</Wrapper>
</>
);
const { bookmarks: topics } = useGetBookmarks();

return (
<Wrapper>
19 changes: 1 addition & 18 deletions frontend/src/pages/SeeAllAllTopics.tsx
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@ import Grid from '../components/common/Grid';
import Space from '../components/common/Space';
import MediaSpace from '../components/common/Space/MediaSpace';
import MediaText from '../components/common/Text/MediaText';
import SkeletonBox from '../components/Skeletons/common/SkeletonBox';
import TopicListSkeleton from '../components/Skeletons/TopicListSkeleton';
import TopicCard from '../components/TopicCard';
import { ARIA_FOCUS, FULLSCREEN } from '../constants';
import useSetLayoutWidth from '../hooks/useSetLayoutWidth';
@@ -19,22 +17,7 @@ function SeeAllAllTopics() {
useSetLayoutWidth(FULLSCREEN);
useSetNavbarHighlight('home');

const { isLoading, allTopics: topics } = useGetAllTopics();

if (isLoading)
return (
<>
<Wrapper>
<Space size={5} />

<SkeletonBox width={160} height={32} />
<Space size={4} />

<Space size={5} />
<TopicListSkeleton />
</Wrapper>
</>
);
const { allTopics: topics } = useGetAllTopics();

return (
<Wrapper>
19 changes: 1 addition & 18 deletions frontend/src/pages/SeeAllBestTopics.tsx
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@ import Grid from '../components/common/Grid';
import Space from '../components/common/Space';
import MediaSpace from '../components/common/Space/MediaSpace';
import MediaText from '../components/common/Text/MediaText';
import SkeletonBox from '../components/Skeletons/common/SkeletonBox';
import TopicListSkeleton from '../components/Skeletons/TopicListSkeleton';
import TopicCard from '../components/TopicCard';
import { ARIA_FOCUS, FULLSCREEN } from '../constants';
import useSetLayoutWidth from '../hooks/useSetLayoutWidth';
@@ -19,22 +17,7 @@ function SeeAllBestTopics() {
useSetLayoutWidth(FULLSCREEN);
useSetNavbarHighlight('home');

const { isLoading, bestTopics: topics } = useGetBestTopics();

if (isLoading)
return (
<>
<Wrapper>
<Space size={5} />

<SkeletonBox width={160} height={32} />
<Space size={4} />

<Space size={5} />
<TopicListSkeleton />
</Wrapper>
</>
);
const { bestTopics: topics } = useGetBestTopics();

return (
<Wrapper>
19 changes: 1 addition & 18 deletions frontend/src/pages/SeeAllNewestTopics.tsx
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@ import Grid from '../components/common/Grid';
import Space from '../components/common/Space';
import MediaSpace from '../components/common/Space/MediaSpace';
import MediaText from '../components/common/Text/MediaText';
import SkeletonBox from '../components/Skeletons/common/SkeletonBox';
import TopicListSkeleton from '../components/Skeletons/TopicListSkeleton';
import TopicCard from '../components/TopicCard';
import { ARIA_FOCUS, FULLSCREEN } from '../constants';
import useSetLayoutWidth from '../hooks/useSetLayoutWidth';
@@ -19,22 +17,7 @@ function SeeAllNewestTopics() {
useSetLayoutWidth(FULLSCREEN);
useSetNavbarHighlight('home');

const { isLoading, newestTopics: topics } = useGetNewestTopics();

if (isLoading)
return (
<>
<Wrapper>
<Space size={5} />

<SkeletonBox width={160} height={32} />
<Space size={4} />

<Space size={5} />
<TopicListSkeleton />
</Wrapper>
</>
);
const { newestTopics: topics } = useGetNewestTopics();

return (
<Wrapper>
17 changes: 9 additions & 8 deletions frontend/src/router.tsx
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import { lazy, ReactNode, Suspense } from 'react';
import { createBrowserRouter } from 'react-router-dom';

import AuthLayout from './components/Layout/AuthLayout';
import TopicListSkeleton from './components/Skeletons/TopicListSkeleton';
import Home from './pages/Home';
import NotFound from './pages/NotFound';
import RootPage from './pages/RootPage';
@@ -79,36 +80,36 @@ const routes: routeElement[] = [
{
path: 'see-all/popularity',
element: (
<SuspenseComp>
<Suspense fallback={<TopicListSkeleton />}>
<SeeAllBestTopics />
</SuspenseComp>
</Suspense>
),
withAuth: false,
},
{
path: 'see-all/near',
element: (
<SuspenseComp>
<Suspense fallback={<TopicListSkeleton />}>
<SeeAllAllTopics />
</SuspenseComp>
</Suspense>
),
withAuth: false,
},
{
path: 'see-all/latest',
element: (
<SuspenseComp>
<Suspense fallback={<TopicListSkeleton />}>
<SeeAllNewestTopics />
</SuspenseComp>
</Suspense>
),
withAuth: false,
},
{
path: 'favorite',
element: (
<SuspenseComp>
<Suspense fallback={<TopicListSkeleton />}>
<Bookmark />
</SuspenseComp>
</Suspense>
),
withAuth: true,
},