diff --git a/app/src/Dashboard.js b/app/src/Dashboard.js index ec776f47..dc921d98 100644 --- a/app/src/Dashboard.js +++ b/app/src/Dashboard.js @@ -25,7 +25,7 @@ export function Dashboard() { // Only show dashboard parts if not searching. let body; if (searchStr) { - body = ; + body = ; } else { body = <> {!wrol_mode && downloads} diff --git a/app/src/components/Common.js b/app/src/components/Common.js index 65c670a9..691ec64c 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -1,16 +1,5 @@ import React, {useContext, useEffect, useState} from "react"; -import { - Card, - Container, - IconGroup, - Image, - Input, - Modal, - Pagination, - Responsive, - TableCell, - TableRow -} from 'semantic-ui-react'; +import {Card, Container, IconGroup, Image, Input, Modal, Pagination, Responsive, TableCell} from 'semantic-ui-react'; import {Link, NavLink} from "react-router-dom"; import Message from "semantic-ui-react/dist/commonjs/collections/Message"; import {useDownloaders, useHotspot, useThrottle} from "../hooks/customHooks"; @@ -196,7 +185,7 @@ export function VideoCard({file}) { ) } -export function VideoRow({file, checkbox}) { +export function VideoRowCells({file}) { const {video} = file; let video_url = `/videos/video/${video.id}`; @@ -216,8 +205,8 @@ export function VideoRow({file, checkbox}) { poster = ; } - return ( - {checkbox} + // Fragment for SelectableRow + return
{poster} @@ -228,10 +217,10 @@ export function VideoRow({file, checkbox}) { {textEllipsis(video.title || video.stem || video.video_path, 100)} - ) + } -export function ArchiveRow({file, checkbox}) { +export function ArchiveRowCells({file}) { const {archive} = file; const archiveUrl = `/archive/${archive.id}`; @@ -246,8 +235,8 @@ export function ArchiveRow({file, checkbox}) { poster = ; } - return ( - {checkbox} + // Fragment for SelectableRow + return (
{poster}
@@ -256,7 +245,7 @@ export function ArchiveRow({file, checkbox}) { {textEllipsis(archive.title || archive.stem, 100)} -
) + ) } export function RequiredAsterisk() { @@ -775,10 +764,7 @@ export function UnsupportedModal(header, message, icon) { export function HotspotStatusIcon() { const {on, setHotspot, dockerized} = useHotspot(); - const {modal, doOpen} = UnsupportedModal( - 'Unsupported on Docker', - 'You cannot toggle the hotspot on Docker.' - ); + const {modal, doOpen} = UnsupportedModal('Unsupported on Docker', 'You cannot toggle the hotspot on Docker.'); const toggleHotspot = (e) => { e.preventDefault(); diff --git a/app/src/components/Files.js b/app/src/components/Files.js index 0567e830..a877eb2c 100644 --- a/app/src/components/Files.js +++ b/app/src/components/Files.js @@ -1,23 +1,10 @@ import React, {useContext} from "react"; import FileBrowser from 'react-keyed-file-browser'; -import { - Card, - Checkbox, - Confirm, - Divider, - Dropdown, - Image, - PlaceholderLine, - TableBody, - TableCell, - TableHeader, - TableHeaderCell, - TableRow, -} from "semantic-ui-react"; +import {Card, Confirm, Divider, Dropdown, Image, PlaceholderLine, TableCell, TableHeaderCell,} from "semantic-ui-react"; import 'react-keyed-file-browser/dist/react-keyed-file-browser.css'; import {deleteFile, refreshDirectoryFiles, refreshFiles} from "../api"; import { - ArchiveRow, + ArchiveRowCells, CardGroupCentered, ExternalCardLink, FileIcon, @@ -28,7 +15,7 @@ import { textEllipsis, uploadDate, VideoCard, - VideoRow + VideoRowCells } from "./Common"; import {useBrowseFiles, useQuery, useSearchFiles} from "../hooks/customHooks"; import {Route, Routes} from "react-router-dom"; @@ -36,7 +23,8 @@ import {CardPlacholder} from "./Placeholder"; import {ArchiveCard} from "./Archive"; import Grid from "semantic-ui-react/dist/commonjs/collections/Grid"; import {ThemeContext} from "../contexts/contexts"; -import {Button, CardIcon, Header, Icon, Placeholder, Segment, Table} from "./Theme"; +import {Button, CardIcon, Header, Icon, Placeholder, Segment} from "./Theme"; +import {SelectableTable} from "./Tables"; const icons = { File: , @@ -215,7 +203,7 @@ export function FileCards({files}) { } } -function ImageRow({file, checkbox}) { +function ImageRowCells({file}) { const url = `/media/${encodeURIComponent(file.path)}`; let poster = ; @@ -224,75 +212,53 @@ function ImageRow({file, checkbox}) { poster = ; } - return ( - - {checkbox} - -
- {poster} -
-
- - -

{textEllipsis(file.title || file.stem || file.path, 100)}

-
-
-
- ) + // Fragment for SelectableRow + return ( + +
+ {poster} +
+
+ + +

{textEllipsis(file.title || file.stem || file.path, 100)}

+
+
+
) } -function FileRow({file, selectOn, onSelect}) { - let checkbox; - if (selectOn) { - const localOnSelect = (e, {checked}) => { - try { - onSelect(file.key, checked); - } catch (e) { - console.error('No onSelect declared'); - } - }; - checkbox = - - - } - +function FileRow({file}) { if (file.model === 'video' && 'video' in file) { - return ; + return ; } else if (file.model === 'archive' && 'archive' in file) { - return ; + return ; } else if (file.mimetype && file.mimetype.startsWith('image/')) { - return ; + return ; } - const onDownloadFile = async () => window.open(`/media/${file.key}`); - return - {checkbox} + // Fragment for SelectableRow + return
onDownloadFile()}> {textEllipsis(file.title)} -
+ } -export function FileTable({files, selectOn, onSelect}) { +export function FileTable({files, selectOn, onSelect, footer}) { if (files && files.length > 0) { - return ( - - - - {selectOn && } - Poster - Title - - - - {files.map(i => )} - -
- ) + const headerContents = ['Poster', 'Title']; + const rows = files.map(i => ); + return ; } else if (files && files.length === 0) { return

No results!

} else { @@ -372,7 +338,12 @@ export function FilesView({ let body; if (view === 'list') { - body = ; + const footer = selectOn && selectElem ? + <> + + {selectElem} + : null; + body = ; } else { body = ; } @@ -396,7 +367,6 @@ export function FilesView({ {menuColumns} - {selectOn && selectElem} {body} {paginator} diff --git a/app/src/components/Tables.js b/app/src/components/Tables.js new file mode 100644 index 00000000..b7c3c5a0 --- /dev/null +++ b/app/src/components/Tables.js @@ -0,0 +1,47 @@ +import {Table} from "./Theme"; +import {Checkbox, TableBody, TableCell, TableFooter, TableHeader, TableHeaderCell, TableRow} from "semantic-ui-react"; +import React from "react"; + +export function SelectableTable({headerContents, selectOn, onSelect, footer, rows}) { + footer = footer ? + + {selectOn && } + {footer} + + : null; + + return + + + {selectOn && } + {headerContents.map(i => {i})} + + + + {rows.map(row => + {row})} + + {footer} +
+} + +function SelectableRow(props) { + const {selectOn, onSelect} = props; + let selectCell; + if (selectOn) { + const localOnSelect = (e, {checked}) => { + try { + onSelect(props.children.key, checked); + } catch (e) { + console.error('No onSelect declared'); + } + }; + selectCell = + + ; + } + return + {selectCell} + {props.children} + +}