Skip to content

Commit 61511be

Browse files
Merge pull request #96 from OpenSIST/dev
fix bug #95
2 parents 9166b56 + 5fee458 commit 61511be

5 files changed

Lines changed: 36 additions & 9 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/ProgramPage/ProgramContent/StarButton.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { StarRounded, StarBorderRounded } from "@mui/icons-material";
2-
import { IconButton, Tooltip } from "@mui/material";
2+
import { IconButton, Tooltip, useTheme } from "@mui/material";
33
import { Form } from "react-router-dom";
44

55
const StarButton = ({programID, metaData}) => {
6+
const theme = useTheme()
7+
const darkMode = theme.palette.mode === "dark"
68
const starred = metaData.ProgramCollection && metaData.ProgramCollection.includes(programID)
9+
const color = darkMode ? "#ff9f0a" : "#ff9500"
710

811
return <Form method='post' style={{display: 'flex'}}>
912
<Tooltip title={starred ? "取消收藏该项目" : "收藏该项目"} arrow>
1013
<IconButton type="submit" name="ActionType" value={starred ? "UnStar" : "Star"}>
11-
{starred ? <StarRounded/> : <StarBorderRounded/>}
14+
{starred ? <StarRounded style= {{color: color}}/> : <StarBorderRounded/>}
1215
</IconButton>
1316
</Tooltip>
1417
</Form>

src/Components/TopBar/StatusBlock/StatusBlock.jsx

Lines changed: 7 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,11 @@ export function StatusBlock() {
3839

3940
useEffect(() => {
4041
if (user === null) {
41-
navigate('/login');
42+
emptyCache().then(() => {
43+
if (window.location.pathname !== '/agreement') {
44+
navigate('/login');
45+
}
46+
});
4247
}
4348
}, [user, navigate]);
4449

src/Data/Common.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,32 @@ 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
2536
* @param response [Response]: response from fetch
2637
* @return: response
2738
*/
2839
if (response.status === 401) {
40+
console.log(window.location.pathname)
41+
if (window.location.pathname === "/agreement") {
42+
return;
43+
}
2944
if (!["/login", "/register", "/reset"].includes(window.location.pathname)) {
3045
window.location.href = "/login";
3146
}
47+
await emptyCache();
3248
return;
3349
}
3450
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)