Skip to content

Commit

Permalink
feat: 전체 도장 갯수를 가져오도록 새 api 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
Leejha committed Oct 19, 2023
1 parent 838887c commit b3e1c54
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ function DrinkStampContainer() {
setRegionOption(value);
};

const { drinkList, subscribe, numberOfStampedDrinks } = useDrinkStampService({
const { drinkList, subscribe, enjoyedDrinkCount } = useDrinkStampService({
page: 0,
size: 10,
region: regionOption,
});

return (
<>
<MyEnjoiedDrinkInfoSection
numberOfStampedDrinks={numberOfStampedDrinks}
/>
<MyEnjoiedDrinkInfoSection enjoyedDrinkCount={enjoyedDrinkCount} />
<StampedDrinkList
regionOption={regionOption}
onChangeRegionOption={onChangeRegionOption}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { DrinkImage } from 'public/images';
import styled, { css } from 'styled-components';

interface Props {
numberOfStampedDrinks: number;
enjoyedDrinkCount: number;
}

function MyEnjoiedDrinkInfoSection({ numberOfStampedDrinks }: Props) {
function MyEnjoiedDrinkInfoSection({ enjoyedDrinkCount }: Props) {
return (
<Section>
<div>
<H2>
우리술 도장을 <br />
<div>
<MainColor>{numberOfStampedDrinks}</MainColor>개 모았어요.
<MainColor>{enjoyedDrinkCount}</MainColor>개 모았어요.
</div>
</H2>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default function useDrinkStampListService(params: DrinkStampListProps) {
page: pageParam?.page || params.page,
}),
{
getNextPageParam: ({ last, number }) => {
getNextPageParam: ({ drinkData }) => {
const { last, number } = drinkData;
if (last) {
return undefined;
}
Expand All @@ -34,11 +35,11 @@ export default function useDrinkStampListService(params: DrinkStampListProps) {
},
);

const numberOfStampedDrinks = data?.pages[0].numberOfElements ?? 0;
const enjoyedDrinkCount = data?.pages[0].enjoyedDrinkCount ?? 0;

const drinkList = data?.pages.flatMap((page) => page.content) ?? [];
const drinkList = data?.pages.flatMap((page) => page.drinkData.content) ?? [];

const [subscribe] = useInfiniteScroll(fetchNextPage);

return { drinkList, fetchNextPage, subscribe, numberOfStampedDrinks };
return { drinkList, fetchNextPage, subscribe, enjoyedDrinkCount };
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import Path from 'lib/Path';
import { modifyDrinkVoteAPI, modifyNormalVoteAPI } from 'lib/apis/vote';
import { queryKeys } from 'lib/queryKeys';
import { queryKeys, reactQueryKeys } from 'lib/queryKeys';
import { useParams, useRouter } from 'next/navigation';
import { DrinkInfoType } from 'src/types/drink';
import { PostVoteType } from 'src/types/vote';
Expand All @@ -27,7 +27,8 @@ export default function useUpdateVoteForm() {
const queryClient = useQueryClient();

const params = useParams();
const { data } = useVoteLoadService(Number(params.id));
const voteId = Number(params.id);
const { data } = useVoteLoadService(voteId);

const [postVoteInfo, setPostVoteInfo] = useState<PostVoteType>({
detail: '',
Expand Down Expand Up @@ -89,6 +90,7 @@ export default function useUpdateVoteForm() {
onSuccess: () => {
queryClient.invalidateQueries([queryKeys.VOTE_LIST]);
queryClient.invalidateQueries(getMyCreatedVoteQueryKey);
queryClient.invalidateQueries(reactQueryKeys.voteDetail(voteId));
router.push(Path.VOTE_HOME);
},
},
Expand All @@ -111,14 +113,14 @@ export default function useUpdateVoteForm() {
title,
titleA,
titleB,
voteId: Number(params.id),
voteId: voteId,
})
: mutateDrinkVote({
title,
detail,
drinkAId,
drinkBId,
voteId: Number(params.id),
voteId: voteId,
});
};

Expand Down
7 changes: 6 additions & 1 deletion apps/jurumarble/src/lib/apis/drink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ interface GetEnjoyedDrinkListRequest {
region?: string;
}

export interface GetEnjoyedDrinkListResponse extends DrinkListResponse {}
interface DrinkData extends DrinkListResponse {}

interface GetEnjoyedDrinkListResponse {
drinkData: DrinkData;
enjoyedDrinkCount: number;
}

export const getEnjoyedDrinkList = async (
params: GetEnjoyedDrinkListRequest,
Expand Down

0 comments on commit b3e1c54

Please sign in to comment.