Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Added actions to items on Explore page.
nzbdav-devdb3383084ed8
diff --git a/frontend/app/clients/backend-client.server.ts b/frontend/app/clients/backend-client.server.tsindex 75b4b67e..cb7f99ab 100644--- a/frontend/app/clients/backend-client.server.ts+++ b/frontend/app/clients/backend-client.server.ts@@ -267,6 +267,7 @@ export type DirectoryItem = {name: string,isDirectory: boolean,size: number | null | undefined,+ nzbBlobId?: string,}export type ConfigItem = {diff --git a/frontend/app/routes/explore/dropdown-options/dropdown-options.module.css b/frontend/app/routes/explore/dropdown-options/dropdown-options.module.cssnew file mode 100644index 00000000..66994596--- /dev/null+++ b/frontend/app/routes/explore/dropdown-options/dropdown-options.module.css@@ -0,0 +1,37 @@+.dropdown {+ position: absolute;+ margin: 0;+ padding: 4px 0;+ list-style: none;+ background-color: hsl(196.8 25% 14.51%);+ border: 1px solid hsl(196 40% 22%);+ border-radius: 6px;+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);+ z-index: 1000;+ right: -1px;+ top: 100%;+}++.option {+ display: block;+}++.optionButton {+ display: block;+ width: 100%;+ padding: 6px 12px;+ background: none;+ border: none;+ text-align: left;+ font-size: 1rem;+ color: #93a1a1;+ cursor: pointer;+ white-space: nowrap;+}++.optionButton:hover,+.optionButton:focus-visible {+ background-color: #002b36;+ color: white;+ outline: none;+}diff --git a/frontend/app/routes/explore/dropdown-options/dropdown-options.module.css.d.ts b/frontend/app/routes/explore/dropdown-options/dropdown-options.module.css.d.tsnew file mode 100644index 00000000..9780f3e9--- /dev/null+++ b/frontend/app/routes/explore/dropdown-options/dropdown-options.module.css.d.ts@@ -0,0 +1,6 @@+declare const styles: {+ readonly dropdown: string;+ readonly option: string;+ readonly optionButton: string;+};+export default styles;diff --git a/frontend/app/routes/explore/dropdown-options/dropdown-options.tsx b/frontend/app/routes/explore/dropdown-options/dropdown-options.tsxnew file mode 100644index 00000000..7876c13a--- /dev/null+++ b/frontend/app/routes/explore/dropdown-options/dropdown-options.tsx@@ -0,0 +1,62 @@+import { useEffect, useRef, type ReactNode } from "react";+import styles from "./dropdown-options.module.css";+import { classNames } from "~/utils/styling";++export type DropdownOptionsProps = {+ isOpen?: boolean;+ options: (DropdownOption | undefined)[];+ onClose?: () => void;+};++export type DropdownOption = {+ option: ReactNode;+ linkTo?: string,+ onSelect?: () => void;+}++export function DropdownOptions({ isOpen = true, options, onClose }: DropdownOptionsProps) {+ const ref = useRef<HTMLUListElement>(null);++ useEffect(() => {+ if (!isOpen) return;++ function handleClick(e: MouseEvent) {+ if (ref.current && !ref.current.contains(e.target as Node)) {+ e.preventDefault();+ onClose?.();+ }+ }++ document.addEventListener("click", handleClick);+ return () => document.removeEventListener("click", handleClick);+ }, [isOpen, onClose]);++ return !isOpen ? null : (+ <ul ref={ref} className={classNames([styles.dropdown])}>+ {options.filter(x => !!x).map((option, index) => (+ <li key={index} className={styles.option}>+ {option.linkTo && <>+ <a href={option.linkTo}>+ <button+ type="button"+ className={styles.optionButton}+ onClick={() => option.onSelect?.()}+ >+ {option.option}+ </button>+ </a>+ </>}+ {!option.linkTo &&+ <button+ type="button"+ className={styles.optionButton}+ onClick={() => option.onSelect?.()}+ >+ {option.option}+ </button>+ }+ </li>+ ))}+ </ul>+ );+}diff --git a/frontend/app/routes/explore/item-menu/item-menu.tsx b/frontend/app/routes/explore/item-menu/item-menu.tsxnew file mode 100644index 00000000..edd5b002--- /dev/null+++ b/frontend/app/routes/explore/item-menu/item-menu.tsx@@ -0,0 +1,95 @@+import { useCallback, useState, type ReactNode } from "react"+import type { ExploreFile } from "../route"+import { DropdownOptions } from "~/routes/explore/dropdown-options/dropdown-options"+import { classNames } from "~/utils/styling"++export type ItemMenuProps = {+ className?: string+ openClassName?: string+ exploreFile: ExploreFile,+ previewPath: string,+}++export function ItemMenu({ className, openClassName, exploreFile, previewPath }: ItemMenuProps): ReactNode {+ const [isOpen, setIsOpen] = useState(false);+ const exportNzbUrl = `/api/download-nzb?nzbBlobId=${exploreFile.nzbBlobId}`;+ const downloadUrl = `${previewPath}&download=true`;++ const onClick = useCallback((e: React.MouseEvent) => {+ e.stopPropagation();+ setIsOpen(x => !x);+ }, []);++ return (+ <>+ <div className={classNames([className, isOpen && openClassName])} onClick={onClick}>+ ⋯+ </div>+ <DropdownOptions isOpen={isOpen} onClose={() => setIsOpen(false)} options={[+ { option: <Preview />, linkTo: previewPath },+ { option: <Download />, linkTo: downloadUrl },+ !!exploreFile.nzbBlobId ? { option: <ExportNzb />, linkTo: exportNzbUrl } : undefined+ ]} />+ </>+ );+}++export function Preview(): ReactNode {+ return (+ <><EyeIcon /> Preview</>+ );+}++export function Download(): ReactNode {+ return (+ <><DownloadIcon /> Download</>+ );+}++export function ExportNzb(): ReactNode {+ return (+ <><ExportIcon /> Export NZB</>+ );+}++export function Delete(): ReactNode {+ return (+ <><TrashIcon /> Delete</>+ );+}++function EyeIcon() {+ return (+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="currentColor" style={{ marginRight: "8px", verticalAlign: "-2px" }}>+ <path d="M16 8s-3-5.5-8-5.5S0 8 0 8s3 5.5 8 5.5S16 8 16 8zM1.173 8a13.133 13.133 0 0 1 1.66-2.043C4.12 4.668 5.88 3.5 8 3.5c2.12 0 3.879 1.168 5.168 2.457A13.133 13.133 0 0 1 14.828 8c-.058.087-.122.183-.195.288-.335.48-.83 1.12-1.465 1.755C11.879 11.332 10.119 12.5 8 12.5c-2.12 0-3.879-1.168-5.168-2.457A13.134 13.134 0 0 1 1.172 8z" />+ <path d="M8 5.5a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5zM4.5 8a3.5 3.5 0 1 1 7 0 3.5 3.5 0 0 1-7 0z" />+ </svg>+ );+}++function DownloadIcon() {+ return (+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="currentColor" style={{ marginRight: "8px", verticalAlign: "-2px" }}>+ <path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z" />+ <path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z" />+ </svg>+ );+}++function ExportIcon() {+ return (+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="currentColor" style={{ marginRight: "8px", verticalAlign: "-2px" }}>+ <path d="M3.5 6a.5.5 0 0 0-.5.5v8a.5.5 0 0 0 .5.5h9a.5.5 0 0 0 .5-.5v-8a.5.5 0 0 0-.5-.5h-2a.5.5 0 0 1 0-1h2A1.5 1.5 0 0 1 14 6.5v8a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 2 14.5v-8A1.5 1.5 0 0 1 3.5 5h2a.5.5 0 0 1 0 1h-2z" />+ <path d="M7.646.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 1.707V10.5a.5.5 0 0 1-1 0V1.707L5.354 3.854a.5.5 0 1 1-.708-.708l3-3z" />+ </svg>+ );+}++function TrashIcon() {+ return (+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="currentColor" style={{ marginRight: "8px", verticalAlign: "-2px" }}>+ <path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z" />+ <path d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z" />+ </svg>+ );+}\ No newline at end of filediff --git a/frontend/app/routes/explore/route.module.css b/frontend/app/routes/explore/route.module.cssindex 813ac9d2..d776b763 100644--- a/frontend/app/routes/explore/route.module.css+++ b/frontend/app/routes/explore/route.module.css@@ -10,14 +10,17 @@}.item {- padding: 15px;+ position: relative;display: flex;flex-direction: row;- align-items: center;- gap: 15px;border: 1px solid #ffffff20;- text-decoration: inherit;- color: inherit;++ a {+ text-decoration: inherit;+ color: inherit;+ width: 100%;+ height: 100%;+ }}.item+.item {@@ -38,16 +41,97 @@@media not (pointer: coarse),(min-width: 900px) {- .item:hover {+ .item:has(.item-content:hover) {background-color: #002b36;cursor: pointer;}}-.item:active {+.item:has(.item-content:active) {background-color: #073642;}+.item-content {+ padding: 15px;+ display: flex;+ flex-direction: row;+ align-items: center;+ gap: 15px;+ text-decoration: inherit;+ color: inherit;+ flex-grow: 1;+}++/* when an .item-content is immediately followed by .item-menu, */+/* set it's right padding to 0 */+.item:has(.item-menu) .item-content {+ padding-right: 5px;+}++.item-info {+ display: flex;+ flex-direction: column;+ line-height: 1;+ gap: 5px;+ transform: translateY(2px);+}++.item-name {+ word-break: break-all;+ overflow-wrap: break-word;+}++.item-size {+ font-size: 12px;+ color: #586e75;+ opacity: 0.8;+}++.loading {+ width: calc(100% - 75px);+ flex-grow: 1;+ position: unset;+ min-height: unset;+}++.hidden * {+ opacity: 50%;+}++.item-menu {+ padding: 15px 20px;+ display: flex;+ flex-direction: row;+ align-items: center;+ text-decoration: inherit;+ color: inherit;+ border-top-right-radius: inherit;+ border-bottom-right-radius: inherit;++ -webkit-touch-callout: none;+ -webkit-user-select: none;+ -khtml-user-select: none;+ -moz-user-select: none;+ -ms-user-select: none;+ user-select: none;+}++.open-item-menu {+ background-color: #ffffff11;+}++@media not (pointer: coarse),+(min-width: 900px) {+ .item-menu:hover {+ cursor: pointer;+ background-color: #ffffff15;+ }++ .item-menu:active {+ background-color: #ffffff11;+ }+}+.directory-icon {flex-shrink: 0;display: inline-block;@@ -86,34 +170,4 @@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 16 16'%3E%3Cg fill='%2393a1a1'%3E%3Cpath d='M6.002 5.5a1.5 1.5 0 1 1-3 0a1.5 1.5 0 0 1 3 0'/%3E%3Cpath d='M2.002 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2zm12 1a1 1 0 0 1 1 1v6.5l-3.777-1.947a.5.5 0 0 0-.577.093l-3.71 3.71l-2.66-1.772a.5.5 0 0 0-.63.062L1.002 12V3a1 1 0 0 1 1-1z'/%3E%3C/g%3E%3C/svg%3E");-}--.item-info {- display: flex;- flex-direction: column;- line-height: 1;- gap: 5px;- transform: translateY(2px);-}--.item-name {- word-break: break-all;- overflow-wrap: break-word;-}--.item-size {- font-size: 12px;- color: #586e75;- opacity: 0.8;-}--.loading {- width: calc(100% - 75px);- flex-grow: 1;- position: unset;- min-height: unset;-}--.hidden * {- opacity: 50%;}\ No newline at end of filediff --git a/frontend/app/routes/explore/route.module.css.d.ts b/frontend/app/routes/explore/route.module.css.d.tsindex a2e27103..03da8ed8 100644--- a/frontend/app/routes/explore/route.module.css.d.ts+++ b/frontend/app/routes/explore/route.module.css.d.ts@@ -4,9 +4,12 @@ declare const styles: {readonly "file-icon": string;readonly "image-icon": string;readonly "item": string;+ readonly "item-content": string;+ readonly "item-menu": string;readonly "item-info": string;readonly "item-name": string;readonly "item-size": string;+ readonly "open-item-menu": string;readonly "video-icon": string;readonly "loading": string;readonly "hidden": string;diff --git a/frontend/app/routes/explore/route.tsx b/frontend/app/routes/explore/route.tsxindex 63a7663d..2bb9d77d 100644--- a/frontend/app/routes/explore/route.tsx+++ b/frontend/app/routes/explore/route.tsx@@ -8,6 +8,7 @@ import { lookup as getMimeType } from 'mime-types';import { getDownloadKey } from "~/auth/downloads.server";import { Loading } from "../_index/components/loading/loading";import { formatFileSize } from "~/utils/file-size";+import { ItemMenu } from "./item-menu/item-menu";export type ExplorePageData = {parentDirectories: string[],@@ -73,19 +74,30 @@ function Body(props: ExplorePageData) {{!isNavigating &&<div>{items.filter(x => x.isDirectory).map((x, index) =>- <Link key={`${index}_dir_item`} to={getDirectoryPath(x.name)} className={getClassName(x)}>- <div className={styles["directory-icon"]} />- <div className={styles["item-name"]}>{x.name}</div>- </Link>+ <div key={`${index}_dir_item`} className={getClassName(x)}>+ <Link to={getDirectoryPath(x.name)}>+ <div className={styles["item-content"]}>+ <div className={styles["directory-icon"]} />+ <div className={styles["item-name"]}>{x.name}</div>+ </div>+ </Link>+ </div>)}{items.filter(x => !x.isDirectory).map((x, index) =>- <a key={`${index}_file_item`} href={getFilePath(x as ExploreFile)} className={getClassName(x)}>- <div className={getIcon(x as ExploreFile)} />- <div className={styles["item-info"]}>- <div className={styles["item-name"]}>{x.name}</div>- <div className={styles["item-size"]}>{formatFileSize(x.size)}</div>- </div>- </a>+ <div key={`${index}_file_item`} className={getClassName(x)}>+ <a href={getFilePath(x as ExploreFile)} className={styles["item-content"]}>+ <div className={getIcon(x as ExploreFile)} />+ <div className={styles["item-info"]}>+ <div className={styles["item-name"]}>{x.name}</div>+ <div className={styles["item-size"]}>{formatFileSize(x.size)}</div>+ </div>+ </a>+ <ItemMenu+ className={styles["item-menu"]}+ openClassName={styles["open-item-menu"]}+ exploreFile={x as ExploreFile}+ previewPath={getFilePath(x as ExploreFile)} />+ </div>)}</div>}