feat: show loading when change profile
This commit is contained in:
parent
7854775de5
commit
741abc0366
@ -27,6 +27,7 @@ export const ProfileBox = styled(Box)(
|
|||||||
}[key]!;
|
}[key]!;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
position: "relative",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
display: "block",
|
display: "block",
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
keyframes,
|
keyframes,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
Menu,
|
Menu,
|
||||||
|
CircularProgress,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { RefreshRounded } from "@mui/icons-material";
|
import { RefreshRounded } from "@mui/icons-material";
|
||||||
import { atomLoadingCache } from "@/services/states";
|
import { atomLoadingCache } from "@/services/states";
|
||||||
@ -28,13 +29,14 @@ const round = keyframes`
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
|
activating: boolean;
|
||||||
itemData: IProfileItem;
|
itemData: IProfileItem;
|
||||||
onSelect: (force: boolean) => void;
|
onSelect: (force: boolean) => void;
|
||||||
onEdit: () => void;
|
onEdit: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ProfileItem = (props: Props) => {
|
export const ProfileItem = (props: Props) => {
|
||||||
const { selected, itemData, onSelect, onEdit } = props;
|
const { selected, activating, itemData, onSelect, onEdit } = props;
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [anchorEl, setAnchorEl] = useState<any>(null);
|
const [anchorEl, setAnchorEl] = useState<any>(null);
|
||||||
@ -192,6 +194,25 @@ export const ProfileItem = (props: Props) => {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
{activating && (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
position: "absolute",
|
||||||
|
display: "flex",
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
top: 10,
|
||||||
|
left: 10,
|
||||||
|
right: 10,
|
||||||
|
bottom: 2,
|
||||||
|
zIndex: 10,
|
||||||
|
backdropFilter: "blur(2px)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CircularProgress size={20} />
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
|
||||||
<Box position="relative">
|
<Box position="relative">
|
||||||
<Typography
|
<Typography
|
||||||
width="calc(100% - 36px)"
|
width="calc(100% - 36px)"
|
||||||
|
@ -35,6 +35,7 @@ const ProfilePage = () => {
|
|||||||
|
|
||||||
const [url, setUrl] = useState("");
|
const [url, setUrl] = useState("");
|
||||||
const [disabled, setDisabled] = useState(false);
|
const [disabled, setDisabled] = useState(false);
|
||||||
|
const [activating, setActivating] = useState("");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
profiles = {},
|
profiles = {},
|
||||||
@ -99,6 +100,8 @@ const ProfilePage = () => {
|
|||||||
|
|
||||||
const onSelect = useLockFn(async (current: string, force: boolean) => {
|
const onSelect = useLockFn(async (current: string, force: boolean) => {
|
||||||
if (!force && current === profiles.current) return;
|
if (!force && current === profiles.current) return;
|
||||||
|
// 避免大多数情况下loading态闪烁
|
||||||
|
const reset = setTimeout(() => setActivating(current), 100);
|
||||||
try {
|
try {
|
||||||
await patchProfiles({ current });
|
await patchProfiles({ current });
|
||||||
mutateLogs();
|
mutateLogs();
|
||||||
@ -107,6 +110,9 @@ const ProfilePage = () => {
|
|||||||
Notice.success("Refresh clash config", 1000);
|
Notice.success("Refresh clash config", 1000);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
Notice.error(err?.message || err.toString(), 4000);
|
Notice.error(err?.message || err.toString(), 4000);
|
||||||
|
} finally {
|
||||||
|
clearTimeout(reset);
|
||||||
|
setActivating("");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -258,6 +264,7 @@ const ProfilePage = () => {
|
|||||||
<Grid item xs={12} sm={6} md={4} lg={3} key={item.file}>
|
<Grid item xs={12} sm={6} md={4} lg={3} key={item.file}>
|
||||||
<ProfileItem
|
<ProfileItem
|
||||||
selected={profiles.current === item.uid}
|
selected={profiles.current === item.uid}
|
||||||
|
activating={activating === item.uid}
|
||||||
itemData={item}
|
itemData={item}
|
||||||
onSelect={(f) => onSelect(item.uid, f)}
|
onSelect={(f) => onSelect(item.uid, f)}
|
||||||
onEdit={() => viewerRef.current?.edit(item)}
|
onEdit={() => viewerRef.current?.edit(item)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user