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