Skip to content

Commit 3d67e7f

Browse files
committed
hotfix: 총 게시글 수 증가 표시 관련 오류 핫픽스
1 parent 0ca05d9 commit 3d67e7f

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/app/(auth-required)/main/Content.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { useInfiniteQuery, useQuery } from '@tanstack/react-query';
44
import { useEffect, useMemo } from 'react';
55
import { useInView } from 'react-intersection-observer';
6-
import { postList, postSummary } from '@/apis';
6+
import { postList, postSummary, totalStats } from '@/apis';
77
import { Section, Summary } from '@/app/components';
88
import { PATHS, SORT_TYPE } from '@/constants';
99
import { useSearchParam } from '@/hooks';
@@ -42,6 +42,12 @@ export const Content = () => {
4242
queryFn: postSummary,
4343
});
4444

45+
const { data: yesterdayPostCount } = useQuery({
46+
queryKey: [PATHS.TOTALSTATS],
47+
queryFn: async () => totalStats('post'),
48+
select: (data) => data.slice(1, 2)[0]?.value,
49+
});
50+
4551
useEffect(() => {
4652
const pages = posts?.pages;
4753
if (!pages?.length || !inView) return;
@@ -59,7 +65,7 @@ export const Content = () => {
5965

6066
return (
6167
<div className="flex w-full h-full gap-[30px] max-MBI:flex-col max-TBL:gap-[20px] overflow-hidden">
62-
{summaries && <Summary {...summaries} />}
68+
{summaries && <Summary {...summaries} yesterdayPostCount={yesterdayPostCount} />}
6369

6470
<div className="w-full flex flex-col gap-[30px] overflow-auto max-TBL:gap-[20px]">
6571
<div className="flex h-fit flex-col items-center p-[20px] bg-BG-SUB gap-5 rounded-[4px]">

src/app/components/Summary/SidebarContent.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ export const SidebarContent = ({ title, content, increasement, typeIsCount, id }
2424
<Inform.Title>{title}</Inform.Title>
2525
<Inform.Horizontal>
2626
<Inform.Content suffix={typeIsCount ? '회' : '개'}>{parseNumber(content)}</Inform.Content>
27-
{increasement && (
27+
{increasement ? (
2828
<Inform.Highlighted suffix="↑">{parseNumber(increasement)}</Inform.Highlighted>
29+
) : (
30+
<></>
2931
)}
3032
</Inform.Horizontal>
3133
</Inform>

src/app/components/Summary/index.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import { PostSummaryDto } from '@/types';
66
import { BarContent } from './BarContent';
77
import { SidebarContent } from './SidebarContent';
88

9-
export const Summary = ({ totalPostCount, stats }: PostSummaryDto) => {
9+
interface IProp {
10+
totalPostCount: number;
11+
yesterdayPostCount?: number;
12+
stats: PostSummaryDto['stats'];
13+
}
14+
15+
export const Summary = ({ totalPostCount, yesterdayPostCount, stats }: IProp) => {
1016
const [open, setOpen] = useState(false);
1117

1218
return (
@@ -28,7 +34,12 @@ export const Summary = ({ totalPostCount, stats }: PostSummaryDto) => {
2834
increasement={stats?.totalLikes - stats?.yesterdayLikes}
2935
id="like"
3036
/>
31-
<SidebarContent title="총 게시글 수" content={totalPostCount} id="post" />
37+
<SidebarContent
38+
title="총 게시글 수"
39+
content={totalPostCount}
40+
increasement={yesterdayPostCount ? totalPostCount - yesterdayPostCount : undefined}
41+
id="post"
42+
/>
3243
</aside>
3344
<section
3445
className={`flex flex-col w-full px-5 bg-BG-SUB rounded-[4px] cursor-pointer MBI:hidden`}
@@ -51,7 +62,11 @@ export const Summary = ({ totalPostCount, stats }: PostSummaryDto) => {
5162
content={stats?.totalLikes}
5263
increasement={stats?.totalLikes - stats?.yesterdayLikes}
5364
/>
54-
<BarContent title="총 게시글 수" content={totalPostCount} />
65+
<BarContent
66+
title="총 게시글 수"
67+
content={totalPostCount}
68+
increasement={yesterdayPostCount ? totalPostCount - yesterdayPostCount : undefined}
69+
/>
5570
</div>
5671
)}
5772
</section>

0 commit comments

Comments
 (0)