import React from 'react';
import { createRoot } from 'react-dom/client';
import SharedFileView from './components/shared-file-view/shared-file-view';
import SharedFileViewTip from './components/shared-file-view/shared-file-view-tip';
import { Utils } from './utils/utils';
import { gettext, siteRoot } from './utils/constants';
import './css/image-file-view.css';
const { fileName, rawPath, err, prevImgPath, nextImgPath, repoEncrypted, fileExt, filePath, sharedToken, lastModified } = window.shared.pageOptions;
const { thumbnailSizeForOriginal } = window.app.pageOptions;
const prevImgURL = `?p=${encodeURIComponent(prevImgPath)}`;
const nextImgURL = `?p=${encodeURIComponent(nextImgPath)}`;
class SharedFileViewImage extends React.Component {
render() {
return } />;
}
}
class FileContent extends React.Component {
componentDidMount() {
document.addEventListener('keydown', (e) => {
if (prevImgPath && e.keyCode == 37) { // press '<-'
location.href = prevImgURL;
}
if (nextImgPath && e.keyCode == 39) { // press '->'
location.href = nextImgURL;
}
});
}
render() {
if (err) {
return ;
}
// some types of images, the browser can't preview them directly, so we need to get thumbnails for them
let thumbnailURL = '';
const fileExtList = ['tif', 'tiff', 'psd', 'heic'];
if (!repoEncrypted && fileExtList.includes(fileExt)) {
thumbnailURL = `${siteRoot}thumbnail/${sharedToken}/${thumbnailSizeForOriginal}${Utils.encodePath(filePath)}?mtime=${lastModified}`;
}
return (
{prevImgPath && (
)}
{nextImgPath && (
)}
);
}
}
const root = createRoot(document.getElementById('wrapper'));
root.render();