Forum: a service of its own and the /forum pages
services/forum (axum, port 8083) on the same database and login, in the forum schema (migration 0038, which also adds the moderator role): nicknames, profiles with shared signs, topics, threads with listening or advice intent, two-level replies, read marks and followed threads, reactions as ratings with points and ranks, newcomer limits (lifted by a purchase), moderation with reasons, bans and a log. Integration tests run in CI. The frontend's /forum pages (light by default, dark on request, phone first with a desktop layout) are switched on by FORUM_URL; the /api/v1 proxy sends /api/v1/forum/* to the forum service. Concept and status: docs/kozosseg.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
"use client";
|
||||
|
||||
import { useRef, useState } from "react";
|
||||
|
||||
import { EMOJI } from "@/lib/forum";
|
||||
|
||||
/**
|
||||
* The text box with an emoji tray (phones have emoji on the keyboard; the
|
||||
* tray is mostly for computers) and the send button.
|
||||
*/
|
||||
export function Composer({
|
||||
id,
|
||||
label,
|
||||
placeholder,
|
||||
initial = "",
|
||||
submitLabel = "Küldés",
|
||||
busy,
|
||||
onSubmit,
|
||||
onCancel,
|
||||
rows = 3,
|
||||
autoFocus = false,
|
||||
}: {
|
||||
id: string;
|
||||
label: string;
|
||||
placeholder?: string;
|
||||
initial?: string;
|
||||
submitLabel?: string;
|
||||
busy: boolean;
|
||||
onSubmit: (text: string) => Promise<boolean>;
|
||||
onCancel?: () => 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);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="fc" onSubmit={submit}>
|
||||
<label htmlFor={id} className="sr-only">
|
||||
{label}
|
||||
</label>
|
||||
<textarea
|
||||
id={id}
|
||||
ref={area}
|
||||
className="fc-text"
|
||||
rows={rows}
|
||||
placeholder={placeholder}
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
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}>
|
||||
Mégse
|
||||
</button>
|
||||
)}
|
||||
<button type="submit" className="btn btn-primary btn-sm" disabled={busy || !text.trim()}>
|
||||
{busy ? "Küldés…" : submitLabel}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user