This repository has been archived by the owner on Dec 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
147 additions
and
134 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default class CustomException extends Error { | ||
public static errorName = "CustomException" as const; | ||
constructor(message: string, err?: Error) { | ||
super(message); | ||
this.name = CustomException.errorName; | ||
this.message = message; | ||
this.cause = err?.message || ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { toast } from "react-toastify"; | ||
import CustomException from "./CustomException"; | ||
|
||
export function onError(error: Error) { | ||
toast( | ||
error.name == CustomException.errorName || error instanceof CustomException | ||
? error.message | ||
: "Something went wrong!", | ||
{ type: "error" } | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
--- | ||
import Layout from "../layouts/Layout.astro"; | ||
import Bazooka from "../components/Bazooka"; | ||
import Bazooka from "../react/Bazooka"; | ||
import Footer from "../components/Footer.astro"; | ||
--- | ||
|
||
<Layout title="Bazooka"> | ||
<main class="max-w-6xl px-4 mt-6 md:mt-14 mx-auto"> | ||
<Bazooka client:idle /> | ||
<Bazooka client:load /> | ||
<Footer /> | ||
</main> | ||
</Layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import CustomException from "../../lib/CustomException"; | ||
import { get } from "../../lib/request"; | ||
import type { Process } from "../../lib/types"; | ||
|
||
export async function fetchProcesses(): Promise<Process[]> { | ||
const data = await get("/processes"); | ||
if (!data.ok) { | ||
throw new CustomException(data.message); | ||
} | ||
|
||
return data.data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import CustomException from "../../lib/CustomException"; | ||
import { post } from "../../lib/request"; | ||
|
||
export async function killProcesses(PIDs: Number[]) { | ||
const body = { | ||
pids: PIDs, | ||
}; | ||
const data = await post("/processes/kill", body); | ||
|
||
if (!data.ok) { | ||
throw new CustomException(data.message); | ||
} | ||
|
||
return data.data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useState } from "react"; | ||
import { ToastContainer } from "react-toastify"; | ||
import Display from "../components/Display"; | ||
import SideBar from "../components/SideBar"; | ||
import { | ||
useQuery, | ||
QueryClient, | ||
QueryClientProvider, | ||
} from "@tanstack/react-query"; | ||
import "react-toastify/dist/ReactToastify.css"; | ||
import { fetchProcesses } from "../queries/process/fetch"; | ||
import type { Process } from "../lib/types"; | ||
import { onError } from "../lib/error"; | ||
|
||
export default function Bazooka() { | ||
const [processes, setProcesses] = useState<Process[]>([]); | ||
const [PIDs, setPIDs] = useState<number[]>([]); | ||
|
||
const queryClient = new QueryClient(); | ||
const { isLoading, refetch } = useQuery({ | ||
queryKey: ["processes"], | ||
queryFn: fetchProcesses, | ||
onSuccess: (data) => { | ||
if (data) { | ||
setProcesses(data); | ||
} | ||
}, | ||
onError, | ||
}); | ||
|
||
return ( | ||
<QueryClientProvider client={queryClient}> | ||
<main className="w-full flex flex-col-reverse md:flex-row gap-6"> | ||
<Display | ||
loading={isLoading} | ||
PIDs={PIDs} | ||
processes={processes} | ||
setProcesses={setProcesses} | ||
setPIDs={setPIDs} | ||
/> | ||
<SideBar PIDs={PIDs} refetch={refetch} queryClient={queryClient} /> | ||
</main> | ||
<ToastContainer | ||
theme="dark" | ||
position="top-right" | ||
autoClose={5000} | ||
hideProgressBar | ||
draggable | ||
closeOnClick | ||
/> | ||
</QueryClientProvider> | ||
); | ||
} |