-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(messages): ✨ add message actions
- Loading branch information
1 parent
c28ba77
commit 25c7e80
Showing
4 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Copy, Trash2 } from "lucide-react"; | ||
import { Button } from "../ui/button"; | ||
import { Id } from "@/convex/_generated/dataModel"; | ||
import useApiMutation from "@/lib/hooks/use-api-mutation"; | ||
import { api } from "@/convex/_generated/api"; | ||
import { toast } from "sonner"; | ||
|
||
type MessageChatActionProps = { | ||
messageId: Id<"messages">; | ||
content: string; | ||
}; | ||
|
||
const MessageChatAction = ({ content, messageId }: MessageChatActionProps) => { | ||
const { mutate: deleteMessage, isPending } = useApiMutation( | ||
api.message.remove | ||
); | ||
|
||
const handleCopy = () => { | ||
navigator.clipboard.writeText(content); | ||
toast.success("Message copied to clipboard"); | ||
}; | ||
|
||
const handleDelete = () => { | ||
deleteMessage({ messageId }) | ||
.then(() => toast.success("Message deleted")) | ||
.catch(() => toast.error("Failed to delete message")); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Button size="icon" variant="ghost" onClick={handleCopy}> | ||
<Copy className="w-4 h-4" /> | ||
</Button> | ||
<Button | ||
size="icon" | ||
variant="ghost" | ||
disabled={isPending} | ||
onClick={handleDelete} | ||
> | ||
<Trash2 className="w-4 h-4" /> | ||
</Button> | ||
</> | ||
); | ||
}; | ||
|
||
export default MessageChatAction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters