-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: userData 저장, 댓글 좋아요 optimistic update 추가 (#18)
* chore: 불필요한 console.log 삭제 * feat: logout api 추가 * feat: toastify 설정 추가 * feat: 사용자 정보 저장 및 로그아웃 추가 * feat: 댓글 작성자와 사용자가 같을 시 삭제 버튼 * feat: header 메뉴 중 로그인이 필요할 시 로그인페이지로 이동 * feat: 댓글 좋아요 Optimistic update 기능 추가
- Loading branch information
Showing
27 changed files
with
4,822 additions
and
2,834 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { axiosInstance } from '.'; | ||
import END_POINTS from '../constants/api'; | ||
|
||
export default async function deleteLike(commentId) { | ||
const { data } = await axiosInstance.delete(END_POINTS.DELETE_LIKE(commentId)); | ||
|
||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { axiosInstance } from '.'; | ||
|
||
export default async function getUserInfo() { | ||
const { data } = await axiosInstance.get('/user'); | ||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { axiosInstance } from '.'; | ||
import END_POINTS from '../constants/api'; | ||
|
||
export default async function postLike(commentId) { | ||
const { data } = await axiosInstance.post(END_POINTS.POST_LIKE(commentId)); | ||
|
||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { axiosInstance } from '.'; | ||
import END_POINTS from '../constants/api'; | ||
|
||
export default async function postLogout() { | ||
const { data } = await axiosInstance.post(END_POINTS.POST_LOGOUT); | ||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { createContext, useCallback, useEffect, useState } from 'react'; | ||
import getUserInfo from '../apis/getUserInfo'; | ||
import postLogout from '../apis/postLogout'; | ||
import { toast } from 'react-toastify'; | ||
export const UserInfoContext = createContext({}); | ||
|
||
export const UserInfoProvider = ({ children }) => { | ||
const [userInfo, setUserInfo] = useState(null); | ||
|
||
const logout = useCallback(async () => { | ||
const data = await postLogout(); | ||
setUserInfo({}); | ||
toast.success(data.message); | ||
}, []); | ||
|
||
const login = useCallback(async () => { | ||
const data = await getUserInfo(); | ||
setUserInfo(data || {}); | ||
}, []); | ||
|
||
useEffect(() => { | ||
login(); | ||
}, [login]); | ||
|
||
return ( | ||
<UserInfoContext.Provider value={{ userInfo, logout }}>{children}</UserInfoContext.Provider> | ||
); | ||
}; |
Oops, something went wrong.