WIP: AGC 资源画布与替换改造 V3.0 #316
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user