Halte die Richtung an der einzelnen Einbindung und mach sie in der Uebersicht waehlbar.
Deploy Development / deploy (push) Successful in 28s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-17 20:17:48 +02:00
1 parent 2664021e7f
commit 95381030bc
12 files changed
+185 -52

No files matched your search

+48 -32
View File
@@ -1,7 +1,7 @@
import { useEffect, useRef, useState } from "react";
import { documentToText, downloadMailPart, fetchFile, fetchMailPart, fetchPaperless, markDirty, textToDocument, api } from "../api.js";
import { ErrorNote } from "./widgets.jsx";
import { dateCaption, DirectionChoice, DirectionColumn, directionWord, formatDate, mailFacts, MarkdownEditor, sourceLabel } from "./content.jsx";
import { dateCaption, DirectionChoice, DirectionColumn, directionValue, directionWord, formatDate, mailFacts, MarkdownEditor, sourceLabel } from "./content.jsx";
import { NavIcon } from "./icons.jsx";
import workerSrc from "pdfjs-dist/build/pdf.worker.min.mjs?url";
@@ -22,7 +22,7 @@ function MailAttachments({ files, current, onOpen }) {
{files.map((file) => (
<li key={`${file.index ?? "name"}-${file.filename}`}>
{onOpen && Number.isInteger(file.index) ? (
<button type="button" className={file.index === current ? "quiet is-current" : "quiet"} aria-current={file.index === current ? "true" : undefined} onClick={() => onOpen(file)}>{file.filename}</button>
<button type="button" className={file.index === current ? "quiet is-current" : "quiet"} aria-pressed={file.index === current} onClick={() => onOpen(file)}>{file.filename}</button>
) : file.filename}
</li>
))}
@@ -30,7 +30,7 @@ function MailAttachments({ files, current, onOpen }) {
);
}
function Correspondence({ element, onOpenRelated }) {
function Correspondence({ element, direction, onOpenRelated }) {
const refers = element.refers_to || [];
const replies = element.referred_by || [];
if (!refers.length && !replies.length) return null;
@@ -38,7 +38,7 @@ function Correspondence({ element, onOpenRelated }) {
id: element.id,
title: element.title,
document_on: element.dates?.document_on || null,
direction: element.external?.detail?.direction || (element.dates?.sent_on && !element.dates?.received_on ? "out" : element.dates?.received_on && !element.dates?.sent_on ? "in" : null),
direction: direction || null,
current: true,
};
const seen = new Set();
@@ -90,7 +90,8 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
const [notice, setNotice] = useState("");
const [annotate, setAnnotate] = useState(false);
const [letter, setLetter] = useState(null);
const [shownIndex, setShownIndex] = useState(null);
const [shownFor, setShownFor] = useState(null);
const shownIndex = shownFor?.elementId === element?.id ? shownFor.index : null;
const canvasRef = useRef(null);
const objectUrl = useRef("");
const closeRef = useRef(null);
@@ -106,28 +107,33 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
setSentOn(element.dates?.sent_on || "");
setReceivedOn(element.dates?.received_on || "");
setSummary(element.summary || "");
setError("");
setNotice("");
setPage(1);
setPdf(null);
setPages(0);
setMedia("");
setLetter(null);
setShownIndex(null);
if (objectUrl.current) {
URL.revokeObjectURL(objectUrl.current);
objectUrl.current = "";
}
setBlobUrl("");
const mail = element.external?.source === "imap";
setPhase(element.kind === "note" || mail ? "ready" : element.preview?.available ? "loading" : "missing");
return undefined;
}, [element?.id, element?.version]);
}, [element?.id, element?.version, element?.summary, element?.document, element?.dates?.document_on, element?.dates?.sent_on, element?.dates?.received_on]);
useEffect(() => {
if (!element) return undefined;
const mail = element.external?.source === "imap";
if (element.kind === "note" || mail) setPhase("ready");
else if (!element.preview?.available) setPhase("missing");
setError("");
return undefined;
}, [element?.id, element?.kind, element?.external?.source, element?.preview?.available]);
useEffect(() => {
if (!element || element.kind === "note" || element.external?.source === "imap" || !element.preview?.available) return undefined;
let alive = true;
let url = "";
setPage(1);
setPdf(null);
setPages(0);
setMedia("");
setLetter(null);
if (objectUrl.current) {
URL.revokeObjectURL(objectUrl.current);
objectUrl.current = "";
}
setBlobUrl("");
setPhase("loading");
const load = element.external?.source === "paperless" ? fetchPaperless(element.id, context) : fetchFile(element.id, context);
load.then(async (blob) => {
@@ -175,15 +181,20 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
}, [element?.id, element?.kind, element?.external?.source, element?.preview?.available, context?.kind, context?.id]);
useEffect(() => {
if (!letter?.complete) return undefined;
const files = letter.attachments || [];
const viewable = files.findIndex((file) => previewKind(file.content_type, file.filename) !== "other");
setShownIndex(viewable >= 0 ? files[viewable].index : (files[0] ? files[0].index : null));
return undefined;
}, [letter]);
useEffect(() => {
if (!element || element.external?.source !== "imap" || shownIndex === null) return undefined;
if (!element || element.external?.source !== "imap") return undefined;
if (shownIndex === null) {
setPhase("ready");
setPdf(null);
setPages(0);
setPage(1);
setMedia("");
if (objectUrl.current) {
URL.revokeObjectURL(objectUrl.current);
objectUrl.current = "";
}
setBlobUrl("");
return undefined;
}
const file = (letter?.attachments || []).find((item) => item.index === shownIndex);
if (!file) return undefined;
let alive = true;
@@ -473,7 +484,7 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
</header>
<div className="reader-pane__stage">
<ErrorNote error={error} />
<Correspondence element={element} onOpenRelated={onOpenRelated} />
<Correspondence element={element} direction={shownDirection} onOpenRelated={onOpenRelated} />
{isMail ? (
<article className="mail-letter">
<p className="mail-letter__way"><DirectionColumn direction={shownDirection} />{directionWord(shownDirection) ? <span>{directionWord(shownDirection)}</span> : null}</p>
@@ -482,7 +493,12 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
{mailDetail.message_cc ? <p><span>Kopie</span> {mailDetail.message_cc}</p> : null}
{letter?.complete ? (
<>
<MailAttachments files={letter.attachments} current={shownIndex} onOpen={(file) => { setError(""); setShownIndex(file.index); }} />
<MailAttachments files={letter.attachments} current={shownIndex} onOpen={(file) => {
setError("");
setShownFor((current) => (
current?.elementId === element.id && current.index === file.index ? null : { elementId: element.id, index: file.index }
));
}} />
{shownFile ? <p className="mail-attachment__caption">Anlage: {shownFile.filename}</p> : null}
{shownFile && phase === "loading" ? <p className="muted">Die Anlage wird geladen …</p> : null}
{media === "image" && blobUrl ? (
@@ -516,7 +532,7 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
) : null}
<form className="stack reader-direction" onSubmit={(event) => event.preventDefault()}>
<DirectionChoice
value={communication.explicit ? (communication.direction || "") : (shownDirection || "")}
value={directionValue(communication)}
disabled={!binding.rights.edit}
onChange={saveDirection}
/>