Skip to content

Usenet streaming with a WebDAV server and a SABnzbd-compatible API

C#

Added actions to queue and history tables (#12)

nzbdav-deva112140d97cc
diff --git a/frontend/app/app.css b/frontend/app/app.css
index 7d4be850..e4e9838d 100644
--- a/frontend/app/app.css
+++ b/frontend/app/app.css
@@ -7,7 +7,6 @@
--page-padding: 25px;
}
-
html, body {
margin: 0;
min-width: 100%;
@@ -16,4 +15,13 @@ html, body {
background-color: var(--body-background-color);
color: white;
font-family: Arial, Helvetica, sans-serif;
+}
+
+/* bootstrap overrides */
+.modal-open {
+ overflow-y: unset !important;
+}
+.modal {
+ --bs-modal-margin: 20px !important;
+ --bs-modal-bg: hsl(196.8 25% 14.51%);
}
\ No newline at end of file
diff --git a/frontend/app/clients/backend-client.server.ts b/frontend/app/clients/backend-client.server.ts
index 3a977450..982e27de 100644
--- a/frontend/app/clients/backend-client.server.ts
+++ b/frontend/app/clients/backend-client.server.ts
@@ -67,13 +67,13 @@ class BackendClient {
return data.authenticated;
}
- public async getQueue(): Promise<any> {
+ public async getQueue(): Promise<QueueResponse> {
const url = process.env.BACKEND_URL + "/api?mode=queue";
const apiKey = process.env.FRONTEND_BACKEND_API_KEY || "";
const response = await fetch(url, { headers: { "x-api-key": apiKey } });
if (!response.ok) {
- throw new Error(`Failed to authenticate: ${(await response.json()).error}`);
+ throw new Error(`Failed to get queue: ${(await response.json()).error}`);
}
const data = await response.json();
@@ -86,7 +86,7 @@ class BackendClient {
const apiKey = process.env.FRONTEND_BACKEND_API_KEY || "";
const response = await fetch(url, { headers: { "x-api-key": apiKey } });
if (!response.ok) {
- throw new Error(`Failed to authenticate: ${(await response.json()).error}`);
+ throw new Error(`Failed to get history: ${(await response.json()).error}`);
}
const data = await response.json();
@@ -208,6 +208,33 @@ class BackendClient {
const data = await response.json();
return data.connected || false;
}
+
+ public async removeFromQueue(nzo_id: string): Promise<any> {
+ const url = process.env.BACKEND_URL
+ + '/api?mode=queue&name=delete'
+ + `&value=${encodeURIComponent(nzo_id)}`;
+ const apiKey = process.env.FRONTEND_BACKEND_API_KEY || "";
+ const response = await fetch(url, { headers: { "x-api-key": apiKey } });
+ if (!response.ok) {
+ throw new Error(`Failed to remove from queue: ${(await response.json()).error}`);
+ }
+
+ return await response.json();
+ }
+
+ public async removeFromHistory(nzo_id: string, del_completed_files: boolean): Promise<any> {
+ let url = process.env.BACKEND_URL
+ + '/api?mode=history&name=delete'
+ + `&value=${encodeURIComponent(nzo_id)}`
+ + `&del_completed_files=${del_completed_files ? 1 : 0}`;
+ const apiKey = process.env.FRONTEND_BACKEND_API_KEY || "";
+ const response = await fetch(url, { headers: { "x-api-key": apiKey } });
+ if (!response.ok) {
+ throw new Error(`Failed to remove from history: ${(await response.json()).error}`);
+ }
+
+ return await response.json();
+ }
}
export const backendClient = new BackendClient();
diff --git a/frontend/app/routes/queue.remove-from-history/route.tsx b/frontend/app/routes/queue.remove-from-history/route.tsx
new file mode 100644
index 00000000..967d392b
--- /dev/null
+++ b/frontend/app/routes/queue.remove-from-history/route.tsx
@@ -0,0 +1,16 @@
+import { redirect } from "react-router";
+import type { Route } from "./+types/route";
+import { backendClient } from "~/clients/backend-client.server";
+import { sessionStorage } from "~/auth/authentication.server";
+
+export async function loader({ request }: Route.ActionArgs) {
+ // ensure user is logged in
+ let session = await sessionStorage.getSession(request.headers.get("cookie"));
+ let user = session.get("user");
+ if (!user) return redirect("/login");
+
+ var url = new URL(request.url);
+ const nzo_id = url.searchParams.get("nzo_id") || "";
+ const del_completed_files = url.searchParams.get("del_completed_files") === "1";
+ return await backendClient.removeFromHistory(nzo_id, del_completed_files);
+}
\ No newline at end of file
diff --git a/frontend/app/routes/queue.remove-from-queue/route.tsx b/frontend/app/routes/queue.remove-from-queue/route.tsx
new file mode 100644
index 00000000..899f4e34
--- /dev/null
+++ b/frontend/app/routes/queue.remove-from-queue/route.tsx
@@ -0,0 +1,14 @@
+import { redirect } from "react-router";
+import type { Route } from "./+types/route";
+import { backendClient } from "~/clients/backend-client.server";
+import { sessionStorage } from "~/auth/authentication.server";
+
+export async function loader({ request }: Route.ActionArgs) {
+ // ensure user is logged in
+ let session = await sessionStorage.getSession(request.headers.get("cookie"));
+ let user = session.get("user");
+ if (!user) return redirect("/login");
+
+ const nzo_id = (new URL(request.url)).searchParams.get("nzo_id") || "";
+ return await backendClient.removeFromQueue(nzo_id);
+}
\ No newline at end of file
diff --git a/frontend/app/routes/queue/components/action-button/action-button.module.css b/frontend/app/routes/queue/components/action-button/action-button.module.css
new file mode 100644
index 00000000..63210505
--- /dev/null
+++ b/frontend/app/routes/queue/components/action-button/action-button.module.css
@@ -0,0 +1,26 @@
+.action-button {
+ padding: 4px 6px;
+ line-height: 16px;
+}
+
+*+.action-button {
+ margin-left: 10px;
+}
+
+.trash-icon {
+ display: inline-block;
+ width: calc(22/24 * 16px);
+ height: 16px;
+ background-repeat: no-repeat;
+ background-size: 100% 100%;
+ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 24'%3E%3Cpath fill='%23adb8b8' d='M16.313 4V2.144C16.313.96 15.353 0 14.169 0H7.831A2.14 2.14 0 0 0 5.69 2.189v-.002V4H0v2h.575c.196.023.372.099.515.214l-.002-.002c.119.157.203.346.239.552l.001.008l1.187 15.106c.094 1.84.094 2.118 2.25 2.118h12.462c2.16 0 2.16-.275 2.25-2.113l1.187-15.1c.036-.217.12-.409.242-.572l-.002.003a1 1 0 0 1 .508-.212h.58v-2h-5.687zM7 2.187c0-.6.487-.938 1.106-.938h5.734c.618 0 1.162.344 1.162.938V4h-8zM6.469 20l-.64-12h1.269l.656 12zm5.225 0H10.32V8h1.375zm3.85 0h-1.275l.656-12h1.269z'/%3E%3C/svg%3E");
+}
+
+.directory-icon {
+ display: inline-block;
+ width: 16px;
+ height: 16px;
+ background-repeat: no-repeat;
+ background-size: 100% 100%;
+ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23adb8b8' d='M2 4.75C2 3.784 2.784 3 3.75 3h4.971c.58 0 1.12.286 1.447.765l1.404 2.063a.25.25 0 0 0 .207.11h6.224c.966 0 1.75.783 1.75 1.75v.117H5.408a.848.848 0 0 0 0 1.695h15.484a1 1 0 0 1 .995 1.102L21 19.25c-.106 1.05-.784 1.75-1.75 1.75H3.75A1.75 1.75 0 0 1 2 19.25z'/%3E%3C/svg%3E");
+}
\ No newline at end of file
diff --git a/frontend/app/routes/queue/components/action-button/action-button.module.css.d.ts b/frontend/app/routes/queue/components/action-button/action-button.module.css.d.ts
new file mode 100644
index 00000000..03cc2438
--- /dev/null
+++ b/frontend/app/routes/queue/components/action-button/action-button.module.css.d.ts
@@ -0,0 +1,7 @@
+declare const styles: {
+ readonly "action-button": string;
+ readonly "trash-icon": string;
+ readonly "directory-icon": string;
+};
+export = styles;
+
diff --git a/frontend/app/routes/queue/components/action-button/action-button.tsx b/frontend/app/routes/queue/components/action-button/action-button.tsx
new file mode 100644
index 00000000..512d9552
--- /dev/null
+++ b/frontend/app/routes/queue/components/action-button/action-button.tsx
@@ -0,0 +1,21 @@
+import { Button } from "react-bootstrap";
+import styles from "./action-button.module.css";
+
+export type ActionButtonProps = {
+ type: "delete" | "explore",
+ disabled?: boolean,
+ onClick?: () => void,
+}
+
+export function ActionButton({ type, disabled, onClick }: ActionButtonProps) {
+ const variant = type === "delete" ? "outline-danger" : "outline-warning";
+ return (
+ <Button
+ className={styles["action-button"]}
+ variant={variant} onClick={onClick}
+ disabled={disabled}>
+ {type === "delete" && <div className={styles["trash-icon"]} />}
+ {type === "explore" && <div className={styles["directory-icon"]} />}
+ </Button>
+ )
+}
\ No newline at end of file
diff --git a/frontend/app/routes/queue/components/confirm-modal/confirm-modal.tsx b/frontend/app/routes/queue/components/confirm-modal/confirm-modal.tsx
new file mode 100644
index 00000000..9e921750
--- /dev/null
+++ b/frontend/app/routes/queue/components/confirm-modal/confirm-modal.tsx
@@ -0,0 +1,50 @@
+import { Button, Form, Modal } from "react-bootstrap";
+import { WordWrap } from "../word-wrap/word-wrap";
+import { useState } from "react";
+
+export type ConfirmModalProps = {
+ show: boolean,
+ title: string,
+ message: string,
+ checkboxMessage?: string,
+ cancelText?: string,
+ confirmText?: string,
+ onCancel: () => void,
+ onConfirm: (isCheckboxChecked?: boolean) => void,
+}
+
+export function ConfirmModal(props: ConfirmModalProps) {
+ const [isCheckboxChecked, setIsCheckboxChecked] = useState(false);
+
+ return (
+ <Modal show={props.show} onHide={props.onCancel} centered scrollable>
+ <Modal.Header closeButton>
+ <Modal.Title>{props.title}</Modal.Title>
+ </Modal.Header>
+ <Modal.Body>
+ <div>
+ <div style={{ fontSize: "12px" }}>
+ <WordWrap>{props.message}</WordWrap>
+ </div>
+ {props.checkboxMessage &&
+ <Form.Check
+ type="checkbox"
+ id="modal-checkbox"
+ style={{ marginTop: '12px' }}
+ label={props.checkboxMessage}
+ checked={isCheckboxChecked}
+ onChange={(e) => setIsCheckboxChecked(Boolean(e.target.checked))} />
+ }
+ </div>
+ </Modal.Body>
+ <Modal.Footer>
+ <Button variant="secondary" onClick={props.onCancel}>
+ {props.cancelText || "Close"}
+ </Button>
+ <Button variant="danger" onClick={() => props.onConfirm(isCheckboxChecked)}>
+ {props.confirmText || "Confirm Removal"}
+ </Button>
+ </Modal.Footer>
+ </Modal>
+ );
+}
\ No newline at end of file
diff --git a/frontend/app/routes/queue/components/history-table/history-table.module.css b/frontend/app/routes/queue/components/history-table/history-table.module.css
deleted file mode 100644
index 03ee91d4..00000000
--- a/frontend/app/routes/queue/components/history-table/history-table.module.css
+++ /dev/null
@@ -1,41 +0,0 @@
-.first-table-header {
- padding-left: 15px !important;
- border-radius: 10px 0 0 0;
-}
-
-.table-header {
- text-align: center;
-}
-
-.last-table-header {
- border-radius: 0 10px 0 0;
- text-align: center;
-}
-
-.row-title {
- max-width: 200px;
- color: #93a1a1 !important;
- --bs-table-bg: transparent;
- padding: 15px 0 !important;
- padding-left: 15px !important;
-}
-
-
-.truncate {
- word-break: break-all;
- line-clamp: 1;
- -webkit-line-clamp: 1;
- -webkit-box-orient: vertical;
- text-overflow: ellipsis;
- display: -webkit-box;
- overflow: hidden;
-}
-
-.row-column {
- max-width: 200px;
- --bs-table-bg: transparent;
- color: #93a1a1 !important;
- text-align: center;
- vertical-align: middle;
- white-space: nowrap;
-}
\ No newline at end of file
diff --git a/frontend/app/routes/queue/components/history-table/history-table.module.css.d.ts b/frontend/app/routes/queue/components/history-table/history-table.module.css.d.ts
deleted file mode 100644
index 79e9ac84..00000000
--- a/frontend/app/routes/queue/components/history-table/history-table.module.css.d.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-declare const styles: {
- readonly "first-table-header": string;
- readonly "last-table-header": string;
- readonly "row-column": string;
- readonly "row-title": string;
- readonly "table-header": string;
- readonly "truncate": string;
-};
-export = styles;
-
diff --git a/frontend/app/routes/queue/components/history-table/history-table.tsx b/frontend/app/routes/queue/components/history-table/history-table.tsx
index 9860e196..9ef9c70a 100644
--- a/frontend/app/routes/queue/components/history-table/history-table.tsx
+++ b/frontend/app/routes/queue/components/history-table/history-table.tsx
@@ -1,44 +1,113 @@
-import type { HistoryResponse } from "~/clients/backend-client.server"
-import styles from "./history-table.module.css"
-import { Table } from "react-bootstrap"
+import type { HistoryResponse, HistorySlot } from "~/clients/backend-client.server"
import { CategoryBadge, formatFileSize, StatusBadge } from "../queue-table/queue-table"
+import { ActionButton } from "../action-button/action-button"
+import { PageTable } from "../page-table/page-table"
+import tableStyles from "../page-table/page-table.module.css"
+import { Truncate } from "../truncate/truncate"
+import { useCallback, useState } from "react"
+import { ConfirmModal } from "../confirm-modal/confirm-modal"
+import { Link } from "react-router"
export type HistoryTableProps = {
history: HistoryResponse
}
export function HistoryTable({ history }: HistoryTableProps) {
-
return (
- <Table responsive>
+ <PageTable responsive>
<thead>
<tr>
- <th className={styles["first-table-header"]}>Name</th>
- <th className={styles["table-header"]}>Category</th>
- <th className={styles["table-header"]}>Status</th>
- <th className={styles["last-table-header"]}>Size</th>
+ <th>Name</th>
+ <th className={tableStyles.disappear}>Category</th>
+ <th className={tableStyles.disappear}>Status</th>
+ <th className={tableStyles.disappear}>Size</th>
+ <th>Actions</th>
</tr>
</thead>
<tbody>
- {history.slots.map((slot, index) =>
- <tr key={index}>
- <td className={styles["row-title"]}>
- <div className={styles.truncate}>
- {slot.name}
- </div>
- </td>
- <td className={styles["row-column"]}>
- <CategoryBadge category={slot.category} />
- </td>
- <td className={styles["row-column"]}>
- <StatusBadge status={slot.status} error={slot.fail_message} />
- </td>
- <td className={styles["row-column"]}>
- {formatFileSize(slot.bytes)}
- </td>
- </tr>
+ {history.slots.map(slot =>
+ <HistoryRow slot={slot} key={slot.nzo_id} />
)}
</tbody>
- </Table>
+ </PageTable>
);
-}
\ No newline at end of file
+}
+
+
+type HistoryRowProps = {
+ slot: HistorySlot
+}
+
+export function HistoryRow({ slot }: HistoryRowProps) {
+ // state
+ const [isConfirmingDelete, setIsConfirmingDelete] = useState(false);
+ const [isDeleting, setIsDeleting] = useState(false);
+ const [isDeleted, setIsDeleted] = useState(false);
+ const className = isDeleting ? tableStyles.deleting : undefined;
+
+ // events
+ const onDelete = useCallback(() => {
+ setIsConfirmingDelete(true);
+ }, [setIsConfirmingDelete]);
+
+ const onCancelDelete = useCallback(() => {
+ setIsConfirmingDelete(false);
+ }, [setIsConfirmingDelete]);
+
+ const onConfirmDelete = useCallback(async (deleteCompletedFiles?: boolean) => {
+ setIsConfirmingDelete(false);
+ setIsDeleting(true);
+ try {
+ const url = '/queue/remove-from-history'
+ + `?nzo_id=${slot.nzo_id}`
+ + `&del_completed_files=${deleteCompletedFiles ? 1 : 0}`;
+ const response = await fetch(url);
+ if (response.ok) {
+ const data = await response.json();
+ if (data.status === true) {
+ setIsDeleted(true);
+ return;
+ }
+ }
+ } catch { }
+ setIsDeleting(false);
+ }, [slot.nzo_id, setIsConfirmingDelete, setIsDeleting, setIsDeleted]);
+
+ // view
+ return isDeleted ? null : (
+ <>
+ <tr className={className}>
+ <td>
+ <Truncate>{slot.nzb_name}</Truncate>
+ <div className={tableStyles.reappear}>
+ <StatusBadge status={slot.status} error={slot.fail_message} />
+ <CategoryBadge category={slot.category} />
+ <div>{formatFileSize(slot.bytes)}</div>
+ </div>
+ </td>
+ <td className={tableStyles.disappear}>
+ <CategoryBadge category={slot.category} />
+ </td>
+ <td className={tableStyles.disappear}>
+ <StatusBadge status={slot.status} error={slot.fail_message} />
+ </td>
+ <td className={tableStyles.disappear}>
+ {formatFileSize(slot.bytes)}
+ </td>
+ <td>
+ <Link to={`/explore/content/${slot.category}/${slot.name}`}>
+ <ActionButton type="explore" />
+ </Link>
+ <ActionButton type="delete" onClick={onDelete} />
+ </td>
+ </tr>
+ <ConfirmModal
+ show={isConfirmingDelete}
+ title="Remove From History?"
+ message={slot.nzb_name}
+ checkboxMessage="Delete mounted files"
+ onConfirm={onConfirmDelete}
+ onCancel={onCancelDelete} />
+ </>
+ )
+}
diff --git a/frontend/app/routes/queue/components/page-table/page-table.module.css b/frontend/app/routes/queue/components/page-table/page-table.module.css
new file mode 100644
index 00000000..4597baf9
--- /dev/null
+++ b/frontend/app/routes/queue/components/page-table/page-table.module.css
@@ -0,0 +1,81 @@
+.container {
+ container-type: inline-size;
+}
+
+.page-table thead tr th {
+ background-color: hsl(192, 100%, 11%) !important;
+ text-align: center;
+ width: 100px;
+}
+
+.page-table thead tr th:first-child {
+ border-radius: 10px 0 0 0;
+ padding-left: 15px !important;
+ text-align: left;
+ width: 50%;
+}
+
+.page-table thead tr th:last-child {
+ border-radius: 0 10px 0 0;
+}
+
+.page-table tbody tr td {
+ max-width: 200px;
+ color: hsl(180, 7%, 70%) !important;
+ --bs-table-bg: hsl(192, 90%, 6%);
+ text-align: center;
+ vertical-align: middle;
+ white-space: nowrap;
+ border-bottom: 1px solid rgba(255, 255, 255, .05);
+}
+
+.page-table tbody tr td:first-child {
+ text-align: left;
+ padding: 15px 0 !important;
+ padding-left: 15px !important;
+}
+
+.page-table tbody tr:last-child td {
+ border-bottom: none;
+}
+
+.page-table tbody tr:last-child td:first-child {
+ border-radius: 0 0 0 10px;
+}
+
+.page-table tbody tr:last-child td:last-child {
+ border-radius: 0 0 10px 0;
+}
+
+.deleting {
+ opacity: 20%;
+}
+
+.reappear {
+ display: none;
+}
+
+.reappear *:has(+*) {
+ margin-right: 10px;
+ margin-bottom: 5px;
+}
+
+.reappear div {
+ margin-left: 5px;
+}
+
+/* mobile */
+@media not (min-width: 900px) {
+ .disappear {
+ display: none;
+ }
+
+ .reappear {
+ display: block;
+ margin-top: 2px;
+ }
+
+ .page-table thead tr th:first-child {
+ width: unset;
+ }
+}
\ No newline at end of file
diff --git a/frontend/app/routes/queue/components/page-table/page-table.module.css.d.ts b/frontend/app/routes/queue/components/page-table/page-table.module.css.d.ts
new file mode 100644
index 00000000..b9648204
--- /dev/null
+++ b/frontend/app/routes/queue/components/page-table/page-table.module.css.d.ts
@@ -0,0 +1,9 @@
+declare const styles: {
+ readonly "container": string;
+ readonly "page-table": string;
+ readonly "disappear": string;
+ readonly "reappear": string;
+ readonly "deleting": string;
+};
+export = styles;
+
diff --git a/frontend/app/routes/queue/components/page-table/page-table.tsx b/frontend/app/routes/queue/components/page-table/page-table.tsx
new file mode 100644
index 00000000..d439130d
--- /dev/null
+++ b/frontend/app/routes/queue/components/page-table/page-table.tsx
@@ -0,0 +1,10 @@
+import { Table, type TableProps } from "react-bootstrap";
+import styles from "./page-table.module.css";
+
+export function PageTable(props: TableProps) {
+ return (
+ <div className={styles.container}>
+ <Table className={styles["page-table"]} {...props} />
+ </div>
+ )
+}
\ No newline at end of file
diff --git a/frontend/app/routes/queue/components/queue-table/queue-table.module.css b/frontend/app/routes/queue/components/queue-table/queue-table.module.css
index 59dc9a3b..3fea6672 100644
--- a/frontend/app/routes/queue/components/queue-table/queue-table.module.css
+++ b/frontend/app/routes/queue/components/queue-table/queue-table.module.css
@@ -1,46 +1,4 @@
-.first-table-header {
- padding-left: 15px !important;
- border-radius: 10px 0 0 0;
-}
-
-.table-header {
- text-align: center;
-}
-
-.last-table-header {
- border-radius: 0 10px 0 0;
- text-align: center;
-}
-
-.row-title {
- max-width: 200px;
- color: #93a1a1 !important;
- --bs-table-bg: transparent;
- padding: 15px 0 !important;
- padding-left: 15px !important;
-}
-
-
-.truncate {
- word-break: break-all;
- line-clamp: 1;
- -webkit-line-clamp: 1;
- -webkit-box-orient: vertical;
- text-overflow: ellipsis;
- display: -webkit-box;
- overflow: hidden;
-}
-
-.row-column {
- max-width: 200px;
- --bs-table-bg: transparent;
- color: #93a1a1 !important;
- text-align: center;
- vertical-align: middle;
- white-space: nowrap;
-}
-
-@media not (pointer: coarse), (min-width: 900px) {
+@media not (pointer: coarse), (min-width: 900px) {
.failure-badge:hover {
cursor: pointer;
}
diff --git a/frontend/app/routes/queue/components/queue-table/queue-table.module.css.d.ts b/frontend/app/routes/queue/components/queue-table/queue-table.module.css.d.ts
index 8b242eda..513489a3 100644
--- a/frontend/app/routes/queue/components/queue-table/queue-table.module.css.d.ts
+++ b/frontend/app/routes/queue/components/queue-table/queue-table.module.css.d.ts
@@ -1,10 +1,4 @@
declare const styles: {
- readonly "first-table-header": string;
- readonly "last-table-header": string;
- readonly "row-column": string;
- readonly "row-title": string;
- readonly "table-header": string;
- readonly "truncate": string;
readonly "failure-badge": string;
};
export = styles;
diff --git a/frontend/app/routes/queue/components/queue-table/queue-table.tsx b/frontend/app/routes/queue/components/queue-table/queue-table.tsx
index 67c5e362..40e217f1 100644
--- a/frontend/app/routes/queue/components/queue-table/queue-table.tsx
+++ b/frontend/app/routes/queue/components/queue-table/queue-table.tsx
@@ -1,6 +1,12 @@
-import type { QueueResponse } from "~/clients/backend-client.server"
+import type { QueueResponse, QueueSlot } from "~/clients/backend-client.server"
import styles from "./queue-table.module.css"
-import { Badge, OverlayTrigger, Table, Tooltip } from "react-bootstrap"
+import tableStyles from "../page-table/page-table.module.css"
+import { Badge, OverlayTrigger, Tooltip } from "react-bootstrap"
+import { ActionButton } from "../action-button/action-button"
+import { PageTable } from "../page-table/page-table"
+import { Truncate } from "../truncate/truncate"
+import { useCallback, useState } from "react"
+import { ConfirmModal } from "../confirm-modal/confirm-modal"
export type QueueTableProps = {
queue: QueueResponse
@@ -8,45 +14,102 @@ export type QueueTableProps = {
export function QueueTable({ queue }: QueueTableProps) {
return (
- <Table responsive>
+ <PageTable responsive striped>
<thead>
<tr>
- <th className={styles["first-table-header"]}>FileName</th>
- <th className={styles["table-header"]}>Category</th>
- <th className={styles["table-header"]}>Status</th>
- <th className={styles["last-table-header"]}>Size</th>
+ <th>Name</th>
+ <th className={tableStyles.disappear}>Category</th>
+ <th className={tableStyles.disappear}>Status</th>
+ <th className={tableStyles.disappear}>Size</th>
+ <th>Actions</th>
</tr>
</thead>
<tbody>
- {queue.slots.map((slot, index) =>
- <tr key={index}>
- <td className={styles["row-title"]}>
- <div className={styles.truncate}>
- {slot.filename}
- </div>
- </td>
- <td className={styles["row-column"]}>
- <CategoryBadge category={slot.cat} />
- </td>
- <td className={styles["row-column"]}>
- <StatusBadge status={slot.status} />
- </td>
- <td className={styles["row-column"]}>
- {formatFileSize(Number(slot.mb) * 1024 * 1024)}
- </td>
- </tr>
+ {queue.slots.map(slot =>
+ <QueueRow slot={slot} key={slot.nzo_id} />
)}
</tbody>
- </Table>
+ </PageTable>
);
}
+type QueueRowProps = {
+ slot: QueueSlot
+}
+
+export function QueueRow({ slot }: QueueRowProps) {
+ // state
+ const [isConfirmingDelete, setIsConfirmingDelete] = useState(false);
+ const [isDeleting, setIsDeleting] = useState(false);
+ const [isDeleted, setIsDeleted] = useState(false);
+ const className = isDeleting ? tableStyles.deleting : undefined;
+
+ // events
+ const onDelete = useCallback(() => {
+ setIsConfirmingDelete(true);
+ }, [setIsConfirmingDelete]);
+
+ const onCancelDelete = useCallback(() => {
+ setIsConfirmingDelete(false);
+ }, [setIsConfirmingDelete]);
+
+ const onConfirmDelete = useCallback(async () => {
+ setIsConfirmingDelete(false);
+ setIsDeleting(true);
+ try {
+ const response = await fetch(`/queue/remove-from-queue?nzo_id=${slot.nzo_id}`);
+ if (response.ok) {
+ const data = await response.json();
+ if (data.status === true) {
+ setIsDeleted(true);
+ return;
+ }
+ }
+ } catch { }
+ setIsDeleting(false);
+ }, [slot.nzo_id, setIsConfirmingDelete, setIsDeleting, setIsDeleted]);
+
+ // view
+ return isDeleted ? null : (
+ <>
+ <tr key={slot.nzo_id} className={className}>
+ <td>
+ <Truncate>{slot.filename}</Truncate>
+ <div className={tableStyles.reappear}>
+ <StatusBadge status={slot.status} />
+ <CategoryBadge category={slot.cat} />
+ <div>{formatFileSize(Number(slot.mb) * 1024 * 1024)}</div>
+ </div>
+ </td>
+ <td className={tableStyles.disappear}>
+ <CategoryBadge category={slot.cat} />
+ </td>
+ <td className={tableStyles.disappear}>
+ <StatusBadge status={slot.status} />
+ </td>
+ <td className={tableStyles.disappear}>
+ {formatFileSize(Number(slot.mb) * 1024 * 1024)}
+ </td>
+ <td>
+ <ActionButton type="delete" disabled={isDeleting} onClick={onDelete} />
+ </td>
+ </tr>
+ <ConfirmModal
+ show={isConfirmingDelete}
+ title="Remove From Queue?"
+ message={slot.filename}
+ onConfirm={onConfirmDelete}
+ onCancel={onCancelDelete} />
+ </>
+ )
+}
+
export function CategoryBadge({ category }: { category: string }) {
const categoryLower = category?.toLowerCase();
let variant = 'secondary';
if (categoryLower === 'movies') variant = 'primary';
if (categoryLower === 'tv') variant = 'info';
- return <Badge bg={variant}>{categoryLower}</Badge>
+ return <Badge bg={variant} style={{ width: '85px' }}>{categoryLower}</Badge>
}
export function StatusBadge({ status, error }: { status: string, error?: string }) {
@@ -64,7 +127,7 @@ export function StatusBadge({ status, error }: { status: string, error?: string
return (
<OverlayTrigger placement="top" overlay={overlay} trigger="click">
- <Badge bg={variant} className={badgeClass}>{statusLower}</Badge>
+ <Badge bg={variant} className={badgeClass} style={{ width: '85px' }}>{statusLower}</Badge>
</OverlayTrigger>
);
}
diff --git a/frontend/app/routes/queue/components/truncate/truncate.module.css b/frontend/app/routes/queue/components/truncate/truncate.module.css
new file mode 100644
index 00000000..c988befe
--- /dev/null
+++ b/frontend/app/routes/queue/components/truncate/truncate.module.css
@@ -0,0 +1,26 @@
+.truncate {
+ word-break: break-all;
+ line-clamp: 1;
+ -webkit-line-clamp: 1;
+ -webkit-box-orient: vertical;
+ text-overflow: ellipsis;
+ display: -webkit-box;
+ overflow: hidden;
+ white-space: initial;
+}
+
+/* mobile */
+@media not (min-width: 900px) {
+ .truncate {
+ line-clamp: 10;
+ -webkit-line-clamp: 10;
+ }
+}
+
+/* desktop */
+@media not (pointer: coarse), (min-width: 900px) {
+ .truncate:active {
+ line-clamp: 10;
+ -webkit-line-clamp: 10;
+ }
+}
\ No newline at end of file
diff --git a/frontend/app/routes/queue/components/truncate/truncate.module.css.d.ts b/frontend/app/routes/queue/components/truncate/truncate.module.css.d.ts
new file mode 100644
index 00000000..7f70591b
--- /dev/null
+++ b/frontend/app/routes/queue/components/truncate/truncate.module.css.d.ts
@@ -0,0 +1,5 @@
+declare const styles: {
+ readonly "truncate": string;
+};
+export = styles;
+
diff --git a/frontend/app/routes/queue/components/truncate/truncate.tsx b/frontend/app/routes/queue/components/truncate/truncate.tsx
new file mode 100644
index 00000000..afe4ba7b
--- /dev/null
+++ b/frontend/app/routes/queue/components/truncate/truncate.tsx
@@ -0,0 +1,10 @@
+import styles from "./truncate.module.css";
+import type { ReactNode } from "react";
+
+export type TruncateProps = {
+ children: ReactNode
+}
+
+export function Truncate({ children }: TruncateProps) {
+ return <div className={styles.truncate}>{children}</div>;
+}
\ No newline at end of file
diff --git a/frontend/app/routes/queue/components/word-wrap/word-wrap.module.css b/frontend/app/routes/queue/components/word-wrap/word-wrap.module.css
new file mode 100644
index 00000000..5b670356
--- /dev/null
+++ b/frontend/app/routes/queue/components/word-wrap/word-wrap.module.css
@@ -0,0 +1,4 @@
+.word-wrap {
+ word-break: break-all;
+ white-space: initial;
+}
\ No newline at end of file
diff --git a/frontend/app/routes/queue/components/word-wrap/word-wrap.module.css.d.ts b/frontend/app/routes/queue/components/word-wrap/word-wrap.module.css.d.ts
new file mode 100644
index 00000000..b6e835f5
--- /dev/null
+++ b/frontend/app/routes/queue/components/word-wrap/word-wrap.module.css.d.ts
@@ -0,0 +1,5 @@
+declare const styles: {
+ readonly "word-wrap": string;
+};
+export = styles;
+
diff --git a/frontend/app/routes/queue/components/word-wrap/word-wrap.tsx b/frontend/app/routes/queue/components/word-wrap/word-wrap.tsx
new file mode 100644
index 00000000..eacbb5e4
--- /dev/null
+++ b/frontend/app/routes/queue/components/word-wrap/word-wrap.tsx
@@ -0,0 +1,10 @@
+import styles from "./word-wrap.module.css";
+import type { ReactNode } from "react";
+
+export type WordWrapProps = {
+ children: ReactNode
+}
+
+export function WordWrap({ children }: WordWrapProps) {
+ return <div className={styles["word-wrap"]}>{children}</div>;
+}
\ No newline at end of file