Skip to content

Commit

Permalink
[ refactor ] add useShowByQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmerry committed Aug 17, 2023
1 parent 62710ee commit d1d54c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
15 changes: 15 additions & 0 deletions src/@components/@common/hooks/useShowByQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useEffect, useState } from "react";

import { LocationType } from "../../../types/cardCollection";

// 파라미터로 보이지 않아야할 locationType 전달
export default function useShowByCardType(locationTypes: LocationType[]) {
const [isShow, setIsShow] = useState<boolean>(false);

useEffect(() => {
const cardType = new URLSearchParams(window.location.search.split("?")[1]).get("type");
setIsShow(!locationTypes.includes((cardType as LocationType) || ""));
}, [locationTypes]);

return { isShow };
}
9 changes: 2 additions & 7 deletions src/@components/CardCollectionPage/Card/MenuModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from "react";

import { LocationType } from "../../../../types/cardCollection";
import useShowByCardType from "../../../@common/hooks/useShowByQuery";
import Modal from "../../../@common/Modal";
import useToast from "../../../@common/Toast/hooks/useToast";
import { handleClickBlacklistType } from "../../hooks/useBlacklist";
Expand All @@ -26,7 +27,7 @@ export default function MenuModal(props: MenuModalProps) {
const { currentCardId, closeHandler, autoSlide, handleClickAddBlacklist, handleClickCancelBlacklist } = props;
const { showToast, blackoutToast } = useToast();

const [isBlockShow, setIsBlockShow] = useState<boolean>(true);
const { isShow: isBlockShow } = useShowByCardType([LocationType.BEST, LocationType.MEDLEY]);

const onSuccessAddBlacklist = () => {
closeHandler();
Expand Down Expand Up @@ -71,12 +72,6 @@ export default function MenuModal(props: MenuModalProps) {
},
];

useEffect(() => {
if (location.search.includes(LocationType.BEST)) setIsBlockShow(false);
else if (location.search.includes(LocationType.MEDLEY)) setIsBlockShow(false);
else setIsBlockShow(true);
}, []);

return (
<Modal theme="WHITE_BOTTOM" closeHandler={closeHandler} isNoCloseBtn>
<St.ModalContainer>
Expand Down

0 comments on commit d1d54c9

Please sign in to comment.