Zeige den Bezug zwischen Schreiben und lies eine E-Mail vor dem Uebernehmen.
Deploy Development / deploy (push) Successful in 27s
Test Suite / pytest-backend (push) Successful in 1m10s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 8s

Die Liste behaelt die Schreiben dazwischen. Richtung, Absender, Empfaenger und Anhaenge bleiben an der Nachricht erkennbar.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-17 17:27:17 +02:00
1 parent 97bffc6175
commit f27df3ff35
19 files changed
+1049 -49

No files matched your search

+110 -15
View File
@@ -1,13 +1,62 @@
import { useEffect, useRef, useState } from "react";
import { documentToText, fetchFile, fetchPaperless, markDirty, textToDocument, api } from "../api.js";
import { ErrorNote } from "./widgets.jsx";
import { formatDate, kindLabel } from "./content.jsx";
import { elementFacts, formatDate } from "./content.jsx";
import { NavIcon } from "./icons.jsx";
import workerSrc from "pdfjs-dist/build/pdf.worker.min.mjs?url";
const SCALES = [0.75, 1, 1.25, 1.5, 2];
export function ReadingPane({ binding, context, backLabel, onClose, onReload, canDetach, canDestroy }) {
function MailAttachments({ files }) {
if (!files?.length) return <p className="muted">Keine Anhänge.</p>;
return (
<ul className="mail-files">
{files.map((file) => <li key={file.filename}>{file.filename}</li>)}
</ul>
);
}
function Correspondence({ element, onOpenRelated }) {
const refers = element.refers_to || [];
const replies = element.referred_by || [];
if (!refers.length && !replies.length) return null;
const current = {
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),
current: true,
};
const seen = new Set();
const items = [];
for (const item of [...refers, current, ...replies]) {
if (seen.has(item.id)) continue;
seen.add(item.id);
items.push({ ...item, current: item.id === element.id });
}
items.sort((left, right) => String(left.document_on || "9999-99-99").localeCompare(String(right.document_on || "9999-99-99")));
return (
<section className="schriftwechsel" aria-label="Schriftwechsel">
<h3>Schriftwechsel</h3>
<p>Verbundene Schreiben bleiben als Bezug sichtbar. Weitere Schreiben, die dazwischen ein- oder ausgegangen sind, bleiben in der Liste an ihrer eigenen Stelle.</p>
{items.map((item) => (
<button
key={item.id}
type="button"
className={item.current ? "schriftwechsel__item is-current" : "schriftwechsel__item"}
disabled={item.current || !onOpenRelated}
onClick={() => onOpenRelated?.(item.id)}
>
<span>{formatDate(item.document_on)}</span>
<strong>{item.current ? `${item.title} · diese Unterlage` : item.title}</strong>
<em>{item.direction === "out" ? "Ausgang" : item.direction === "in" ? "Eingang" : ""}</em>
</button>
))}
</section>
);
}
export function ReadingPane({ binding, context, backLabel, onClose, onReload, canDetach, canDestroy, onOpenRelated }) {
const element = binding?.element;
const [error, setError] = useState("");
const [phase, setPhase] = useState("idle");
@@ -21,8 +70,11 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
const [note, setNote] = useState("");
const [summary, setSummary] = useState("");
const [documentOn, setDocumentOn] = useState("");
const [sentOn, setSentOn] = useState("");
const [receivedOn, setReceivedOn] = useState("");
const [notice, setNotice] = useState("");
const [annotate, setAnnotate] = useState(false);
const [letter, setLetter] = useState(null);
const canvasRef = useRef(null);
const closeRef = useRef(null);
@@ -34,6 +86,8 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
if (!element) return undefined;
setText(element.kind === "note" ? documentToText(element.document) : "");
setDocumentOn(element.dates?.document_on || "");
setSentOn(element.dates?.sent_on || "");
setReceivedOn(element.dates?.received_on || "");
setSummary(element.summary || "");
setError("");
setNotice("");
@@ -41,16 +95,18 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
setPdf(null);
setPages(0);
setMedia("");
setPhase(element.kind === "note" ? "ready" : element.preview?.available ? "loading" : "missing");
setLetter(null);
const mail = element.external?.source === "imap";
setPhase(element.kind === "note" || mail ? "ready" : element.preview?.available ? "loading" : "missing");
return undefined;
}, [element?.id, element?.version]);
useEffect(() => {
if (!element || element.kind === "note" || !element.preview?.available) return undefined;
if (!element || element.kind === "note" || element.external?.source === "imap" || !element.preview?.available) return undefined;
let alive = true;
let url = "";
setPhase("loading");
const load = element.kind === "external_ref" ? fetchPaperless(element.id, context) : fetchFile(element.id, context);
const load = element.external?.source === "paperless" ? fetchPaperless(element.id, context) : fetchFile(element.id, context);
load.then(async (blob) => {
if (!alive) return;
url = URL.createObjectURL(blob);
@@ -93,7 +149,27 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
alive = false;
if (url) URL.revokeObjectURL(url);
};
}, [element?.id, element?.preview?.available, context?.kind, context?.id]);
}, [element?.id, element?.kind, element?.external?.source, element?.preview?.available, context?.kind, context?.id]);
useEffect(() => {
if (!element || element.external?.source !== "imap") return undefined;
let alive = true;
const params = new URLSearchParams();
if (context?.kind && context?.id) {
params.set("context_kind", context.kind);
params.set("context_id", context.id);
}
api(`/api/v1/external-refs/${element.id}/mail?${params}`)
.then((data) => {
if (alive) setLetter(data);
})
.catch(() => {
if (alive) setLetter(null);
});
return () => {
alive = false;
};
}, [element?.id, element?.external?.source, context?.kind, context?.id]);
useEffect(() => () => {
pdf?.destroy?.();
@@ -143,7 +219,7 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
async function openOriginal() {
setError("");
try {
const blob = element.kind === "external_ref"
const blob = element.external?.source === "paperless"
? await fetchPaperless(element.id, context)
: await fetchFile(element.id, context);
const url = URL.createObjectURL(blob);
@@ -194,8 +270,8 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
body: {
expected_version: element.version,
document_on: documentOn || null,
sent_on: element.dates?.sent_on || null,
received_on: element.dates?.received_on || null,
sent_on: sentOn || null,
received_on: receivedOn || null,
context,
},
});
@@ -249,11 +325,9 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
);
}
const typeLabel = element.kind === "file" && element.file?.content_type === "application/pdf"
? "PDF"
: element.kind === "external_ref"
? (element.external?.source === "imap" ? "E-Mail" : kindLabel(element.kind))
: kindLabel(element.kind);
const typeLabel = elementFacts(element);
const isMail = element.external?.source === "imap";
const mailDetail = letter || element.external?.detail || {};
return (
<section className="reader-pane" aria-label="Leser">
@@ -266,7 +340,7 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
<p>{formatDate(element.dates?.document_on)} · {typeLabel}</p>
</div>
<div className="reader-pane__tools">
{element.kind !== "note" ? (
{element.kind !== "note" && !isMail ? (
<button type="button" className="icon-button" aria-label="Original öffnen" onClick={openOriginal}>
<NavIcon name="link" />
</button>
@@ -278,6 +352,19 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
</header>
<div className="reader-pane__stage">
<ErrorNote error={error} />
<Correspondence element={element} onOpenRelated={onOpenRelated} />
{isMail ? (
<article className="mail-letter">
<p>{mailDetail.direction === "out" ? "Ausgang" : "Eingang"}</p>
<p><span>Von</span> {mailDetail.message_from || "Ohne Absender"}</p>
<p><span>An</span> {mailDetail.message_to || "Ohne Empfänger"}</p>
{mailDetail.message_cc ? <p><span>Kopie</span> {mailDetail.message_cc}</p> : null}
<MailAttachments files={mailDetail.attachments} />
{letter?.text ? <pre className="mail-letter__body">{letter.text}</pre> : (
<p className="muted">Der Text wird aus dem Postfach geladen, sobald das Konto erreichbar ist. Absender und Empfänger bleiben an der E-Mail gespeichert.</p>
)}
</article>
) : null}
{element.kind === "note" ? (
<form className="reader-note" onSubmit={saveNote}>
<label>
@@ -368,6 +455,14 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
{element.kind === "note" ? "Bezugsdatum, optional" : "Dokumentdatum, optional"}
<input type="date" value={documentOn} onChange={(event) => { setDocumentOn(event.target.value); markDirty(true); }} />
</label>
<label>
Versand, optional
<input type="date" value={sentOn} onChange={(event) => { setSentOn(event.target.value); markDirty(true); }} />
</label>
<label>
Zugang, optional
<input type="date" value={receivedOn} onChange={(event) => { setReceivedOn(event.target.value); markDirty(true); }} />
</label>
<button type="submit" className="quiet">Datum speichern</button>
</form>
) : null}