Skip to content

Commit

Permalink
feat(queue): stop queue button
Browse files Browse the repository at this point in the history
  • Loading branch information
Zibbp committed May 16, 2023
1 parent c81f1c5 commit d811af3
Showing 1 changed file with 65 additions and 4 deletions.
69 changes: 65 additions & 4 deletions src/components/Queue/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import { createStyles, Loader, Text, ThemeIcon, Tooltip } from "@mantine/core";
import { useQuery } from "@tanstack/react-query";
import {
ActionIcon,
createStyles,
Loader,
Text,
ThemeIcon,
Tooltip,
} from "@mantine/core";
import { useMutation, useQuery } from "@tanstack/react-query";
import { useApi } from "../../hooks/useApi";
import GanymedeLoader from "../Utils/GanymedeLoader";
import { DataTable } from "mantine-datatable";
import { IconCheck, IconPlayerPause, IconX } from "@tabler/icons";
import {
IconCheck,
IconPlayerPause,
IconPlayerStop,
IconSquareX,
IconX,
} from "@tabler/icons";
import Link from "next/link";
import { useEffect, useState } from "react";
import { showNotification } from "@mantine/notifications";

const useStyles = createStyles((theme) => ({
errBadge: {
Expand All @@ -24,6 +38,7 @@ const QueueTable = () => {
const [perPage, setPerPage] = useState(10);
const [records, setRecords] = useState(null);
const [initialRecords, setInitialRecords] = useState(false);
const [loading, setLoading] = useState(false);
const { isLoading, error, data } = useQuery({
queryKey: ["queue"],
queryFn: async () =>
Expand All @@ -49,6 +64,31 @@ const QueueTable = () => {
}
}, [data, page, perPage]);

const stopQueueItem = useMutation({
mutationKey: ["stop-queue"],
mutationFn: (id: string) => {
setLoading(true);
return useApi(
{
method: "POST",
url: `/api/v1/queue/${id}/stop`,
withCredentials: true,
},
false
)
.then(() => {
setLoading(false);
showNotification({
title: "Stopped Queue Item",
message: "Video and chat download has been stopped",
});
})
.catch((err) => {
setLoading(false);
});
},
});

const checkFailed = (record) => {
if (
record.task_vod_create_folder == "failed" ||
Expand Down Expand Up @@ -134,7 +174,28 @@ const QueueTable = () => {
{
accessor: "actions",
title: "Actions",
render: ({ id }) => <Link href={"/queue/" + id}>View</Link>,
render: ({ id, live_archive }) => (
<div
style={{
display: "flex",
justifyContent: "space-between",
alignItems: "center",
}}
>
<Link href={"/queue/" + id}>View</Link>
{live_archive && (
<Tooltip label="Stop queue item" withinPortal>
<ActionIcon
color="red"
variant="light"
onClick={() => stopQueueItem.mutate(id)}
>
<IconSquareX size="1.125rem" />
</ActionIcon>
</Tooltip>
)}
</div>
),
},
]}
totalRecords={data.length}
Expand Down

0 comments on commit d811af3

Please sign in to comment.