Skip to content

Commit

Permalink
게시물 개수 표시 기능 수정 (#726)
Browse files Browse the repository at this point in the history
* design: 헤더 높이에 따른 드롭다운 gap 수정

* feat: 변경된 게시물 개수 api 적용
  • Loading branch information
gyeongza authored Feb 19, 2024
1 parent 6d3da8a commit c2bc983
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 44 deletions.
6 changes: 5 additions & 1 deletion frontend/src/apis/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
GetDetailedRunnerPostResponse,
GetOtherSupporterPostCountResponse,
GetRunnerPostResponse,
ReviewStatus,
getRunnerPostRequestParams,
GetPostCountResponse,
} from '@/types/runnerPost';
import { GetSearchTagResponse } from '@/types/tags';
import {
Expand Down Expand Up @@ -108,6 +108,10 @@ export const getSupporterRank = () => {
return request.get<GetSupporterRankResponse>('/rank/supporter', false);
};

export const getPostCount = () => {
return request.get<GetPostCountResponse>('/posts/runner/count', false);
};

export const postRunnerPostCreation = (formData: CreateRunnerPostRequest) => {
const body = JSON.stringify(formData);
return request.post<void>(`/posts/runner`, body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,36 @@ import { css, keyframes, styled } from 'styled-components';
import { REVIEW_STATUS_FILTER_TEXT } from '@/constants';
import Text from '@/components/common/Text/Text';
import Flex from '@/components/common/Flex/Flex';
import { ReviewStatusFilter } from '@/types/runnerPost';
import useTotalCount from '@/hooks/query/useTotalCount';
import { PostCount, ReviewStatusFilter } from '@/types/runnerPost';
import { usePostCount } from '@/hooks/query/usePostCount';
import useViewport from '@/hooks/useViewport';

interface Props {
reviewStatus: ReviewStatusFilter;
handleClickRadioButton: (e: React.ChangeEvent<HTMLInputElement>) => void;
}

const RunnerPostFilter = ({ reviewStatus, handleClickRadioButton }: Props) => {
const { totalCounts, isAllLoaded } = useTotalCount();
const { data: totalCount } = usePostCount();
const { isMobile } = useViewport();

function transformPostCountToReviewStatusFilter(postCount: PostCount): { [key in ReviewStatusFilter]: number } {
const all = Object.values(postCount).reduce((acc, currentValue) => acc + currentValue, 0);

return {
NOT_STARTED: postCount.notStarted,
IN_PROGRESS: postCount.inProgress,
OVERDUE: postCount.overdue,
DONE: postCount.done,
ALL: all,
};
}

if (!totalCount) {
return <div style={isMobile ? { height: '38px' } : { height: '46px' }}></div>;
}

const reviewStatusCounts = transformPostCountToReviewStatusFilter(totalCount);

return (
<S.FilterContainer>
Expand All @@ -34,7 +54,7 @@ const RunnerPostFilter = ({ reviewStatus, handleClickRadioButton }: Props) => {
<Flex align="end" gap={3}>
<Text color={isSelected ? 'red' : 'gray600'}>{text}</Text>
<Text color={isSelected ? 'red' : 'gray600'} typography="t8">
({isAllLoaded ? totalCounts[value as ReviewStatusFilter] : 0})
({reviewStatusCounts[value as ReviewStatusFilter]})
</Text>
</Flex>
</S.Label>
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/hooks/query/usePostCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getPostCount } from '@/apis/apis';
import { PostCount } from '@/types/runnerPost';
import { useQuery } from '@tanstack/react-query';

export const usePostCount = () => {
const queryResult = useQuery<PostCount>({
queryKey: ['runnerPostCount'],

queryFn: () => getPostCount().then((res) => res.data),
});

return {
...queryResult,
data: queryResult.data,
};
};
34 changes: 0 additions & 34 deletions frontend/src/hooks/query/useTotalCount.ts

This file was deleted.

4 changes: 2 additions & 2 deletions frontend/src/layout/MyMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const MyMenu = () => {
<S.NotificationContainer>
<Dropdown
onClose={handleCloseDropdown}
gapFromTrigger="52px"
gapFromTrigger="42px"
isDropdownOpen={isNotificationDropdownOpen}
trigger={
<S.NotificationIcon
Expand All @@ -67,7 +67,7 @@ const MyMenu = () => {
</S.NotificationContainer>
<Dropdown
onClose={handleCloseDropdown}
gapFromTrigger="57px"
gapFromTrigger="47px"
isDropdownOpen={isProfileDropdownOpen}
trigger={
<S.AvatarContainer onClick={handleProfileDropdown}>
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/mocks/data/postCount.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"data": {
"notStarted": 1,
"inProgress": 2,
"overdue": 3,
"done": 4
}
}
3 changes: 1 addition & 2 deletions frontend/src/mocks/data/runnerPostList.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
],
"pageInfo": {
"isLast": false,
"nextCursor": 1,
"totalCount": 129
"nextCursor": 1
}
}
5 changes: 5 additions & 0 deletions frontend/src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import myPagePostList from './data/myPagePost/myPagePostList.json';
import tagList from './data/tagList.json';
import notificationList from './data/notification.json';
import rank from './data/rank.json';
import postCount from './data/postCount.json';
import { BATON_BASE_URL } from '@/constants';
import { getRestMinute } from '@/utils/jwt';

Expand Down Expand Up @@ -66,6 +67,10 @@ export const handlers = [
return res(ctx.delay(300), ctx.status(201));
}),

rest.get(`${BATON_BASE_URL}/posts/runner/count`, async (req, res, ctx) => {
return res(ctx.delay(300), ctx.status(200), ctx.json(postCount));
}),

rest.get(`${BATON_BASE_URL}/profile/me`, async (req, res, ctx) => {
const jwt = req.headers.get('Authorization');

Expand Down
13 changes: 12 additions & 1 deletion frontend/src/types/runnerPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ export interface RunnerPost {
reviewStatus: ReviewStatus;
}

export interface PostCount {
notStarted: number;
inProgress: number;
overdue: number;
done: number;
}

export interface GetPostCountResponse {
data: PostCount;
}

export interface RunnerProfile {
name: string;
imageUrl: string;
Expand Down Expand Up @@ -63,7 +74,7 @@ export interface PageInfo {

interface requestParams {
tagName?: string;
reviewStatus: ReviewStatus | ReviewStatusFilter | null;
reviewStatus: ReviewStatus | null;
}

export interface getRunnerPostRequestParams extends pageParamsRequest, requestParams {}
Expand Down

0 comments on commit c2bc983

Please sign in to comment.