diff --git a/chat/package.json b/chat/package.json index cad728b22..418a4ec56 100644 --- a/chat/package.json +++ b/chat/package.json @@ -1,6 +1,6 @@ { "name": "chat", - "version": "0.1.15", + "version": "0.1.17", "main": "./src/index.tsx", "license": "MIT", "dependencies": { diff --git a/chat/src/features/chat/UserInput.tsx b/chat/src/features/chat/UserInput.tsx index 7a0f67c1e..c5c3ffa62 100644 --- a/chat/src/features/chat/UserInput.tsx +++ b/chat/src/features/chat/UserInput.tsx @@ -6,6 +6,7 @@ import React, { useRef, useMemo, useState, + useEffect, } from "react"; import { useChat, useDrawer, useEmojis } from "../../hooks"; import { EmojiDrawer, QuickEmojis } from "../emoji"; @@ -13,7 +14,6 @@ import "./UserInput.css"; export function UserInput() { const { draft, sendMessage, updateDraft } = useChat(); - const { reveal, hide, open } = useDrawer(); const builtChatInput = useRef(null); const { visible, addQuery } = useEmojis(); const form = useRef(null); @@ -53,25 +53,6 @@ export function UserInput() { }, [handleSendMessage] ); - const handleToggleEmojiDrawer = useCallback(() => { - if (open) { - builtChatInput.current?.focus(); - hide(); - } else { - reveal({ - title: "Select an emoji", - content: ( - builtChatInput.current?.focus()} - /> - ), - }); - } - }, [open]); - const handleSelectEmoji = useCallback((emoji: string) => { - updateDraft((prev) => `${prev} :${emoji}: `); - }, []); const handleInsertQuickEmoji = useCallback( (emoji: string) => { const [openEmojiToken, closeEmojiToken] = locateEmojiTokens(draft); @@ -88,6 +69,18 @@ export function UserInput() { builtChatInput.current?.scrollIntoView({ behavior: "smooth" }); }, []); + // Listen for changes from the Emoji Modal and reflect them in draft + useEffect(() => { + const handleEmojiInsert = (event: CustomEvent<{ emoji: string }>) => + updateDraft((prev) => `${prev} ${event.detail.emoji} `); + + document.addEventListener("emojiInserted", handleEmojiInsert); + + return () => { + document.removeEventListener("emojiInserted", handleEmojiInsert); + } + }, []); + return (
{quickEmojis.length > 0 && ( @@ -122,6 +115,7 @@ export function UserInput() { onChange={handleChange} onKeyUp={handleKeyUp} onFocus={handleFocus} + onInput={console.log} placeholder="Message" autoComplete="off" value={draft} diff --git a/files/assets/js/emoji_modal.js b/files/assets/js/emoji_modal.js index 4a8849741..88a0e34a9 100644 --- a/files/assets/js/emoji_modal.js +++ b/files/assets/js/emoji_modal.js @@ -345,6 +345,9 @@ function emojiAddToInput(event) emojiInputTargetDOM.setRangeText(strToInsert); + const emojiInsertedEvent = new CustomEvent("emojiInserted", { detail: { emoji: strToInsert } }); + document.dispatchEvent(emojiInsertedEvent); + // Sir, come out and drink your Chromium complaint web // I HATE CHROME. I HATE CHROME if(window.chrome !== undefined)