-
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.
refactor(client): user 상태 관리 server state만 사용하여 리팩토링 (#396)
- Loading branch information
1 parent
797335e
commit 8b23a2a
Showing
7 changed files
with
29 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,27 @@ | ||
import { useAtom } from 'jotai'; | ||
import { useEffect, useState } from 'react'; | ||
import { userAtom } from '../../stores/user/userAtom'; | ||
import { LOCAL_STORAGE_KEY } from '@/constants/storage'; | ||
import { useGetUser } from '@/hooks/api/user/useGetUser'; | ||
import { LocalStorage } from '@/libs/api/storage'; | ||
|
||
export const useUser = () => { | ||
const userQuery = useGetUser(); | ||
const { user, ...userQuery } = useGetUser(); | ||
const [isLoading, setIsLoading] = useState(true); | ||
const [user, setUser] = useAtom(userAtom); | ||
const [isLogin, setIsLogin] = useState(false); | ||
const accessToken = LocalStorage.getItem('siac'); | ||
|
||
useEffect(() => { | ||
const accessToken = LocalStorage.getItem(LOCAL_STORAGE_KEY.accessToken); | ||
|
||
if (userQuery.data) { | ||
const user = { | ||
isLogin: Boolean(accessToken), | ||
hasNotification: userQuery.data.hasNotification, | ||
...userQuery.data.user, | ||
}; | ||
setUser(user); | ||
if (user) { | ||
setIsLogin(Boolean(accessToken)); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [accessToken]); | ||
|
||
const timerId = setTimeout(() => { | ||
useEffect(() => { | ||
if (!userQuery.isLoading || !userQuery.isFetching) { | ||
setIsLoading(false); | ||
}, 300); | ||
|
||
return () => clearTimeout(timerId); | ||
}, [setUser, userQuery.data]); | ||
} else { | ||
setIsLoading(true); | ||
} | ||
}, [userQuery.isFetching, userQuery.isLoading]); | ||
|
||
return { ...userQuery, isLoading, user: { ...user } }; | ||
return { user, isLogin, ...userQuery, isLoading }; | ||
}; |
This file was deleted.
Oops, something went wrong.