fix: add @typescript-eslint/no-floating-promises rule (#2764)

Co-authored-by: himself65 <himself65@outlook.com>
This commit is contained in:
LongYinan
2023-06-13 14:55:23 +08:00
committed by GitHub
parent bbac03107e
commit 1c8f1a05d0
25 changed files with 342 additions and 239 deletions

View File

@@ -12,47 +12,48 @@ import { openAIApiKeyAtom, useChatAtoms } from '../core/hooks';
import { detailContentActionsStyle, detailContentStyle } from './index.css';
if (typeof window === 'undefined') {
import('@blocksuite/blocks').then(({ FormatQuickBar }) => {
FormatQuickBar.customElements.push((_page, getSelection) => {
const div = document.createElement('div');
const root = createRoot(div);
import('@blocksuite/blocks')
.then(({ FormatQuickBar }) => {
FormatQuickBar.customElements.push((_page, getSelection) => {
const div = document.createElement('div');
const root = createRoot(div);
const AskAI = (): ReactElement => {
const { conversationAtom } = useChatAtoms();
const call = useSetAtom(conversationAtom);
const AskAI = (): ReactElement => {
const { conversationAtom } = useChatAtoms();
const call = useSetAtom(conversationAtom);
const onClickAskAI = useCallback(() => {
const selection = getSelection();
if (selection != null) {
const text = selection.models
.map(model => {
return model.text?.toString();
})
.filter((v): v is string => Boolean(v))
.join('\n');
console.log('selected text:', text);
call(
`I selected some text from the document: \n"${text}."`
).catch(err => {
console.error(err);
});
}
}, [call]);
return (
<div
onClick={() => {
const selection = getSelection();
if (selection != null) {
const text = selection.models
.map(model => {
return model.text?.toString();
})
.filter((v): v is string => Boolean(v))
.join('\n');
console.log('selected text:', text);
void call(
`I selected some text from the document: \n"${text}."`
);
}
}}
>
Ask AI
</div>
return <div onClick={onClickAskAI}>Ask AI</div>;
};
root.render(
<StrictMode>
<Provider store={rootStore}>
<AskAI />
</Provider>
</StrictMode>
);
};
root.render(
<StrictMode>
<Provider store={rootStore}>
<AskAI />
</Provider>
</StrictMode>
);
return div;
return div;
});
})
.catch(error => {
console.error(error);
});
});
}
const Actions = () => {

View File

@@ -49,9 +49,14 @@ const getConversationAtom = (chat: ConversationChain) => {
throw new Error();
}
const memory = chat.memory as BufferMemory;
void memory.chatHistory.getMessages().then(messages => {
setAtom(messages);
});
memory.chatHistory
.getMessages()
.then(messages => {
setAtom(messages);
})
.catch(err => {
console.error(err);
});
const llmStart = (): void => {
setAtom(conversations => [...conversations, new AIChatMessage('')]);
};
@@ -86,9 +91,14 @@ const getConversationAtom = (chat: ConversationChain) => {
});
// refresh messages
const memory = chat.memory as BufferMemory;
void memory.chatHistory.getMessages().then(messages => {
set(conversationBaseAtom, messages);
});
memory.chatHistory
.getMessages()
.then(messages => {
set(conversationBaseAtom, messages);
})
.catch(err => {
console.error(err);
});
}
);
conversationWeakMap.set(chat, conversationAtom);