Creating ebook details modal for ebook card. Linking to epub reader when possible in ebook card.

This commit is contained in:
Roland 2022-12-19 10:40:01 -07:00
parent 3e8e45183f
commit 875f6f2606
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
6 changed files with 57 additions and 15 deletions

View file

@ -20,10 +20,10 @@ import {Dashboard} from "./Dashboard";
import {Donate} from "./components/Donate";
function PageNotFound() {
return (<Container fluid>
return <Container fluid>
<h1 className="display-4">Page Not Found!</h1>
<p>The page you requested cannot be found</p>
</Container>)
</Container>
}
function Dot() {

View file

@ -1,6 +1,7 @@
import React, {useContext} from "react";
import FileBrowser from 'react-keyed-file-browser';
import {
Button as SButton,
CardContent,
CardDescription,
CardHeader,
@ -9,7 +10,9 @@ import {
Container,
Divider,
Dropdown,
Header as SHeader,
Image,
Modal,
PlaceholderLine,
TableCell,
TableHeaderCell,
@ -150,29 +153,65 @@ function EbookCard({file}) {
let {ebook, suffix} = file;
const downloadUrl = `/download/${encodeURIComponent(file.path)}`;
const viewerUrl = `/epub.html?url=${downloadUrl}`;
const isEpub = file['mimetype'].startsWith('application/epub');
const viewerUrl = isEpub ? `/epub.html?url=${downloadUrl}` : null;
let cover = <CardIcon><FileIcon file={file}/></CardIcon>;
if (ebook && ebook.cover_path) {
const coverSrc = `/media/${encodeURIComponent(ebook.cover_path)}`;
cover = <CardPosterLink to={downloadUrl} poster_url={coverSrc} external={true}/>;
cover = <CardPosterLink to={viewerUrl || downloadUrl} poster_url={coverSrc} external={true}/>;
}
suffix = suffix ? _.trimStart(suffix, '.').toUpperCase() : null;
const downloadButton = <ExternalCardLink to={downloadUrl}>
<SButton
icon='download'
content='Download'
labelPosition='left'/>
</ExternalCardLink>;
const detailsButton = <Button
icon='file alternate'
content='Details'
labelPosition='left'
disabled={!ebook}
onClick={() => setDetailsOpen(true)}
/>;
const [detailsOpen, setDetailsOpen] = React.useState(false);
const detailsModal = <Modal closeIcon
open={detailsOpen}
onClose={() => setDetailsOpen(false)}
trigger={detailsButton}
>
<Modal.Header><SHeader as='h1'>{ebook.title || file.title}</SHeader></Modal.Header>
<Modal.Content>
<SHeader as='h3'>Author: {ebook.creator}</SHeader>
<p>{humanFileSize(ebook.size)}</p>
<SHeader as='h5'>eBook Path</SHeader>
<pre>{ebook ? ebook.ebook_path : file.path}</pre>
<SHeader as='h5'>Cover Path</SHeader>
<pre>{ebook && ebook.cover_path ? ebook.cover_path : 'N/A'}</pre>
</Modal.Content>
<Modal.Actions>
{downloadButton}
</Modal.Actions>
</Modal>;
const color = mimetypeColor(file.mimetype);
return <Card color={color}>
{cover}
<CardContent {...s}>
<CardHeader>
<Container textAlign='left'>
<ExternalCardLink to={downloadUrl}>{ebook ? ebook.title : file.title}</ExternalCardLink>
<ExternalCardLink to={viewerUrl || downloadUrl}>
{ebook ? ebook.title : file.title}
</ExternalCardLink>
</Container>
</CardHeader>
<CardMeta>
<pre {...s}>{suffix}</pre>
{isEpub && <ExternalCardLink to={viewerUrl}><Button content='View'/></ExternalCardLink>}
{detailsModal}
</CardMeta>
</CardContent>
</Card>

View file

@ -15,13 +15,12 @@ import {VideoCard} from "./Videos";
const MEDIA_PATH = '/media';
function videoFileLink(video, name, directory = false) {
const path = video[name];
function videoFileLink(path, directory = false) {
if (path) {
const href = directory ?
`${MEDIA_PATH}/${encodeURIComponent(path)}/` :
`${MEDIA_PATH}/${encodeURIComponent(path)}`;
return <a href={href}>
return <a href={href} target='_blank' rel='noopener noreferrer'>
<pre>{path}</pre>
</a>
} else {
@ -134,19 +133,19 @@ function VideoPage({videoFile, prevFile, nextFile, setFavorite, ...props}) {
let filesPane = {
menuItem: 'Files', render: () => <TabPane>
<h3>Video File</h3>
{videoFileLink(video, 'video_path')}
{videoFileLink(video['video_path'])}
<h4>Info JSON File</h4>
{videoFileLink(video, 'info_json_path')}
{videoFileLink(video['info_json_path'])}
<h4>Caption File</h4>
{videoFileLink(video, 'caption_path')}
{videoFileLink(video['caption_path'])}
<h4>Poster File</h4>
{videoFileLink(video, 'poster_path')}
{videoFileLink(video['poster_path'])}
<h4>Directory</h4>
{videoFileLink(video, 'directory', true)}
{videoFileLink(videoFile['directory'], true)}
</TabPane>
}

View file

@ -245,7 +245,6 @@ class Video(ModelHelper, Base):
censored=self.censored,
channel=self.channel,
channel_id=self.channel_id,
directory=self.video_path.parent if self.video_path else None,
modification_datetime=self.modification_datetime,
duration=self.duration,
favorite=self.favorite,

View file

@ -36,6 +36,10 @@ http {
alias /opt/wrolpi/icon.png;
}
location /epub.html {
alias /opt/wrolpi/app/public/epub.html;
}
location / {
# React APP
proxy_pass http://127.0.0.1:5000;

View file

@ -54,6 +54,7 @@ class File(ModelHelper, Base):
path = self.path.relative_to(get_media_directory())
d = dict(
associated=self.associated,
directory=self.path.parent,
full_stem=self.full_stem,
key=path, # React browser expects this.
mimetype=self.mimetype,