Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: 리뷰 서머리 차트 캐싱 오류 수정 #524

Merged
merged 5 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions frontend/src/components/PetProfile/PetListBottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,26 @@ const PetListBottomSheet = () => (
<Loading>
<Dialog.BackDrop />
<Dialog.Content asChild>
{({ openHandler }) => <PetListContainer toggleDialog={openHandler} />}
<ContentLayout>
<DialogHeader>어떤 아이 식품을 찾으세요?</DialogHeader>
<DialogContent>
<PetList />
</DialogContent>
<ButtonWrapper>
<Dialog.Close asChild>
<CloseButton type="button">닫기</CloseButton>
</Dialog.Close>
</ButtonWrapper>
</ContentLayout>
</Dialog.Content>
</Loading>
</Dialog.Portal>
</Dialog>
);

interface PetListContainerProps {
toggleDialog: VoidFunction;
}

const PetListContainer = (props: PetListContainerProps) => {
const { toggleDialog } = props;

return (
<Layout>
<DialogHeader>어떤 아이 식품을 찾으세요?</DialogHeader>
<DialogContent>
<PetList />
</DialogContent>
<ButtonWrapper>
<CloseButton type="button" onClick={toggleDialog}>
닫기
</CloseButton>
</ButtonWrapper>
</Layout>
);
};

export default PetListBottomSheet;

const Layout = styled.div`
const ContentLayout = styled.div`
position: fixed;
z-index: 1001;
bottom: 0;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/constants/time.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const ONE_HOUR = 3600000;

const ONE_MINUTE = 3600000;
const ONE_MINUTE = 60000;

export { ONE_HOUR, ONE_MINUTE };
6 changes: 5 additions & 1 deletion frontend/src/hooks/petProfile/usePetProfileEdition.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeEvent, useState } from 'react';
import { ChangeEvent, useEffect, useState } from 'react';

import {
AGE_GROUP,
Expand Down Expand Up @@ -33,6 +33,10 @@ export const usePetProfileEdition = () => {
const [isValidWeightInput, setIsValidWeightInput] = useState(true);
const isValidForm = isValidNameInput && isValidAgeSelect && isValidWeightInput;

useEffect(() => {
setPet(petItem);
}, [petItem]);

const onChangeName = (e: ChangeEvent<HTMLInputElement>) => {
const petName = e.target.value;

Expand Down
10 changes: 5 additions & 5 deletions frontend/src/hooks/query/food.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { useInfiniteQuery, useQuery } from '@tanstack/react-query';
import { getFoodDetail, getFoodList, getFoodListFilterMeta } from '@/apis/food';
import { Parameter } from '@/types/common/utility';

const QUERY_KEY = {
export const FOOD_QUERY_KEY = {
foodList: 'foodList',
foodDetail: 'foodDetail',
foodDetail: (petFoodId: string) => ['foodDetail', petFoodId],
petFoods: 'petFoods',
foodListFilterMeta: 'foodListFilterMeta',
};
Expand All @@ -14,7 +14,7 @@ const SIZE_PER_PAGE = 20;

export const useFoodListInfiniteQuery = (payload: Parameter<typeof getFoodList>) => {
const { data, ...restQuery } = useInfiniteQuery({
queryKey: [QUERY_KEY.petFoods, Object.values(payload).join()],
queryKey: [FOOD_QUERY_KEY.petFoods, location.search],
queryFn: ({ pageParam = { ...payload, size: String(SIZE_PER_PAGE) } }) =>
getFoodList(pageParam),
getNextPageParam: (lastFoodListRes, allFoodListRes) => {
Expand All @@ -37,7 +37,7 @@ export const useFoodListInfiniteQuery = (payload: Parameter<typeof getFoodList>)

export const useFoodDetailQuery = (payload: Parameter<typeof getFoodDetail>) => {
const { data, ...restQuery } = useQuery({
queryKey: [QUERY_KEY.foodDetail, payload.petFoodId],
queryKey: FOOD_QUERY_KEY.foodDetail(payload.petFoodId),
queryFn: () => getFoodDetail(payload),
});

Expand All @@ -49,7 +49,7 @@ export const useFoodDetailQuery = (payload: Parameter<typeof getFoodDetail>) =>

export const useFoodListFilterMetaQuery = () => {
const { data, ...restQuery } = useQuery({
queryKey: [QUERY_KEY.foodListFilterMeta],
queryKey: [FOOD_QUERY_KEY.foodListFilterMeta],
queryFn: getFoodListFilterMeta,
});
return {
Expand Down
26 changes: 15 additions & 11 deletions frontend/src/hooks/query/petProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ import {
} from '@/types/petProfile/remote';
import { zipgoLocalStorage } from '@/utils/localStorage';

const QUERY_KEY = { breedList: 'breedList', petItem: 'petItem', petList: 'petList' };
const PET_PROFILE_QUERY_KEY = {
breedList: 'breedList',
petItem: (petId: number) => ['petItem', petId],
petList: 'petList',
};

export const useBreedListQuery = () => {
const { data, ...restQuery } = useQuery({
queryKey: [QUERY_KEY.breedList],
queryKey: [PET_PROFILE_QUERY_KEY.breedList],
queryFn: () => getBreeds(),
});

Expand All @@ -29,22 +33,19 @@ export const useBreedListQuery = () => {

export const usePetItemQuery = (payload: Parameter<typeof getPet>) => {
const { data, ...restQuery } = useQuery({
queryKey: [QUERY_KEY.petItem],
queryKey: PET_PROFILE_QUERY_KEY.petItem(payload.petId),
queryFn: () => getPet(payload),
});
const queryClient = useQueryClient();
const resetPetItemQuery = () => queryClient.removeQueries([QUERY_KEY.petItem]);

return {
petItem: data,
...restQuery,
resetPetItemQuery,
};
};

export const usePetListQuery = () => {
const { data, ...restQuery } = useQuery({
queryKey: [QUERY_KEY.petList],
queryKey: [PET_PROFILE_QUERY_KEY.petList],
queryFn: () => getPets(),
});

Expand Down Expand Up @@ -86,7 +87,7 @@ export const useAddPetMutation = () => {
};

export const useEditPetMutation = () => {
const { resetPetItemQuery } = usePetItemQuery({ petId: 0 });
const queryClient = useQueryClient();
const { petProfile: petProfileInHeader, updatePetProfile: updatePetProfileInHeader } =
usePetProfile();

Expand All @@ -100,7 +101,8 @@ export const useEditPetMutation = () => {
onSuccess: (putPetRes, newPetProfile, context) => {
if (newPetProfile.id === petProfileInHeader?.id) updatePetProfileInHeader(newPetProfile);

resetPetItemQuery();
queryClient.invalidateQueries([PET_PROFILE_QUERY_KEY.petList]);
queryClient.invalidateQueries(PET_PROFILE_QUERY_KEY.petItem(newPetProfile.id));

alert('반려동물 정보 수정이 완료되었습니다.');
},
Expand All @@ -113,8 +115,9 @@ export const useEditPetMutation = () => {
};

export const useRemovePetMutation = () => {
const queryClient = useQueryClient();
const { refetch: refetchPetList } = usePetListQuery();
const { resetPetItemQuery } = usePetItemQuery({ petId: 0 });

const {
petProfile: petProfileInHeader,
updatePetProfile: updatePetProfileInHeader,
Expand All @@ -141,7 +144,8 @@ export const useRemovePetMutation = () => {
if (!newestPet) resetPetProfileInHeader();
}

resetPetItemQuery();
queryClient.invalidateQueries([PET_PROFILE_QUERY_KEY.petList]);
queryClient.invalidateQueries(PET_PROFILE_QUERY_KEY.petItem(deletePetReq.petId));

alert('반려동물 정보를 삭제했습니다.');
},
Expand Down
15 changes: 10 additions & 5 deletions frontend/src/hooks/query/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import { routerPath } from '@/router/routes';
import { Parameter } from '@/types/common/utility';
import { GetReviewsRes } from '@/types/review/remote';

import { FOOD_QUERY_KEY } from './food';

const QUERY_KEY = {
reviewItem: 'reviewItem',
reviewList: (petFoodId: string) => ['reviewList', petFoodId, location.search],
reviewSummary: 'reviewSummary',
reviewSummary: (petFoodId: string) => ['reviewSummary', petFoodId],
reviewListMeta: 'reviewListMeta',
};

Expand Down Expand Up @@ -60,7 +62,8 @@ export const useAddReviewMutation = () => {
mutationFn: postReview,
onSuccess: (_, { petFoodId }) => {
queryClient.invalidateQueries(QUERY_KEY.reviewList(petFoodId));
queryClient.invalidateQueries([QUERY_KEY.reviewSummary]);
queryClient.invalidateQueries(QUERY_KEY.reviewSummary(petFoodId));
queryClient.invalidateQueries(FOOD_QUERY_KEY.foodDetail(petFoodId));

alert('리뷰 작성이 완료되었습니다.');

Expand All @@ -79,7 +82,8 @@ export const useEditReviewMutation = () => {
mutationFn: putReview,
onSuccess: (_, { petFoodId }) => {
queryClient.invalidateQueries(QUERY_KEY.reviewList(petFoodId));
queryClient.invalidateQueries([QUERY_KEY.reviewSummary]);
queryClient.invalidateQueries(QUERY_KEY.reviewSummary(petFoodId));
queryClient.invalidateQueries(FOOD_QUERY_KEY.foodDetail(petFoodId));

alert('리뷰 수정이 완료되었습니다.');

Expand All @@ -97,7 +101,8 @@ export const useRemoveReviewMutation = () => {
mutationFn: deleteReview,
onSuccess: (_, { petFoodId }) => {
queryClient.invalidateQueries(QUERY_KEY.reviewList(petFoodId));
queryClient.invalidateQueries([QUERY_KEY.reviewSummary]);
queryClient.invalidateQueries(QUERY_KEY.reviewSummary(petFoodId));
queryClient.invalidateQueries(FOOD_QUERY_KEY.foodDetail(petFoodId));
},
});

Expand All @@ -106,7 +111,7 @@ export const useRemoveReviewMutation = () => {

export const useReviewSummaryQuery = (payload: Parameter<typeof getReviewSummary>) => {
const { data, ...restQuery } = useQuery({
queryKey: [QUERY_KEY.reviewSummary],
queryKey: QUERY_KEY.reviewSummary(payload.petFoodId),
queryFn: () => getReviewSummary(payload),
});

Expand Down