fix(chart): keep account and chart-view birth truth consistent

This commit is contained in:
jesse-ux
2026-09-22 12:14:50 +08:00
parent dd4141a030
commit cc7ef8a339
21 changed files with 1243 additions and 90 deletions
+6 -2
View File
@@ -76,9 +76,13 @@ export function useChartPage() {
void fetchChartView({ layers: [layer] })
.then((result) => {
if (result.body?.status === "ok") {
const stored = writeChartPage({ kind: "view", view: result.body });
if (stored.kind !== "view" || stored.view.status !== "ok") {
setView(stored.kind === "view" ? stored.view : result.body);
return;
}
loadedLayers.current.add(layer);
writeChartPage({ kind: "view", view: result.body });
setView(result.body);
setView(stored.view);
}
})
.catch((error: unknown) => {
@@ -17,6 +17,7 @@ import {
type BirthTimeConsultationConsentState,
type LatestAccountRequestGuard,
} from "@/lib/birth-time-consultation-consent";
import { readChartBirthFingerprint } from "@/lib/chart-birth-truth";
import { composerDraftSnapshot } from "@/lib/composer-draft";
import {
activeChartStorageKey,
@@ -25,6 +26,11 @@ import {
LoginRedirectError,
saveCloudChartProfile,
} from "@/lib/home-cloud-sync";
import {
accountChartPinStillCurrent,
beginChartCacheAccountRead,
pinChartSnapshotIdentity,
} from "@/lib/secondary-page-data";
import {
birthProfileDeclarationChanged,
buildSelfChartRecord,
@@ -124,9 +130,14 @@ export function useProfileOnboarding(params: ProfileOnboardingParams) {
async function refreshAccount() {
const requestIdentity = accountRefreshGuard.current.begin();
const chartRead = beginChartCacheAccountRead();
try {
const latest = await fetchAccount();
if (!accountRefreshGuard.current.isCurrent(requestIdentity)) return;
const fingerprint = readChartBirthFingerprint(latest);
if (fingerprint && accountChartPinStillCurrent(chartRead)) {
pinChartSnapshotIdentity({ accountId: latest.user.id, fingerprint });
}
const nextProfile = readProfile(latest.profile);
const activeOther = activeChartId !== "self"
&& chartLibrary.find((record) => record.id === activeChartId && record.role === "other");
@@ -231,10 +242,13 @@ export function useProfileOnboarding(params: ProfileOnboardingParams) {
const payload = await response.json().catch(() => null) as {
error?: string;
birthTime?: unknown;
chartBirth?: { fingerprint?: unknown };
} | null;
if (!response.ok) {
throw new Error(payload?.error || "账户资料暂时无法保存。");
}
const fingerprint = readChartBirthFingerprint(payload);
if (fingerprint) pinChartSnapshotIdentity({ accountId: account.user.id, fingerprint });
const savedProfile = applyPersistedBirthTime(nextProfile, payload?.birthTime);
setAccount((current) => current ? { ...current, profile: savedProfile } : current);
setActiveChartId("self");