Files
Jyotisha/frontend/src/components/current-subject-switcher.tsx
T
jesse-ux d08ffdc0a6
Independent Staging Quality Gate / validate (push) Failing after 6m46s
Independent Staging Quality Gate / publish (push) Skipped
fix: keep western labels near their planets and chats on the current person
Cap planet captions at 30 degrees with a third ring, fall back only within the current person's sessions, and load self when the people catalog fails.
2026-09-25 23:02:17 +08:00

66 lines
1.9 KiB
TypeScript

"use client";
import { useEffect, useState } from "react";
import { SubjectSwitcher } from "@/components/subject-switcher";
import { loadSubjectCatalog, setCurrentSubject, subjectCatalogOthersUnavailable, subscribeSubjectCatalog, useCurrentSubject } from "@/lib/current-subject";
import type { ChatProfileCatalogStatus } from "@/lib/chat-profile-picker-model";
import type { ChartLibraryRecord } from "@/lib/home-types";
export function CurrentSubjectSwitcher() {
const subjectId = useCurrentSubject();
const [library, setLibrary] = useState<ChartLibraryRecord[]>([]);
const [status, setStatus] = useState<ChatProfileCatalogStatus>("loading");
function reload() {
setStatus("loading");
void loadSubjectCatalog(true)
.then((next) => {
setLibrary(next);
setStatus(subjectCatalogOthersUnavailable() ? "degraded" : "ready");
})
.catch(() => setStatus("failed"));
}
useEffect(() => {
let cancelled = false;
const refresh = () => {
void loadSubjectCatalog()
.then((next) => {
if (cancelled) return;
setLibrary(next);
setStatus(subjectCatalogOthersUnavailable() ? "degraded" : "ready");
})
.catch(() => {
if (!cancelled) setStatus("failed");
});
};
refresh();
const unsubscribe = subscribeSubjectCatalog(refresh);
return () => {
cancelled = true;
unsubscribe();
};
}, []);
const selected = subjectId === "self"
? library.find((record) => record.role === "self")
: library.find((record) => record.id === subjectId);
const label = selected?.profile.name.trim()
|| (subjectId === "self" ? "我" : "未命名资料");
return (
<SubjectSwitcher
library={library}
status={status}
selectedId={subjectId}
label={label}
onChoose={(row) => {
setCurrentSubject(row.id);
return true;
}}
onReload={reload}
/>
);
}