Skip to content

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

C#

Added checkboxes to queue/history page.

nzbdav-deva8395dfc277f
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
index 63210505..d08c1755 100644
--- a/frontend/app/routes/queue/components/action-button/action-button.module.css
+++ b/frontend/app/routes/queue/components/action-button/action-button.module.css
@@ -1,26 +1,38 @@
.action-button {
padding: 4px 6px;
line-height: 16px;
-}
+ width: fit-content;
+ height: fit-content;
+ display: flex;
+ flex-direction: row;
+ gap: 5px;
+ align-items: center;
+
+ &:hover {
+ .trash-icon {
+ fill: white;
+ }
-*+.action-button {
- margin-left: 10px;
+ .directory-icon {
+ fill: white;
+ }
+ }
}
.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");
+ fill: #adb8b8;
}
.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");
+ fill: #adb8b8;
+}
+
+.text {
+ /* color: #adb8b8; */
}
\ 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
index 03cc2438..8fd6feb8 100644
--- 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
@@ -2,6 +2,7 @@ declare const styles: {
readonly "action-button": string;
readonly "trash-icon": string;
readonly "directory-icon": string;
+ readonly "text": 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
index 512d9552..0789bd5b 100644
--- a/frontend/app/routes/queue/components/action-button/action-button.tsx
+++ b/frontend/app/routes/queue/components/action-button/action-button.tsx
@@ -1,21 +1,40 @@
import { Button } from "react-bootstrap";
import styles from "./action-button.module.css";
+import type { ReactNode } from "react";
export type ActionButtonProps = {
type: "delete" | "explore",
+ text?: string,
disabled?: boolean,
onClick?: () => void,
}
-export function ActionButton({ type, disabled, onClick }: ActionButtonProps) {
+export function ActionButton({ type, text, 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"]} />}
+ {type === "delete" && <TrashIcon />}
+ {type === "explore" && <DirectoryIcon />}
+ {text && <div className={styles.text}>{text}</div>}
</Button>
)
+}
+
+function DirectoryIcon() {
+ return (
+ <svg className={styles["directory-icon"]} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 24">
+ <path 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" />
+ </svg>
+ )
+}
+
+function TrashIcon() {
+ return (
+ <svg className={styles["trash-icon"]} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 24">
+ <path 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" />
+ </svg>
+ )
}
\ 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
index 9e921750..6092150e 100644
--- a/frontend/app/routes/queue/components/confirm-modal/confirm-modal.tsx
+++ b/frontend/app/routes/queue/components/confirm-modal/confirm-modal.tsx
@@ -1,6 +1,6 @@
import { Button, Form, Modal } from "react-bootstrap";
import { WordWrap } from "../word-wrap/word-wrap";
-import { useState } from "react";
+import { useCallback, useState } from "react";
export type ConfirmModalProps = {
show: boolean,
@@ -16,8 +16,18 @@ export type ConfirmModalProps = {
export function ConfirmModal(props: ConfirmModalProps) {
const [isCheckboxChecked, setIsCheckboxChecked] = useState(false);
+ const onConfirm = useCallback((isChecked?: boolean) => {
+ props.onConfirm(isChecked);
+ setIsCheckboxChecked(false);
+ }, [props.onConfirm, setIsCheckboxChecked]);
+
+ const onCancel = useCallback(() => {
+ props.onCancel();
+ setIsCheckboxChecked(false);
+ }, [props.onCancel, setIsCheckboxChecked]);
+
return (
- <Modal show={props.show} onHide={props.onCancel} centered scrollable>
+ <Modal show={props.show} onHide={onCancel} centered scrollable>
<Modal.Header closeButton>
<Modal.Title>{props.title}</Modal.Title>
</Modal.Header>
@@ -38,10 +48,10 @@ export function ConfirmModal(props: ConfirmModalProps) {
</div>
</Modal.Body>
<Modal.Footer>
- <Button variant="secondary" onClick={props.onCancel}>
+ <Button variant="secondary" onClick={onCancel}>
{props.cancelText || "Close"}
</Button>
- <Button variant="danger" onClick={() => props.onConfirm(isCheckboxChecked)}>
+ <Button variant="danger" onClick={() => onConfirm(isCheckboxChecked)}>
{props.confirmText || "Confirm Removal"}
</Button>
</Modal.Footer>
diff --git a/frontend/app/routes/queue/components/empty-queue/empty-queue.tsx b/frontend/app/routes/queue/components/empty-queue/empty-queue.tsx
index 32e0dde6..44c33047 100644
--- a/frontend/app/routes/queue/components/empty-queue/empty-queue.tsx
+++ b/frontend/app/routes/queue/components/empty-queue/empty-queue.tsx
@@ -1,3 +1,4 @@
+import pageStyles from "../../route.module.css"
import { useCallback, useRef } from "react";
import styles from "./empty-queue.module.css"
import { useDropzone, type FileWithPath } from 'react-dropzone'
@@ -30,6 +31,9 @@ export function EmptyQueue() {
return (
<fetcher.Form ref={formRef} method="POST" encType="multipart/form-data">
+ <div className={pageStyles["section-title"]}>
+ <h3>Queue</h3>
+ </div>
<div {...className([styles.container, isDragActive && styles["drag-active"]])} {...getRootProps()}>
<input {...getInputProps()} />
<input ref={inputRef} name="nzbFile" type="file" style={{ display: 'none' }} />
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 6fab94fd..b771c85c 100644
--- a/frontend/app/routes/queue/components/history-table/history-table.tsx
+++ b/frontend/app/routes/queue/components/history-table/history-table.tsx
@@ -1,63 +1,115 @@
-import type { HistorySlot } from "~/clients/backend-client.server"
-import { CategoryBadge, formatFileSize } from "../queue-table/queue-table"
+import pageStyles from "../../route.module.css"
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 { PageRow, PageTable } from "../page-table/page-table"
import { useCallback, useState } from "react"
import { ConfirmModal } from "../confirm-modal/confirm-modal"
import { Link } from "react-router"
-import { StatusBadge } from "../status-badge/status-badge"
+import { type TriCheckboxState } from "../tri-checkbox/tri-checkbox"
+import type { PresentationHistorySlot } from "../../route"
export type HistoryTableProps = {
- historySlots: HistorySlot[]
+ historySlots: PresentationHistorySlot[],
+ onIsSelectedChanged: (nzo_ids: Set<string>, isSelected: boolean) => void,
+ onIsRemovingChanged: (nzo_ids: Set<string>, isRemoving: boolean) => void,
+ onRemoved: (nzo_ids: Set<string>) => void,
}
-export function HistoryTable({ historySlots }: HistoryTableProps) {
+export function HistoryTable({ historySlots, onIsSelectedChanged, onIsRemovingChanged, onRemoved }: HistoryTableProps) {
+ const [isConfirmingRemoval, setIsConfirmingRemoval] = useState(false);
+ var selectedCount = historySlots.filter(x => !!x.isSelected).length;
+ var headerCheckboxState: TriCheckboxState = selectedCount === 0 ? 'none' : selectedCount === historySlots.length ? 'all' : 'some';
+
+ const onSelectAll = useCallback((isSelected: boolean) => {
+ onIsSelectedChanged(new Set<string>(historySlots.map(x => x.nzo_id)), isSelected);
+ }, [historySlots, onIsSelectedChanged]);
+
+ const onRemove = useCallback(() => {
+ setIsConfirmingRemoval(true);
+ }, [setIsConfirmingRemoval]);
+
+ const onCancelRemoval = useCallback(() => {
+ setIsConfirmingRemoval(false);
+ }, [setIsConfirmingRemoval]);
+
+ const onConfirmRemoval = useCallback(async (deleteCompletedFiles?: boolean) => {
+ var nzo_ids = new Set<string>(historySlots.filter(x => !!x.isSelected).map(x => x.nzo_id));
+ setIsConfirmingRemoval(false);
+ onIsRemovingChanged(nzo_ids, true);
+ try {
+ const url = `/api?mode=history&name=delete&del_completed_files=${deleteCompletedFiles ? 1 : 0}`;
+ const response = await fetch(url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json;charset=UTF-8',
+ },
+ body: JSON.stringify({ nzo_ids: Array.from(nzo_ids) }),
+ });
+ if (response.ok) {
+ const data = await response.json();
+ if (data.status === true) {
+ onRemoved(nzo_ids);
+ return;
+ }
+ }
+ } catch { }
+ onIsRemovingChanged(nzo_ids, false);
+ }, [historySlots, setIsConfirmingRemoval, onIsRemovingChanged, onRemoved]);
+
return (
- <PageTable responsive>
- <thead>
- <tr>
- <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>
+ <>
+ <div className={pageStyles["section-title"]}>
+ <h3>History</h3>
+ {headerCheckboxState !== 'none' &&
+ <ActionButton type="delete" onClick={onRemove} />
+ }
+ </div>
+ <PageTable headerCheckboxState={headerCheckboxState} onHeaderCheckboxChange={onSelectAll}>
{historySlots.map(slot =>
- <HistoryRow slot={slot} key={slot.nzo_id} />
+ <HistoryRow
+ key={slot.nzo_id}
+ slot={slot}
+ onIsSelectedChanged={(id, isSelected) => onIsSelectedChanged(new Set<string>([id]), isSelected)}
+ onIsRemovingChanged={(id, isRemoving) => onIsRemovingChanged(new Set<string>([id]), isRemoving)}
+ onRemoved={(id) => onRemoved(new Set([id]))}
+ />
)}
- </tbody>
- </PageTable>
+ </PageTable>
+
+ <ConfirmModal
+ show={isConfirmingRemoval}
+ title="Remove From History?"
+ message={`${selectedCount} item(s) will be removed`}
+ checkboxMessage="Delete mounted files"
+ onConfirm={onConfirmRemoval}
+ onCancel={onCancelRemoval} />
+ </>
);
}
type HistoryRowProps = {
- slot: HistorySlot
+ slot: PresentationHistorySlot,
+ onIsSelectedChanged: (nzo_id: string, isSelected: boolean) => void,
+ onIsRemovingChanged: (nzo_id: string, isRemoving: boolean) => void,
+ onRemoved: (nzo_id: string) => void
}
-export function HistoryRow({ slot }: HistoryRowProps) {
+export function HistoryRow({ slot, onIsSelectedChanged, onIsRemovingChanged, onRemoved }: HistoryRowProps) {
// state
- const [isConfirmingDelete, setIsConfirmingDelete] = useState(false);
- const [isDeleting, setIsDeleting] = useState(false);
- const [isDeleted, setIsDeleted] = useState(false);
- const className = isDeleting ? tableStyles.deleting : undefined;
+ const [isConfirmingRemoval, setIsConfirmingRemoval] = useState(false);
// events
- const onDelete = useCallback(() => {
- setIsConfirmingDelete(true);
- }, [setIsConfirmingDelete]);
+ const onRemove = useCallback(() => {
+ setIsConfirmingRemoval(true);
+ }, [setIsConfirmingRemoval]);
- const onCancelDelete = useCallback(() => {
- setIsConfirmingDelete(false);
- }, [setIsConfirmingDelete]);
+ const onCancelRemoval = useCallback(() => {
+ setIsConfirmingRemoval(false);
+ }, [setIsConfirmingRemoval]);
- const onConfirmDelete = useCallback(async (deleteCompletedFiles?: boolean) => {
- setIsConfirmingDelete(false);
- setIsDeleting(true);
+ const onConfirmRemoval = useCallback(async (deleteCompletedFiles?: boolean) => {
+ setIsConfirmingRemoval(false);
+ onIsRemovingChanged(slot.nzo_id, true);
try {
const url = '/api?mode=history&name=delete'
+ `&value=${encodeURIComponent(slot.nzo_id)}`
@@ -66,49 +118,42 @@ export function HistoryRow({ slot }: HistoryRowProps) {
if (response.ok) {
const data = await response.json();
if (data.status === true) {
- setIsDeleted(true);
+ onRemoved(slot.nzo_id);
return;
}
}
} catch { }
- setIsDeleting(false);
- }, [slot.nzo_id, setIsConfirmingDelete, setIsDeleting, setIsDeleted]);
+ onIsRemovingChanged(slot.nzo_id, false);
+ }, [slot.nzo_id, setIsConfirmingRemoval, onIsRemovingChanged, onRemoved]);
// view
- return isDeleted ? null : (
+ return (
<>
- <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>
+ <PageRow
+ isSelected={!!slot.isSelected}
+ isRemoving={!!slot.isRemoving}
+ name={slot.name}
+ category={slot.category}
+ status={slot.status}
+ error={slot.fail_message}
+ fileSizeBytes={slot.bytes}
+ actions={
+ <>
+ <Link to={`/explore/content/${slot.category}/${slot.name}`}>
+ <ActionButton type="explore" disabled={!!slot.isRemoving} />
+ </Link>
+ <ActionButton type="delete" disabled={!!slot.isRemoving} onClick={onRemove} />
+ </>
+ }
+ onRowSelectionChanged={isSelected => onIsSelectedChanged(slot.nzo_id, isSelected)}
+ />
<ConfirmModal
- show={isConfirmingDelete}
+ show={isConfirmingRemoval}
title="Remove From History?"
message={slot.nzb_name}
checkboxMessage="Delete mounted files"
- onConfirm={onConfirmDelete}
- onCancel={onCancelDelete} />
+ onConfirm={onConfirmRemoval}
+ onCancel={onCancelRemoval} />
</>
)
}
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
index 87dfd541..fbed42f8 100644
--- a/frontend/app/routes/queue/components/page-table/page-table.module.css
+++ b/frontend/app/routes/queue/components/page-table/page-table.module.css
@@ -2,80 +2,124 @@
container-type: inline-size;
}
-.page-table thead tr th {
- background-color: hsl(192, 100%, 11%) !important;
- text-align: center;
- width: 100px;
-}
+.page-table {
-.page-table thead tr th:first-child {
- border-radius: 10px 0 0 0;
- padding-left: 15px !important;
- text-align: left;
- width: 50%;
-}
+ /* header column */
+ th {
+ padding: 0;
+ padding-top: 8px;
+ padding-bottom: 8px;
+ background-color: hsl(192, 100%, 11%) !important;
+ text-align: center;
+ width: 100px;
-.page-table thead tr th:last-child {
- border-radius: 0 10px 0 0;
-}
+ /* first header column */
+ &:first-child {
+ border-radius: 10px 0 0 0;
+ text-align: left;
+ width: 50%;
+ }
-.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);
-}
+ /* last header column */
+ &:last-child {
+ border-radius: 0 10px 0 0;
+ }
+ }
-.page-table tbody tr td:first-child {
- text-align: left;
- padding: 15px 0 !important;
- padding-left: 15px !important;
-}
+ /* body column */
+ td {
+ padding: 0;
+ padding-top: 11px;
+ padding-bottom: 11px;
+ 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:last-child td {
- border-bottom: none;
-}
+ /* first body column */
+ &:first-child {
+ text-align: left;
+ }
+ }
-.page-table tbody tr:last-child td:first-child {
- border-radius: 0 0 0 10px;
-}
+ /* last row */
+ tr:last-child {
-.page-table tbody tr:last-child td:last-child {
- border-radius: 0 0 10px 0;
-}
+ /* cell on the last row */
+ td {
+ border-bottom: none;
-.deleting {
- opacity: 20%;
-}
+ /* first cell on the last row */
+ &:first-child {
+ border-radius: 0 0 0 10px;
+ }
-.reappear {
- display: none;
+ /* last cell on the last row */
+ &:last-child {
+ border-radius: 0 0 10px 0;
+ }
+ }
+ }
+
+ /* when a row is being removed, set opacity to 50% */
+ .removing {
+ opacity: 20%;
+ }
}
-.reappear *:has(+*) {
- margin-right: 10px;
+.badges {
+ display: flex;
+ margin-top: 3px;
margin-bottom: 5px;
+ gap: 10px;
}
-.reappear > div {
- margin-left: 5px;
+.actions {
+ display: flex;
+ flex-direction: row;
+ justify-content: center;
+ align-items: center;
+ gap: 10px;
+}
+
+/* desktop */
+@media (min-width: 900px) {
+ .mobile {
+ display: none;
+ }
+
+ .skinny {
+ display: none;
+ }
}
/* mobile */
-@media not (min-width: 900px) {
- .disappear {
+@media not (min-width: 900px) {
+ .desktop {
display: none;
}
- .reappear {
+ .skinny {
+ display: none;
+ }
+
+ .mobile {
display: block;
- margin-top: 2px;
}
.page-table thead tr th:first-child {
width: unset;
}
+}
+
+/* really skinny devices */
+@media not (min-width: 410px) {
+ .actions {
+ flex-direction: column;
+ align-items: end;
+ margin-right: 20px;
+ }
}
\ 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
index b9648204..7c41c2cc 100644
--- 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
@@ -1,9 +1,12 @@
declare const styles: {
readonly "container": string;
readonly "page-table": string;
- readonly "disappear": string;
- readonly "reappear": string;
- readonly "deleting": string;
+ readonly "removing": string;
+ readonly "badges": string;
+ readonly "actions": string;
+ readonly "desktop": string;
+ readonly "mobile": string;
+ readonly "skinny": 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
index d439130d..5f52f42d 100644
--- a/frontend/app/routes/queue/components/page-table/page-table.tsx
+++ b/frontend/app/routes/queue/components/page-table/page-table.tsx
@@ -1,10 +1,101 @@
-import { Table, type TableProps } from "react-bootstrap";
+import { Badge, Table } from "react-bootstrap";
import styles from "./page-table.module.css";
+import type { ReactNode } from "react";
+import { TriCheckbox, type TriCheckboxState } from "../tri-checkbox/tri-checkbox";
+import { Truncate } from "../truncate/truncate";
+import { StatusBadge } from "../status-badge/status-badge";
-export function PageTable(props: TableProps) {
+export type PageTableProps = {
+ striped?: boolean,
+ children?: ReactNode,
+ headerCheckboxState: TriCheckboxState,
+ onHeaderCheckboxChange: (isChecked: boolean) => void
+}
+
+export function PageTable({ striped, children, headerCheckboxState, onHeaderCheckboxChange: onTitleCheckboxChange }: PageTableProps) {
return (
<div className={styles.container}>
- <Table className={styles["page-table"]} {...props} />
+ <Table className={styles["page-table"]} responsive striped={striped}>
+ <thead>
+ <tr>
+ <th>
+ <TriCheckbox state={headerCheckboxState} onChange={onTitleCheckboxChange}>
+ Name
+ </TriCheckbox>
+ </th>
+ <th className={styles.desktop}>Category</th>
+ <th className={styles.desktop}>Status</th>
+ <th className={styles.desktop}>Size</th>
+ <th>Actions</th>
+ </tr>
+ </thead>
+ <tbody>
+ {children}
+ </tbody>
+ </Table>
</div>
)
+}
+
+export type PageRowProps = {
+ isSelected: boolean,
+ isRemoving: boolean,
+ name: string,
+ category: string,
+ status: string,
+ percentage?: string,
+ error?: string,
+ fileSizeBytes: number,
+ actions: ReactNode,
+ onRowSelectionChanged: (isSelected: boolean) => void
+}
+export function PageRow(props: PageRowProps) {
+ return (
+ <tr className={props.isRemoving ? styles.removing : undefined}>
+ <td>
+ <TriCheckbox state={props.isSelected} onChange={props.onRowSelectionChanged}>
+ <Truncate>{props.name}</Truncate>
+ <div className={styles.mobile}>
+ <div className={styles.badges}>
+ <StatusBadge status={props.status} percentage={props.percentage} error={props.error} />
+ <CategoryBadge category={props.category} />
+ </div>
+ <div>{formatFileSize(props.fileSizeBytes)}</div>
+ </div>
+ </TriCheckbox>
+ </td>
+ <td className={styles.desktop}>
+ <CategoryBadge category={props.category} />
+ </td>
+ <td className={styles.desktop}>
+ <StatusBadge status={props.status} percentage={props.percentage} error={props.error} />
+ </td>
+ <td className={styles.desktop}>
+ {formatFileSize(props.fileSizeBytes)}
+ </td>
+ <td>
+ <div className={styles.actions}>
+ {props.actions}
+ </div>
+ </td>
+ </tr>
+ );
+}
+
+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} style={{ width: '85px' }}>{categoryLower}</Badge>
+}
+
+export function formatFileSize(bytes: number) {
+ var suffix = "B";
+ if (bytes >= 1024) { bytes /= 1024; suffix = "KB"; }
+ if (bytes >= 1024) { bytes /= 1024; suffix = "MB"; }
+ if (bytes >= 1024) { bytes /= 1024; suffix = "GB"; }
+ if (bytes >= 1024) { bytes /= 1024; suffix = "TB"; }
+ if (bytes >= 1024) { bytes /= 1024; suffix = "PB"; }
+ return `${bytes.toFixed(2)} ${suffix}`;
}
\ No newline at end of file
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 812bd517..4c690812 100644
--- a/frontend/app/routes/queue/components/queue-table/queue-table.tsx
+++ b/frontend/app/routes/queue/components/queue-table/queue-table.tsx
@@ -1,61 +1,114 @@
-import type { QueueSlot } from "~/clients/backend-client.server"
-import tableStyles from "../page-table/page-table.module.css"
-import { Badge } from "react-bootstrap"
+import pageStyles from "../../route.module.css"
import { ActionButton } from "../action-button/action-button"
-import { PageTable } from "../page-table/page-table"
-import { Truncate } from "../truncate/truncate"
+import { PageRow, PageTable } from "../page-table/page-table"
import { useCallback, useState } from "react"
import { ConfirmModal } from "../confirm-modal/confirm-modal"
-import { StatusBadge } from "../status-badge/status-badge"
+import type { PresentationQueueSlot } from "../../route"
+import type { TriCheckboxState } from "../tri-checkbox/tri-checkbox"
export type QueueTableProps = {
- queueSlots: QueueSlot[]
+ queueSlots: PresentationQueueSlot[],
+ onIsSelectedChanged: (nzo_ids: Set<string>, isSelected: boolean) => void,
+ onIsRemovingChanged: (nzo_ids: Set<string>, isRemoving: boolean) => void,
+ onRemoved: (nzo_ids: Set<string>) => void,
}
-export function QueueTable({ queueSlots }: QueueTableProps) {
+export function QueueTable({ queueSlots, onIsSelectedChanged, onIsRemovingChanged, onRemoved }: QueueTableProps) {
+ const [isConfirmingRemoval, setIsConfirmingRemoval] = useState(false);
+ var selectedCount = queueSlots.filter(x => !!x.isSelected).length;
+ var headerCheckboxState: TriCheckboxState = selectedCount === 0 ? 'none' : selectedCount === queueSlots.length ? 'all' : 'some';
+
+ const onSelectAll = useCallback((isSelected: boolean) => {
+ onIsSelectedChanged(new Set<string>(queueSlots.map(x => x.nzo_id)), isSelected);
+ }, [queueSlots, onIsSelectedChanged]);
+
+ const onRemove = useCallback(() => {
+ setIsConfirmingRemoval(true);
+ }, [setIsConfirmingRemoval]);
+
+ const onCancelRemoval = useCallback(() => {
+ setIsConfirmingRemoval(false);
+ }, [setIsConfirmingRemoval]);
+
+ const onConfirmRemoval = useCallback(async () => {
+ var nzo_ids = new Set<string>(queueSlots.filter(x => !!x.isSelected).map(x => x.nzo_id));
+ setIsConfirmingRemoval(false);
+ onIsRemovingChanged(nzo_ids, true);
+ try {
+ const url = `/api?mode=queue&name=delete`;
+ const response = await fetch(url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json;charset=UTF-8',
+ },
+ body: JSON.stringify({ nzo_ids: Array.from(nzo_ids) }),
+ });
+ if (response.ok) {
+ const data = await response.json();
+ if (data.status === true) {
+ onRemoved(nzo_ids);
+ return;
+ }
+ }
+ } catch { }
+ onIsRemovingChanged(nzo_ids, false);
+ }, [queueSlots, setIsConfirmingRemoval, onIsRemovingChanged, onRemoved]);
+
return (
- <PageTable responsive striped>
- <thead>
- <tr>
- <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>
- {queueSlots.map(slot =>
- <QueueRow slot={slot} key={slot.nzo_id} />
- )}
- </tbody>
- </PageTable>
+ <>
+ <div className={pageStyles["section-title"]}>
+ <h3>Queue</h3>
+ {headerCheckboxState !== 'none' &&
+ <ActionButton type="delete" onClick={onRemove} />
+ }
+ </div>
+ <div style={{ minHeight: "300px" }}>
+ <PageTable headerCheckboxState={headerCheckboxState} onHeaderCheckboxChange={onSelectAll} striped>
+ {queueSlots.map(slot =>
+ <QueueRow
+ key={slot.nzo_id}
+ slot={slot}
+ onIsSelectedChanged={(id, isSelected) => onIsSelectedChanged(new Set<string>([id]), isSelected)}
+ onIsRemovingChanged={(id, isRemoving) => onIsRemovingChanged(new Set<string>([id]), isRemoving)}
+ onRemoved={(id) => onRemoved(new Set([id]))}
+ />
+ )}
+ </PageTable>
+ </div>
+
+ <ConfirmModal
+ show={isConfirmingRemoval}
+ title="Remove From Queue?"
+ message={`${selectedCount} item(s) will be removed`}
+ onConfirm={onConfirmRemoval}
+ onCancel={onCancelRemoval} />
+ </>
);
}
type QueueRowProps = {
- slot: QueueSlot
+ slot: PresentationQueueSlot
+ onIsSelectedChanged: (nzo_id: string, isSelected: boolean) => void,
+ onIsRemovingChanged: (nzo_id: string, isRemoving: boolean) => void,
+ onRemoved: (nzo_id: string) => void
}
-export function QueueRow({ slot }: QueueRowProps) {
+export function QueueRow({ slot, onIsSelectedChanged, onIsRemovingChanged, onRemoved }: QueueRowProps) {
// state
- const [isConfirmingDelete, setIsConfirmingDelete] = useState(false);
- const [isDeleting, setIsDeleting] = useState(false);
- const [isDeleted, setIsDeleted] = useState(false);
- const className = isDeleting ? tableStyles.deleting : undefined;
+ const [isConfirmingRemoval, setIsConfirmingRemoval] = useState(false);
// events
- const onDelete = useCallback(() => {
- setIsConfirmingDelete(true);
- }, [setIsConfirmingDelete]);
+ const onRemove = useCallback(() => {
+ setIsConfirmingRemoval(true);
+ }, [setIsConfirmingRemoval]);
- const onCancelDelete = useCallback(() => {
- setIsConfirmingDelete(false);
- }, [setIsConfirmingDelete]);
+ const onCancelRemoval = useCallback(() => {
+ setIsConfirmingRemoval(false);
+ }, [setIsConfirmingRemoval]);
- const onConfirmDelete = useCallback(async () => {
- setIsConfirmingDelete(false);
- setIsDeleting(true);
+ const onConfirmRemoval = useCallback(async () => {
+ setIsConfirmingRemoval(false);
+ onIsRemovingChanged(slot.nzo_id, true);
try {
const url = '/api?mode=queue&name=delete'
+ `&value=${encodeURIComponent(slot.nzo_id)}`;
@@ -63,64 +116,34 @@ export function QueueRow({ slot }: QueueRowProps) {
if (response.ok) {
const data = await response.json();
if (data.status === true) {
- setIsDeleted(true);
+ onRemoved(slot.nzo_id);
return;
}
}
} catch { }
- setIsDeleting(false);
- }, [slot.nzo_id, setIsConfirmingDelete, setIsDeleting, setIsDeleted]);
+ onIsRemovingChanged(slot.nzo_id, false);
+ }, [slot.nzo_id, setIsConfirmingRemoval, onIsRemovingChanged, onRemoved]);
// view
- return isDeleted ? null : (
+ return (
<>
- <tr key={slot.nzo_id} className={className}>
- <td>
- <Truncate>{slot.filename}</Truncate>
- <div className={tableStyles.reappear}>
- <StatusBadge status={slot.status} percentage={slot.percentage} />
- <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} percentage={slot.percentage} />
- </td>
- <td className={tableStyles.disappear}>
- {formatFileSize(Number(slot.mb) * 1024 * 1024)}
- </td>
- <td>
- <ActionButton type="delete" disabled={isDeleting} onClick={onDelete} />
- </td>
- </tr>
+ <PageRow
+ isSelected={!!slot.isSelected}
+ isRemoving={!!slot.isRemoving}
+ name={slot.filename}
+ category={slot.cat}
+ status={slot.status}
+ percentage={slot.percentage}
+ fileSizeBytes={Number(slot.mb) * 1024 * 1024}
+ actions={<ActionButton type="delete" disabled={!!slot.isRemoving} onClick={onRemove} />}
+ onRowSelectionChanged={isSelected => onIsSelectedChanged(slot.nzo_id, isSelected)}
+ />
<ConfirmModal
- show={isConfirmingDelete}
+ show={isConfirmingRemoval}
title="Remove From Queue?"
message={slot.filename}
- onConfirm={onConfirmDelete}
- onCancel={onCancelDelete} />
+ onConfirm={onConfirmRemoval}
+ onCancel={onCancelRemoval} />
</>
)
-}
-
-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} style={{ width: '85px' }}>{categoryLower}</Badge>
-}
-
-
-export function formatFileSize(bytes: number) {
- var suffix = "B";
- if (bytes >= 1024) { bytes /= 1024; suffix = "KB"; }
- if (bytes >= 1024) { bytes /= 1024; suffix = "MB"; }
- if (bytes >= 1024) { bytes /= 1024; suffix = "GB"; }
- if (bytes >= 1024) { bytes /= 1024; suffix = "TB"; }
- if (bytes >= 1024) { bytes /= 1024; suffix = "PB"; }
- return `${bytes.toFixed(2)} ${suffix}`;
}
\ No newline at end of file
diff --git a/frontend/app/routes/queue/components/status-badge/status-badge.module.css b/frontend/app/routes/queue/components/status-badge/status-badge.module.css
index 31d50f57..06bf485f 100644
--- a/frontend/app/routes/queue/components/status-badge/status-badge.module.css
+++ b/frontend/app/routes/queue/components/status-badge/status-badge.module.css
@@ -1,3 +1,7 @@
+.container {
+ display: inline-block;
+}
+
.badge {
display: inline-block;
line-height: 1;
@@ -19,6 +23,7 @@
}
.progress {
+ display: block;
position: absolute;
top: 0;
left: 0;
@@ -28,6 +33,12 @@
transition: width 500ms ease-in-out;
}
+@media not (min-width: 900px) {
+ .container {
+ display: flex;
+ }
+}
+
@media not (pointer: coarse),
(min-width: 900px) {
.failure-badge:hover {
diff --git a/frontend/app/routes/queue/components/status-badge/status-badge.module.css.d.ts b/frontend/app/routes/queue/components/status-badge/status-badge.module.css.d.ts
index c6f46324..ceb53426 100644
--- a/frontend/app/routes/queue/components/status-badge/status-badge.module.css.d.ts
+++ b/frontend/app/routes/queue/components/status-badge/status-badge.module.css.d.ts
@@ -1,4 +1,5 @@
declare const styles: {
+ readonly "container": string;
readonly "badge": string;
readonly "badge-text": string;
readonly "progress": string;
diff --git a/frontend/app/routes/queue/components/status-badge/status-badge.tsx b/frontend/app/routes/queue/components/status-badge/status-badge.tsx
index 5a402342..efa409b7 100644
--- a/frontend/app/routes/queue/components/status-badge/status-badge.tsx
+++ b/frontend/app/routes/queue/components/status-badge/status-badge.tsx
@@ -33,7 +33,7 @@ export function StatusBadge({ status, percentage, error }: StatusBadgeProps) {
return (
<OverlayTrigger placement="top" overlay={overlay} trigger="click">
- <div style={{ display: 'inline-block' }}>
+ <div className={styles.container}>
<Badge className={badgeClass} color={color} percentNum={percentNum}>{badgeText}</Badge>
</div>
</OverlayTrigger>
diff --git a/frontend/app/routes/queue/components/tri-checkbox/tri-checkbox.module.css b/frontend/app/routes/queue/components/tri-checkbox/tri-checkbox.module.css
new file mode 100644
index 00000000..7e996343
--- /dev/null
+++ b/frontend/app/routes/queue/components/tri-checkbox/tri-checkbox.module.css
@@ -0,0 +1,12 @@
+.container {
+ display: flex;
+ flex-direction: row;
+ /* justify-content: center; */
+ align-items: center;
+}
+
+.checkbox {
+ width: 45px;
+ min-width: 45px;
+ text-align: center;
+}
\ No newline at end of file
diff --git a/frontend/app/routes/queue/components/tri-checkbox/tri-checkbox.module.css.d.ts b/frontend/app/routes/queue/components/tri-checkbox/tri-checkbox.module.css.d.ts
new file mode 100644
index 00000000..753917a6
--- /dev/null
+++ b/frontend/app/routes/queue/components/tri-checkbox/tri-checkbox.module.css.d.ts
@@ -0,0 +1,6 @@
+declare const styles: {
+ readonly "container": string;
+ readonly "checkbox": string;
+};
+export = styles;
+
diff --git a/frontend/app/routes/queue/components/tri-checkbox/tri-checkbox.tsx b/frontend/app/routes/queue/components/tri-checkbox/tri-checkbox.tsx
new file mode 100644
index 00000000..c0859eb0
--- /dev/null
+++ b/frontend/app/routes/queue/components/tri-checkbox/tri-checkbox.tsx
@@ -0,0 +1,35 @@
+import { Form } from "react-bootstrap";
+import { useEffect, useRef, type ReactNode } from "react";
+import styles from "./tri-checkbox.module.css";
+
+export type TriCheckboxState = "all" | "some" | "none" | boolean
+export type TriCheckboxProps = {
+ state: TriCheckboxState,
+ onChange?: (isChecked: boolean) => void,
+ children: ReactNode
+}
+
+export function TriCheckbox({ state, onChange, children }: TriCheckboxProps) {
+ const checkboxRef = useRef<HTMLInputElement>(null);
+ useEffect(() => {
+ if (checkboxRef && checkboxRef.current) {
+ checkboxRef.current.indeterminate = (state === "some");
+ }
+ }, [checkboxRef, state])
+
+ return (
+ <div className={styles.container}>
+ <div className={styles.checkbox}>
+ <Form.Check
+ ref={checkboxRef}
+ checked={state === "all" || state === true}
+ onChange={(e) => onChange && onChange(e.target.checked)}
+ />
+ </div>
+ <div>
+ {children}
+ </div>
+ </div>
+
+ )
+}
\ No newline at end of file
diff --git a/frontend/app/routes/queue/route.module.css b/frontend/app/routes/queue/route.module.css
index 4ef9a8e6..bb43c964 100644
--- a/frontend/app/routes/queue/route.module.css
+++ b/frontend/app/routes/queue/route.module.css
@@ -12,6 +12,7 @@
.section-title {
margin-bottom: 30px;
-}
-
-.section-body {}
\ No newline at end of file
+ display: flex;
+ gap: 10px;
+ align-items: baseline;
+}
\ No newline at end of file
diff --git a/frontend/app/routes/queue/route.module.css.d.ts b/frontend/app/routes/queue/route.module.css.d.ts
index 82813f8f..7b61e07e 100644
--- a/frontend/app/routes/queue/route.module.css.d.ts
+++ b/frontend/app/routes/queue/route.module.css.d.ts
@@ -1,7 +1,6 @@
declare const styles: {
readonly "container": string;
readonly "section": string;
- readonly "section-body": string;
readonly "section-title": string;
};
export = styles;
diff --git a/frontend/app/routes/queue/route.tsx b/frontend/app/routes/queue/route.tsx
index 4aa4ac8d..da46fd7c 100644
--- a/frontend/app/routes/queue/route.tsx
+++ b/frontend/app/routes/queue/route.tsx
@@ -7,7 +7,7 @@ import { backendClient, type HistorySlot, type QueueSlot } from "~/clients/backe
import { EmptyQueue } from "./components/empty-queue/empty-queue";
import { HistoryTable } from "./components/history-table/history-table";
import { QueueTable } from "./components/queue-table/queue-table";
-import { useEffect, useState } from "react";
+import { useCallback, useEffect, useState } from "react";
import { receiveMessage } from "~/utils/websocket-util";
const topicNames = {
@@ -27,12 +27,6 @@ const topicSubscriptions = {
[topicNames.historyItemRemoved]: 'event',
}
-type BodyProps = {
- queueSlots: QueueSlot[],
- historySlots: HistorySlot[],
- error?: string,
-};
-
export async function loader({ request }: Route.LoaderArgs) {
var queuePromise = backendClient.getQueue();
var historyPromise = backendClient.getHistory();
@@ -45,100 +39,121 @@ export async function loader({ request }: Route.LoaderArgs) {
}
export default function Queue(props: Route.ComponentProps) {
- const [queueSlots, setQueueSlots] = useState(props.loaderData.queueSlots);
- const [historySlots, setHistorySlots] = useState(props.loaderData.historySlots);
+ const [queueSlots, setQueueSlots] = useState<PresentationQueueSlot[]>(props.loaderData.queueSlots);
+ const [historySlots, setHistorySlots] = useState<PresentationHistorySlot[]>(props.loaderData.historySlots);
const error = props.actionData?.error;
+ // queue events
+ const onAddQueueSlot = useCallback((queueSlot: QueueSlot) => {
+ setQueueSlots(slots => [...slots, queueSlot]);
+ }, [setQueueSlots]);
+
+ const onSelectQueueSlots = useCallback((ids: Set<string>, isSelected: boolean) => {
+ setQueueSlots(slots => slots.map(x => ids.has(x.nzo_id) ? { ...x, isSelected } : x));
+ }, [setQueueSlots]);
+
+ const onRemovingQueueSlots = useCallback((ids: Set<string>, isRemoving: boolean) => {
+ setQueueSlots(slots => slots.map(x => ids.has(x.nzo_id) ? { ...x, isRemoving } : x));
+ }, [setQueueSlots]);
+
+ const onRemoveQueueSlots = useCallback((ids: Set<string>) => {
+ setQueueSlots(slots => slots.filter(x => !ids.has(x.nzo_id)));
+ }, [setQueueSlots]);
+
+ const onChangeQueueSlotStatus = useCallback((message: string) => {
+ const [nzo_id, status] = message.split('|');
+ setQueueSlots(slots => slots.map(x => x.nzo_id === nzo_id ? { ...x, status } : x));
+ }, [setQueueSlots]);
+
+ const onChangeQueueSlotPercentage = useCallback((message: string) => {
+ const [nzo_id, percentage] = message.split('|');
+ setQueueSlots(slots => slots.map(x => x.nzo_id === nzo_id ? { ...x, percentage } : x));
+ }, [setQueueSlots]);
+
+ // history events
+ const onAddHistorySlot = useCallback((historySlot: HistorySlot) => {
+ setHistorySlots(slots => [historySlot, ...slots]);
+ }, [setHistorySlots]);
+
+ const onSelectHistorySlots = useCallback((ids: Set<string>, isSelected: boolean) => {
+ setHistorySlots(slots => slots.map(x => ids.has(x.nzo_id) ? { ...x, isSelected } : x));
+ }, [setHistorySlots]);
+
+ const onRemovingHistorySlots = useCallback((ids: Set<string>, isRemoving: boolean) => {
+ setHistorySlots(slots => slots.map(x => ids.has(x.nzo_id) ? { ...x, isRemoving } : x));
+ }, [setHistorySlots]);
+
+ const onRemoveHistorySlots = useCallback((ids: Set<string>) => {
+ setHistorySlots(slots => slots.filter(x => !ids.has(x.nzo_id)));
+ }, [setHistorySlots]);
+
+ // websocket
+ const onWebsocketMessage = useCallback((topic: string, message: string) => {
+ if (topic == topicNames.queueItemAdded)
+ onAddQueueSlot(JSON.parse(message));
+ else if (topic == topicNames.queueItemRemoved)
+ onRemoveQueueSlots(new Set<string>(message.split(',')));
+ else if (topic == topicNames.queueItemStatus)
+ onChangeQueueSlotStatus(message);
+ else if (topic == topicNames.queueItemPercentage)
+ onChangeQueueSlotPercentage(message);
+ else if (topic == topicNames.historyItemAdded)
+ onAddHistorySlot(JSON.parse(message));
+ else if (topic == topicNames.historyItemRemoved)
+ onRemoveHistorySlots(new Set<string>(message.split(',')));
+ }, [
+ onAddQueueSlot,
+ onRemoveQueueSlots,
+ onChangeQueueSlotStatus,
+ onChangeQueueSlotPercentage,
+ onAddHistorySlot,
+ onRemoveHistorySlots,
+ ]);
useEffect(() => {
let ws: WebSocket;
let disposed = false;
function connect() {
ws = new WebSocket(window.location.origin.replace(/^http/, 'ws'));
- ws.onmessage = receiveMessage(onMessage);
+ ws.onmessage = receiveMessage(onWebsocketMessage);
ws.onopen = () => { ws.send(JSON.stringify(topicSubscriptions)); }
ws.onclose = () => { !disposed && setTimeout(() => connect(), 1000); };
ws.onerror = () => { ws.close() };
return () => { disposed = true; ws.close(); }
}
- function onMessage(topic: string, message: string) {
- if (topic == topicNames.queueItemStatus)
- onChangeQueueSlotStatus(message);
- if (topic == topicNames.queueItemPercentage)
- onChangeQueueSlotPercentage(message);
- else if (topic == topicNames.queueItemAdded)
- onAddQueueSlot(JSON.parse(message));
- else if (topic == topicNames.queueItemRemoved)
- onRemoveQueueSlot(message);
- else if (topic == topicNames.historyItemAdded)
- onAddHistorySlot(JSON.parse(message));
- else if (topic == topicNames.historyItemRemoved)
- onRemoveHistorySlot(message);
- }
-
- function onChangeQueueSlotStatus(message: string) {
- const [nzo_id, status] = message.split('|');
- setQueueSlots(slots => slots.map(x => x.nzo_id === nzo_id ? { ...x, status } : x))
- }
-
- function onChangeQueueSlotPercentage(message: string) {
- const [nzo_id, percentage] = message.split('|');
- setQueueSlots(slots => slots.map(x => x.nzo_id === nzo_id ? { ...x, percentage } : x))
- }
-
- function onAddQueueSlot(queueSlot: QueueSlot) {
- setQueueSlots(slots => [...slots, queueSlot])
- }
-
- function onRemoveQueueSlot(id: string) {
- setQueueSlots(slots => slots.filter(x => x.nzo_id !== id));
- }
-
- function onAddHistorySlot(historySlot: HistorySlot) {
- setHistorySlots(slots => [historySlot, ...slots])
- }
-
- function onRemoveHistorySlot(id: string) {
- setHistorySlots(slots => slots.filter(x => x.nzo_id !== id));
- }
-
return connect();
- }, [setQueueSlots, setHistorySlots]);
+ }, [onWebsocketMessage]);
- return (
- <Body queueSlots={queueSlots} historySlots={historySlots} error={error} />
- );
-}
-
-function Body({ queueSlots, historySlots, error }: BodyProps) {
return (
<div className={styles.container}>
+ {/* error message */}
+ {error &&
+ <Alert variant="danger">
+ {error}
+ </Alert>
+ }
+
{/* queue */}
<div className={styles.section}>
- <h3 className={styles["section-title"]}>
- Queue
- </h3>
- <div className={styles["section-body"]}>
- {/* error message */}
- {error &&
- <Alert variant="danger">
- {error}
- </Alert>
- }
- {queueSlots.length > 0 ? <QueueTable queueSlots={queueSlots} /> : <EmptyQueue />}
- </div>
+ {queueSlots.length > 0 ?
+ <QueueTable queueSlots={queueSlots}
+ onIsSelectedChanged={onSelectQueueSlots}
+ onIsRemovingChanged={onRemovingQueueSlots}
+ onRemoved={onRemoveQueueSlots}
+ /> :
+ <EmptyQueue />}
</div>
{/* history */}
{historySlots.length > 0 &&
<div className={styles.section}>
- <h3 className={styles["section-title"]}>
- History
- </h3>
- <div className={styles["section-body"]}>
- <HistoryTable historySlots={historySlots} />
- </div>
+ <HistoryTable
+ historySlots={historySlots}
+ onIsSelectedChanged={onSelectHistorySlots}
+ onIsRemovingChanged={onRemovingHistorySlots}
+ onRemoved={onRemoveHistorySlots}
+ />
</div>
}
</div>
@@ -165,4 +180,14 @@ export async function action({ request }: Route.ActionArgs) {
}
throw error;
}
+}
+
+export type PresentationHistorySlot = HistorySlot & {
+ isSelected?: boolean,
+ isRemoving?: boolean,
+}
+
+export type PresentationQueueSlot = QueueSlot & {
+ isSelected?: boolean,
+ isRemoving?: boolean,
}
\ No newline at end of file