Forum: typing notices, smileys to emoji while typing, no emoji tray
"Holdfény gépel…" shows in threads and private conversations: the page says over the live connection (every few seconds while typing) that its member types, and the forum service passes it to those who may see that place, never back to the typer. The emoji tray is gone (phones have their emoji keyboard); character smileys turn into emoji as they are typed, from a longer list shared with the server (which also converts titles now; <3 is a red heart). Emoji show in colour: the forum's font stack names the systems' colour emoji fonts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { useRef, useState } from "react";
|
||||
import { useState } from "react";
|
||||
|
||||
import { EMOJI } from "@/lib/forum";
|
||||
import { convertEmoticons, withEmoji } from "@/lib/emoticons";
|
||||
|
||||
/**
|
||||
* The text box with an emoji tray (phones have emoji on the keyboard; the
|
||||
* tray is mostly for computers) and the send button.
|
||||
* The text box and the send button. Character smileys (`:)`, `<3`) turn into
|
||||
* emoji as they are typed; phones bring their own emoji keyboard.
|
||||
* `onTyping`: called on every keystroke (the "… gépel" notice).
|
||||
*/
|
||||
export function Composer({
|
||||
id,
|
||||
@@ -17,6 +18,7 @@ export function Composer({
|
||||
busy,
|
||||
onSubmit,
|
||||
onCancel,
|
||||
onTyping,
|
||||
rows = 3,
|
||||
autoFocus = false,
|
||||
}: {
|
||||
@@ -28,36 +30,17 @@ export function Composer({
|
||||
busy: boolean;
|
||||
onSubmit: (text: string) => Promise<boolean>;
|
||||
onCancel?: () => void;
|
||||
onTyping?: () => void;
|
||||
rows?: number;
|
||||
autoFocus?: boolean;
|
||||
}) {
|
||||
const [text, setText] = useState(initial);
|
||||
const [tray, setTray] = useState(false);
|
||||
const area = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
function insert(emoji: string) {
|
||||
const el = area.current;
|
||||
if (!el) {
|
||||
setText((t) => t + emoji);
|
||||
return;
|
||||
}
|
||||
const start = el.selectionStart ?? text.length;
|
||||
const end = el.selectionEnd ?? text.length;
|
||||
const next = text.slice(0, start) + emoji + text.slice(end);
|
||||
setText(next);
|
||||
requestAnimationFrame(() => {
|
||||
el.focus();
|
||||
el.setSelectionRange(start + emoji.length, start + emoji.length);
|
||||
});
|
||||
}
|
||||
|
||||
async function submit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!text.trim() || busy) return;
|
||||
if (await onSubmit(text)) {
|
||||
setText("");
|
||||
setTray(false);
|
||||
}
|
||||
const final = convertEmoticons(text, text.length, true).text;
|
||||
if (await onSubmit(final)) setText("");
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -67,38 +50,18 @@ export function Composer({
|
||||
</label>
|
||||
<textarea
|
||||
id={id}
|
||||
ref={area}
|
||||
className="fc-text"
|
||||
rows={rows}
|
||||
placeholder={placeholder}
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
onChange={(e) => {
|
||||
withEmoji(e, setText);
|
||||
onTyping?.();
|
||||
}}
|
||||
maxLength={10000}
|
||||
autoFocus={autoFocus}
|
||||
/>
|
||||
{tray && (
|
||||
<div className="fc-tray" role="group" aria-label="Emoji">
|
||||
{EMOJI.map((e) => (
|
||||
<button key={e} type="button" className="fc-emoji" onClick={() => insert(e)} aria-label={`${e} beszúrása`}>
|
||||
{e}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="fc-actions">
|
||||
<button
|
||||
type="button"
|
||||
className="fc-icon-btn"
|
||||
aria-label="Emoji"
|
||||
aria-expanded={tray}
|
||||
onClick={() => setTray((t) => !t)}
|
||||
>
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="9" />
|
||||
<path d="M8.5 14.5a4 4 0 0 0 7 0" />
|
||||
<path d="M9 9.5h.01M15 9.5h.01" strokeWidth="2.6" />
|
||||
</svg>
|
||||
</button>
|
||||
<span className="fc-spacer" />
|
||||
{onCancel && (
|
||||
<button type="button" className="btn btn-ghost btn-sm" onClick={onCancel}>
|
||||
|
||||
Reference in New Issue
Block a user