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

fix: 바텀 시트 두 번 열리던거 수정 #174

Merged
merged 7 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions src/apis/comment/useComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ const reactComment = (commentId: number, reaction: 'like' | 'hate', enable: bool
});
};

const useComments = (topicId: number, enabled: boolean) => {
const useComments = (topicId: number) => {
return useInfiniteQuery({
queryKey: [COMMENT_KEY, topicId],
queryFn: (params) => getComments({ topicId: topicId, page: params.pageParam, size: 20 }),
initialPageParam: 0,
getNextPageParam: (lastPage) =>
lastPage.pageInfo.last ? undefined : lastPage.pageInfo.page + 1,
enabled: enabled,
});
};

Expand Down Expand Up @@ -77,7 +76,9 @@ const useReactComment = (topicId: number, commentId: number) => {
queryClient.setQueryData(
[COMMENT_KEY, topicId],
(oldData: InfiniteData<PagingDataResponse<CommentResponse>, unknown> | undefined) => {
if (!oldData) {return oldData;}
if (!oldData) {
return oldData;
}
return {
...oldData,
pages: oldData.pages.map((page) => {
Expand Down
2 changes: 1 addition & 1 deletion src/apis/topic/useTopics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import client from '@apis/fetch';
export const TOPIC_KEY = 'topics';

const getTopics = () => {
return client.get<PagingDataResponse<TopicResponse>>('/topics/info/voting');
return client.get<PagingDataResponse<TopicResponse>>('/topics/info/voting?size=100');
};

const useTopics = () => {
Expand Down
1 change: 0 additions & 1 deletion src/components/Home/Comment/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { colors } from '@styles/theme';

import { MeatballIcon, ReportIcon } from '@icons/index';

import { CommentAuthorProfileImg } from './Comment.styles';
import Thumbs from './Thumbs';

interface CommentProps {
Expand Down
3 changes: 0 additions & 3 deletions src/components/Home/TopicCard/TopicCard.styles.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { motion } from 'framer-motion';
import { styled } from 'styled-components';

import { colors } from '@styles/theme';

export const Container = styled.div`
height: 100%;
background-color: ${(props) => props.theme.colors.navy};
Expand Down
6 changes: 3 additions & 3 deletions src/components/Home/TopicCard/TopicCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useSwiperSlide } from 'swiper/react';

import { useLatestComment } from '@apis/comment/useComment';
import useVoteTopic from '@apis/topic/useVoteTopic';
import ProfileImg from '@components/commons/ProfileImg/ProfileImg';
import Text from '@components/commons/Text/Text';
import ChoiceSlider from '@components/Home/ChoiceSlider/ChoiceSlider';
import CommentBox from '@components/Home/CommentBox/CommentBox';
Expand All @@ -24,7 +25,6 @@ import {
TopicContainer,
Topic,
UserInfoContainer,
UserProfileImage,
TopicCardContainer,
SelectTextContainer,
} from './TopicCard.styles';
Expand Down Expand Up @@ -57,7 +57,7 @@ const TopicCard = ({ topic }: TopicCardProps) => {

const [, setSearchParams] = useSearchParams();
const swiperSlide = useSwiperSlide();
const { BottomSheet: CommentSheet, toggleSheet } = useBottomSheet({});
const { BottomSheet: CommentSheet, toggleSheet, isOpen } = useBottomSheet({});
const voteMutation = useVoteTopic();
const { data: latestCommentData, isSuccess } = useLatestComment(
topic.topicId,
Expand Down Expand Up @@ -107,7 +107,7 @@ const TopicCard = ({ topic }: TopicCardProps) => {
<Topic>{topic.topicTitle}</Topic>
</TopicContainer>
<UserInfoContainer>
<UserProfileImage src={topic.author.profileImageUrl || ''} />
<ProfileImg url={topic.author.profileImageUrl} size={20} />
<Text size={14} weight={'regular'} color={colors.white_60}>
{topic.author.nickname}
</Text>
Expand Down
19 changes: 6 additions & 13 deletions src/components/Home/TopicComments/TopicComments.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo, useState } from 'react';
import React, { memo, useLayoutEffect, useState } from 'react';

import { useComments, useCreateComment } from '@apis/comment/useComment';
import { Row } from '@components/commons/Flex/Flex';
Expand All @@ -22,17 +22,16 @@ interface TopicCommentsProps {
}

const TopicComments = memo(({ topic }: TopicCommentsProps) => {
const { data: comments, fetchNextPage } = useComments(
topic.topicId,
topic.selectedOption !== null
);
const { data, fetchNextPage } = useComments(topic.topicId);
const commentMutation = useCreateComment(topic.topicId);
const [newComment, setNewComment] = useState('');

const commentCount = comments?.pages.reduce((acc, page) => {
const commentCount = data?.pages.reduce((acc, page) => {
return acc + page.data.length;
}, 0);

const comments = React.useMemo(() => data?.pages.flatMap((page) => page.data), [data]);

return (
<TopicCommentsContainer>
<TopicCommentsHeader className="draggable">
Expand All @@ -46,13 +45,7 @@ const TopicComments = memo(({ topic }: TopicCommentsProps) => {
</Row>
</TopicCommentsHeader>
<CommentsContainer>
{comments?.pages.map((group, i) => (
<React.Fragment key={i}>
{group.data.map((comment) => (
<Comment key={comment.commentId} comment={comment} />
))}
</React.Fragment>
))}
{comments?.map((comment) => <Comment key={comment.commentId} comment={comment} />)}
</CommentsContainer>
<CommentInputContainer>
<CommentInput
Expand Down
25 changes: 14 additions & 11 deletions src/hooks/useBottomSheet/useBottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@ const useBottomSheet = (props: UseBottomSheetProps) => {
setIsOpen((prev) => !prev);
}, []);

const Sheet = ({ children }: { children: React.ReactNode }) => (
<BottomSheet
open={isOpen}
setIsOpen={setIsOpen}
snapPoints={snapPoints}
initialSnap={initialSnap}
transparent={transparent}
>
{children}
</BottomSheet>
const Sheet = useCallback(
({ children }: { children: React.ReactNode }) => (
<BottomSheet
open={isOpen}
setIsOpen={setIsOpen}
snapPoints={snapPoints}
initialSnap={initialSnap}
transparent={transparent}
>
{children}
</BottomSheet>
),
[isOpen]
);

return { BottomSheet: Sheet, toggleSheet };
return { BottomSheet: Sheet, toggleSheet, isOpen };
};

export default useBottomSheet;
Loading