Modifying Archive page to match Video page, specifically using tabs for the about/files.

This commit is contained in:
Roland 2023-08-26 20:28:34 -06:00
parent 7013ae0f6d
commit 17a1aa903c
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
4 changed files with 103 additions and 44 deletions

View file

@ -28,6 +28,7 @@ import {
mimetypeColor,
PageContainer,
PreviewLink,
PreviewPath,
SearchInput,
SortButton,
TabLinks,
@ -42,15 +43,29 @@ import {FileCards, FileRowTagIcon, FilesView} from "./Files";
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
import _ from "lodash";
import {Media, ThemeContext} from "../contexts/contexts";
import {Button, Card, CardIcon, Header, Icon, Loader, Placeholder, Segment} from "./Theme";
import {Button, Card, CardIcon, darkTheme, Header, Loader, Placeholder, Segment, Tab, TabPane} from "./Theme";
import {SortableTable} from "./SortableTable";
import {taggedImageLabel, TagsSelector} from "../Tags";
import {toast} from "react-semantic-toasts-2";
function archiveFileLink(path, directory = false) {
if (path) {
const href = directory ?
`/media/${encodeMediaPath(path)}/`
: `/media/${encodeMediaPath(path)}`;
return <a href={href} target='_blank' rel='noopener noreferrer'>
<pre>{path}</pre>
</a>
} else {
return <p>Unknown</p>
}
}
function ArchivePage() {
const navigate = useNavigate();
const {archiveId} = useParams();
const {archiveFile, history, fetchArchive} = useArchive(archiveId);
const {theme} = useContext(ThemeContext);
let title;
if (archiveFile && archiveFile.archive) {
@ -113,7 +128,10 @@ function ArchivePage() {
confirmButton='Update'
onClick={localUpdateArchive}
obeyWROLMode={true}
>Update</APIButton>;
style={{marginTop: '0.5em'}}
>
Update
</APIButton>;
const deleteButton = <APIButton
text='Delete'
color='red'
@ -121,7 +139,9 @@ function ArchivePage() {
confirmButton='Delete'
onClick={localDeleteArchive}
obeyWROLMode={true}
>Delete</APIButton>;
>
Delete
</APIButton>;
let historyList = <Loader active/>;
if (history && history.length === 0) {
@ -131,7 +151,7 @@ function ArchivePage() {
}
const domain = data.domain ? data.domain : null;
let domainHeader;
let domainHeader = <p>Unknown</p>;
if (domain) {
const domainUrl = `/archive?domain=${domain}`;
domainHeader = <Header as='h4'>
@ -141,16 +161,6 @@ function ArchivePage() {
</Header>;
}
let urlHeader;
if (data.url) {
urlHeader = <Header as='h5'>
<ExternalCardLink to={data.url}>
<Icon name='external'/>
{textEllipsis(data.url)}
</ExternalCardLink>
</Header>;
}
const localAddTag = async (name) => {
await tagFileGroup(archiveFile, name);
await fetchArchive();
@ -161,6 +171,54 @@ function ArchivePage() {
await fetchArchive();
}
const aboutPane = {
menuItem: 'About', render: () => <TabPane>
<Header as={'h3'}>Domain</Header>
{domainHeader}
<Header as='h3'>Size</Header>
{humanFileSize(size)}
<Header as={'h3'}>URL</Header>
<p>{data.url ? <a href={data.url}>{data.url}</a> : 'N/A'}</p>
</TabPane>
};
const localPreviewPath = (path, mimetype) => {
if (path) {
return <PreviewPath path={path} mimetype={mimetype} taggable={false}>{path}</PreviewPath>
} else {
return 'Unknown'
}
}
const filesPane = {
menuItem: 'Files', render: () => <TabPane>
<Header as={'h3'}>Singlefile File</Header>
{localPreviewPath(data.singlefile_path, 'text/html')}
<Header as={'h3'}>Readability File</Header>
{localPreviewPath(data.readability_path, 'text/html')}
<Header as={'h3'}>Readability Text File</Header>
{localPreviewPath(data.readability_txt_path, 'text/plain')}
<Header as={'h3'}>Readability JSON File</Header>
{localPreviewPath(data.readability_json_path, 'application/json')}
<Header as={'h3'}>Screenshot File</Header>
{data.screenshot_path ?
archiveFileLink(data.screenshot_path)
: 'Unknown'}
<Header as={'h3'}>Directory</Header>
{archiveFileLink(archiveFile.directory, true)}
</TabPane>
};
const tabPanes = [aboutPane, filesPane];
const tabMenu = theme === darkTheme ? {inverted: true, attached: true} : {attached: true};
return <>
<BackButton/>
@ -170,12 +228,7 @@ function ArchivePage() {
<Header as='h2'>{textEllipsis(archiveFile.title || data.url)}</Header>
</ExternalCardLink>
<Header as='h3'>{isoDatetimeToString(data.archive_datetime)}</Header>
{domainHeader}
{urlHeader}
<Header as='h5'>{humanFileSize(size)}</Header>
{singlefileButton}
{readabilityLink}
{updateButton}
{deleteButton}
</Segment>
@ -184,6 +237,8 @@ function ArchivePage() {
<TagsSelector selectedTagNames={archiveFile['tags']} onAdd={localAddTag} onRemove={localRemoveTag}/>
</Segment>
<Tab menu={tabMenu} panes={tabPanes}/>
<Segment>
<HelpHeader
headerContent='History'

View file

@ -209,8 +209,8 @@ export function PreviewLink({file, children, className, ...props}) {
</span>
}
export function PreviewPath({path, mimetype, ...props}) {
return <PreviewLink file={{path, mimetype}} {...props}/>
export function PreviewPath({path, mimetype, taggable = true, ...props}) {
return <PreviewLink file={{path, mimetype, taggable}} {...props}/>
}
export function RequiredAsterisk() {

View file

@ -186,11 +186,13 @@ export function FilePreviewProvider({children}) {
await localFetchFile();
}
function setModalContent(content, url, downloadURL, path) {
function setModalContent(content, url, downloadURL, path, taggable = true) {
const openButton = url ? <Button color='blue' as='a' href={url}>Open</Button> : null;
const closeButton = <Button onClick={handleClose}>Close</Button>;
const tagsDisplay = <TagsSelector selectedTagNames={previewFile['tags']} onAdd={localAddTag}
onRemove={localRemoveTag}/>;
const tagsDisplay = taggable ?
<TagsSelector selectedTagNames={previewFile['tags']} onAdd={localAddTag}
onRemove={localRemoveTag}/>
: null;
const downloadButton = downloadURL ?
<Button color='yellow' as='a' href={downloadURL} floated='left'>Download</Button>
: null;
@ -250,7 +252,7 @@ export function FilePreviewProvider({children}) {
}
if (previewFile && !_.isEmpty(previewFile)) {
const {mimetype, size} = previewFile;
const {mimetype, size, taggable} = previewFile;
const path = previewFile['primary_path'] || previewFile['path'];
console.debug('Previewing file', previewFile);
const lowerPath = path.toLowerCase();
@ -260,27 +262,27 @@ export function FilePreviewProvider({children}) {
// Large text files should be downloaded.
window.open(downloadURL);
} else if (mimetype.startsWith('text/') || mimetype.startsWith('application/json')) {
setModalContent(getIframePreviewModal(previewFile), url, downloadURL, path);
setModalContent(getIframePreviewModal(previewFile), url, downloadURL, path, taggable);
} else if (mimetype.startsWith('video/')) {
setModalContent(getVideoPreviewModal(previewFile), url, downloadURL, path);
setModalContent(getVideoPreviewModal(previewFile), url, downloadURL, path, taggable);
} else if (mimetype.startsWith('audio/')) {
setModalContent(getAudioPreviewModal(previewFile), url, downloadURL, path);
setModalContent(getAudioPreviewModal(previewFile), url, downloadURL, path, taggable);
} else if (mimetype.startsWith('application/epub')) {
const viewerURL = getEpubViewerURL(previewFile);
setModalContent(getIframePreviewModal(previewFile, viewerURL), viewerURL, downloadURL, path);
setModalContent(getIframePreviewModal(previewFile, viewerURL), viewerURL, downloadURL, path, taggable);
} else if (mimetype.startsWith('application/pdf')) {
setModalContent(getIframePreviewModal(previewFile), url, downloadURL, path);
setModalContent(getIframePreviewModal(previewFile), url, downloadURL, path, taggable);
} else if (mimetype.startsWith('image/')) {
setModalContent(getImagePreviewModal(previewFile), url, null, path);
setModalContent(getImagePreviewModal(previewFile), url, null, path, taggable);
} else if (mimetype.startsWith('model/stl')) {
setModalContent(getSTLPreviewModal(previewFile), null, downloadURL, path);
setModalContent(getSTLPreviewModal(previewFile), null, downloadURL, path, taggable);
} else if (mimetype.startsWith('application/octet-stream') && lowerPath.endsWith('.mp3')) {
setModalContent(getAudioPreviewModal(previewFile), url, downloadURL, path);
setModalContent(getAudioPreviewModal(previewFile), url, downloadURL, path, taggable);
} else if (mimetype.startsWith('application/octet-stream') && lowerPath.endsWith('.stl')) {
setModalContent(getSTLPreviewModal(previewFile), null, downloadURL, path);
setModalContent(getSTLPreviewModal(previewFile), null, downloadURL, path, taggable);
} else {
// No special handler for this file type, just open it.
setModalContent(getGenericPreviewModal(previewFile), url, downloadURL, path);
setModalContent(getGenericPreviewModal(previewFile), url, downloadURL, path, taggable);
}
}
}, [previewFile]);

View file

@ -150,28 +150,30 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
};
const {poster_file, info_json_file} = video;
let filesPane = {
const filesPane = {
menuItem: 'Files', render: () => <TabPane>
<h3>Video File</h3>
{videoFileLink(video['video_path'])}
<h4>Info JSON File</h4>
{info_json_file &&
<PreviewPath
path={info_json_file['path']}
mimetype={info_json_file['mimetype']}>{info_json_file['path']}</PreviewPath>
<PreviewPath path={info_json_file['path']} mimetype={info_json_file['mimetype']} taggable={false}>
{info_json_file['path']}
</PreviewPath>
}
<h4>Caption Files</h4>
{caption_files &&
caption_files.map(i => <p key={i['path']}><PreviewPath {...i}>{i['path']}</PreviewPath></p>)
caption_files.map(i => <p key={i['path']}><PreviewPath {...i} taggable={false}>
{i['path']}
</PreviewPath></p>)
}
<h4>Poster File</h4>
{poster_file &&
<PreviewPath
path={poster_file['path']}
mimetype={poster_file['mimetype']}>{poster_file['path']}</PreviewPath>
<PreviewPath path={poster_file['path']} mimetype={poster_file['mimetype']} taggable={false}>
{poster_file['path']}
</PreviewPath>
}
<h4>Directory</h4>
@ -179,7 +181,7 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
</TabPane>
}
let tabPanes = [descriptionPane, aboutPane, filesPane, captionsPane];
const tabPanes = [descriptionPane, aboutPane, filesPane, captionsPane];
const tabMenu = theme === darkTheme ? {inverted: true, attached: true} : {attached: true};
const localAddTag = async (name) => {