fix: Slight UI regression when changing servers on latest version #288

This commit is contained in:
Prayag Prajapati committed 2024-04-29 21:46:41 +05:30
1 parent b94442560c
commit 688ac6aee5
1 file changed
+13 -55
+13 -55
View File
@@ -103,22 +103,18 @@ const Settings = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const [updating, setUpdating] = useState(false); const [updating, setUpdating] = useState(false);
const [serverState, setServerState] = useState();
const [ask, setAsk] = useState(false);
const [action, setAction] = useState(null);
const [addServerDialog, setAddServerDialog] = useState(false); const [addServerDialog, setAddServerDialog] = useState(false);
const [serverIp, setServerIp] = useState(""); const [serverIp, setServerIp] = useState("");
const handleServerChange = useMutation({ const handleServerChange = useMutation({
mutationFn: async () => { mutationFn: async (server: RecommendedServerInfo) => {
await delUser(); await delUser();
await setDefaultServer(serverState.id); await setDefaultServer(server.id);
await defaultServer.refetch(); await defaultServer.refetch();
createApi(serverState.address, null); createApi(server.address, undefined);
queryClient.removeQueries(); queryClient.removeQueries();
}, },
onSuccess: async () => { onSuccess: async () => {
setAsk(false);
setSettingsDialogOpen(false); setSettingsDialogOpen(false);
navigate("/login/index"); navigate("/login/index");
}, },
@@ -130,7 +126,11 @@ const Settings = () => {
}, },
}); });
const handleDelete = async (server: RecommendedServerInfo) => { const handleDelete = useMutation({
mutationKey: ["server-delete"],
mutationFn: async (server: RecommendedServerInfo) => {
const ab = server.id === defaultServer.data;
enqueueSnackbar(`${ab}`);
await delServer(server.id); await delServer(server.id);
if (server.id === defaultServer.data) { if (server.id === defaultServer.data) {
@@ -145,14 +145,14 @@ const Settings = () => {
useApi.setState(useApi.getInitialState()); useApi.setState(useApi.getInitialState());
} }
setSettingsDialogOpen(false); setSettingsDialogOpen(false);
queryClient.removeQueries(); await queryClient.removeQueries();
navigate("/"); navigate("/");
} }
enqueueSnackbar("Server deleted successfully!", { variant: "success" }); enqueueSnackbar("Server deleted successfully!", { variant: "success" });
setAsk(false);
await serversOnDisk.refetch(); await serversOnDisk.refetch();
await defaultServer.refetch(); await defaultServer.refetch();
}; },
});
const addServer = useMutation({ const addServer = useMutation({
mutationFn: async () => { mutationFn: async () => {
@@ -579,9 +579,7 @@ const Settings = () => {
fontSize: "1.64em", fontSize: "1.64em",
}} }}
onClick={() => { onClick={() => {
setAsk(true); handleServerChange.mutate(server);
setAction("change-server");
setServerState(server);
}} }}
disabled={handleServerChange.isPending} disabled={handleServerChange.isPending}
> >
@@ -595,9 +593,7 @@ const Settings = () => {
}} }}
disabled={handleServerChange.isPending} disabled={handleServerChange.isPending}
onClick={() => { onClick={() => {
setAsk(true); handleDelete.mutate(server);
setAction("delete-server");
setServerState(server);
}} }}
> >
<div className="material-symbols-rounded"> <div className="material-symbols-rounded">
@@ -780,44 +776,6 @@ const Settings = () => {
)} )}
</motion.div> </motion.div>
</AnimatePresence> </AnimatePresence>
{/* Show dialog before deleting or changing server */}
<Dialog open={ask} fullWidth maxWidth="xs">
<DialogTitle>Are you sure?</DialogTitle>
<DialogActions
style={{
alignItems: "center",
justifyContent: "center",
padding: "1em",
gap: "1em",
}}
>
<Button
variant="contained"
color="error"
fullWidth
onClick={() => setAsk(false)}
>
No
</Button>
<Button
variant="contained"
color="success"
fullWidth
style={{
margin: 0,
}}
onClick={() => {
if (action === "change-server") {
handleServerChange.mutate();
} else if (action === "delete-server") {
handleDelete(serverState);
}
}}
>
yes
</Button>
</DialogActions>
</Dialog>
{/* Add Server */} {/* Add Server */}
<Dialog open={addServerDialog} fullWidth> <Dialog open={addServerDialog} fullWidth>