-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimizations added with global posts state
- Loading branch information
1 parent
03bf46d
commit fe7e7bf
Showing
12 changed files
with
162 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { atom } from "recoil"; | ||
|
||
const postsAtom = atom({ | ||
key: "postsAtom", | ||
default: [], | ||
}); | ||
|
||
export default postsAtom; |
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,34 @@ | ||
import userAtom from "../atoms/userAtom"; | ||
import { useSetRecoilState } from "recoil"; | ||
import useShowToast from "./useShowToast"; | ||
|
||
const useLogout = () => { | ||
const setUser = useSetRecoilState(userAtom); | ||
const showToast = useShowToast(); | ||
|
||
const logout = async () => { | ||
try { | ||
const res = await fetch("/api/users/logout", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
const data = await res.json(); | ||
|
||
if (data.error) { | ||
showToast("Error", data.error, "error"); | ||
return; | ||
} | ||
|
||
localStorage.removeItem("user-threads"); | ||
setUser(null); | ||
} catch (error) { | ||
showToast("Error", error, "error"); | ||
} | ||
}; | ||
|
||
return logout; | ||
}; | ||
|
||
export default useLogout; |
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
Oops, something went wrong.