feat(characters): use local character catalog

This commit is contained in:
2026-07-17 16:03:18 +08:00
parent a210a98d98
commit b3ebd5cf3b
96 changed files with 1023 additions and 522 deletions
@@ -3,6 +3,7 @@
import { useEffect, useState } from "react";
import type { LoginStatus } from "@/data/schemas/auth";
import { DEFAULT_CHARACTER_ID } from "@/data/constants/character";
import { useHasHydrated } from "@/hooks/use-has-hydrated";
import { loadSplashLatestMessagePreview } from "@/lib/chat/splash_latest_message";
import { useSplashLatestMessageCache } from "@/providers/splash-latest-message-provider";
@@ -12,6 +13,7 @@ import { Result } from "@/utils/result";
const log = new Logger("SplashLatestMessage");
export interface UseSplashLatestMessageInput {
characterId?: string;
hasInitialized: boolean;
isAuthLoading: boolean;
loginStatus: LoginStatus;
@@ -29,6 +31,7 @@ interface SplashLatestMessageState {
}
export function useSplashLatestMessage({
characterId = DEFAULT_CHARACTER_ID,
hasInitialized,
isAuthLoading,
loginStatus,
@@ -45,7 +48,7 @@ export function useSplashLatestMessage({
hasInitialized &&
!isAuthLoading &&
loginStatus !== "notLoggedIn";
const requestKey = shouldLoad ? loginStatus : "";
const requestKey = shouldLoad ? `${loginStatus}:${characterId}` : "";
useEffect(() => {
if (!shouldLoad) return;
@@ -53,7 +56,10 @@ export function useSplashLatestMessage({
let cancelled = false;
const loadLatestMessage = async () => {
const result = await loadSplashLatestMessagePreview({ cache });
const result = await loadSplashLatestMessagePreview({
cache,
characterId,
});
if (cancelled) return;
if (Result.isErr(result)) {
@@ -77,7 +83,7 @@ export function useSplashLatestMessage({
return () => {
cancelled = true;
};
}, [cache, requestKey, shouldLoad]);
}, [cache, characterId, requestKey, shouldLoad]);
if (!shouldLoad) return { message: null, isLoading: false };
if (state.key !== requestKey || !state.loaded) {