Show sent messages before the server confirms them
The composer now puts the bubble and clears the input as soon as you send, so a slow connection never holds either. The bot's status row reads "<name> is getting your message..." until the saved message arrives (by response or push), then switches to thinking. A failed send removes the bubble and restores the text and files.
This commit is contained in:
@@ -104,10 +104,28 @@ export default function useComposerAttachments({ bot_id, workspace_id }: Params)
|
||||
setPending((prev) => prev.filter((item) => item.key != key));
|
||||
};
|
||||
|
||||
/**
|
||||
* Puts files already uploaded back, after a send that didn't make it.
|
||||
*/
|
||||
const restore = ({ attachments }: { attachments: BotMessageAttachment[] }) => {
|
||||
if (!attachments.length) return;
|
||||
|
||||
setPending((prev) => [
|
||||
...prev,
|
||||
...attachments.map((attachment) => ({
|
||||
key: `restored-${attachment.id}-${Date.now()}`,
|
||||
name: attachment.name,
|
||||
status: "ready" as const,
|
||||
attachment,
|
||||
})),
|
||||
]);
|
||||
};
|
||||
|
||||
return {
|
||||
pending,
|
||||
add,
|
||||
remove,
|
||||
restore,
|
||||
clear: () => {
|
||||
revoke({ items: pending });
|
||||
setPending([]);
|
||||
|
||||
Reference in New Issue
Block a user