various fixes

This commit is contained in:
Kevin
2026-03-23 13:21:07 +08:00
parent 9c2e0329ca
commit b9ecfd02a4
18 changed files with 393 additions and 277 deletions

View File

@@ -24,7 +24,10 @@ import { Skeleton } from '@/components/ui/skeleton';
import { Text } from '@/components/ui/text';
import { ScreenGutter } from '@/constants/layout';
import { useCreateConversation } from '@/features/conversation/hooks';
import { buildFrameworkChapterPlaceholders } from '@/features/memoir/framework-chapter-keys';
import {
buildFrameworkChapterPlaceholders,
mergeFrameworkChaptersWithFetched,
} from '@/features/memoir/framework-chapter-keys';
import { useChapters, useCheckCoverGeneration } from '@/features/memoir/hooks';
import type { ChapterViewModel } from '@/features/memoir/types';
@@ -263,6 +266,11 @@ export default function MemoirScreen() {
[t],
);
const displayChapters = useMemo(
() => mergeFrameworkChaptersWithFetched(frameworkPlaceholders, chapters),
[frameworkPlaceholders, chapters],
);
useEffect(() => {
if (didRunInitialCoverCheckRef.current) return;
didRunInitialCoverCheckRef.current = true;
@@ -318,19 +326,8 @@ export default function MemoirScreen() {
</>
) : isError ? (
<MemoirLoadError onRetry={() => void refetch()} />
) : chapters.length === 0 ? (
frameworkPlaceholders.map((item) => (
<ChapterCard
key={item.id}
item={item}
variant="drafting"
t={t as (key: string) => string}
onReadPress={() => handleReadChapter(item.id)}
onContinuePress={handleStartChapter}
/>
))
) : (
chapters.map((item) => (
displayChapters.map((item) => (
<ChapterCard
key={item.id}
item={item}

View File

@@ -35,3 +35,17 @@ export function buildFrameworkChapterPlaceholders(
wordCount: 0,
}));
}
/**
* 列表页始终展示 8 个框架槽位:已有章节用接口数据,其余槽位仍用框架占位(与「零章节」时一致)。
*/
export function mergeFrameworkChaptersWithFetched(
placeholders: ChapterViewModel[],
fetched: ChapterViewModel[],
): ChapterViewModel[] {
const byOrder = new Map<number, ChapterViewModel>();
for (const vm of fetched) {
byOrder.set(vm.orderIndex, vm);
}
return placeholders.map((p) => byOrder.get(p.orderIndex) ?? p);
}