fix(editor): switch view is not allowed during upload (#12018)
Closes: [BS-3352](https://linear.app/affine-design/issue/BS-3352/[improvement]-附件上传时禁止切-view)  <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved the logic for enabling or disabling the embed and card actions in the attachment toolbar, ensuring actions are only available when the file is ready and conditions are met. - **Refactor** - Enhanced reliability by centralizing block state checks and refining conditions for action availability in the attachment dropdown menu. - Centralized resource state management with a new computed signal, improving consistency in loading and error state handling. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -94,18 +94,32 @@ export const attachmentViewDropdownMenu = {
|
||||
},
|
||||
],
|
||||
content(ctx) {
|
||||
const model = ctx.getCurrentModelByType(AttachmentBlockModel);
|
||||
if (!model) return null;
|
||||
const block = ctx.getCurrentBlockByType(AttachmentBlockComponent);
|
||||
if (!block) return null;
|
||||
|
||||
const model = block.model;
|
||||
const embedProvider = ctx.std.get(AttachmentEmbedProvider);
|
||||
const actions = this.actions.map(action => ({ ...action }));
|
||||
const viewType$ = computed(() => {
|
||||
const [cardAction, embedAction] = actions;
|
||||
const actions = computed(() => {
|
||||
const [cardAction, embedAction] = this.actions.map(action => ({
|
||||
...action,
|
||||
}));
|
||||
|
||||
const ok = block.resourceController.resolvedState$.value.state === 'none';
|
||||
const sourceId = Boolean(model.props.sourceId$.value);
|
||||
const embed = model.props.embed$.value ?? false;
|
||||
// 1. Check whether `sourceId` exists.
|
||||
// 2. Check if `embedded` is allowed.
|
||||
// 3. Check `blobState$`
|
||||
const allowed = ok && sourceId && embedProvider.embedded(model) && !embed;
|
||||
|
||||
cardAction.disabled = !embed;
|
||||
embedAction.disabled = embed && embedProvider.embedded(model);
|
||||
embedAction.disabled = !allowed;
|
||||
|
||||
return [cardAction, embedAction];
|
||||
});
|
||||
const viewType$ = computed(() => {
|
||||
const [cardAction, embedAction] = actions.value;
|
||||
const embed = model.props.embed$.value ?? false;
|
||||
return embed ? embedAction.label : cardAction.label;
|
||||
});
|
||||
const onToggle = (e: CustomEvent<boolean>) => {
|
||||
@@ -123,7 +137,7 @@ export const attachmentViewDropdownMenu = {
|
||||
model,
|
||||
html`<affine-view-dropdown-menu
|
||||
@toggle=${onToggle}
|
||||
.actions=${actions}
|
||||
.actions=${actions.value}
|
||||
.context=${ctx}
|
||||
.viewType$=${viewType$}
|
||||
></affine-view-dropdown-menu>`
|
||||
|
||||
Reference in New Issue
Block a user