mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 11:06:25 +08:00
5590cdd8f1
Closes: [BS-3564](https://linear.app/affine-design/issue/BS-3564/ui-embed-view-报错-ui-加-title) Closes: [BS-3454](https://linear.app/affine-design/issue/BS-3454/点击-reload-后应该隐藏-attachment-embed-view-左下角-status(待新状态)) <img width="807" alt="Screenshot 2025-05-28 at 17 23 26" src="https://github.com/user-attachments/assets/9ecc29f8-73c6-4441-bc38-dfe9bd876542" /> <img width="820" alt="Screenshot 2025-05-28 at 17 45 37" src="https://github.com/user-attachments/assets/68e6db17-a814-4df4-a9fa-067ca03dec30" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for retrying failed uploads of attachments and images, allowing users to re-upload files directly from the error status interface. - The error status dialog now dynamically displays "Retry" for upload failures and "Reload" for download failures, with appropriate actions for each. - **Enhancements** - Improved clarity and consistency in file type display and icon usage for attachments and citations. - Button labels in the attachment interface now have capitalized text for better readability. - **Bug Fixes** - Streamlined error handling and status updates for attachment and image uploads/downloads, reducing redundant UI elements. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
166 lines
4.0 KiB
TypeScript
166 lines
4.0 KiB
TypeScript
import {
|
|
fontBaseStyle,
|
|
panelBaseColorsStyle,
|
|
} from '@blocksuite/affine-shared/styles';
|
|
import { unsafeCSSVar, unsafeCSSVarV2 } from '@blocksuite/affine-shared/theme';
|
|
import {
|
|
createButtonPopper,
|
|
stopPropagation,
|
|
} from '@blocksuite/affine-shared/utils';
|
|
import { WithDisposable } from '@blocksuite/global/lit';
|
|
import { InformationIcon } from '@blocksuite/icons/lit';
|
|
import { PropTypes, requiredProperties } from '@blocksuite/std';
|
|
import { css, html, LitElement } from 'lit';
|
|
import { property, query } from 'lit/decorators.js';
|
|
|
|
@requiredProperties({
|
|
message: PropTypes.string,
|
|
needUpload: PropTypes.boolean,
|
|
action: PropTypes.instanceOf(Function),
|
|
})
|
|
export class ResourceStatus extends WithDisposable(LitElement) {
|
|
static override styles = css`
|
|
button.status {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: 24px;
|
|
height: 24px;
|
|
border-radius: 50%;
|
|
font-size: 18px;
|
|
outline: none;
|
|
border: none;
|
|
cursor: pointer;
|
|
color: ${unsafeCSSVarV2('button/pureWhiteText')};
|
|
background: ${unsafeCSSVarV2('status/error')};
|
|
box-shadow: ${unsafeCSSVar('overlayShadow')};
|
|
}
|
|
|
|
${panelBaseColorsStyle('.popper')}
|
|
${fontBaseStyle('.popper')}
|
|
.popper {
|
|
display: none;
|
|
outline: none;
|
|
padding: 8px;
|
|
border-radius: 8px;
|
|
width: 260px;
|
|
font-style: normal;
|
|
font-weight: 400;
|
|
line-height: 22px;
|
|
font-size: ${unsafeCSSVar('fontSm')};
|
|
|
|
&[data-show] {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 4px;
|
|
}
|
|
}
|
|
|
|
.header {
|
|
font-weight: 500;
|
|
}
|
|
|
|
.content {
|
|
font-feature-settings:
|
|
'liga' off,
|
|
'clig' off;
|
|
color: ${unsafeCSSVarV2('text/primary')};
|
|
}
|
|
|
|
.footer {
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
margin-top: 4px;
|
|
}
|
|
|
|
button.action {
|
|
display: flex;
|
|
align-items: center;
|
|
padding: 2px 12px;
|
|
border-radius: 8px;
|
|
border: none;
|
|
background: none;
|
|
cursor: pointer;
|
|
outline: none;
|
|
color: ${unsafeCSSVarV2('button/primary')};
|
|
}
|
|
`;
|
|
|
|
private _popper: ReturnType<typeof createButtonPopper> | null = null;
|
|
|
|
private _updatePopper() {
|
|
this._popper?.dispose();
|
|
this._popper = createButtonPopper({
|
|
reference: this._trigger,
|
|
popperElement: this._content,
|
|
mainAxis: 8,
|
|
allowedPlacements: ['top-start', 'bottom-start'],
|
|
});
|
|
}
|
|
|
|
override firstUpdated() {
|
|
this._updatePopper();
|
|
this.disposables.addFromEvent(this, 'click', stopPropagation);
|
|
this.disposables.addFromEvent(this, 'keydown', (e: KeyboardEvent) => {
|
|
e.stopPropagation();
|
|
if (e.key === 'Escape') {
|
|
this._popper?.hide();
|
|
}
|
|
});
|
|
this.disposables.addFromEvent(this._trigger, 'click', (_: MouseEvent) => {
|
|
this._popper?.toggle();
|
|
});
|
|
this.disposables.addFromEvent(
|
|
this._actionButton,
|
|
'click',
|
|
(_: MouseEvent) => {
|
|
this._popper?.hide();
|
|
this.action();
|
|
}
|
|
);
|
|
this.disposables.add(() => this._popper?.dispose());
|
|
}
|
|
|
|
override render() {
|
|
const { message, needUpload } = this;
|
|
const { type, label } = needUpload
|
|
? {
|
|
type: 'Upload',
|
|
label: 'Retry',
|
|
}
|
|
: {
|
|
type: 'Download',
|
|
label: 'Reload',
|
|
};
|
|
|
|
return html`
|
|
<button class="status">${InformationIcon()}</button>
|
|
<div class="popper">
|
|
<div class="header">${type} failed</div>
|
|
<div class="content">${message}</div>
|
|
<div class="footer">
|
|
<button class="action">${label}</button>
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
@query('div.popper')
|
|
private accessor _content!: HTMLDivElement;
|
|
|
|
@query('button.status')
|
|
private accessor _trigger!: HTMLButtonElement;
|
|
|
|
@query('button.action')
|
|
private accessor _actionButton!: HTMLButtonElement;
|
|
|
|
@property({ attribute: false })
|
|
accessor message!: string;
|
|
|
|
@property({ attribute: false })
|
|
accessor needUpload!: boolean;
|
|
|
|
@property({ attribute: false })
|
|
accessor action!: () => void;
|
|
}
|