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

Feat/#315 card blacklist #321

Merged
merged 16 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions src/@components/CardCollectionPage/Card/MenuModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Modal from "../../../@common/Modal";
import useToast from "../../../@common/Toast/hooks/useToast";
import useBlacklist from "../../hooks/useBlacklist";
import { autoSlideType } from "../../hooks/useCardSwiper";
import * as St from "./style";

interface MenuModalProps {
currentCardId: string;
closeHandler: () => void;
autoSlide: autoSlideType;
}

type ModalItem = {
Expand All @@ -16,7 +18,7 @@ type ModalItem = {
};

export default function MenuModal(props: MenuModalProps) {
const { currentCardId, closeHandler } = props;
const { currentCardId, closeHandler, autoSlide } = props;
const { showToast, blackoutToast } = useToast();
const { handleClickAddBlacklist, handleClickCancelBlacklist } = useBlacklist(() => console.log("todo"));

Expand All @@ -41,8 +43,12 @@ export default function MenuModal(props: MenuModalProps) {
showToast({
message: "🚫 해당 대화주제가 더 이상 추천되지 않아요",
duration: 3.5,
handleClickCancel: () => handleClickCancelBlacklist({ _id: currentCardId, onSuccess: blackoutToast }),
handleClickCancel: () => {
handleClickCancelBlacklist({ _id: currentCardId, onSuccess: blackoutToast });
autoSlide.slideUp();
},
});
autoSlide.slideDown();
},
});
},
Expand Down
6 changes: 4 additions & 2 deletions src/@components/CardCollectionPage/Card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import React from "react";

import { GTM_CLASS_NAME } from "../../../util/const/gtm";
import useModal from "../../@common/hooks/useModal";
import { autoSlideType } from "../hooks/useCardSwiper";
import TagsSlider from "../TagsSlider";
import CardMenu from "./CardMenu";
import MenuModal from "./MenuModal";
import St from "./style";

interface LoginCheckProps {
autoSlide: autoSlideType;
openLoginModalHandler: () => void;
_id: string;
content: string;
Expand All @@ -16,7 +18,7 @@ interface LoginCheckProps {
}

const Card = (props: LoginCheckProps) => {
const { _id, content, tags } = props;
const { _id, content, tags, autoSlide } = props;
const { isModalOpen: isMenuModalOpen, toggleModal: toggleMenuModal } = useModal();

return (
Expand All @@ -28,7 +30,7 @@ const Card = (props: LoginCheckProps) => {
</St.TagsWrapper>
</St.Container>
<CardMenu {...props} toggleMenuModal={toggleMenuModal} />
{isMenuModalOpen && <MenuModal currentCardId={_id} closeHandler={toggleMenuModal} />}
{isMenuModalOpen && <MenuModal currentCardId={_id} closeHandler={toggleMenuModal} autoSlide={autoSlide} />}
</St.Card>
);
};
Expand Down
6 changes: 3 additions & 3 deletions src/@components/CardCollectionPage/CardSlider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ interface CardSliderProps {

const CardSlider = (props: CardSliderProps) => {
const { openLoginModalHandler, cardLists, lastCardObsvRef } = props;
const { swiperSettings } = useCardSwiper();
const { swiperSettings, swiperRef, autoSlide } = useCardSwiper();

return (
<St.Wrapper>
<Swiper {...swiperSettings}>
<Swiper {...swiperSettings} ref={swiperRef}>
{cardLists.map((cardList) => (
<SwiperSlide key={cardList._id}>
<Card openLoginModalHandler={openLoginModalHandler} {...cardList} />
<Card autoSlide={autoSlide} openLoginModalHandler={openLoginModalHandler} {...cardList} />
</SwiperSlide>
))}
<SwiperSlide>
Expand Down
16 changes: 14 additions & 2 deletions src/@components/CardCollectionPage/hooks/useCardSwiper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { useRef } from "react";
import { useRecoilState, useSetRecoilState } from "recoil";
import { Pagination } from "swiper";
import { SwiperProps } from "swiper/react";
import { SwiperProps, SwiperRef } from "swiper/react";

import { isSliderDownState, sliderIdxState } from "../../../core/atom/slider";

export type autoSlideType = {
slideDown: () => void;
slideUp: () => void;
};

export default function useCardSwiper() {
const [sliderIdx, setSliderIdx] = useRecoilState(sliderIdxState);
const setIsSliderDown = useSetRecoilState(isSliderDownState);
const swiperRef = useRef<SwiperRef>(null);

const swiperSettings: SwiperProps = {
slidesPerView: "auto",
Expand All @@ -20,5 +27,10 @@ export default function useCardSwiper() {
},
};

return { swiperSettings };
const autoSlide: autoSlideType = {
slideDown: () => swiperRef.current?.swiper.slideTo(sliderIdx + 1),
slideUp: () => swiperRef.current?.swiper.slideTo(sliderIdx),
};
Comment on lines +30 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

슬라이드 자동으로 이렇게 넘겼구나! 라이브러리 사용 너무 잘해😆😆


return { swiperSettings, swiperRef, autoSlide };
}