mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-19 14:36:22 -05:00
Creating SelectableTable to handle selection logic. Converting FileView to use SelectTable.
This commit is contained in:
parent
2a16cdd98e
commit
d1bbccf7f4
4 changed files with 100 additions and 97 deletions
|
|
@ -25,7 +25,7 @@ export function Dashboard() {
|
|||
// Only show dashboard parts if not searching.
|
||||
let body;
|
||||
if (searchStr) {
|
||||
body = <FilesSearchView showLimit={true} showSelect={true} showSelectButton={true}/>;
|
||||
body = <FilesSearchView showLimit={true} showSelectButton={true}/>;
|
||||
} else {
|
||||
body = <>
|
||||
{!wrol_mode && downloads}
|
||||
|
|
|
|||
|
|
@ -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}) {
|
|||
</Card>)
|
||||
}
|
||||
|
||||
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 = <FileIcon file={file} size='large'/>;
|
||||
}
|
||||
|
||||
return (<TableRow>
|
||||
{checkbox}
|
||||
// Fragment for SelectableRow
|
||||
return <React.Fragment>
|
||||
<TableCell>
|
||||
<center>
|
||||
{poster}
|
||||
|
|
@ -228,10 +217,10 @@ export function VideoRow({file, checkbox}) {
|
|||
{textEllipsis(video.title || video.stem || video.video_path, 100)}
|
||||
</CardLink>
|
||||
</TableCell>
|
||||
</TableRow>)
|
||||
</React.Fragment>
|
||||
}
|
||||
|
||||
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 = <FileIcon file={file} size='large'/>;
|
||||
}
|
||||
|
||||
return (<TableRow>
|
||||
{checkbox}
|
||||
// Fragment for SelectableRow
|
||||
return (<React.Fragment>
|
||||
<TableCell>
|
||||
<center>{poster}</center>
|
||||
</TableCell>
|
||||
|
|
@ -256,7 +245,7 @@ export function ArchiveRow({file, checkbox}) {
|
|||
{textEllipsis(archive.title || archive.stem, 100)}
|
||||
</CardLink>
|
||||
</TableCell>
|
||||
</TableRow>)
|
||||
</React.Fragment>)
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -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: <Icon name='file'/>,
|
||||
|
|
@ -215,7 +203,7 @@ export function FileCards({files}) {
|
|||
}
|
||||
}
|
||||
|
||||
function ImageRow({file, checkbox}) {
|
||||
function ImageRowCells({file}) {
|
||||
const url = `/media/${encodeURIComponent(file.path)}`;
|
||||
|
||||
let poster = <FileIcon file={file} size='large'/>;
|
||||
|
|
@ -224,75 +212,53 @@ function ImageRow({file, checkbox}) {
|
|||
poster = <Image wrapped src={url} width='50px'/>;
|
||||
}
|
||||
|
||||
return (
|
||||
<Table.Row>
|
||||
{checkbox}
|
||||
<TableCell>
|
||||
<center>
|
||||
{poster}
|
||||
</center>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<ExternalCardLink to={url}>
|
||||
<p>{textEllipsis(file.title || file.stem || file.path, 100)}</p>
|
||||
</ExternalCardLink>
|
||||
</TableCell>
|
||||
</Table.Row>
|
||||
)
|
||||
// Fragment for SelectableRow
|
||||
return (<React.Fragment>
|
||||
<TableCell>
|
||||
<center>
|
||||
{poster}
|
||||
</center>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<ExternalCardLink to={url}>
|
||||
<p>{textEllipsis(file.title || file.stem || file.path, 100)}</p>
|
||||
</ExternalCardLink>
|
||||
</TableCell>
|
||||
</React.Fragment>)
|
||||
}
|
||||
|
||||
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 = <TableCell>
|
||||
<Checkbox onChange={localOnSelect}/>
|
||||
</TableCell>
|
||||
}
|
||||
|
||||
function FileRow({file}) {
|
||||
if (file.model === 'video' && 'video' in file) {
|
||||
return <VideoRow key={file['path']} file={file} checkbox={checkbox}/>;
|
||||
return <VideoRowCells file={file}/>;
|
||||
} else if (file.model === 'archive' && 'archive' in file) {
|
||||
return <ArchiveRow key={file['path']} file={file} checkbox={checkbox}/>;
|
||||
return <ArchiveRowCells file={file}/>;
|
||||
} else if (file.mimetype && file.mimetype.startsWith('image/')) {
|
||||
return <ImageRow key={file['path']} file={file} checkbox={checkbox}/>;
|
||||
return <ImageRowCells file={file}/>;
|
||||
}
|
||||
|
||||
const onDownloadFile = async () => window.open(`/media/${file.key}`);
|
||||
|
||||
return <TableRow>
|
||||
{checkbox}
|
||||
// Fragment for SelectableRow
|
||||
return <React.Fragment>
|
||||
<TableCell>
|
||||
<center><FileIcon file={file} size='large'/></center>
|
||||
</TableCell>
|
||||
<TableCell onClick={() => onDownloadFile()}>
|
||||
{textEllipsis(file.title)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</React.Fragment>
|
||||
}
|
||||
|
||||
export function FileTable({files, selectOn, onSelect}) {
|
||||
export function FileTable({files, selectOn, onSelect, footer}) {
|
||||
if (files && files.length > 0) {
|
||||
return (
|
||||
<Table unstackable striped compact='very'>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
{selectOn && <TableHeaderCell/>}
|
||||
<TableHeaderCell>Poster</TableHeaderCell>
|
||||
<TableHeaderCell>Title</TableHeaderCell>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{files.map(i => <FileRow key={i['path']} file={i} selectOn={selectOn} onSelect={onSelect}/>)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)
|
||||
const headerContents = ['Poster', 'Title'];
|
||||
const rows = files.map(i => <FileRow key={i['key']} file={i}/>);
|
||||
return <SelectableTable
|
||||
headerContents={headerContents}
|
||||
selectOn={selectOn}
|
||||
onSelect={onSelect}
|
||||
footer={footer}
|
||||
rows={rows}
|
||||
/>;
|
||||
} else if (files && files.length === 0) {
|
||||
return <Segment><p>No results!</p></Segment>
|
||||
} else {
|
||||
|
|
@ -372,7 +338,12 @@ export function FilesView({
|
|||
|
||||
let body;
|
||||
if (view === 'list') {
|
||||
body = <FileTable files={files} selectOn={selectOn} onSelect={onSelect}/>;
|
||||
const footer = selectOn && selectElem ?
|
||||
<>
|
||||
<TableHeaderCell/>
|
||||
<TableHeaderCell>{selectElem}</TableHeaderCell>
|
||||
</> : null;
|
||||
body = <FileTable files={files} selectOn={selectOn} onSelect={onSelect} footer={footer}/>;
|
||||
} else {
|
||||
body = <FileCards files={files}/>;
|
||||
}
|
||||
|
|
@ -396,7 +367,6 @@ export function FilesView({
|
|||
</Grid.Column>
|
||||
{menuColumns}
|
||||
</Grid>
|
||||
{selectOn && selectElem}
|
||||
{body}
|
||||
{paginator}
|
||||
</>
|
||||
|
|
|
|||
47
app/src/components/Tables.js
Normal file
47
app/src/components/Tables.js
Normal file
|
|
@ -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 ? <TableFooter>
|
||||
<TableRow>
|
||||
{selectOn && <TableHeaderCell/>}
|
||||
{footer}
|
||||
</TableRow>
|
||||
</TableFooter> : null;
|
||||
|
||||
return <Table unstackable striped compact='very'>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
{selectOn && <TableHeaderCell/>}
|
||||
{headerContents.map(i => <TableHeaderCell key={i}>{i}</TableHeaderCell>)}
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{rows.map(row =>
|
||||
<SelectableRow key={row.key} selectOn={selectOn} onSelect={onSelect}>{row}</SelectableRow>)}
|
||||
</TableBody>
|
||||
{footer}
|
||||
</Table>
|
||||
}
|
||||
|
||||
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 = <TableCell>
|
||||
<Checkbox onChange={localOnSelect}/>
|
||||
</TableCell>;
|
||||
}
|
||||
return <TableRow key={props.children.key}>
|
||||
{selectCell}
|
||||
{props.children}
|
||||
</TableRow>
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue