mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Renaming previewPath to previewFile to match existing path/file style.
This commit is contained in:
parent
a82917fdf7
commit
87b179eeb9
5 changed files with 26 additions and 27 deletions
|
|
@ -23,7 +23,8 @@ import {
|
|||
HelpHeader,
|
||||
isoDatetimeToString,
|
||||
mimetypeColor,
|
||||
PageContainer, PreviewLink,
|
||||
PageContainer,
|
||||
PreviewLink,
|
||||
SearchInput,
|
||||
TabLinks,
|
||||
textEllipsis,
|
||||
|
|
@ -68,14 +69,14 @@ function ArchivePage() {
|
|||
|
||||
const singlefileUrl = archive.singlefile_path ? `/media/${encodeURIComponent(archive.singlefile_path)}` : null;
|
||||
const screenshotUrl = archive.screenshot_path ? `/media/${encodeURIComponent(archive.screenshot_path)}` : null;
|
||||
const readabilityUrl = archive.readability_path ? `/media/${encodeURIComponent(archive.readability_path)}` : null;
|
||||
const readabilityUrl = archive.readability_path;
|
||||
|
||||
const singlefileButton = <ExternalCardLink to={singlefileUrl}>
|
||||
<Button content='View' color='blue'/>
|
||||
</ExternalCardLink>;
|
||||
|
||||
const readabilityLink = readabilityUrl ?
|
||||
<ExternalCardLink to={readabilityUrl}><Button content='Article'/></ExternalCardLink> :
|
||||
<PreviewLink file={{path: readabilityUrl, mimetype: 'text/html'}}><Button content='Article'/></PreviewLink> :
|
||||
<Button disabled content='Article'/>;
|
||||
|
||||
const screenshot = screenshotUrl ?
|
||||
|
|
|
|||
|
|
@ -144,11 +144,11 @@ export function ExternalCardLink({to, ...props}) {
|
|||
|
||||
export function PreviewLink({file, children, className, ...props}) {
|
||||
const {t} = useContext(ThemeContext);
|
||||
const {setPreviewPath} = React.useContext(FilePreviewContext);
|
||||
const {setPreviewFile} = React.useContext(FilePreviewContext);
|
||||
className = className ? `clickable ${className}` : `clickable `;
|
||||
return <div className={className} onClick={() => setPreviewPath(file)} {...props} {...t}>
|
||||
return <span className={className} onClick={() => setPreviewFile(file)} {...props} {...t}>
|
||||
{children}
|
||||
</div>
|
||||
</span>
|
||||
}
|
||||
|
||||
export function RequiredAsterisk() {
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ export function FileBrowser() {
|
|||
key: 'path', text: 'Path', sortBy: i => i['path'].toLowerCase()
|
||||
}, {key: 'size', text: 'Size', sortBy: 'size'},];
|
||||
|
||||
const {setPreviewPath} = React.useContext(FilePreviewContext);
|
||||
const {setPreviewFile} = React.useContext(FilePreviewContext);
|
||||
|
||||
const onSelect = (path) => {
|
||||
if (path.endsWith('/') && selectedPath === path) {
|
||||
|
|
@ -185,7 +185,7 @@ export function FileBrowser() {
|
|||
key={i['key']}
|
||||
path={i}
|
||||
onFolderClick={onFolderClick}
|
||||
onFileClick={(i) => setPreviewPath(i)}
|
||||
onFileClick={(i) => setPreviewFile(i)}
|
||||
sortData={sortData}
|
||||
selectedPath={selectedPath}
|
||||
onSelect={onSelect}
|
||||
|
|
|
|||
|
|
@ -63,15 +63,15 @@ function getVideoModal(path) {
|
|||
}
|
||||
|
||||
export const FilePreviewContext = React.createContext({
|
||||
previewPath: null, setPreviewPath: null, previewModal: null, setPreviewModal: null,
|
||||
previewFile: null, setPreviewFile: null, previewModal: null, setPreviewModal: null,
|
||||
});
|
||||
|
||||
export function FilePreviewWrapper({children}) {
|
||||
const [previewPath, setPreviewPath] = React.useState(null);
|
||||
const [previewFile, setPreviewFile] = React.useState(null);
|
||||
const [previewModal, setPreviewModal] = React.useState(null);
|
||||
|
||||
const value = {
|
||||
previewPath, setPreviewPath, previewModal, setPreviewModal,
|
||||
previewFile, setPreviewFile, previewModal, setPreviewModal,
|
||||
};
|
||||
|
||||
function setModalContent(content, url, downloadURL) {
|
||||
|
|
@ -85,38 +85,36 @@ export function FilePreviewWrapper({children}) {
|
|||
{downloadURL &&
|
||||
<SButton color='yellow' onClick={() => window.open(downloadURL)} floated='left'>Download</SButton>}
|
||||
<SButton color='blue' onClick={() => window.open(url)}>Open</SButton>
|
||||
<SButton onClick={() => setPreviewPath(null)}>Close</SButton>
|
||||
<SButton onClick={() => setPreviewFile(null)}>Close</SButton>
|
||||
</ModalActions>
|
||||
</Modal>);
|
||||
}
|
||||
|
||||
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 (previewFile && !_.isEmpty(previewFile)) {
|
||||
const {mimetype, size} = previewFile;
|
||||
console.debug(`useFilePreview path=${previewFile['path']} mimetype=${mimetype}`);
|
||||
const url = getMediaPathURL(previewFile);
|
||||
const downloadURL = getDownloadPathURL(previewFile);
|
||||
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(previewPath), url, downloadURL);
|
||||
setModalContent(getIframeModal(previewFile), url, downloadURL);
|
||||
} else if (mimetype.startsWith('video/')) {
|
||||
setModalContent(getVideoModal(previewPath), url, downloadURL);
|
||||
setModalContent(getVideoModal(previewFile), url, downloadURL);
|
||||
} else if (mimetype.startsWith('application/epub')) {
|
||||
const viewerURL = getEpubViewerURL(previewPath);
|
||||
console.dir(previewPath);
|
||||
console.log(viewerURL);
|
||||
setModalContent(getEpubModal(previewPath), viewerURL, downloadURL);
|
||||
const viewerURL = getEpubViewerURL(previewFile);
|
||||
setModalContent(getEpubModal(previewFile), viewerURL, downloadURL);
|
||||
} else if (mimetype.startsWith('image/')) {
|
||||
setModalContent(getImageModal(previewPath), url);
|
||||
setModalContent(getImageModal(previewFile), url);
|
||||
} else {
|
||||
// No special handler for this file type, just open it.
|
||||
window.open(downloadURL);
|
||||
}
|
||||
}
|
||||
}, [previewPath]);
|
||||
}, [previewFile]);
|
||||
|
||||
return <FilePreviewContext.Provider value={value}>
|
||||
{children}
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ function EbookCard({file}) {
|
|||
|
||||
function ImageCard({file}) {
|
||||
const {s} = useContext(ThemeContext);
|
||||
const {setPreviewPath} = React.useContext(FilePreviewContext);
|
||||
const {setPreviewFile} = React.useContext(FilePreviewContext);
|
||||
const url = `/media/${encodeURIComponent(file.path)}`;
|
||||
|
||||
let poster = <FileIcon file={file}/>;
|
||||
|
|
@ -97,7 +97,7 @@ function ImageCard({file}) {
|
|||
poster = <Image wrapped
|
||||
src={url}
|
||||
style={{position: 'relative', width: '100%'}}
|
||||
onClick={() => setPreviewPath(file)}
|
||||
onClick={() => setPreviewFile(file)}
|
||||
/>
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue