From 539b2e87adbb5a38a653c0f97cb28d5d77c99afc Mon Sep 17 00:00:00 2001 From: fundon Date: Wed, 30 Apr 2025 06:36:22 +0000 Subject: [PATCH] refactor(editor): get loading icon with theme (#12079) ## Summary by CodeRabbit - **New Features** - Introduced a unified loading spinner icon that adapts to light or dark themes automatically. - **Refactor** - Streamlined loading icon usage across the app by replacing multiple theme-based icons with a single helper function for consistent and simplified icon management. - **Chores** - Removed an unused dependency to improve package management. --- .../affine/blocks/attachment/package.json | 1 - .../blocks/attachment/src/attachment-block.ts | 10 +++-- .../affine/blocks/attachment/tsconfig.json | 1 - .../affine/blocks/embed/src/common/utils.ts | 9 +++-- .../embed/src/embed-linked-doc-block/utils.ts | 12 +++--- .../embed/src/embed-synced-doc-block/utils.ts | 8 ++-- .../affine/components/src/icons/index.ts | 1 + .../affine/components/src/icons/loading.ts | 40 +++++++++++++++++++ .../affine/components/src/icons/text.ts | 35 ---------------- .../src/footnote-node/footnote-popup.ts | 7 ++-- .../components/generating-placeholder.ts | 14 ++----- .../i18n/src/i18n-completenesses.json | 2 +- tools/utils/src/workspace.gen.ts | 1 - yarn.lock | 1 - 14 files changed, 70 insertions(+), 72 deletions(-) create mode 100644 blocksuite/affine/components/src/icons/loading.ts diff --git a/blocksuite/affine/blocks/attachment/package.json b/blocksuite/affine/blocks/attachment/package.json index 7a3f5ab8aa..5b379a9a50 100644 --- a/blocksuite/affine/blocks/attachment/package.json +++ b/blocksuite/affine/blocks/attachment/package.json @@ -10,7 +10,6 @@ "author": "toeverything", "license": "MIT", "dependencies": { - "@blocksuite/affine-block-embed": "workspace:*", "@blocksuite/affine-block-surface": "workspace:*", "@blocksuite/affine-components": "workspace:*", "@blocksuite/affine-ext-loader": "workspace:*", diff --git a/blocksuite/affine/blocks/attachment/src/attachment-block.ts b/blocksuite/affine/blocks/attachment/src/attachment-block.ts index adba0a6d96..53e1f3b85a 100644 --- a/blocksuite/affine/blocks/attachment/src/attachment-block.ts +++ b/blocksuite/affine/blocks/attachment/src/attachment-block.ts @@ -1,9 +1,11 @@ -import { getEmbedCardIcons } from '@blocksuite/affine-block-embed'; import { CaptionedBlockComponent, SelectedStyle, } from '@blocksuite/affine-components/caption'; -import { getAttachmentFileIcon } from '@blocksuite/affine-components/icons'; +import { + getAttachmentFileIcon, + getLoadingIconWith, +} from '@blocksuite/affine-components/icons'; import { Peekable } from '@blocksuite/affine-components/peek'; import { toast } from '@blocksuite/affine-components/toast'; import { @@ -297,7 +299,7 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent { + return html` + + + + `; +}; + +export const LightLoadingIcon = LoadingIcon('white'); + +export const DarkLoadingIcon = LoadingIcon('black'); + +export const getLoadingIconWith = (theme: ColorScheme) => + theme === ColorScheme.Light ? LightLoadingIcon : DarkLoadingIcon; diff --git a/blocksuite/affine/components/src/icons/text.ts b/blocksuite/affine/components/src/icons/text.ts index fee39e592b..8c218badb3 100644 --- a/blocksuite/affine/components/src/icons/text.ts +++ b/blocksuite/affine/components/src/icons/text.ts @@ -443,41 +443,6 @@ export const PaletteIcon = icons.PaletteIcon({ height: '20', }); -const LoadingIcon = (color: string) => { - return html` - - - - `; -}; - -export const LightLoadingIcon = LoadingIcon('white'); - -export const DarkLoadingIcon = LoadingIcon('black'); - export const EmbedCardLightBannerIcon = html` { const theme = this.std.get(ThemeProvider).theme; - return theme === ColorScheme.Light ? LightLoadingIcon : DarkLoadingIcon; + return getLoadingIconWith(theme); }; private readonly _onClick = () => { diff --git a/packages/frontend/core/src/blocksuite/ai/widgets/ai-panel/components/generating-placeholder.ts b/packages/frontend/core/src/blocksuite/ai/widgets/ai-panel/components/generating-placeholder.ts index bae797fe51..16c30ffe4e 100644 --- a/packages/frontend/core/src/blocksuite/ai/widgets/ai-panel/components/generating-placeholder.ts +++ b/packages/frontend/core/src/blocksuite/ai/widgets/ai-panel/components/generating-placeholder.ts @@ -1,9 +1,6 @@ -import { - DarkLoadingIcon, - LightLoadingIcon, -} from '@blocksuite/affine/components/icons'; +import { getLoadingIconWith } from '@blocksuite/affine/components/icons'; import { WithDisposable } from '@blocksuite/affine/global/lit'; -import { ColorScheme } from '@blocksuite/affine/model'; +import type { ColorScheme } from '@blocksuite/affine/model'; import { unsafeCSSVar } from '@blocksuite/affine/shared/theme'; import { baseTheme } from '@toeverything/theme'; import { @@ -91,6 +88,7 @@ export class GeneratingPlaceholder extends WithDisposable(LitElement) { protected override render() { const loadingText = this.stages[this.loadingProgress - 1] || ''; + const loadingIcon = getLoadingIconWith(this.theme); return html`
Answer
` : nothing}
-
- ${this.theme === ColorScheme.Light - ? DarkLoadingIcon - : LightLoadingIcon} -
+
${loadingIcon}
${loadingText}
diff --git a/packages/frontend/i18n/src/i18n-completenesses.json b/packages/frontend/i18n/src/i18n-completenesses.json index e88fc0ba34..c3443254c2 100644 --- a/packages/frontend/i18n/src/i18n-completenesses.json +++ b/packages/frontend/i18n/src/i18n-completenesses.json @@ -5,7 +5,7 @@ "de": 98, "el-GR": 98, "en": 100, - "es-AR": 99, + "es-AR": 98, "es-CL": 100, "es": 98, "fa": 98, diff --git a/tools/utils/src/workspace.gen.ts b/tools/utils/src/workspace.gen.ts index 88d69114ae..47d036553d 100644 --- a/tools/utils/src/workspace.gen.ts +++ b/tools/utils/src/workspace.gen.ts @@ -74,7 +74,6 @@ export const PackageList = [ location: 'blocksuite/affine/blocks/attachment', name: '@blocksuite/affine-block-attachment', workspaceDependencies: [ - 'blocksuite/affine/blocks/embed', 'blocksuite/affine/blocks/surface', 'blocksuite/affine/components', 'blocksuite/affine/ext-loader', diff --git a/yarn.lock b/yarn.lock index 7e87938581..e011e41897 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2407,7 +2407,6 @@ __metadata: version: 0.0.0-use.local resolution: "@blocksuite/affine-block-attachment@workspace:blocksuite/affine/blocks/attachment" dependencies: - "@blocksuite/affine-block-embed": "workspace:*" "@blocksuite/affine-block-surface": "workspace:*" "@blocksuite/affine-components": "workspace:*" "@blocksuite/affine-ext-loader": "workspace:*"