feat: reactive after save when profile content changes

This commit is contained in:
dongchengjie
2024-06-29 09:21:50 +08:00
parent 3f1caa702b
commit 9ee5390ec7
12 changed files with 157 additions and 71 deletions

View File

@@ -17,7 +17,7 @@ import {
} from "@mui/material";
import { RefreshRounded, DragIndicator } from "@mui/icons-material";
import { useLoadingCache, useSetLoadingCache } from "@/services/states";
import { updateProfile, deleteProfile, viewProfile } from "@/services/cmds";
import { updateProfile, viewProfile } from "@/services/cmds";
import { Notice } from "@/components/base";
import { EditorViewer } from "@/components/profile/editor-viewer";
import { ProfileBox } from "./profile-box";
@@ -36,10 +36,20 @@ interface Props {
itemData: IProfileItem;
onSelect: (force: boolean) => void;
onEdit: () => void;
onChange?: (prev?: string, curr?: string) => void;
onDelete: () => void;
}
export const ProfileItem = (props: Props) => {
const { selected, activating, itemData, onSelect, onEdit } = props;
const {
selected,
activating,
itemData,
onSelect,
onEdit,
onChange,
onDelete,
} = props;
const { attributes, listeners, setNodeRef, transform, transition } =
useSortable({ id: props.id });
@@ -53,6 +63,7 @@ export const ProfileItem = (props: Props) => {
// local file mode
// remote file mode
// remote file mode
const hasUrl = !!itemData.url;
const hasExtra = !!extra; // only subscription url has extra info
const hasHome = !!itemData.home; // only subscription url has home page
@@ -162,16 +173,6 @@ export const ProfileItem = (props: Props) => {
}
});
const onDelete = useLockFn(async () => {
setAnchorEl(null);
try {
await deleteProfile(itemData.uid);
mutate("getProfiles");
} catch (err: any) {
Notice.error(err?.message || err.toString());
}
});
const urlModeMenu = (
hasHome ? [{ label: "Home", handler: onOpenHome }] : []
).concat([
@@ -242,7 +243,7 @@ export const ProfileItem = (props: Props) => {
backdropFilter: "blur(2px)",
}}
>
<CircularProgress size={20} />
<CircularProgress color="inherit" size={20} />
</Box>
)}
<Box position="relative">
@@ -312,7 +313,7 @@ export const ProfileItem = (props: Props) => {
</Typography>
) : (
hasUrl && (
<Typography noWrap title={`From ${from}`}>
<Typography noWrap title={`${t("From")} ${from}`}>
{from}
</Typography>
)
@@ -323,7 +324,7 @@ export const ProfileItem = (props: Props) => {
flex="1 0 auto"
fontSize={14}
textAlign="right"
title={`Updated Time: ${parseExpire(updated)}`}
title={`${t("Update Time")}: ${parseExpire(updated)}`}
>
{updated > 0 ? dayjs(updated * 1000).fromNow() : ""}
</Typography>
@@ -334,17 +335,21 @@ export const ProfileItem = (props: Props) => {
{/* the third line show extra info or last updated time */}
{hasExtra ? (
<Box sx={{ ...boxStyle, fontSize: 14 }}>
<span title="Used / Total">
<span title={t("Used / Total")}>
{parseTraffic(upload + download)} / {parseTraffic(total)}
</span>
<span title="Expire Time">{expire}</span>
<span title={t("Expire Time")}>{expire}</span>
</Box>
) : (
<Box sx={{ ...boxStyle, fontSize: 12, justifyContent: "flex-end" }}>
<span title="Updated Time">{parseExpire(updated)}</span>
<span title={t("Update Time")}>{parseExpire(updated)}</span>
</Box>
)}
<LinearProgress variant="determinate" value={progress} />
<LinearProgress
variant="determinate"
value={progress}
style={{ opacity: progress > 0 ? 1 : 0 }}
/>
</ProfileBox>
<Menu
@@ -390,11 +395,12 @@ export const ProfileItem = (props: Props) => {
open={fileOpen}
language="yaml"
schema="clash"
onChange={onChange}
onClose={() => setFileOpen(false)}
/>
<ConfirmViewer
title="Confirm deletion"
message="This operation is not reversible"
title={t("Confirm deletion")}
message={t("This operation is not reversible")}
open={confirmOpen}
onClose={() => setConfirmOpen(false)}
onConfirm={() => {