Skip to content

Commit fa0e433

Browse files
empty cache when user is kick out
1 parent 03421a8 commit fa0e433

4 files changed

Lines changed: 25 additions & 7 deletions

File tree

src/Components/Profile/ProfileSideBar/ProfileSideBar.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import PersonAddAltIcon from '@mui/icons-material/PersonAddAlt';
2626
import {ConnectWithoutContact, Edit, Refresh, HomeRounded, LinkedIn, Link as LinkIcon, Mail} from "@mui/icons-material";
2727
import {blue, grey} from "@mui/material/colors";
2828
import {CollapseSideBar} from "../../common";
29-
import React, {useState} from "react";
29+
import React, {useEffect, useState} from "react";
3030
import Grid2 from "@mui/material/Unstable_Grid2";
3131
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
3232
import {faQq, faWeixin} from "@fortawesome/free-brands-svg-icons";
@@ -41,7 +41,9 @@ export function ProfileSideBar({loaderData}) {
4141
const [anonymousOpen, setAnonymousOpen] = useState(false);
4242
const [editContactOpen, setEditContactOpen] = useState(false);
4343
const [contact, setContact] = useState(userContact);
44-
44+
useEffect(() => {
45+
setAnonymous(displayName !== user);
46+
}, [displayName, user])
4547
return (
4648
<CollapseSideBar
4749
sx={{
@@ -107,7 +109,7 @@ export function ProfileSideBar({loaderData}) {
107109
</Badge>
108110
<Form method='post' style={{position: 'absolute', right: '10px'}}>
109111
<Tooltip title='刷新侧边栏信息' arrow>
110-
<IconButton type='submit' variant="outlined" name='button' value='Refresh' >
112+
<IconButton type='submit' variant="outlined" name='button' value='Refresh'>
111113
<Refresh fontSize='large'/>
112114
</IconButton>
113115
</Tooltip>

src/Components/TopBar/StatusBlock/StatusBlock.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import React, {useContext, useEffect} from "react";
44
import localforage from "localforage";
55
import {getAvatar, getDisplayName, getMetaData, logout, useUser} from "../../../Data/UserData";
66
import {Avatar, Box, IconButton, ListItemIcon, Menu, MenuItem, Tooltip, Typography, useTheme} from "@mui/material";
7-
import {AccountBoxRounded, StarRounded, LockResetRounded, LogoutRounded, ExitToAppRounded} from "@mui/icons-material";
7+
import {AccountBoxRounded, StarRounded, LockResetRounded, ExitToAppRounded} from "@mui/icons-material";
88
import {blue} from "@mui/material/colors";
99
import {ThemeContext} from "../../../index";
1010
import Brightness4Icon from '@mui/icons-material/Brightness4';
1111
import Brightness7Icon from '@mui/icons-material/Brightness7';
12+
import {emptyCache} from "../../../Data/Common";
1213

1314
export async function loader() {
1415
const displayName = await getDisplayName();
@@ -38,7 +39,9 @@ export function StatusBlock() {
3839

3940
useEffect(() => {
4041
if (user === null) {
41-
navigate('/login');
42+
emptyCache().then(() => {
43+
navigate('/login');
44+
});
4245
}
4346
}, [user, navigate]);
4447

src/Data/Common.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ export async function headerGenerator(auth = false, contentType = 'application/j
1919
return header;
2020
}
2121

22+
export async function emptyCache() {
23+
/*
24+
* Empty the cache
25+
*/
26+
const theme = await localforage.getItem('theme');
27+
await localforage.clear();
28+
if (theme) {
29+
await localforage.setItem('theme', theme);
30+
}
31+
}
32+
2233
export async function handleErrors(response) {
2334
/*
2435
* Handle the error of the response
@@ -29,6 +40,7 @@ export async function handleErrors(response) {
2940
if (!["/login", "/register", "/reset"].includes(window.location.pathname)) {
3041
window.location.href = "/login";
3142
}
43+
await emptyCache();
3244
return;
3345
}
3446
if (response.status !== 200) {

src/Data/UserData.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
COLLECT_PROGRAM,
1313
UNCOLLECT_PROGRAM,
1414
} from "../APIs/APIs";
15-
import {blobToBase64, handleErrors, headerGenerator} from "./Common";
15+
import {blobToBase64, emptyCache, handleErrors, headerGenerator} from "./Common";
1616
import {useState} from "react";
1717
import {getApplicants, setApplicants} from "./ApplicantData";
1818
import {getRecordByApplicant, setRecord} from "./RecordData";
@@ -84,7 +84,8 @@ export async function logout() {
8484
const content = await response.json();
8585
alert(`${content.error}, Error code: ${response.status}`);
8686
}
87-
await localforage.clear(); // clear all the cache data
87+
// await localforage.clear(); // clear all the cache data
88+
await emptyCache(); // clear all the cache data
8889
return redirect("/login");
8990
}
9091

0 commit comments

Comments
 (0)