Local fallbacks were creating fake saves and resurrecting deleted rows. Pin and archive now live on chat_sessions so they follow the account. Co-authored-by: Cursor <cursoragent@cursor.com>
26 lines
815 B
TypeScript
26 lines
815 B
TypeScript
export type ChartLibrarySessionBranch = "clear" | "hydrate-then-persist" | "persist-self";
|
|
|
|
export function chartLibrarySessionBranch(
|
|
accountId: string | null | undefined,
|
|
loadedAccount: string,
|
|
): ChartLibrarySessionBranch {
|
|
if (!accountId) return "clear";
|
|
if (loadedAccount !== accountId) return "hydrate-then-persist";
|
|
return "persist-self";
|
|
}
|
|
|
|
export function chartLibraryFromCloudOthers<T extends { role: "self" | "other" }, P>(
|
|
cloudLibrary: readonly T[],
|
|
profile: P,
|
|
upsertSelfChart: (library: T[], profile: P) => T[],
|
|
): T[] {
|
|
return upsertSelfChart(cloudLibrary.filter((record) => record.role !== "self"), profile);
|
|
}
|
|
|
|
export function chartLibraryOnCloudFailure<T, P>(
|
|
profile: P,
|
|
upsertSelfChart: (library: T[], profile: P) => T[],
|
|
): T[] {
|
|
return upsertSelfChart([], profile);
|
|
}
|