Files
Homelab-manager/web/src/pages/Immich.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

172 lines
7.8 KiB
TypeScript

import { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { api, type ImmichInfo } from "../api/client";
import EmptyState from "../components/EmptyState";
import TimeAgo from "../components/TimeAgo";
import { BlockSkeleton } from "../components/Skeleton";
import { ErrorNotice } from "../components/Notice";
import { formatBytes } from "./settings/StorageSettings";
import { readableError } from "../utils/errors";
import PageIntro from "../components/PageIntro";
import FigureHistory from "../components/FigureHistory";
import { t } from "../i18n";
function Badge({ i }: { i: ImmichInfo }) {
if (!i.enabled) return <span className="badge bg-secondary-lt text-secondary">Off</span>;
if (!i.state) return <span className="badge bg-secondary-lt text-secondary">{t("Not read yet")}</span>;
if (!i.fresh) return <span className="badge bg-yellow-lt text-yellow">Can&rsquo;t be read</span>;
if (i.problems.some((x) => x.severity === "critical")) return <span className="badge bg-red-lt text-red">{t("Needs a look")}</span>;
if (i.problems.length > 0) return <span className="badge bg-yellow-lt text-yellow">{t("Needs a look")}</span>;
return <span className="badge bg-green-lt text-green">{t("In order")}</span>;
}
const n = (v: number | null) => (v === null ? "—" : v.toLocaleString());
function Card({ i }: { i: ImmichInfo }) {
const s = i.state;
const failed = s?.queues?.reduce((total, q) => total + q.failed, 0) ?? 0;
const percent = s?.disk?.percent ?? null;
return (
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">
{i.name} <Badge i={i} />
</h3>
<div className="card-actions text-secondary small">{i.status ? <>read <TimeAgo value={i.status.at} /></> : "not read yet"}</div>
</div>
<div className="card-body">
{i.status && !i.status.ok && <div className="text-yellow mb-2">The last attempt to read it failed: {i.status.error ?? "no answer"}.</div>}
{i.problems.length > 0 && (
<ul className="mb-3">
{i.problems.map((x) => (
<li key={x.key} className={x.severity === "critical" ? "text-red" : ""}>
{x.message}
</li>
))}
</ul>
)}
{s && (
<>
<div className="text-secondary small mb-3">
{[s.version ? `version ${s.version}` : null, s.updateAvailable && s.latestVersion ? `${s.latestVersion} is out` : null].filter(Boolean).join(" · ")}
</div>
<div className="row g-3 mb-3">
<div className="col-6 col-lg-3">
<div className="card card-sm h-100">
<div className="card-body">
<div className="text-secondary small">Photos</div>
<div className="h2 mb-0">{n(s.photos)}</div>
</div>
</div>
</div>
<div className="col-6 col-lg-3">
<div className="card card-sm h-100">
<div className="card-body">
<div className="text-secondary small">Videos</div>
<div className="h2 mb-0">{n(s.videos)}</div>
</div>
</div>
</div>
<div className="col-6 col-lg-3">
<div className="card card-sm h-100">
<div className="card-body">
<div className="text-secondary small">Library</div>
<div className="h2 mb-0">{s.usageBytes === null ? "—" : formatBytes(s.usageBytes)}</div>
</div>
</div>
</div>
<div className="col-6 col-lg-3">
<div className="card card-sm h-100">
<div className="card-body">
<div className="text-secondary small">Disk under it</div>
<div className="h2 mb-0">{percent === null ? "—" : `${Math.round(percent)} %`}</div>
{s.disk && (
<>
<div className="progress progress-sm mt-1" aria-hidden="true">
<div className="progress-bar" style={{ width: `${Math.max(0, Math.min(100, percent ?? 0))}%`, background: (percent ?? 0) >= 95 ? "#d63939" : (percent ?? 0) >= 90 ? "#f59f00" : "#2fb344" }} />
</div>
<div className="text-secondary small">
{formatBytes(s.disk.used)} of {formatBytes(s.disk.size)}
</div>
</>
)}
</div>
</div>
</div>
</div>
<h4>Background jobs{failed > 0 && <span className="text-red fw-normal ms-2">{failed} failed</span>}</h4>
{!s.queues ? (
<div className="text-secondary">Immich did not answer about its jobs (the API key needs to be allowed to read them).</div>
) : (
<div className="table-responsive">
<table className="table table-vcenter table-sm">
<thead>
<tr>
<th>Queue</th>
<th className="text-end">{t("Active")}</th>
<th className="text-end">Waiting</th>
<th className="text-end">Failed</th>
<th />
</tr>
</thead>
<tbody>
{s.queues.map((q) => (
<tr key={q.name}>
<td>{q.name}</td>
<td className="text-end">{q.active.toLocaleString()}</td>
<td className="text-end">{q.waiting.toLocaleString()}</td>
<td className={`text-end ${q.failed > 0 ? "text-red fw-bold" : "text-secondary"}`}>{q.failed.toLocaleString()}</td>
<td>{q.paused && <span className="badge bg-secondary-lt text-secondary">paused</span>}</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</>
)}
<FigureHistory integrationId={i.id} name={i.name} />
</div>
</div>
);
}
/** Immich: whether the photo library is healthy — the disk under it, how many it holds, and whether its background jobs are failing quietly. */
export default function Immich() {
const [data, setData] = useState<ImmichInfo[] | null>(null);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const load = () =>
api.immich
.list()
.then((r) => {
setData(r.immiches);
setError(null);
})
.catch((err) => setError(readableError(err)));
void load();
const t = setInterval(load, 60_000);
return () => clearInterval(t);
}, []);
return (
<>
<h2 className="page-title">Immich</h2>
<PageIntro>
Photos are what cannot be made again, and Immich fails quietly. It is read every few minutes with an API key (see <Link to="/integrations">{t("Integrations")}</Link>). A <strong>disk under the library that is filling up</strong> and <strong>background jobs that have failed</strong> (thumbnails and
metadata that were never made) are alerts — see <Link to="/alerts">{t("Alerts")}</Link>.
</PageIntro>
<ErrorNotice error={error} />
{!data && !error && <BlockSkeleton lines={4} />}
{data && data.length === 0 && (
<div className="card">
<div className="card-body">
<EmptyState title="No Immich connected" hint="Add one under Integrations with its address and an API key (Account Settings → API Keys; read permissions are enough)." />
</div>
</div>
)}
{data?.map((i) => <Card key={i.id} i={i} />)}
</>
);
}