From 562c0848b13c21c233742c47168d0517db38b0a1 Mon Sep 17 00:00:00 2001 From: Lars Date: Sun, 18 Oct 2026 17:35:48 +0200 Subject: [PATCH] =?UTF-8?q?Schlie=C3=9Fe=20den=20Leser,=20wenn=20eine=20en?= =?UTF-8?q?tfernte=20Datei=20die=20Navigation=20ausblendet.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- frontend/src/pages/Cases.jsx | 16 +++++++++--- frontend/src/pages/Matters.jsx | 18 ++++++++++---- frontend/src/pages/ReadingPane.jsx | 29 ++++++++++++++++------ frontend/src/pages/Shell.jsx | 39 +++++++++++++++++++++++++++--- frontend/src/pages/content.jsx | 37 ++++++++++++++++------------ 5 files changed, 104 insertions(+), 35 deletions(-) diff --git a/frontend/src/pages/Cases.jsx b/frontend/src/pages/Cases.jsx index 69cc7d2..ec4f1f1 100644 --- a/frontend/src/pages/Cases.jsx +++ b/frontend/src/pages/Cases.jsx @@ -209,12 +209,12 @@ function chapterOrigin(base, chapters, chapterId) { function mergedCaseItems(record, direction, caseId) { const rows = [ - ...(record.bindings || []).map((binding) => ({ + ...(record.bindings || []).filter((binding) => binding?.element).map((binding) => ({ ...binding, origin: chapterOrigin("Direkt in dieser Akte", record.chapters, binding.chapter_id), readerHref: `/cases/${caseId}?eintrag=${binding.id}${binding.chapter_id ? `&kapitel=${binding.chapter_id}` : ""}`, })), - ...(record.contained || []).flatMap((group) => (group.bindings || []).map((binding) => ({ + ...(record.contained || []).flatMap((group) => (group.bindings || []).filter((binding) => binding?.element).map((binding) => ({ ...binding, origin: chapterOrigin(matterOrigin(group), group.chapters, binding.chapter_id), readerHref: `/matters/${group.matter_id}?context_kind=case&context_id=${caseId}&eintrag=${binding.id}${binding.chapter_id ? `&kapitel=${binding.chapter_id}` : ""}`, @@ -396,6 +396,14 @@ export function CaseDetail() { } }, [record, id, rawScope, overview, chapterId, params, setParams, navigate]); + useEffect(() => { + if (!record || record.id !== id || overview || !entryId) return; + if ((record.bindings || []).some((item) => item.id === entryId)) return; + const updated = new URLSearchParams(params); + updated.delete("eintrag"); + setParams(updated, { replace: true }); + }, [record, id, overview, entryId, params, setParams]); + useEffect(() => { if (entryId) return; restoreScroll(listRef.current, `tsumugu-scroll:case:${id}:${chapterId}:${overview ? "over" : "direct"}`); @@ -486,7 +494,7 @@ export function CaseDetail() { width={width} structureOpen={structureOpen} setStructureOpen={setStructureOpen} - hasEntry={Boolean(entryId) && !overview} + hasEntry={Boolean(entry) && !overview} listRef={listRef} nav={( setStructureOpen(false) : null} /> )} - reader={entryId && !overview ? ( + reader={entry ? ( ({ id: item.case_id, - title: item.label.replaceAll("Unterakte ", "").replaceAll("Akte ", "").replaceAll(" → ", " / "), + title: String(item.label || "Akte").replaceAll("Unterakte ", "").replaceAll("Akte ", "").replaceAll(" → ", " / "), kind: "Akte", href: `/matters/${record.id}?context_kind=case&context_id=${item.case_id}`, current: false, @@ -328,6 +328,14 @@ export function MatterDetail() { }; }, [inherited?.kind, inherited?.id]); + useEffect(() => { + if (!record || record.id !== id || !entryId) return; + if ((record.bindings || []).some((item) => item.id === entryId)) return; + const updated = new URLSearchParams(params); + updated.delete("eintrag"); + setParams(updated, { replace: true }); + }, [record, id, entryId, params, setParams]); + useEffect(() => { if (entryId) return; restoreScroll(listRef.current, `tsumugu-scroll:${id}:${chapterId}`); @@ -408,10 +416,10 @@ export function MatterDetail() { })); const contexts = (record.placements || []).map((item) => ({ id: item.case_id, - label: item.label.replaceAll("Unterakte ", "").replaceAll("Akte ", "").replaceAll(" → ", " / "), + label: String(item.label || "Akte").replaceAll("Unterakte ", "").replaceAll("Akte ", "").replaceAll(" → ", " / "), })); const contextValue = inherited?.kind === "case" ? inherited.id : (contexts.length === 1 ? contexts[0].id : ""); - const nodes = caseTree ? caseNodes(caseTree, parentTree, id, inherited.id) : placementNodes(record); + const nodes = caseTree && inherited ? caseNodes(caseTree, parentTree, id, inherited.id) : placementNodes(record); const links = [ ...(record.cross_links || []).map((item) => ({ id: `cross-${item.id}`, @@ -435,7 +443,7 @@ export function MatterDetail() { width={width} structureOpen={structureOpen} setStructureOpen={setStructureOpen} - hasEntry={Boolean(entryId)} + hasEntry={Boolean(entry)} listRef={listRef} nav={( setStructureOpen(false) : null} /> )} - reader={entryId ? ( + reader={entry ? ( { if (!alive) return; - const viewport = pdfPage.getViewport({ scale }); const canvas = canvasRef.current; - const context2d = canvas.getContext("2d"); + const context2d = canvas?.getContext("2d"); + if (!canvas || !context2d) return; + const viewport = pdfPage.getViewport({ scale }); canvas.width = viewport.width; canvas.height = viewport.height; const render = pdfPage.render({ canvasContext: context2d, viewport }); @@ -440,16 +441,28 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca const search = new URLSearchParams(); search.set("context_kind", context.kind); search.set("context_id", context.id); - await api(`/api/v1/bindings/${binding.id}?${search}`, { method: "DELETE" }); - onClose(); - onReload(); + setError(""); + try { + await api(`/api/v1/bindings/${binding.id}?${search}`, { method: "DELETE" }); + markDirty(false); + onClose(); + onReload(); + } catch (err) { + setError(err.message); + } } async function destroy() { if (!window.confirm("Überall löschen? Alle Einbindungen verschwinden. Eine Paperless-Quelle bleibt unangetastet.")) return; - await api(`/api/v1/elements/${element.id}/delete`, { method: "POST", body: { expected_version: element.version } }); - onClose(); - onReload(); + setError(""); + try { + await api(`/api/v1/elements/${element.id}/delete`, { method: "POST", body: { expected_version: element.version } }); + markDirty(false); + onClose(); + onReload(); + } catch (err) { + setError(err.message); + } } if (!binding) { diff --git a/frontend/src/pages/Shell.jsx b/frontend/src/pages/Shell.jsx index 94fec86..e8f57f0 100644 --- a/frontend/src/pages/Shell.jsx +++ b/frontend/src/pages/Shell.jsx @@ -1,5 +1,5 @@ -import { useContext, useEffect, useRef, useState } from "react"; -import { NavLink, Outlet, useNavigate } from "react-router-dom"; +import { Component, useContext, useEffect, useRef, useState } from "react"; +import { NavLink, Outlet, useLocation, useNavigate } from "react-router-dom"; import { SessionContext } from "../session.js"; import { Mark, NavIcon } from "./icons.jsx"; @@ -24,9 +24,40 @@ const MOBILE = [ { to: "/search", label: "Suche", short: "Suche", icon: "search" }, ]; +class PageBoundary extends Component { + constructor(props) { + super(props); + this.state = { failed: false }; + } + + static getDerivedStateFromError() { + return { failed: true }; + } + + componentDidUpdate(previous) { + if (previous.resetKey !== this.props.resetKey && this.state.failed) { + this.setState({ failed: false }); + } + } + + render() { + if (this.state.failed) { + return ( +
+

Die Ansicht ist abgebrochen.

+

Die Navigation bleibt verfügbar. Öffne die Seite erneut oder wechsle über das Menü.

+ +
+ ); + } + return this.props.children; + } +} + export function Shell() { const { session, logout } = useContext(SessionContext); const navigate = useNavigate(); + const location = useLocation(); const [expanded, setExpanded] = useState(() => { try { return localStorage.getItem(NAV_KEY) !== "0"; @@ -170,7 +201,9 @@ export function Shell() { ) : null}
- + + +