Simpl-Resultat/src/components/settings/DocsContent.tsx
le king fu f02fd95ab1
All checks were successful
PR Check / rust (pull_request) Successful in 22m55s
PR Check / frontend (pull_request) Successful in 2m27s
refactor(settings): split monolithic Settings page into 3 sub-pages (#190)
The single 12-card SettingsPage is replaced by a hub at /settings linking
to three thematic sub-pages mounted via a shared SettingsLayout (Outlet):

  /settings           SettingsHomePage     (3 cards-cluster + PageHelp)
  /settings/users     UsersSettingsPage    (Account, License, DocsContent)
  /settings/data      DataSettingsPage     (Categories, DataManagement,
                                            PriceFetchConsentToggle)
  /settings/systems   SystemsSettingsPage  (Version, UpdateCard,
                                            ChangelogContent, LogViewer)

DocsPage and ChangelogPage are extracted into reusable DocsContent /
ChangelogContent components and the standalone /docs and /changelog
routes become Navigate redirects to preserve external bookmarks and
release-note links. UpdateCard is extracted from the inline updater
block for symmetry and testability.

TokenStoreFallbackBanner is mounted once in SettingsLayout, surfacing
the OS-keychain-fallback warning across the four main routes only.
The two existing /settings/categories/{standard,migrate} sub-routes
stay flat (siblings of SettingsLayout) to keep their focused flows
free of the banner — their internal back-links now point to
/settings/data.

i18n FR/EN gain settings.{home, users, data, systems, backToHome};
docs/architecture.md and CHANGELOG{,.fr}.md updated. Pure refactor of
presentation: no new business logic, no Tauri commands, no SQL
migrations.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 09:50:02 -04:00

201 lines
6.4 KiB
TypeScript

import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { useLocation } from "react-router-dom";
import {
Rocket,
LayoutDashboard,
Upload,
ArrowLeftRight,
Tags,
SlidersHorizontal,
PiggyBank,
BarChart3,
Wallet,
Settings,
Lightbulb,
ListChecks,
Footprints,
Printer,
Users,
} from "lucide-react";
const SECTIONS = [
{ key: "gettingStarted", icon: Rocket },
{ key: "profiles", icon: Users },
{ key: "dashboard", icon: LayoutDashboard },
{ key: "import", icon: Upload },
{ key: "transactions", icon: ArrowLeftRight },
{ key: "categories", icon: Tags },
{ key: "adjustments", icon: SlidersHorizontal },
{ key: "budget", icon: PiggyBank },
{ key: "reports", icon: BarChart3 },
{ key: "balance", icon: Wallet },
{ key: "settings", icon: Settings },
] as const;
export default function DocsContent() {
const { t } = useTranslation();
const location = useLocation();
const sectionRefs = useRef<Record<string, HTMLElement | null>>({});
const [activeSection, setActiveSection] = useState<string>(SECTIONS[0].key);
useEffect(() => {
const observer = new IntersectionObserver(
(entries) => {
for (const entry of entries) {
if (entry.isIntersecting) {
setActiveSection(entry.target.id);
}
}
},
{ rootMargin: "-30% 0px -60% 0px", threshold: 0 },
);
for (const { key } of SECTIONS) {
const el = sectionRefs.current[key];
if (el) observer.observe(el);
}
return () => observer.disconnect();
}, []);
useEffect(() => {
const hash = location.hash.replace("#", "");
if (hash && sectionRefs.current[hash]) {
requestAnimationFrame(() => {
sectionRefs.current[hash]?.scrollIntoView({
behavior: "smooth",
block: "start",
});
});
}
}, [location.hash]);
const scrollToSection = (key: string) => {
sectionRefs.current[key]?.scrollIntoView({
behavior: "smooth",
block: "start",
});
};
return (
<div className="space-y-6">
<div className="flex items-center justify-between gap-3">
<h2 className="text-xl font-semibold">{t("docs.title")}</h2>
<button
onClick={() => window.print()}
className="print:hidden flex items-center gap-2 px-3 py-2 text-sm rounded-lg bg-[var(--card)] border border-[var(--border)] text-[var(--muted-foreground)] hover:text-[var(--foreground)] hover:bg-[var(--muted)] transition-colors"
title={t("docs.print")}
>
<Printer size={16} />
{t("docs.print")}
</button>
</div>
<nav
className="print:hidden bg-[var(--card)] border border-[var(--border)] rounded-xl p-3"
aria-label={t("docs.title")}
>
<ul className="flex flex-wrap gap-1">
{SECTIONS.map(({ key, icon: Icon }) => (
<li key={key}>
<button
onClick={() => scrollToSection(key)}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs transition-colors ${
activeSection === key
? "bg-[var(--primary)] text-white font-medium"
: "text-[var(--muted-foreground)] hover:bg-[var(--border)] hover:text-[var(--foreground)]"
}`}
>
<Icon size={13} />
{t(`docs.${key}.title`)}
</button>
</li>
))}
</ul>
</nav>
{SECTIONS.map(({ key, icon: Icon }) => (
<section
key={key}
id={key}
ref={(el) => {
sectionRefs.current[key] = el;
}}
className="bg-[var(--card)] border border-[var(--border)] rounded-xl p-6 space-y-4 scroll-mt-4"
>
<div className="flex items-center gap-3">
<div className="w-9 h-9 rounded-lg bg-[var(--primary)]/10 flex items-center justify-center text-[var(--primary)]">
<Icon size={20} />
</div>
<h3 className="text-lg font-semibold">{t(`docs.${key}.title`)}</h3>
</div>
<p className="text-[var(--muted-foreground)]">
{t(`docs.${key}.overview`)}
</p>
<div>
<h4 className="flex items-center gap-2 text-sm font-semibold uppercase tracking-wider text-[var(--muted-foreground)] mb-2">
<ListChecks size={14} />
{t("docs.features")}
</h4>
<ul className="space-y-1">
{(
t(`docs.${key}.features`, { returnObjects: true }) as string[]
).map((item, i) => (
<li key={i} className="flex items-start gap-2 text-sm">
<span className="text-[var(--primary)] mt-0.5 shrink-0">
&bull;
</span>
{item}
</li>
))}
</ul>
</div>
<div>
<h4 className="flex items-center gap-2 text-sm font-semibold uppercase tracking-wider text-[var(--muted-foreground)] mb-2">
<Footprints size={14} />
{key === "gettingStarted"
? t("docs.quickStart")
: t("docs.howTo")}
</h4>
<ol className="space-y-1 list-decimal list-inside">
{(
t(`docs.${key}.steps`, { returnObjects: true }) as string[]
).map((item, i) => (
<li key={i} className="text-sm">
{item}
</li>
))}
</ol>
</div>
<div className="bg-[var(--background)] rounded-lg p-4">
<h4 className="flex items-center gap-2 text-sm font-semibold uppercase tracking-wider text-[var(--muted-foreground)] mb-2">
<Lightbulb size={14} />
{t("docs.tipsHeader")}
</h4>
<ul className="space-y-1">
{(
t(`docs.${key}.tips`, { returnObjects: true }) as string[]
).map((item, i) => (
<li
key={i}
className="flex items-start gap-2 text-sm text-[var(--muted-foreground)]"
>
<Lightbulb
size={13}
className="text-[var(--primary)] mt-0.5 shrink-0"
/>
{item}
</li>
))}
</ul>
</div>
</section>
))}
</div>
);
}