Skip to content

Commit

Permalink
fix: 진행중인 나눔 내역 sort 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
a-honey committed Feb 29, 2024
1 parent e03356f commit 1862efa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/hooks/queries/mypage/useGetMyShares.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { ShareSortType, ShareStatusType } from '@/types/friendship';

import type { MySharesSortType } from '@/types/mypage';
import type { ShareData } from '@/types/share';
import type { ShareStatusType } from '@/types/friendship';
import { queryKeys } from '../queryKeys';
import { useBaseInfiniteQuery } from '../useBaseInfiniteQuery';

const useGetMyShares = ({ sort, status }: { sort: ShareSortType; status: ShareStatusType }) =>
const useGetMyShares = ({ sort, status }: { sort: MySharesSortType; status: ShareStatusType }) =>
useBaseInfiniteQuery<ShareData[]>({
queryKey: queryKeys.MY_SHARES(sort, status),
url: `/users/me/shares/all`,
url: `/users/me/shares/${sort}`,
params: { status, sort: 'string' },
});

Expand Down
4 changes: 3 additions & 1 deletion src/hooks/queries/queryKeys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { FriendshipSortType, ShareSortType, ShareStatusType } from '@/types/friendship';

import type { MySharesSortType } from '@/types/mypage';

export const queryKeys = {
COUNT: () => ['count'],
MY_FRIDGE_LIST: () => ['my_fridge_list'],
Expand All @@ -15,7 +17,7 @@ export const queryKeys = {
KAKAO: () => ['kakao'],
GOOGLE: () => ['google'],
SHARES: (sort: ShareSortType, status: ShareStatusType) => ['shares', sort, status],
MY_SHARES: (sort: ShareSortType, status: ShareStatusType) => ['my-shares', sort, status],
MY_SHARES: (sort: MySharesSortType, status: ShareStatusType) => ['my-shares', sort, status],
ME: () => ['my-info'],
FRIENDSHIPS: (sort: FriendshipSortType) => ['friendship', sort],
DELETE_FRIENDSHIP: () => ['deleteFriendship'],
Expand Down
11 changes: 6 additions & 5 deletions src/pages/mypage/share/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Modal, ModalBody, ModalContent, ModalOverlay, useDisclosure } from '@chakra-ui/react';
import { RadioButtonField, SortButton, TabButton } from '@/components/atoms';
import type { ShareSortType, ShareStatusType } from '@/types/friendship';
import type { ShareStatusType } from '@/types/friendship';
import type { SortLabel, TabLabel } from '@/types/common';
import { useRef, useState } from 'react';

Expand All @@ -11,16 +11,17 @@ import ShareListItem from '@/components/organisms/ShareListItem';
import { SuspenseFallback } from '@/components/templates';
import { useObserver } from '@/hooks/useObserver';
import { useGetMyShares } from '@/hooks/queries/mypage';
import type { MySharesSortType } from '@/types/mypage';

const TABS: TabLabel[] = [
{ label: '나눔 중', value: 'SHARE_IN_PROGRESS' },
{ label: '나눔 완료', value: 'SHARE_END' },
];

const SORT_TYPES: SortLabel[] = [
{ label: '전체 나눔글', value: 'registeredDate' },
{ label: '작성한 나눔글', value: 'dueDate' },
{ label: '참여한 나눔글', value: 'dueDate' },
{ label: '전체 나눔글', value: 'all' },
{ label: '작성한 나눔글', value: 'created' },
{ label: '참여한 나눔글', value: 'applied' },
];

const MySharePage: NextPage = () => {
Expand All @@ -29,7 +30,7 @@ const MySharePage: NextPage = () => {
const { isOpen, onOpen, onClose } = useDisclosure();
const bottom = useRef<HTMLDivElement>(null);
const { data, fetchNextPage, isFetchingNextPage } = useGetMyShares({
sort: curSortType.value as ShareSortType,
sort: curSortType.value as MySharesSortType,
status: curTab.value as ShareStatusType,
});

Expand Down
1 change: 1 addition & 0 deletions src/types/mypage/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type MySharesSortType = 'all' | 'applied' | 'created';

0 comments on commit 1862efa

Please sign in to comment.