Skip to content

Commit

Permalink
fix: 유저가 작성한 토픽인 경우 조회 가능하도록 수정 (#219)
Browse files Browse the repository at this point in the history
* fix: get method to throw error

* fix: check if member created topic

* fiX: remove console.log

* refactor: remove another console.logs
  • Loading branch information
Jinho1011 authored Feb 19, 2024
1 parent 7664e48 commit 581907a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/apis/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Fetch {
this.baseURL = import.meta.env.VITE_API_BASE_URL;
}

async get<T>(path: string, qs?: Record<string, any>): Promise<T> {
async get<TData>(path: string, qs?: Record<string, any>) {
const queryString = qs ? `?${new URLSearchParams(qs).toString()}` : '';
const response = await fetch(`${this.baseURL}${path}${queryString}`, {
method: 'GET',
Expand All @@ -26,8 +26,13 @@ class Fetch {
...(this.accessToken && { Authorization: `Bearer ${this.accessToken}` }),
},
});
const data: T = await response.json();
return data;
const data = await response.json();

if (!response.ok) {
throw new ResponseError(data);
}

return data as TData;
}

async post<TData>({
Expand Down
11 changes: 8 additions & 3 deletions src/components/Home/TopicCard/TopicCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import useBottomSheet from '@hooks/useBottomSheet/useBottomSheet';
import { LatestComment } from '@interfaces/api/comment';
import { Choice, TopicResponse } from '@interfaces/api/topic';

import { useAuthStore } from '@store/auth';

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

import { LeftDoubleArrowIcon, RightDoubleArrowIcon } from '@icons/index';
Expand All @@ -38,12 +40,15 @@ interface TopicCardProps {

const TopicCard = ({ topic }: TopicCardProps) => {
const [, setSearchParams] = useSearchParams();
const memberId = useAuthStore((store) => store.memberId);
const isMyTopic = topic.author.id === memberId;

const swiperSlide = useSwiperSlide();
const { BottomSheet: CommentSheet, toggleSheet } = useBottomSheet({});
const voteMutation = useVoteTopic();
const { data: latestCommentData, isSuccess } = useLatestComment(
topic.topicId,
topic.selectedOption !== null
topic.selectedOption !== null || isMyTopic
);
const [latestComment, setLatestComment] = useState<LatestComment | undefined>();

Expand All @@ -65,7 +70,7 @@ const TopicCard = ({ topic }: TopicCardProps) => {
}, [isSuccess]);

const handleOnClickCommentBox = () => {
if (topic.selectedOption !== null) {
if (isMyTopic || topic.selectedOption !== null) {
toggleSheet();
}
};
Expand Down Expand Up @@ -137,7 +142,7 @@ const TopicCard = ({ topic }: TopicCardProps) => {
</SelectTextContainer>
<CommentBox
side={topic.topicSide}
hasVoted={topic.selectedOption !== null}
hasVoted={topic.selectedOption !== null || isMyTopic}
topicId={topic.topicId}
commentCount={0}
voteCount={0}
Expand Down
1 change: 0 additions & 1 deletion src/hooks/useOAuth/useOAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export default function useOAuth({ type }: UseOAuthProps) {
navigate('/');
}
} catch (err) {
console.log('🚀 ~ handleLogin ~ err:', err);
if (err instanceof ResponseError) {
if (err.errorData.abCode === 'ILLEGAL_JOIN_STATUS') {
navigate(`/signup`, {
Expand Down
1 change: 0 additions & 1 deletion src/utils/scrollLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const enableScrollLock = () => {
// 스크롤 잠금 해제
export const disableScrollLock = () => {
const { body } = document;
console.log('🚀 ~ disableScrollLock ~ body:', body.getAttribute('scrollY'));

if (body.getAttribute('scrollY')) {
body.style.removeProperty('overflow');
Expand Down

0 comments on commit 581907a

Please sign in to comment.