mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00: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,
|
||||
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;
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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%;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user