-
Notifications
You must be signed in to change notification settings - Fork 2
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 : profile/follow button 에러수정 #80
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,50 @@ | ||
import { useState } from 'react'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import useSessionStorage from '@hooks/useSessionStorage'; | ||
import { deleteFollowUser, postFollowUser } from '@apis/follow'; | ||
import { Button } from '@components/Button'; | ||
import { User } from '@/types'; | ||
|
||
interface FollowButtonProps { | ||
followDataId: string; | ||
followingDataId: string; // 삭제용 - following data id | ||
followingUserId: string; // 팔로우용 - 팔로우할 userId | ||
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. postFollowUser -> followUser 개인적으로는 이게 더 직관적으로 보여서 제안드렸는데 어떻게 생각하시나용 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네트워크 요청 함수는 앞에 메소드를 붙이는 컨벤션이 있어서 deleteFollowUser, postFollowUser는 유지해야 할 것 같아요! ㅠ followingDataId는 userId가 아닌 진짜 following 데이터 아이디랍니다.. ㅠㅠ |
||
following?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default 값을 부여하고 있어서 옵셔널로 처리하지 않으셔도 괜찮지 않을까요? |
||
} | ||
|
||
const FollowButton = ({ followDataId }: FollowButtonProps) => { | ||
const [followed, setFollowed] = useState(true); | ||
const FollowButton = ({ | ||
followingDataId, | ||
followingUserId, | ||
following = true | ||
}: FollowButtonProps) => { | ||
const [followed, setFollowed] = useState(following); | ||
const [dataId, setDataId] = useState(followingDataId); | ||
const [userSessionData] = useSessionStorage<Pick<User, '_id' | 'token'>>( | ||
'userData', | ||
{ | ||
_id: '', | ||
token: '' | ||
} | ||
); | ||
const { token, _id } = userSessionData; | ||
const { token } = userSessionData; | ||
Comment on lines
21
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const [userSessionData] = useSessionStorage<Pick<User, 'token'>>(
'userData',
{
token: ''
}
); 세션에서 토큰만 가져온다면 이렇게 작성해주시면 됩니다! |
||
|
||
const { refetch } = useQuery({ | ||
queryKey: ['follow'], | ||
queryFn: async () => { | ||
const data = followed | ||
? await deleteFollowUser(followDataId, token) | ||
: await postFollowUser(_id, token); | ||
const { mutate } = useMutation( | ||
() => | ||
followed | ||
? deleteFollowUser(dataId, token) | ||
: postFollowUser(followingUserId, token), | ||
{ | ||
onSuccess: (data) => { | ||
if (!followed) { | ||
setDataId(data._id); | ||
} | ||
|
||
return data; | ||
}, | ||
enabled: false | ||
}); | ||
setFollowed((prev) => !prev); | ||
} | ||
} | ||
); | ||
|
||
const handleClickFollow = async () => { | ||
await refetch(); | ||
setFollowed((prev) => !prev); | ||
const handleClickFollow = () => { | ||
mutate(); | ||
}; | ||
|
||
return ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export const PROFILE_TABS = { | ||
MEDITATION: '명상', | ||
FOLLOWING: '팔로워', | ||
FOLLOWER: '팔로잉', | ||
FOLLOWING: '팔로잉', | ||
FOLLOWER: '팔로워', | ||
INFO: '명상정보' | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 'bearer ' 부분을 api단이 아닌 UI레이어에서 붙여서 보내주는데 통일해야겠네요?! 어느쪽이 더 좋을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
api단이 더 좋을 것 같아요! 아니면 세션에 저장할 때 bearer을 붙이고 저장하는건 어떨까요?