u
This commit is contained in:
@@ -47,6 +47,7 @@ import { generateTextThumbnail } from '../../utils/textThumbnail';
|
||||
import { extractPdfText } from '../../utils/pdfText';
|
||||
import { getDeliveryEditorAutomat } from '../../automats/deliveryEditorAutomat';
|
||||
import { setLastDeliveryPath, userSettingsAutomat, setViewerPosition } from '../../automats';
|
||||
import chatAutomat from '../../automats/chatAutomat';
|
||||
|
||||
import { fetchDeliveryLedgerSummary } from '../../utils/deliveryLedger';
|
||||
import {
|
||||
@@ -101,6 +102,7 @@ class LieferungNeuPage extends PureComponent {
|
||||
this.handlePdfUpload = this.handlePdfUpload.bind(this);
|
||||
this.handlePdfRescan = this.handlePdfRescan.bind(this);
|
||||
this.handlePdfDelete = this.handlePdfDelete.bind(this);
|
||||
this.handleMentionInChat = this.handleMentionInChat.bind(this);
|
||||
this.handleAttachmentClick = this.handleAttachmentClick.bind(this);
|
||||
this.handleCloseTextEditor = this.handleCloseTextEditor.bind(this);
|
||||
this.handleTextEditorPositionChange = this.handleTextEditorPositionChange.bind(this);
|
||||
@@ -657,17 +659,20 @@ class LieferungNeuPage extends PureComponent {
|
||||
const existingTxt = this.state.attachments?.find(
|
||||
(a) => a.parentPdfId === attachment.id || a.name === txtName,
|
||||
);
|
||||
let targetTxt = existingTxt;
|
||||
if (existingTxt) {
|
||||
this.automat.actions.updateAttachment({
|
||||
const updated = {
|
||||
id: existingTxt.id,
|
||||
file: txtFile,
|
||||
size: txtFile.size,
|
||||
text,
|
||||
thumbnail: txtThumbnail || existingTxt.thumbnail,
|
||||
isDirty: true,
|
||||
});
|
||||
};
|
||||
this.automat.actions.updateAttachment(updated);
|
||||
targetTxt = { ...existingTxt, ...updated };
|
||||
} else {
|
||||
this.automat.actions.addAttachment({
|
||||
targetTxt = {
|
||||
id: `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
||||
file: txtFile,
|
||||
name: txtFile.name,
|
||||
@@ -677,14 +682,52 @@ class LieferungNeuPage extends PureComponent {
|
||||
text,
|
||||
parentPdfId: attachment.id,
|
||||
uploadedAt: new Date().toISOString(),
|
||||
});
|
||||
};
|
||||
this.automat.actions.addAttachment(targetTxt);
|
||||
}
|
||||
this.handleAttachmentClick(targetTxt);
|
||||
enqueueSnackbar('Text aus PDF extrahiert und geöffnet', { variant: 'success' });
|
||||
} catch (txtErr) {
|
||||
console.error('Fehler beim Aktualisieren der Textdatei:', txtErr);
|
||||
enqueueSnackbar('Fehler beim Extrahieren von Text aus der PDF', { variant: 'error' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async handleMentionInChat(attachment) {
|
||||
if (!attachment) return;
|
||||
let text = attachment.text;
|
||||
if (!text && (!attachment.file || attachment.file.size === 0)) {
|
||||
const file = await this.ensureAttachmentFile(attachment);
|
||||
if (file) {
|
||||
try {
|
||||
text = await file.text();
|
||||
} catch (e) {
|
||||
console.error('Fehler beim Lesen des Texts:', e);
|
||||
}
|
||||
}
|
||||
} else if (!text && (attachment.file instanceof Blob || attachment.file instanceof File)) {
|
||||
try {
|
||||
text = await attachment.file.text();
|
||||
} catch (e) {
|
||||
console.error('Fehler beim Lesen des Texts:', e);
|
||||
}
|
||||
}
|
||||
|
||||
const trimmed = (text || '').trim();
|
||||
if (!trimmed) {
|
||||
enqueueSnackbar('Datei enthält keinen Text zum Erwähnen im Chat.', { variant: 'warning' });
|
||||
return;
|
||||
}
|
||||
|
||||
const size = attachment.size || new Blob([trimmed]).size;
|
||||
chatAutomat.actions.insertExtractionSnippet({
|
||||
text: trimmed,
|
||||
size,
|
||||
});
|
||||
enqueueSnackbar('Text im Chat erwähnt', { variant: 'success' });
|
||||
}
|
||||
|
||||
handlePdfDelete(attachment) {
|
||||
if (!attachment?.id) return;
|
||||
this.automat.actions.removeAttachment(attachment.id);
|
||||
@@ -1058,6 +1101,7 @@ class LieferungNeuPage extends PureComponent {
|
||||
onPdfRescan={this.handlePdfRescan}
|
||||
onPdfDelete={this.handlePdfDelete}
|
||||
onAttachmentClick={this.handleAttachmentClick}
|
||||
onMentionInChat={this.handleMentionInChat}
|
||||
onSave={this.handleSave}
|
||||
onPartyChange={this.handlePartyChange}
|
||||
onDateChange={this.handleDateChange}
|
||||
|
||||
Reference in New Issue
Block a user