1
0
mirror of https://github.com/spacebarchat/client.git synced 2024-11-22 02:12:38 +01:00

fix leave server and better handling

This commit is contained in:
Puyodead1 2023-12-19 11:39:34 -05:00
parent ba31016686
commit 39716d74ca
No known key found for this signature in database
GPG Key ID: BA5F91AAEF68E5CE

View File

@ -1,22 +1,34 @@
import { Routes } from "@spacebarchat/spacebar-api-types/v9"; import { Routes } from "@spacebarchat/spacebar-api-types/v9";
import { useState } from "react"; import { useState } from "react";
import { useNavigate } from "react-router-dom";
import { ModalProps, modalController } from "../../controllers/modals"; import { ModalProps, modalController } from "../../controllers/modals";
import useLogger from "../../hooks/useLogger";
import { useAppStore } from "../../stores/AppStore"; import { useAppStore } from "../../stores/AppStore";
import { Modal } from "./ModalComponents"; import { Modal } from "./ModalComponents";
export function LeaveServerModal({ target, ...props }: ModalProps<"leave_server">) { export function LeaveServerModal({ target, ...props }: ModalProps<"leave_server">) {
const app = useAppStore(); const app = useAppStore();
const logger = useLogger("LeaveServerModal");
const navigate = useNavigate();
const [isDisabled, setDisabled] = useState(false); const [isDisabled, setDisabled] = useState(false);
async function leaveGuild() { async function leaveGuild() {
setDisabled(true); setDisabled(true);
await app.rest await app.rest
.delete(Routes.guildMember(target.id, "@me")) .delete(Routes.userGuild(target.id))
.then(() => { .then(() => {
modalController.pop("close"); modalController.pop("close");
navigate("/channels/@me");
}) })
.catch((e) => { .catch((e) => {
console.error(e); logger.error(e);
modalController.pop("close");
modalController.push({
type: "error",
error: e,
title: "Failed to leave server",
description: "An error occurred while trying to leave the server.",
});
}) })
.finally(() => setDisabled(false)); .finally(() => setDisabled(false));
} }