no redux
This commit is contained in:
@@ -8,8 +8,43 @@ import PictureAsPdfIcon from '@mui/icons-material/PictureAsPdf';
|
||||
import SyncIcon from '@mui/icons-material/Sync';
|
||||
import DeleteOutlineOutlinedIcon from '@mui/icons-material/DeleteOutlineOutlined';
|
||||
import { tileBaseSx, TILE_SIZE } from 'dashgui/tiles';
|
||||
import { generateTextThumbnail } from '../../utils/textThumbnail';
|
||||
|
||||
export class Attachment extends PureComponent {
|
||||
state = {
|
||||
generatedThumbnail: null,
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
this.ensureThumbnail();
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (this.props.attachment !== prevProps.attachment) {
|
||||
this.ensureThumbnail();
|
||||
}
|
||||
}
|
||||
|
||||
async ensureThumbnail() {
|
||||
const { attachment } = this.props;
|
||||
if (!attachment || attachment.thumbnail) return;
|
||||
const isCsv = attachment.type === 'text/csv' || attachment.name?.toLowerCase().endsWith('.csv');
|
||||
const isText = attachment.type?.startsWith('text/') || attachment.name?.toLowerCase().endsWith('.txt') || isCsv;
|
||||
if (!isText) return;
|
||||
|
||||
const source = attachment.text || attachment.file;
|
||||
if (!source) return;
|
||||
|
||||
try {
|
||||
const thumb = await generateTextThumbnail(source);
|
||||
if (thumb && this.props.attachment === attachment) {
|
||||
this.setState({ generatedThumbnail: thumb });
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Fehler beim Generieren des Text-Thumbnails:', err);
|
||||
}
|
||||
}
|
||||
|
||||
handleRescan = (e) => {
|
||||
e?.stopPropagation?.();
|
||||
const { attachment, onRescan } = this.props;
|
||||
@@ -56,7 +91,7 @@ export class Attachment extends PureComponent {
|
||||
|
||||
render() {
|
||||
const { attachment, disabled, sx } = this.props;
|
||||
const thumbnail = attachment?.thumbnail;
|
||||
const thumbnail = attachment?.thumbnail || this.state.generatedThumbnail;
|
||||
const name = attachment?.name || 'Dokument';
|
||||
const size = attachment?.size;
|
||||
const isPdf = attachment?.type === 'application/pdf' || name.toLowerCase().endsWith('.pdf');
|
||||
|
||||
Reference in New Issue
Block a user