Skip to content

Commit

Permalink
refactor: (#110) 카테고리별 게시글 URL 경로 및 API 연동 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilpop8663 committed Jul 25, 2023
1 parent ad86c28 commit e8a4b52
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 5 additions & 2 deletions frontend/src/api/wus/postList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ interface PostListByOption {
categoryId?: number;
}

const BASE_URL = process.env.VOTOGETHER_MOCKING_URL;

export const makePostListUrl = ({
categoryId,
postStatus,
Expand All @@ -22,13 +24,14 @@ export const makePostListUrl = ({
const requestedStatus = REQUEST_STATUS_OPTION[postStatus];
const requestedSorting = REQUEST_SORTING_OPTION[postSorting];

const POST_BASE_URL = `${BASE_URL}/posts`;
const OPTION_URL = `status=${requestedStatus}&sorting=${requestedSorting}&pages=${pageNumber}`;

if (categoryId) {
return `/posts?categoryId=${categoryId}&${OPTION_URL}`;
return `${POST_BASE_URL}?categoryId=${categoryId}&${OPTION_URL}`;
}

return `/posts?${OPTION_URL}`;
return `${POST_BASE_URL}?${OPTION_URL}`;
};

export const getPostList = async ({
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/components/post/PostList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { useSearchParams } from 'react-router-dom';
import { useParams } from 'react-router-dom';

import { usePostList } from '@hooks/query/usePostList';
import { useIntersectionObserver } from '@hooks/useIntersectionObserver';
Expand All @@ -11,11 +11,10 @@ import Skeleton from '@components/common/Skeleton';
import { SORTING_OPTION, STATUS_OPTION } from '@components/post/PostListPage/constants';
import type { PostSorting, PostStatus } from '@components/post/PostListPage/types';

import { CATEGORY_ID } from './constants';
import * as S from './style';

export default function PostList() {
const [searchParams] = useSearchParams();
const { categoryId } = useParams<{ categoryId?: string }>();
const { targetRef, isIntersecting } = useIntersectionObserver({
root: null,
rootMargin: '',
Expand All @@ -26,8 +25,6 @@ export default function PostList() {
const { selectedOption: selectedSortingOption, handleOptionChange: handleSortingOptionChange } =
useSelect<PostSorting>('latest');

const categoryId = searchParams.get(CATEGORY_ID);

const { data, fetchNextPage, hasNextPage, isFetchingNextPage } = usePostList({
postSorting: selectedSortingOption,
postStatus: selectedStatusOption,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/routes/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const router = createBrowserRouter([
path: 'posts/result/:postId',
element: <VoteStatisticsPage />,
},
{ path: 'posts/category/:categoryId', element: <Home /> },
],
},
]);
Expand Down

0 comments on commit e8a4b52

Please sign in to comment.