Files
Jyotisha/frontend/src/components/chat-profile-picker.tsx
T
jesse-ux ab6c55f822 feat: keep up to five chart subjects on typed columns
Chart, ephemeris, reports, daily language, consult, and synastry read birth data only through resolveSubjectBirth. The current person is a request parameter outside Home(). /people replaces the settings chart pane, and deleting someone removes that person's chats and reports.
2026-09-25 04:19:05 +08:00

69 lines
2.0 KiB
TypeScript

"use client";
import { setCurrentSubject } from "@/lib/current-subject";
import {
chatProfileChoice,
chatProfileDisplayName,
chatProfileSelectedId,
chatSessionSubjectLocked,
type ChatProfileCatalogStatus,
type ChatProfilePickerRow,
} from "@/lib/chat-profile-picker-model";
import type { ChartLibraryRecord, ChatSession } from "@/lib/home-types";
import { SubjectSwitcher } from "@/components/subject-switcher";
export type ChatProfilePickerProps = {
readonly session: ChatSession;
readonly library: readonly ChartLibraryRecord[];
readonly status: ChatProfileCatalogStatus;
readonly requestInFlight: boolean;
readonly onBindEmpty: (chartProfileId: string) => Promise<boolean>;
readonly onOpenNew: (chartProfileId: string) => Promise<boolean>;
readonly onReload: () => void;
};
export function ChatProfilePicker({
session,
library,
status,
requestInFlight,
onBindEmpty,
onOpenNew,
onReload,
}: ChatProfilePickerProps) {
const label = chatProfileDisplayName({ session, status, library });
const selectedId = chatProfileSelectedId(session);
const locked = chatSessionSubjectLocked(session);
const deleted = status === "ready" && Boolean(selectedId) && selectedId !== "self" && !library.some((record) => (
record.role === "other" && record.id === selectedId
));
async function choose(row: ChatProfilePickerRow): Promise<boolean> {
const choice = chatProfileChoice({
session,
chartProfileId: row.id,
requestInFlight,
libraryReady: status === "ready",
selectable: row.complete,
});
if (choice.action === "ignore") return false;
setCurrentSubject(choice.chartProfileId);
if (choice.action === "bind") return onBindEmpty(choice.chartProfileId);
return onOpenNew(choice.chartProfileId);
}
return (
<SubjectSwitcher
library={library}
status={status}
selectedId={selectedId}
label={label}
locked={locked}
requestInFlight={requestInFlight}
deleted={deleted}
onChoose={choose}
onReload={onReload}
/>
);
}