mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 12:36:24 +08:00
refactor(editor): split openFileOrFiles into openSingleFileWith and openFilesWith (#12523)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Improved file selection dialogs for attachments, imports, and uploads, allowing for more consistent and streamlined file picking across the app. - **Bug Fixes** - Resolved inconsistencies when selecting single or multiple files, ensuring a smoother user experience during file import and upload. - **Refactor** - Unified and simplified file selection logic throughout the app for better reliability and maintainability. - Standardized import functions to uniformly handle arrays of files, enhancing consistency in file processing. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -5,7 +5,7 @@ import track from '@affine/track';
|
||||
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit';
|
||||
import { scrollbarStyle } from '@blocksuite/affine/shared/styles';
|
||||
import { unsafeCSSVar, unsafeCSSVarV2 } from '@blocksuite/affine/shared/theme';
|
||||
import { openFileOrFiles } from '@blocksuite/affine/shared/utils';
|
||||
import { openFilesWith } from '@blocksuite/affine/shared/utils';
|
||||
import { ShadowlessElement } from '@blocksuite/affine/std';
|
||||
import type { DocMeta } from '@blocksuite/affine/store';
|
||||
import {
|
||||
@@ -159,9 +159,7 @@ export class ChatPanelAddPopover extends SignalWatcher(
|
||||
};
|
||||
|
||||
private readonly _addFileChip = async () => {
|
||||
const files = await openFileOrFiles({
|
||||
multiple: true,
|
||||
});
|
||||
const files = await openFilesWith();
|
||||
if (!files || files.length === 0) return;
|
||||
|
||||
const images = files.filter(file => file.type.startsWith('image/'));
|
||||
|
||||
@@ -3,7 +3,7 @@ import { stopPropagation } from '@affine/core/utils';
|
||||
import type { CopilotSessionType } from '@affine/graphql';
|
||||
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit';
|
||||
import { unsafeCSSVar, unsafeCSSVarV2 } from '@blocksuite/affine/shared/theme';
|
||||
import { openFileOrFiles } from '@blocksuite/affine/shared/utils';
|
||||
import { openFilesWith } from '@blocksuite/affine/shared/utils';
|
||||
import type { EditorHost } from '@blocksuite/affine/std';
|
||||
import {
|
||||
CloseIcon,
|
||||
@@ -533,10 +533,7 @@ export class AIChatInput extends SignalWatcher(WithDisposable(LitElement)) {
|
||||
private readonly _uploadImageFiles = async (_e: MouseEvent) => {
|
||||
if (this._isImageUploadDisabled) return;
|
||||
|
||||
const images = await openFileOrFiles({
|
||||
acceptType: 'Images',
|
||||
multiple: true,
|
||||
});
|
||||
const images = await openFilesWith('Images');
|
||||
if (!images) return;
|
||||
if (this.chatContextValue.images.length + images.length > MAX_IMAGE_COUNT) {
|
||||
toast(`You can only upload up to ${MAX_IMAGE_COUNT} images`);
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
type DataViewCellLifeCycle,
|
||||
EditorHostKey,
|
||||
} from '@blocksuite/affine/blocks/database';
|
||||
import { openFileOrFiles } from '@blocksuite/affine/shared/utils';
|
||||
import { openFilesWith } from '@blocksuite/affine/shared/utils';
|
||||
import type { BlobEngine } from '@blocksuite/affine/sync';
|
||||
import {
|
||||
DeleteIcon,
|
||||
@@ -402,7 +402,7 @@ const FileCellComponent: ForwardRefRenderFunction<
|
||||
>
|
||||
<Button
|
||||
onClick={() => {
|
||||
openFileOrFiles({ multiple: true })
|
||||
openFilesWith()
|
||||
.then(files => {
|
||||
files?.forEach(file => {
|
||||
manager.uploadFile(file);
|
||||
@@ -447,7 +447,7 @@ const FileCellComponent: ForwardRefRenderFunction<
|
||||
<div className={styles.uploadContainer}>
|
||||
<div
|
||||
onClick={() => {
|
||||
openFileOrFiles({ multiple: true })
|
||||
openFilesWith()
|
||||
.then(files => {
|
||||
files?.forEach(file => {
|
||||
manager.uploadFile(file);
|
||||
|
||||
Reference in New Issue
Block a user