diff --git a/app/src/App.css b/app/src/App.css index 4010137c..0201b28c 100644 --- a/app/src/App.css +++ b/app/src/App.css @@ -133,3 +133,46 @@ td.file-path { top: 20px; right: 20px; } + +textarea.otp { + width: 100%; + color: #333; +} + +.inline-header h1 { + display: inline-block; +} + +.inline-header h2 { + display: inline-block; +} + +.inline-header h3 { + display: inline-block; +} + +.inline-header h4 { + display: inline-block; +} + +.inline-header h5 { + display: inline-block; +} + +.inline-header span { + margin-left: 1em; +} + +.card-icon { + min-height: 163px; + text-align: center; + padding-top: 53px; +} + +.card-icon.inverted { + background-color: #222222; +} + +.clickable { + cursor: pointer; +} diff --git a/app/src/App.js b/app/src/App.js index cc00277d..6913ada0 100644 --- a/app/src/App.js +++ b/app/src/App.js @@ -18,6 +18,7 @@ import {Dashboard} from "./Dashboard"; import {Donate} from "./components/Donate"; import {useEventsInterval} from "./Events"; import {SemanticToastContainer} from "react-semantic-toasts-2"; +import {FilePreviewWrapper} from "./components/FilePreview"; function PageNotFound() { const {t} = useContext(ThemeContext); @@ -78,13 +79,16 @@ export default function App() { useEventsInterval(); return - {/* Context and style to handle switching between mobile/computer. */} - - - - - - - + + {/* Context and style to handle switching between mobile/computer. */} + + {/* Toasts can be on any page. */} + + + + + + + } diff --git a/app/src/components/Apps.js b/app/src/components/Apps.js index 741fc92f..91af9468 100644 --- a/app/src/components/Apps.js +++ b/app/src/components/Apps.js @@ -1,7 +1,6 @@ import React, {useContext} from 'react'; import {Divider, SegmentGroup, StatisticLabel, StatisticValue} from "semantic-ui-react"; import {Link, Route, Routes} from "react-router-dom"; -import "../static/wrolpi.css"; import {decryptOTP, encryptOTP} from "../api"; import {humanFileSize, mimetypeColor, PageContainer, toLocaleString, useTitle} from "./Common"; import {ThemeContext} from "../contexts/contexts"; diff --git a/app/src/components/Archive.js b/app/src/components/Archive.js index 28f9dc15..2ef471da 100644 --- a/app/src/components/Archive.js +++ b/app/src/components/Archive.js @@ -23,7 +23,7 @@ import { HelpHeader, isoDatetimeToString, mimetypeColor, - PageContainer, + PageContainer, PreviewLink, SearchInput, TabLinks, textEllipsis, diff --git a/app/src/components/Common.js b/app/src/components/Common.js index e2f2180e..30fa9867 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -5,6 +5,7 @@ import Message from "semantic-ui-react/dist/commonjs/collections/Message"; import {useDirectories, useDownloaders, useHotspot, useSettings, useThrottle} from "../hooks/customHooks"; import {Media, StatusContext, ThemeContext} from "../contexts/contexts"; import {Button, darkTheme, Form, Header, Icon, lightTheme, Menu, Popup, Statistic} from "./Theme"; +import {FilePreviewContext} from "./FilePreview"; export const API_URI = process.env && process.env.REACT_APP_API_URI ? process.env.REACT_APP_API_URI : `${window.location.protocol}//${window.location.host}/api`; export const VIDEOS_API = `${API_URI}/videos`; @@ -141,6 +142,15 @@ export function ExternalCardLink({to, ...props}) { } +export function PreviewLink({file, children, className, ...props}) { + const {t} = useContext(ThemeContext); + const {setPreviewPath} = React.useContext(FilePreviewContext); + className = className ? `clickable ${className}` : `clickable `; + return
setPreviewPath(file)} {...props} {...t}> + {children} +
+} + export function RequiredAsterisk() { return * } @@ -436,14 +446,16 @@ export function CardPosterLink({to, poster_url, imageLabel, external = false}) { style={{maxHeight: '163px', width: 'auto'}} />; if (external === true) { - return + return {image} - } else { + } else if (to) { // Link using React Router. return {image} + } else { + return
{image}
; } } diff --git a/app/src/components/FileBrowser.js b/app/src/components/FileBrowser.js index 0886fd7c..38a34358 100644 --- a/app/src/components/FileBrowser.js +++ b/app/src/components/FileBrowser.js @@ -1,18 +1,5 @@ import {Button, Icon, Placeholder} from "./Theme"; -import { - Button as SButton, - Checkbox, - Confirm, - Image, - Modal, - ModalActions, - ModalContent, - PlaceholderLine, - TableCell, - TableFooter, - TableHeaderCell, - TableRow -} from "semantic-ui-react"; +import {Checkbox, Confirm, PlaceholderLine, TableCell, TableFooter, TableHeaderCell, TableRow} from "semantic-ui-react"; import {FileIcon, humanFileSize} from "./Common"; import React from "react"; import {deleteFile} from "../api"; @@ -20,7 +7,7 @@ import _ from 'lodash'; import {SortableTable} from "./SortableTable"; import {useBrowseFiles} from "../hooks/customHooks"; import {DirectoryRefreshButton, FilesRefreshButton} from "./Files"; -import {useFilePreview} from "./FilePreview"; +import {FilePreviewContext} from "./FilePreview"; function depthIndentation(path) { // Repeated spaces for every folder a path is in. @@ -113,7 +100,7 @@ export function FileBrowser() { key: 'path', text: 'Path', sortBy: i => i['path'].toLowerCase() }, {key: 'size', text: 'Size', sortBy: 'size'},]; - const {modal, setPath} = useFilePreview(); + const {setPreviewPath} = React.useContext(FilePreviewContext); const onSelect = (path) => { if (path.endsWith('/') && selectedPath === path) { @@ -198,13 +185,12 @@ export function FileBrowser() { key={i['key']} path={i} onFolderClick={onFolderClick} - onFileClick={(i) => setPath(i)} + onFileClick={(i) => setPreviewPath(i)} sortData={sortData} selectedPath={selectedPath} onSelect={onSelect} />} footer={footer} /> - {modal} } diff --git a/app/src/components/FilePreview.js b/app/src/components/FilePreview.js index 7dee4b93..255024f2 100644 --- a/app/src/components/FilePreview.js +++ b/app/src/components/FilePreview.js @@ -1,4 +1,4 @@ -import React, {useEffect} from "react"; +import React from "react"; import _ from "lodash"; import {Button as SButton, Image, Modal, ModalActions, ModalContent} from "semantic-ui-react"; @@ -11,7 +11,7 @@ function getDownloadPathURL(path) { } function getEpubViewerURL(path) { - return `/epub.html?url=${getDownloadPathURL(path)}`; + return `/epub.html?url=download/${encodeURIComponent(path['path'])}`; } function getIframeModal(path) { @@ -62,51 +62,64 @@ function getVideoModal(path) { } -export function useFilePreview() { - const [path, setPath] = React.useState(null); - const [modal, setModal] = React.useState(null); +export const FilePreviewContext = React.createContext({ + previewPath: null, setPreviewPath: null, previewModal: null, setPreviewModal: null, +}); + +export function FilePreviewWrapper({children}) { + const [previewPath, setPreviewPath] = React.useState(null); + const [previewModal, setPreviewModal] = React.useState(null); + + const value = { + previewPath, setPreviewPath, previewModal, setPreviewModal, + }; function setModalContent(content, url, downloadURL) { - setModal( setModal(null)} + setPreviewModal( setPreviewModal(null)} > {content} {downloadURL && window.open(downloadURL)} floated='left'>Download} window.open(url)}>Open - setPath(null)}>Close + setPreviewPath(null)}>Close ); } - useEffect(() => { - setModal(null); - if (path && !_.isEmpty(path)) { - const {mimetype, size} = path; - console.debug(`useFilePreview path=${path['path']} mimetype=${mimetype}`); - const url = getMediaPathURL(path); - const downloadURL = getDownloadPathURL(path); + React.useEffect(() => { + setPreviewModal(null); + if (previewPath && !_.isEmpty(previewPath)) { + const {mimetype, size} = previewPath; + console.debug(`useFilePreview path=${previewPath['path']} mimetype=${mimetype}`); + const url = getMediaPathURL(previewPath); + const downloadURL = getDownloadPathURL(previewPath); if (mimetype.startsWith('text/') && size >= 10000) { // Large text files should be downloaded. window.open(downloadURL); } else if (mimetype.startsWith('text/') || mimetype.startsWith('application/json')) { - setModalContent(getIframeModal(path), url, downloadURL); + setModalContent(getIframeModal(previewPath), url, downloadURL); } else if (mimetype.startsWith('video/')) { - setModalContent(getVideoModal(path), url, downloadURL); + setModalContent(getVideoModal(previewPath), url, downloadURL); } else if (mimetype.startsWith('application/epub')) { - const viewerURL = getEpubViewerURL(path); - setModalContent(getEpubModal(path), viewerURL, downloadURL); + const viewerURL = getEpubViewerURL(previewPath); + console.dir(previewPath); + console.log(viewerURL); + setModalContent(getEpubModal(previewPath), viewerURL, downloadURL); } else if (mimetype.startsWith('image/')) { - setModalContent(getImageModal(path), url); + setModalContent(getImageModal(previewPath), url); } else { // No special handler for this file type, just open it. window.open(downloadURL); } } - }, [path]); + }, [previewPath]); - return {modal, setPath}; + return + {children} + {previewModal} + } diff --git a/app/src/components/Files.js b/app/src/components/Files.js index 248cbf91..4226a88c 100644 --- a/app/src/components/Files.js +++ b/app/src/components/Files.js @@ -1,15 +1,12 @@ import React, {useContext} from "react"; import { - Button as SButton, CardContent, CardDescription, CardHeader, CardMeta, Container, Dropdown, - Header as SHeader, Image, - Modal, PlaceholderLine, TableCell, TableHeaderCell, @@ -26,6 +23,7 @@ import { mimetypeColor, PageContainer, Paginator, + PreviewLink, textEllipsis, useTitle } from "./Common"; @@ -42,6 +40,7 @@ import _ from 'lodash'; import {FileBrowser} from "./FileBrowser"; import {refreshDirectoryFiles, refreshFiles} from "../api"; import {useSubscribeEventName} from "../Events"; +import {FilePreviewContext} from "./FilePreview"; export function FilesPage() { @@ -58,51 +57,19 @@ function EbookCard({file}) { const isEpub = file['mimetype'].startsWith('application/epub'); const viewerUrl = isEpub ? `/epub.html?url=${downloadUrl}` : null; - let cover = ; + let cover = ; if (ebook && ebook.cover_path) { const coverSrc = `/media/${encodeURIComponent(ebook.cover_path)}`; - cover = ; + cover = ; } suffix = suffix ? _.trimStart(suffix, '.').toUpperCase() : null; - const downloadButton = - - ; - - const detailsButton =