memoize refresSession function
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import { SessionContext } from "@/app/context/Context";
|
||||
import { CharacterContext, SessionContext } from "@/app/context/Context";
|
||||
import { Button } from "@mui/material";
|
||||
import { useContext } from "react";
|
||||
|
||||
export const RefreshButton = () => {
|
||||
const { refreshSession } = useContext(SessionContext);
|
||||
const { characters } = useContext(CharacterContext);
|
||||
return (
|
||||
<Button
|
||||
style={{ width: "100%" }}
|
||||
variant="contained"
|
||||
onClick={refreshSession}
|
||||
onClick={() => refreshSession(characters)}
|
||||
>
|
||||
Refresh
|
||||
</Button>
|
||||
|
@@ -13,7 +13,7 @@ export const CharacterContext = createContext<{
|
||||
|
||||
export const SessionContext = createContext<{
|
||||
sessionReady: boolean;
|
||||
refreshSession: () => void;
|
||||
refreshSession: (characters: AccessToken[]) => void;
|
||||
setSessionReady: Dispatch<SetStateAction<boolean>>;
|
||||
EVE_SSO_CALLBACK_URL: string;
|
||||
EVE_SSO_CLIENT_ID: string;
|
||||
|
@@ -67,6 +67,12 @@ const Home = () => {
|
||||
[characters]
|
||||
);
|
||||
|
||||
const refreshSession = useCallback((characters: AccessToken[]) => {
|
||||
Promise.all(characters.map((c) => refreshToken(c)))
|
||||
.then(setCharacters)
|
||||
.finally(() => setSessionReady(true));
|
||||
}, []);
|
||||
|
||||
// Handle EVE SSO callback
|
||||
useEffect(() => {
|
||||
if (code) {
|
||||
@@ -92,12 +98,6 @@ const Home = () => {
|
||||
localStorage.setItem("characters", JSON.stringify(characters));
|
||||
}, [characters]);
|
||||
|
||||
const refreshSession = () => {
|
||||
Promise.all(characters.map((c) => refreshToken(c)))
|
||||
.then(setCharacters)
|
||||
.finally(() => setSessionReady(true));
|
||||
};
|
||||
|
||||
return (
|
||||
<SessionContext.Provider
|
||||
value={{
|
||||
|
Reference in New Issue
Block a user