修复部分功能画布不显示加载态

原先只在「该栏目有可预览素材且一张都没落地」时转圈;版本、音频这类不请求预览的栏目既不转圈,卡片又要等依赖图就绪才渲染,表现为美术资源转完后项目版本才一起出现
判定改为:有资源且(卡片尚未渲染 或 需要预览但一张都没落地)就转圈,每个栏目各自独立结束
补充 resourceBookModel 用例覆盖卡片未渲染与无需预览两种情况
This commit is contained in:
2026-09-09 17:11:14 +08:00
parent 0914703032
commit cca4881e13
3 changed files with 41 additions and 10 deletions
@@ -5783,6 +5783,12 @@ export default function ProjectDevelopmentView({
registerElement={registerResourceBookThumbnail}
loading={resourceBookIsLoading({
resourceCount:
projectResourcesByCategory.get(category)
?.length ?? 0,
cardsReady:
sortMode !== 'dependency' ||
resourceGraphInitializationReady,
previewableCount:
resourceBookCategorySettledPreviews.get(category)
?.previewable ?? 0,
settledPreviewCount:
@@ -80,15 +80,23 @@ export function resourceBookShowsChildCards(state: ResourceBookState) {
}
/**
* 每个功能画布框内各自显示加载态:该栏目还有资源、但一张预览都没落地时转圈
* 预览失败同样算落地,避免一直转圈;加载态不拦截点击,没加载出来也能进栏目。
* 每个功能画布框内各自显示加载态。两种情况都要转圈
* 1. 卡片本身还没渲染出来(依赖图/布局就绪之前整块画布是空的);
* 2. 卡片已渲染,但该栏目需要预览的素材一张都还没落地。
* 预览失败同样算落地,避免一直转圈;加载态不拦截点击,没加载完也能进栏目。
*/
export function resourceBookIsLoading({
resourceCount,
cardsReady,
previewableCount,
settledPreviewCount,
}: {
resourceCount: number;
cardsReady: boolean;
previewableCount: number;
settledPreviewCount: number;
}) {
return resourceCount > 0 && settledPreviewCount <= 0;
if (resourceCount <= 0) return false;
if (!cardsReady) return true;
return previewableCount > 0 && settledPreviewCount <= 0;
}
@@ -106,21 +106,38 @@ describe('resource book state machine', () => {
});
describe('resource book loading state', () => {
const ready = {
resourceCount: 3,
cardsReady: true,
previewableCount: 3,
settledPreviewCount: 1,
};
it('never spins for an empty section', () => {
expect(
resourceBookIsLoading({ resourceCount: 0, settledPreviewCount: 0 }),
).toBe(false);
expect(resourceBookIsLoading({ ...ready, resourceCount: 0 })).toBe(false);
});
it('spins while a section still has no settled preview', () => {
it('spins while the section cards are not rendered yet', () => {
expect(resourceBookIsLoading({ ...ready, cardsReady: false })).toBe(true);
});
it('spins while the section still has no settled preview', () => {
expect(
resourceBookIsLoading({ resourceCount: 3, settledPreviewCount: 0 }),
resourceBookIsLoading({ ...ready, settledPreviewCount: 0 }),
).toBe(true);
});
it('stops as soon as one preview in that section settles', () => {
it('does not wait for previews on sections that never request them', () => {
expect(
resourceBookIsLoading({ resourceCount: 3, settledPreviewCount: 1 }),
resourceBookIsLoading({
...ready,
previewableCount: 0,
settledPreviewCount: 0,
}),
).toBe(false);
});
it('stops as soon as one preview in that section settles', () => {
expect(resourceBookIsLoading(ready)).toBe(false);
});
});