This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GptDelete.tsx
56 lines (51 loc) · 1.98 KB
/
GptDelete.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"use client";
import React, { useState } from "react";
import { api } from "~/utils/trpc";
import { InfinitySpin } from "react-loader-spinner";
const GptDeleteButton: React.FC = () => {
const [isDeleting, setIsDeleting] = useState<boolean>(false);
const [deleteOK, setDeleteOK] = useState<boolean | null>(null);
const deleteMutation = api.lgptApi.deleteSource.useMutation();
const handleDeleteClick = () => {
setIsDeleting(true);
deleteMutation
.mutateAsync()
.then((deleteOK) => {
setIsDeleting(false);
setDeleteOK(deleteOK);
})
.catch((deleteError) => {
setIsDeleting(false);
setDeleteOK(false);
console.error(deleteError);
});
};
return (
<>
<div className="mt-5 flex flex-col items-center justify-center">
<button
className="w-full rounded-full bg-red-950 px-4 py-2 text-center font-bold text-white transition duration-300 ease-in-out hover:bg-rose-900"
onClick={handleDeleteClick}
>
Delete Source Files
</button>
{isDeleting && (
<div className="mt-5 flex flex-col items-center justify-center text-zinc-200">
Deleting Source Directory...
<InfinitySpin width="200" color="#4fa94d" />
</div>
)}
{!isDeleting && deleteOK !== null && (
<div className="deleteFeedback max-w-[50vw] overflow-hidden">
{deleteOK ? (
<p>Source Directory Deleted and Recreated</p>
) : (
<p>Failed to Delete Source Directory</p>
)}
</div>
)}
</div>
</>
);
};
export default GptDeleteButton;