Skip to content

Commit

Permalink
feat: 베스트 게시물 표시 기능 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
heonq committed Dec 7, 2024
1 parent 224c32f commit 9f03bc5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/components/community/bestArticle/bestArticleListClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,43 @@ import { getArticleList } from '@/services/api/article';
import { GetArticleListResponse } from '@/services/types/article';
import { useQuery } from '@tanstack/react-query';
import BestArticleCard from './bestArticleCard';
import { useAtom } from 'jotai';
import { screenWidthAtom } from '@/lib/store/atoms';
import { MEDIA_QUERY } from '@/constants/mediaQuery';

export default function BestArticleListClient({
initialData,
}: {
initialData: GetArticleListResponse;
}) {
const [screenWidth] = useAtom(screenWidthAtom);
const { data } = useQuery({
queryKey: ['bestArticles'],
queryFn: () => getArticleList({ skip: 0, take: 3, orderBy: 'recent' }),
queryFn: () =>
getArticleList({
skip: 0,
take: 3,
orderBy: 'recent',
}),
initialData,
});

return (
<>
{data.data.map((article) => {
return (
<BestArticleCard
key={article.id}
nickname='총명한 판다'
title={article.title}
likes={999}
createdAt={article.createdAt}
articleId={article.id}
/>
);
})}
{data.data
.slice(0, MEDIA_QUERY.bestArticlePageSize[screenWidth!])
.map((article) => {
return (
<BestArticleCard
key={article.id}
nickname='총명한 판다'
title={article.title}
likes={999}
createdAt={article.createdAt}
articleId={article.id}
/>
);
})}
</>
);
}
5 changes: 5 additions & 0 deletions src/constants/mediaQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ export const MEDIA_QUERY = Object.freeze({
medium: 6,
small: 4,
}),
bestArticlePageSize: Object.freeze({
large: 3,
medium: 2,
small: 1,
}),
});

0 comments on commit 9f03bc5

Please sign in to comment.