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: change searchParams on change topic #136

Merged
merged 1 commit into from
Jan 10, 2024
Merged
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
13 changes: 13 additions & 0 deletions src/components/Home/TopicCard/TopicCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { useEffect, useState } from 'react';
import { useSearchParams } from 'react-router-dom';
import { useSwiperSlide } from 'swiper/react';

import { useLatestComment } from '@apis/comment/useComment';
import useVoteTopic from '@apis/topic/useVoteTopic';
Expand Down Expand Up @@ -53,6 +55,8 @@ const TopicCard = ({ topic }: TopicCardProps) => {
},
]; // TBD: 투표 선택지가 비어있는 더미 데이터가 존재해서 만들어둠

const [, setSearchParams] = useSearchParams();
const swiperSlide = useSwiperSlide();
const { BottomSheet: CommentSheet, toggleSheet } = useBottomSheet({});
const voteMutation = useVoteTopic();
const { data: latestCommentData, isSuccess } = useLatestComment(
Expand All @@ -61,6 +65,15 @@ const TopicCard = ({ topic }: TopicCardProps) => {
);
const [latestComment, setLatestComment] = useState<LatestComment | undefined>();

useEffect(() => {
if (swiperSlide.isActive) {
setSearchParams((searchParams) => {
searchParams.set('topicId', topic.topicId.toString());
return searchParams;
});
}
}, [swiperSlide]);

useEffect(() => {
if (isSuccess) {
setLatestComment(latestCommentData.data[0] as LatestComment);
Expand Down