Skip to content

Commit

Permalink
[ feat ] NavigateRecentCollection 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmerry committed Jul 8, 2023
1 parent 341f58d commit 937f53b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/@components/@common/BestPiickleCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LocationType } from "../../../types/cardCollection";
import { GTM_CLASS_NAME } from "../../../util/const/gtm";
import useNavigateCardCollection, { NavigateCardCollectionBestType } from "../hooks/useNavigateCardCollection";
import useNavigateCardCollection, { NavigateRecentCollectionType } from "../hooks/useNavigateCardCollection";
import * as St from "./style";

interface BestPiickleCardProps {
Expand All @@ -20,7 +20,7 @@ export default function BestPiickleCard(props: BestPiickleCardProps) {
const { content, tags } = bestPiickle;
const GTM_IDX_KEY = `mainBestPiickle${idx + 1}`;

const navigateCardCollection = useNavigateCardCollection(locationType) as NavigateCardCollectionBestType;
const navigateCardCollection = useNavigateCardCollection(locationType) as NavigateRecentCollectionType;

const onClickCard = () => {
if (!canNavigate) return;
Expand Down
4 changes: 3 additions & 1 deletion src/@components/@common/hooks/useNavigateCardCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type NavigateCardCollectionBookMarkType = (sliderIdx?: number) => void;
export type NavigateCardCollectionCategoryType = (categoryId: string, sliderIdx?: number) => void;
export type NavigateCardCollectionFilterType = (filterTypes: string[], sliderIdx?: number) => void;
export type NavigateCardCollectionMedleyType = (medleyId: string, sliderIdx?: number) => void;
export type NavigateRecentCollectionType = (sliderIdx?: number) => void;

export default function useNavigateCardCollection(locationType: LocationType) {
const navigate = useNavigate();
Expand Down Expand Up @@ -57,8 +58,9 @@ export default function useNavigateCardCollection(locationType: LocationType) {
navigate(`${routePaths.CardCollection}?type=${LocationType.MEDLEY}&medleyId=${medleyId}`);
setSliderIdx(sliderIdx);
};

case LocationType.RECENT:
return (medleyId: string, sliderIdx = 0) => {
return (sliderIdx = 0) => {
navigate(`${routePaths.CardCollection}?type=${LocationType.RECENT}`);
setSliderIdx(sliderIdx);
};
Expand Down
6 changes: 6 additions & 0 deletions src/@components/CardCollectionPage/hooks/useCardLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import useCardListsFilter from "./useCardListsFilter";
interface ExtendedCardList extends Array<CardList> {
cardList?: CardList[]; // with category id
cards?: CardList[]; // with medly id
cardResponseDtos?: CardList[];
}

export function useCardLists() {
Expand Down Expand Up @@ -43,6 +44,8 @@ function getReturnCardLists(
return data?.data.data.cardList;
case LocationType.MEDLEY:
return data?.data.data.cards;
case LocationType.RECENT:
return data?.data.data.cardResponseDtos;
default:
return data?.data.data;
}
Expand Down Expand Up @@ -88,6 +91,9 @@ function getSWRFetchingKeyByLocation(cardsTypeLocation: CardsTypeLocation) {
case LocationType.FILTER: {
return `${PATH.CATEGORIES_}${PATH.CATEGORIES_CARDS}?${cardsTypeLocation.filterTypes}`;
}
case LocationType.RECENT:
return `${PATH.CARDS_}${PATH.CARDS_RECENT}`;

case LocationType.ALL:
default: {
const searchParams = qs.stringify(
Expand Down
7 changes: 6 additions & 1 deletion src/types/cardCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ interface MedleyTypeLocation {
medleyId: string;
}

interface RecentTypeLocation {
type: LocationType.RECENT;
}

export type CardsTypeLocation =
| AllTypeLocation
| BestTypeLocation
| BookmarkTypeLocation
| CategoryTypeLocation
| FilterTypeLocation
| MedleyTypeLocation;
| MedleyTypeLocation
| RecentTypeLocation;

export interface CardList {
_id: string;
Expand Down

0 comments on commit 937f53b

Please sign in to comment.