Halte die gewaehlte Inhaltsliste beim Oeffnen und mache Typ sowie das Logo auf dunkler Flaeche aus der Lieferung erkennbar.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
dc8a9c2db6
commit
97bffc6175
71 files changed
+572
-142
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import workerSrc from "pdfjs-dist/build/pdf.worker.min.mjs?url";
|
||||
import { api, fetchFile, fetchPaperless } from "../api.js";
|
||||
import { contentSourceSymbol, contentSymbol } from "../content-symbol.mjs";
|
||||
import { Modal } from "./Modal.jsx";
|
||||
import { ErrorNote } from "./widgets.jsx";
|
||||
|
||||
@@ -220,82 +220,89 @@ export function WorkSwitch({ view, onView }) {
|
||||
);
|
||||
}
|
||||
|
||||
const SYMBOL_LABEL = {
|
||||
pdf: "PDF",
|
||||
document: "Textdokument",
|
||||
note: "Notiz",
|
||||
email: "E-Mail",
|
||||
image: "Bild",
|
||||
audio: "Audio",
|
||||
video: "Video",
|
||||
spreadsheet: "Tabelle",
|
||||
presentation: "Präsentation",
|
||||
archive: "Archiv",
|
||||
link: "Verweis",
|
||||
attachment: "Anhang",
|
||||
file: "Datei",
|
||||
code: "Code",
|
||||
};
|
||||
|
||||
function elementSymbol(element) {
|
||||
if (element?.external?.source === "imap") return "email";
|
||||
return contentSymbol(element || {});
|
||||
}
|
||||
|
||||
function sourceLabel(element) {
|
||||
if (element.kind === "note") return "Notiz";
|
||||
if (element.kind === "external_ref") return element.external?.source === "paperless" ? "Paperless" : "Referenz";
|
||||
if (element.file?.content_type === "application/pdf") return "PDF";
|
||||
if (element.file?.content_type?.startsWith("image/")) return "Bild";
|
||||
if (element.kind === "file") return "Datei";
|
||||
return kindLabel(element.kind);
|
||||
const type = SYMBOL_LABEL[elementSymbol(element)] || "Datei";
|
||||
if (element.external?.source === "paperless") return `${type} · Paperless`;
|
||||
if (element.external?.source === "imap") return "E-Mail";
|
||||
if (element.kind === "external_ref" && type === "Verweis") return "Referenz";
|
||||
return type;
|
||||
}
|
||||
|
||||
function blurb(element) {
|
||||
return element.summary || element.excerpt || "";
|
||||
}
|
||||
|
||||
function PdfThumb({ url, title }) {
|
||||
const canvasRef = useRef(null);
|
||||
const [failed, setFailed] = useState(false);
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
let doc;
|
||||
(async () => {
|
||||
try {
|
||||
const pdfjs = await import("pdfjs-dist");
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;
|
||||
const bytes = await fetch(url).then((response) => response.arrayBuffer());
|
||||
doc = await pdfjs.getDocument({ data: bytes }).promise;
|
||||
const pdfPage = await doc.getPage(1);
|
||||
if (!alive || !canvasRef.current) return;
|
||||
const base = pdfPage.getViewport({ scale: 1 });
|
||||
const viewport = pdfPage.getViewport({ scale: 148 / base.width });
|
||||
const canvas = canvasRef.current;
|
||||
canvas.width = viewport.width;
|
||||
canvas.height = viewport.height;
|
||||
await pdfPage.render({ canvasContext: canvas.getContext("2d"), viewport }).promise;
|
||||
} catch {
|
||||
if (alive) setFailed(true);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
alive = false;
|
||||
doc?.destroy?.();
|
||||
};
|
||||
}, [url]);
|
||||
if (failed) return <span className="thumb thumb--empty">Vorschau nicht verfügbar</span>;
|
||||
return <canvas ref={canvasRef} className="thumb thumb--pdf" aria-label={`Vorschau ${title}`} />;
|
||||
function TypeGlyph({ name, tone, size = 28 }) {
|
||||
return (
|
||||
<img
|
||||
className={tone === "dark" ? "type-glyph type-glyph--dark" : "type-glyph type-glyph--light"}
|
||||
src={`/ui/content-symbols-v1/${tone}/${name}.svg`}
|
||||
width={size}
|
||||
height={size}
|
||||
alt=""
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function Thumb({ element, context }) {
|
||||
function EntryMark({ element, context }) {
|
||||
const symbol = elementSymbol(element);
|
||||
const photo = symbol === "image" && Boolean(element.preview?.available);
|
||||
const [url, setUrl] = useState("");
|
||||
const [media, setMedia] = useState("");
|
||||
const [failed, setFailed] = useState(false);
|
||||
useEffect(() => {
|
||||
if (!element.preview?.available) return undefined;
|
||||
if (!photo) return undefined;
|
||||
let alive = true;
|
||||
let current = "";
|
||||
const load = element.preview.source === "paperless" ? fetchPaperless(element.id, context) : fetchFile(element.id, context);
|
||||
load.then((blob) => {
|
||||
if (!alive) return;
|
||||
if (!alive || !blob.type.startsWith("image/")) return;
|
||||
current = URL.createObjectURL(blob);
|
||||
setUrl(current);
|
||||
if (blob.type.startsWith("image/")) setMedia("image");
|
||||
else if (blob.type.includes("pdf")) setMedia("pdf");
|
||||
else setMedia("other");
|
||||
}).catch(() => {
|
||||
if (alive) setFailed(true);
|
||||
if (alive) setUrl("");
|
||||
});
|
||||
return () => {
|
||||
alive = false;
|
||||
if (current) URL.revokeObjectURL(current);
|
||||
};
|
||||
}, [element.id, element.preview?.available, element.preview?.source, context?.kind, context?.id]);
|
||||
if (element.kind === "note") return <span className="thumb thumb--note">Notiz</span>;
|
||||
if (url && media === "image") return <img className="thumb" alt="" src={url} />;
|
||||
if (url && media === "pdf") return <PdfThumb url={url} title={element.title} />;
|
||||
if (failed) return <span className="thumb thumb--empty">Vorschau nicht verfügbar</span>;
|
||||
if (element.preview?.available) return <span className="thumb thumb--empty">Vorschau wird geladen</span>;
|
||||
return <span className="thumb thumb--empty">Keine Vorschau</span>;
|
||||
}, [photo, element.id, element.preview?.source, context?.kind, context?.id]);
|
||||
return (
|
||||
<span className={url ? "entry-mark entry-mark--photo" : "entry-mark"}>
|
||||
{url ? <img className="entry-mark__photo" alt="" src={url} /> : (
|
||||
<>
|
||||
<TypeGlyph name={symbol} tone="light" />
|
||||
<TypeGlyph name={symbol} tone="dark" />
|
||||
</>
|
||||
)}
|
||||
{url ? (
|
||||
<span className="entry-mark__badge">
|
||||
<TypeGlyph name="image" tone="light" size={14} />
|
||||
<TypeGlyph name="image" tone="dark" size={14} />
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export async function saveChapterOrder({ containerKind, containerId, record, context, ids }) {
|
||||
@@ -703,6 +710,7 @@ export function ContentBoard({
|
||||
const movable = canMoveChapters && section.id !== "loose";
|
||||
const fromIndex = chapters.findIndex((chapter) => chapter.id === draggingId);
|
||||
const classes = ["content-section"];
|
||||
if (!onlyChapter && section.title) classes.push("content-section--group");
|
||||
if (draggingId === section.id) classes.push("is-dragging");
|
||||
if (!expanded) classes.push("is-collapsed");
|
||||
const insertBefore = indicator?.kind === "chapter" && fromIndex > indicator.index && chapterIndex === indicator.index;
|
||||
@@ -721,7 +729,7 @@ export function ContentBoard({
|
||||
draggable={movable && !pending}
|
||||
onPointerDownCapture={(event) => {
|
||||
if (!movable) return;
|
||||
if (event.target.closest("input, textarea, select, a, label, .chapter-move")) return;
|
||||
if (event.target.closest("input, textarea, select, a, label, .chapter-move, .chapter-date")) return;
|
||||
beginDrag(event, { kind: "chapter", chapterId: section.id });
|
||||
}}
|
||||
onDragStart={(event) => {
|
||||
@@ -742,25 +750,28 @@ export function ContentBoard({
|
||||
</span>
|
||||
) : null}
|
||||
<h3 className="chapter-title">{section.title}</h3>
|
||||
{section.documentOn ? <span className="muted">{formatDate(section.documentOn)}</span> : null}
|
||||
{section.id !== "loose" ? (
|
||||
<span className="chapter-date">
|
||||
<span className="chapter-date__label">Kapiteldatum</span>
|
||||
{canSort ? (
|
||||
<input
|
||||
type="date"
|
||||
aria-label={`Kapiteldatum für ${section.title}`}
|
||||
value={section.documentOn || ""}
|
||||
disabled={pending}
|
||||
onChange={(event) => saveChapterDate(section.id, event.target.value)}
|
||||
/>
|
||||
) : (
|
||||
<span className="chapter-date__value">{section.documentOn ? formatDate(section.documentOn) : "ohne Datum"}</span>
|
||||
)}
|
||||
</span>
|
||||
) : null}
|
||||
{movable ? (
|
||||
<span className="chapter-move">
|
||||
<button type="button" className="quiet" aria-label={`${section.title} nach oben`} disabled={pending || chapters[0]?.id === section.id} onClick={() => moveChapter(section.id, -1)}>Nach oben</button>
|
||||
<button type="button" className="quiet" aria-label={`${section.title} nach unten`} disabled={pending || chapters[chapters.length - 1]?.id === section.id} onClick={() => moveChapter(section.id, 1)}>Nach unten</button>
|
||||
</span>
|
||||
) : null}
|
||||
{canSort && section.id !== "loose" ? (
|
||||
<label className="chapter-date">
|
||||
Datum
|
||||
<input
|
||||
type="date"
|
||||
aria-label={`Datum für ${section.title}`}
|
||||
value={section.documentOn || ""}
|
||||
disabled={pending}
|
||||
onChange={(event) => saveChapterDate(section.id, event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
{expanded && section.title && !section.items.length ? <p className="muted">Noch nichts in diesem Kapitel.</p> : null}
|
||||
@@ -769,6 +780,7 @@ export function ContentBoard({
|
||||
const element = binding.element;
|
||||
const href = itemHref(binding);
|
||||
const text = blurb(element);
|
||||
const sourceSymbol = contentSourceSymbol(element);
|
||||
return (
|
||||
<li key={binding.id} data-binding={binding.id} className={`preview-row${draggingId === binding.id ? " is-dragging" : ""}${selectedId === binding.id ? " is-selected" : ""}`}>
|
||||
{indicator?.sectionId === section.id && indicator?.kind !== "chapter" && indicator.index === index ? <div className="insert-line" /> : null}
|
||||
@@ -791,7 +803,7 @@ export function ContentBoard({
|
||||
<span className="handle__grip" aria-hidden="true" />
|
||||
</button>
|
||||
) : null}
|
||||
<Thumb element={element} context={context} />
|
||||
<EntryMark element={element} context={context} />
|
||||
<Link
|
||||
className="preview-row__main"
|
||||
to={href}
|
||||
@@ -803,7 +815,15 @@ export function ContentBoard({
|
||||
}}
|
||||
>
|
||||
<strong>{element.title}</strong>
|
||||
<span className="preview-row__meta">{formatDate(fachDate(element))} · {sourceLabel(element)}</span>
|
||||
<span className="preview-row__meta">
|
||||
{sourceSymbol ? (
|
||||
<span className="source-mark">
|
||||
<TypeGlyph name={sourceSymbol} tone="light" size={16} />
|
||||
<TypeGlyph name={sourceSymbol} tone="dark" size={16} />
|
||||
</span>
|
||||
) : null}
|
||||
{formatDate(fachDate(element))} · {sourceLabel(element)}
|
||||
</span>
|
||||
{text ? <span className="preview-row__text">{text}</span> : null}
|
||||
{binding.origin ? <span className="preview-row__origin">{binding.origin}{binding.shared ? " · weitere Einbindung" : ""}</span> : null}
|
||||
{!onlyChapter && !binding.origin && binding.chapter_id ? (
|
||||
|
||||
Reference in new issue
Block a user