There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
feat: add notification when chat panel action success (#7490)
donteatfriedrice53eb4aca8d1a
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/actions/actions-handle.ts b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/actions/actions-handle.tsindex 3a857e5d83..0efd53a405 100644--- a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/actions/actions-handle.ts+++ b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/actions/actions-handle.ts@@ -26,6 +26,7 @@ const CommonActions = [{icon: ReplaceIcon,title: 'Replace selection',+ toast: 'Successfully replaced',handler: async (host: EditorHost,content: string,@@ -39,7 +40,7 @@ const CommonActions = [currentBlockSelections,}).run();- if (!data.selectedBlocks) return;+ if (!data.selectedBlocks) return false;reportResponse('result:replace');@@ -52,7 +53,7 @@ const CommonActions = [currentTextSelection.from.length,content);- return;+ return true;}}@@ -63,11 +64,13 @@ const CommonActions = [data.selectedBlocks.map(block => block.model),currentTextSelection);+ return true;},},{icon: InsertBelowIcon,title: 'Insert below',+ toast: 'Successfully inserted',handler: async (host: EditorHost,content: string,@@ -83,13 +86,14 @@ const CommonActions = [currentImageSelections,}).run();- if (!data.selectedBlocks) return;+ if (!data.selectedBlocks) return false;reportResponse('result:insert');await insertBelow(host,content,data.selectedBlocks[data.selectedBlocks?.length - 1]);+ return true;},},];@@ -99,6 +103,7 @@ export const PageEditorActions = [{icon: CreateIcon,title: 'Create as a doc',+ toast: 'New doc created',handler: (host: EditorHost, content: string) => {reportResponse('result:add-page');const newDoc = host.doc.collection.createDoc();@@ -122,6 +127,8 @@ export const PageEditorActions = [complete = true;insertFromMarkdown(newHost, content, noteId, 0).catch(console.error);})();++ return true;},},];@@ -131,6 +138,7 @@ export const EdgelessEditorActions = [{icon: CreateIcon,title: 'Add to edgeless as note',+ toast: 'New note created',handler: async (host: EditorHost, content: string) => {reportResponse('result:add-note');const { doc } = host;@@ -157,6 +165,8 @@ export const EdgelessEditorActions = [elements: [id],editing: false,});++ return true;},},];diff --git a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/actions/copy-more.ts b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/actions/copy-more.tsindex ef786ed5d9..e874b9de7c 100644--- a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/actions/copy-more.ts+++ b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/actions/copy-more.ts@@ -110,6 +110,16 @@ export class ChatCopyMore extends WithDisposable(LitElement) {this._morePopper?.toggle();}+ private readonly _notifySuccess = (title: string) => {+ const rootService = this.host.spec.getService('affine:page');+ const { notificationService } = rootService;+ notificationService?.notify({+ title: title,+ accent: 'success',+ onClose: function (): void {},+ });+ };+private async _retry() {const { doc } = this.host;try {@@ -180,7 +190,14 @@ export class ChatCopyMore extends WithDisposable(LitElement) {</style><div class="copy-more">${content- ? html`<div @click=${() => copyText(host, content)}>+ ? html`<div+ @click=${async () => {+ const success = await copyText(host, content);+ if (success) {+ this._notifySuccess('Copied to clipboard');+ }+ }}+ >${CopyIcon}<affine-tooltip>Copy</affine-tooltip></div>`@@ -205,13 +222,18 @@ export class ChatCopyMore extends WithDisposable(LitElement) {action => action.title,action => {return html`<div- @click=${() =>- action.handler(+ @click=${async () => {+ const success = await action.handler(host,content,this.curTextSelection,this.curBlockSelections- )}+ );++ if (success) {+ this._notifySuccess(action.toast);+ }+ }}>${action.icon}<div>${action.title}</div>diff --git a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-messages.ts b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-messages.tsindex 5af2592f15..fbff7ca715 100644--- a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-messages.ts+++ b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/chat-panel-messages.ts@@ -545,13 +545,22 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {return;}- await action.handler(+ const success = await action.handler(host,content,this._currentTextSelection,this._currentBlockSelections,this._currentImageSelections);+ const rootService = host.spec.getService('affine:page');+ const { notificationService } = rootService;+ if (success) {+ notificationService?.notify({+ title: action.toast,+ accent: 'success',+ onClose: function (): void {},+ });+ }}}>${action.title}diff --git a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/index.ts b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/index.tsindex 519ad9ef22..fd2c16e1f5 100644--- a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/index.ts+++ b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/index.ts@@ -28,7 +28,8 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {.chat-panel-container {display: flex;flex-direction: column;- padding: 0 12px;+ padding: 0 16px;+ padding-top: 8px;height: 100%;}diff --git a/packages/frontend/core/src/blocksuite/presets/ai/utils/editor-actions.ts b/packages/frontend/core/src/blocksuite/presets/ai/utils/editor-actions.tsindex 8684566167..7db08538b1 100644--- a/packages/frontend/core/src/blocksuite/presets/ai/utils/editor-actions.ts+++ b/packages/frontend/core/src/blocksuite/presets/ai/utils/editor-actions.ts@@ -140,9 +140,5 @@ export const copyText = async (host: EditorHost, text: string) => {.flatMap(model => model.children);const slice = Slice.fromModels(previewDoc, models);await host.std.clipboard.copySlice(slice);- const { notificationService } = host.std.spec.getService('affine:page');- if (notificationService) {- notificationService.toast('Copied to clipboard');- }return true;};