mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-24 18:02:47 +08:00
feat: add notification when chat panel action success (#7490)
[BS-318](https://linear.app/affine-design/issue/BS-318/右侧边栏-ai-title-位置不统一) [BS-418](https://linear.app/affine-design/issue/BS-418/chat-panel-response-成功后,添加-toast)
This commit is contained in:
@@ -26,6 +26,7 @@ const CommonActions = [
|
|||||||
{
|
{
|
||||||
icon: ReplaceIcon,
|
icon: ReplaceIcon,
|
||||||
title: 'Replace selection',
|
title: 'Replace selection',
|
||||||
|
toast: 'Successfully replaced',
|
||||||
handler: async (
|
handler: async (
|
||||||
host: EditorHost,
|
host: EditorHost,
|
||||||
content: string,
|
content: string,
|
||||||
@@ -39,7 +40,7 @@ const CommonActions = [
|
|||||||
currentBlockSelections,
|
currentBlockSelections,
|
||||||
})
|
})
|
||||||
.run();
|
.run();
|
||||||
if (!data.selectedBlocks) return;
|
if (!data.selectedBlocks) return false;
|
||||||
|
|
||||||
reportResponse('result:replace');
|
reportResponse('result:replace');
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ const CommonActions = [
|
|||||||
currentTextSelection.from.length,
|
currentTextSelection.from.length,
|
||||||
content
|
content
|
||||||
);
|
);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,11 +64,13 @@ const CommonActions = [
|
|||||||
data.selectedBlocks.map(block => block.model),
|
data.selectedBlocks.map(block => block.model),
|
||||||
currentTextSelection
|
currentTextSelection
|
||||||
);
|
);
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: InsertBelowIcon,
|
icon: InsertBelowIcon,
|
||||||
title: 'Insert below',
|
title: 'Insert below',
|
||||||
|
toast: 'Successfully inserted',
|
||||||
handler: async (
|
handler: async (
|
||||||
host: EditorHost,
|
host: EditorHost,
|
||||||
content: string,
|
content: string,
|
||||||
@@ -83,13 +86,14 @@ const CommonActions = [
|
|||||||
currentImageSelections,
|
currentImageSelections,
|
||||||
})
|
})
|
||||||
.run();
|
.run();
|
||||||
if (!data.selectedBlocks) return;
|
if (!data.selectedBlocks) return false;
|
||||||
reportResponse('result:insert');
|
reportResponse('result:insert');
|
||||||
await insertBelow(
|
await insertBelow(
|
||||||
host,
|
host,
|
||||||
content,
|
content,
|
||||||
data.selectedBlocks[data.selectedBlocks?.length - 1]
|
data.selectedBlocks[data.selectedBlocks?.length - 1]
|
||||||
);
|
);
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -99,6 +103,7 @@ export const PageEditorActions = [
|
|||||||
{
|
{
|
||||||
icon: CreateIcon,
|
icon: CreateIcon,
|
||||||
title: 'Create as a doc',
|
title: 'Create as a doc',
|
||||||
|
toast: 'New doc created',
|
||||||
handler: (host: EditorHost, content: string) => {
|
handler: (host: EditorHost, content: string) => {
|
||||||
reportResponse('result:add-page');
|
reportResponse('result:add-page');
|
||||||
const newDoc = host.doc.collection.createDoc();
|
const newDoc = host.doc.collection.createDoc();
|
||||||
@@ -122,6 +127,8 @@ export const PageEditorActions = [
|
|||||||
complete = true;
|
complete = true;
|
||||||
insertFromMarkdown(newHost, content, noteId, 0).catch(console.error);
|
insertFromMarkdown(newHost, content, noteId, 0).catch(console.error);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -131,6 +138,7 @@ export const EdgelessEditorActions = [
|
|||||||
{
|
{
|
||||||
icon: CreateIcon,
|
icon: CreateIcon,
|
||||||
title: 'Add to edgeless as note',
|
title: 'Add to edgeless as note',
|
||||||
|
toast: 'New note created',
|
||||||
handler: async (host: EditorHost, content: string) => {
|
handler: async (host: EditorHost, content: string) => {
|
||||||
reportResponse('result:add-note');
|
reportResponse('result:add-note');
|
||||||
const { doc } = host;
|
const { doc } = host;
|
||||||
@@ -157,6 +165,8 @@ export const EdgelessEditorActions = [
|
|||||||
elements: [id],
|
elements: [id],
|
||||||
editing: false,
|
editing: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -110,6 +110,16 @@ export class ChatCopyMore extends WithDisposable(LitElement) {
|
|||||||
this._morePopper?.toggle();
|
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() {
|
private async _retry() {
|
||||||
const { doc } = this.host;
|
const { doc } = this.host;
|
||||||
try {
|
try {
|
||||||
@@ -180,7 +190,14 @@ export class ChatCopyMore extends WithDisposable(LitElement) {
|
|||||||
</style>
|
</style>
|
||||||
<div class="copy-more">
|
<div class="copy-more">
|
||||||
${content
|
${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}
|
${CopyIcon}
|
||||||
<affine-tooltip>Copy</affine-tooltip>
|
<affine-tooltip>Copy</affine-tooltip>
|
||||||
</div>`
|
</div>`
|
||||||
@@ -205,13 +222,18 @@ export class ChatCopyMore extends WithDisposable(LitElement) {
|
|||||||
action => action.title,
|
action => action.title,
|
||||||
action => {
|
action => {
|
||||||
return html`<div
|
return html`<div
|
||||||
@click=${() =>
|
@click=${async () => {
|
||||||
action.handler(
|
const success = await action.handler(
|
||||||
host,
|
host,
|
||||||
content,
|
content,
|
||||||
this.curTextSelection,
|
this.curTextSelection,
|
||||||
this.curBlockSelections
|
this.curBlockSelections
|
||||||
)}
|
);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
this._notifySuccess(action.toast);
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
${action.icon}
|
${action.icon}
|
||||||
<div>${action.title}</div>
|
<div>${action.title}</div>
|
||||||
|
|||||||
@@ -545,13 +545,22 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await action.handler(
|
const success = await action.handler(
|
||||||
host,
|
host,
|
||||||
content,
|
content,
|
||||||
this._currentTextSelection,
|
this._currentTextSelection,
|
||||||
this._currentBlockSelections,
|
this._currentBlockSelections,
|
||||||
this._currentImageSelections
|
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}
|
${action.title}
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
|
|||||||
.chat-panel-container {
|
.chat-panel-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding: 0 12px;
|
padding: 0 16px;
|
||||||
|
padding-top: 8px;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -140,9 +140,5 @@ export const copyText = async (host: EditorHost, text: string) => {
|
|||||||
.flatMap(model => model.children);
|
.flatMap(model => model.children);
|
||||||
const slice = Slice.fromModels(previewDoc, models);
|
const slice = Slice.fromModels(previewDoc, models);
|
||||||
await host.std.clipboard.copySlice(slice);
|
await host.std.clipboard.copySlice(slice);
|
||||||
const { notificationService } = host.std.spec.getService('affine:page');
|
|
||||||
if (notificationService) {
|
|
||||||
notificationService.toast('Copied to clipboard');
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user