feat: enable force select profile
This commit is contained in:
parent
99a8e25411
commit
5eddf4f1aa
@ -41,11 +41,11 @@ interface Props {
|
|||||||
index: number;
|
index: number;
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
itemData: CmdType.ProfileItem;
|
itemData: CmdType.ProfileItem;
|
||||||
onClick: () => void;
|
onSelect: (force: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProfileItem: React.FC<Props> = (props) => {
|
const ProfileItem: React.FC<Props> = (props) => {
|
||||||
const { index, selected, itemData, onClick } = props;
|
const { index, selected, itemData, onSelect } = props;
|
||||||
|
|
||||||
const { mutate } = useSWRConfig();
|
const { mutate } = useSWRConfig();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@ -68,6 +68,11 @@ const ProfileItem: React.FC<Props> = (props) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onForceSelect = () => {
|
||||||
|
setAnchorEl(null);
|
||||||
|
onSelect(true);
|
||||||
|
};
|
||||||
|
|
||||||
const onUpdateWrapper = (withProxy: boolean) => async () => {
|
const onUpdateWrapper = (withProxy: boolean) => async () => {
|
||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
if (loading) return;
|
if (loading) return;
|
||||||
@ -136,7 +141,7 @@ const ProfileItem: React.FC<Props> = (props) => {
|
|||||||
|
|
||||||
return { bgcolor, color, "& h2": { color: h2color } };
|
return { bgcolor, color, "& h2": { color: h2color } };
|
||||||
}}
|
}}
|
||||||
onClick={onClick}
|
onClick={() => onSelect(false)}
|
||||||
onContextMenu={handleContextMenu}
|
onContextMenu={handleContextMenu}
|
||||||
>
|
>
|
||||||
<Box display="flex" justifyContent="space-between">
|
<Box display="flex" justifyContent="space-between">
|
||||||
@ -211,7 +216,8 @@ const ProfileItem: React.FC<Props> = (props) => {
|
|||||||
anchorPosition={position}
|
anchorPosition={position}
|
||||||
anchorReference="anchorPosition"
|
anchorReference="anchorPosition"
|
||||||
>
|
>
|
||||||
<MenuItem onClick={onEdit}>Edit</MenuItem>
|
<MenuItem onClick={onForceSelect}>Select</MenuItem>
|
||||||
|
<MenuItem onClick={onEdit}>Edit(VScode)</MenuItem>
|
||||||
<MenuItem onClick={onUpdateWrapper(false)}>Update</MenuItem>
|
<MenuItem onClick={onUpdateWrapper(false)}>Update</MenuItem>
|
||||||
<MenuItem onClick={onUpdateWrapper(true)}>Update(Proxy)</MenuItem>
|
<MenuItem onClick={onUpdateWrapper(true)}>Update(Proxy)</MenuItem>
|
||||||
<MenuItem onClick={onDelete}>Delete</MenuItem>
|
<MenuItem onClick={onDelete}>Delete</MenuItem>
|
||||||
|
@ -80,20 +80,18 @@ const ProfilePage = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const lockRef = useRef(false);
|
const lockRef = useRef(false);
|
||||||
const onProfileChange = (index: number) => {
|
const onSelect = async (index: number, force: boolean) => {
|
||||||
if (index === profiles.current || lockRef.current) return;
|
|
||||||
if (lockRef.current) return;
|
if (lockRef.current) return;
|
||||||
|
if (!force && index === profiles.current) return;
|
||||||
lockRef.current = true;
|
lockRef.current = true;
|
||||||
selectProfile(index)
|
try {
|
||||||
.then(() => {
|
await selectProfile(index);
|
||||||
mutate("getProfiles", { ...profiles, current: index }, true);
|
mutate("getProfiles", { ...profiles, current: index }, true);
|
||||||
})
|
} catch (err: any) {
|
||||||
.catch((err) => {
|
err && Notice.error(err.toString());
|
||||||
console.error(err);
|
} finally {
|
||||||
})
|
lockRef.current = false;
|
||||||
.finally(() => {
|
}
|
||||||
lockRef.current = false;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -125,7 +123,7 @@ const ProfilePage = () => {
|
|||||||
index={idx}
|
index={idx}
|
||||||
selected={profiles.current === idx}
|
selected={profiles.current === idx}
|
||||||
itemData={item}
|
itemData={item}
|
||||||
onClick={() => onProfileChange(idx)}
|
onSelect={(f) => onSelect(idx, f)}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
))}
|
))}
|
||||||
|
Loading…
Reference in New Issue
Block a user