About 1,600 more headings, buttons, table columns, status words, placeholders and short messages are translated. Tables of words built when the app loads are now read when they are drawn, so they follow the language, and a test fails if text is translated at load time. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
41 lines
2.0 KiB
TypeScript
41 lines
2.0 KiB
TypeScript
import type { ReactNode } from "react";
|
|
import { IconEye, IconEyeOff } from "@tabler/icons-react";
|
|
import { setCardHidden, useDashboardLayout } from "../utils/dashboardLayout";
|
|
import { t } from "../i18n";
|
|
|
|
/** Whether the person has hidden a dashboard card, whether they are arranging the dashboard, and so whether the card is to be drawn (hidden ones are drawn, dimmed, while arranging). */
|
|
export function useCardState(label: string): { hidden: boolean; editing: boolean; shown: boolean } {
|
|
const { layout, editing } = useDashboardLayout();
|
|
const hidden = layout.hidden.includes(label);
|
|
return { hidden, editing, shown: !hidden || editing };
|
|
}
|
|
|
|
/** The bar above a card while the dashboard is being arranged: its name and a button to hide it or bring it back. */
|
|
export function HideBar({ label, hidden }: { label: string; hidden: boolean }) {
|
|
return (
|
|
<div className="card-customise">
|
|
<span className="small text-secondary">{label}</span>
|
|
<button type="button" className="btn btn-sm ms-auto d-inline-flex align-items-center gap-1" aria-pressed={hidden} onClick={() => void setCardHidden(label, !hidden)}>
|
|
{hidden ? <IconEye size={16} aria-hidden="true" /> : <IconEyeOff size={16} aria-hidden="true" />}
|
|
{hidden ? "Show" : t("Hide")}
|
|
<span className="visually-hidden"> {label}</span>
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* A card at the top of the dashboard that the person can hide. Hidden, it is gone; while they arrange the dashboard (Customise) it is there, dimmed, under a bar that hides it or brings it back.
|
|
* It is kept the same way as the other cards' arrangement — on their user record, so it follows them to any browser — and Reset to default shows it again.
|
|
*/
|
|
export default function Hideable({ label, children }: { label: string; children: ReactNode }) {
|
|
const { hidden, editing, shown } = useCardState(label);
|
|
if (!shown) return null;
|
|
return (
|
|
<div className={`hideable ${hidden ? "card-hidden" : ""}`}>
|
|
{editing && <HideBar label={label} hidden={hidden} />}
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|