Files
Homelab-manager/web/src/components/SetupGuide.tsx
T
bobbanandClaude Sonnet 5.5 645816d5a8 Add a Swedish interface with a per-person language switch
A small translation system (the English text is its own key, so anything
without a Swedish entry stays English) and a Language switch in the user menu,
saved on the account (users.language) and following the browser when no choice
has been made. Swedish covers the menu, shared parts (search, tables, dialogs,
relative times), the sign-in page and the everyday pages: Dashboard, Alerts,
Servers, Updates, Maintenance, My work, Coming up, To do, Integrations and the
display settings. Server-written messages stay English for now.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 21:49:49 +01:00

99 lines
3.5 KiB
TypeScript

import { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { IconCircle, IconCircleCheck, IconX } from "@tabler/icons-react";
import { t } from "../i18n";
export interface SetupStep {
id: string;
title: string;
description: string;
to: string;
/** What to call the button that goes there. */
action: string;
done: boolean;
}
const DISMISSED_KEY = "hlm-setup-dismissed";
export const SHOW_SETUP_EVENT = "show-setup-guide";
function wasDismissed(): boolean {
try {
return localStorage.getItem(DISMISSED_KEY) === "1";
} catch {
return false;
}
}
/**
* A checklist for a new installation, at the top of the dashboard: what to set up, which steps are already done (worked out from
* what exists, never ticked by hand), and a way to put it away. It goes by itself once everything is done.
*/
export default function SetupGuide({ steps }: { steps: SetupStep[] }) {
const [dismissed, setDismissed] = useState(wasDismissed);
// The command palette can bring it back.
useEffect(() => {
const show = () => {
try {
localStorage.removeItem(DISMISSED_KEY);
} catch {
// not remembered; it shows for this visit anyway
}
setDismissed(false);
};
window.addEventListener(SHOW_SETUP_EVENT, show);
return () => window.removeEventListener(SHOW_SETUP_EVENT, show);
}, []);
const done = steps.filter((s) => s.done).length;
if (dismissed || steps.length === 0 || done === steps.length) return null;
const dismiss = () => {
try {
localStorage.setItem(DISMISSED_KEY, "1");
} catch {
// not remembered; it is gone for this visit anyway
}
setDismissed(true);
};
return (
<div className="card mb-3" role="region" aria-labelledby="setup-guide-title">
<div className="card-header">
<div>
<h3 className="card-title" id="setup-guide-title">
{t("Getting started")}
</h3>
<div className="text-secondary small">
{done} of {steps.length} done
</div>
</div>
<div className="card-actions">
<button type="button" className="btn btn-sm btn-ghost-secondary" onClick={dismiss} aria-label={t("Hide the getting started guide")} title={t("Hide this guide (bring it back from the search box: Ctrl K)")}>
<IconX size={16} />
</button>
</div>
</div>
<div className="progress progress-sm rounded-0" role="progressbar" aria-label={t("Setup progress")} aria-valuemin={0} aria-valuemax={steps.length} aria-valuenow={done}>
<div className="progress-bar bg-green" style={{ width: `${(done / steps.length) * 100}%` }} />
</div>
<ul className="list-group list-group-flush">
{steps.map((s) => (
<li key={s.id} className="list-group-item d-flex align-items-center gap-3">
{s.done ? <IconCircleCheck size={22} className="text-green flex-shrink-0" aria-label={t("Done")} /> : <IconCircle size={22} className="text-secondary flex-shrink-0" aria-label={t("Not done yet")} />}
<div className="flex-fill" style={{ minWidth: 0 }}>
<div className={s.done ? "text-secondary" : "fw-medium"}>{s.title}</div>
{!s.done && <div className="text-secondary small">{s.description}</div>}
</div>
{!s.done && (
<Link to={s.to} className="btn btn-sm btn-primary flex-shrink-0">
{s.action}
</Link>
)}
</li>
))}
</ul>
</div>
);
}