Forum: whom a reply answers, icon badges, the new features on the pages
- Replies stay two levels deep, but a reply to a reply says whom it is
for ("↪ Holdfény"): posts.reply_to_id.
- The question stands apart on its own card; the listening reminder above
the reply box is gone.
- Every rank and badge has its own line icon (Vándor, Kereső, Fonó,
Csillagfonó, Sorsfonó; Moderátor, Meghallgató, Támogató, Szálindító).
- Pages for the new features: own avatar upload and the moderator's reset,
the listener and supporter switches, mention and weekly summary e-mails
(the weekly one off by default), "@" suggestions and mention links, the
daily sky thread by "Sorsfonalak", "Most itt vannak", joining restricted
topics, and the moderators' Témák tab (requests; topics for the admin).
- Members-only topics say so to members too.
- The privacy notice (HU, EN) and point 8.1 of the terms cover own
pictures, badges, mentions, restricted topics and the weekly summary;
the data export and account deletion include them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -1,13 +1,26 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
import { api } from "@/lib/api";
|
||||
import { convertEmoticons, withEmoji } from "@/lib/emoticons";
|
||||
import type { ForumAuthor } from "@/lib/forum";
|
||||
|
||||
import { Avatar } from "./Avatar";
|
||||
|
||||
/** "@Ho" right before the caret: what was typed after the "@", and where it starts. */
|
||||
function mentionAt(text: string, caret: number): { query: string; start: number } | null {
|
||||
const before = text.slice(0, caret);
|
||||
const match = /(?:^|\s)@([^\s@]{1,24})$/.exec(before);
|
||||
if (!match) return null;
|
||||
return { query: match[1], start: caret - match[1].length - 1 };
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
* `mentions`: typing "@Ho" offers the members whose nickname starts so.
|
||||
*/
|
||||
export function Composer({
|
||||
id,
|
||||
@@ -19,6 +32,7 @@ export function Composer({
|
||||
onSubmit,
|
||||
onCancel,
|
||||
onTyping,
|
||||
mentions = false,
|
||||
rows = 3,
|
||||
autoFocus = false,
|
||||
}: {
|
||||
@@ -31,16 +45,54 @@ export function Composer({
|
||||
onSubmit: (text: string) => Promise<boolean>;
|
||||
onCancel?: () => void;
|
||||
onTyping?: () => void;
|
||||
mentions?: boolean;
|
||||
rows?: number;
|
||||
autoFocus?: boolean;
|
||||
}) {
|
||||
const [text, setText] = useState(initial);
|
||||
const [suggest, setSuggest] = useState<{ query: string; start: number; members: ForumAuthor[] } | null>(null);
|
||||
const area = useRef<HTMLTextAreaElement>(null);
|
||||
const timer = useRef<number | undefined>(undefined);
|
||||
|
||||
useEffect(() => () => window.clearTimeout(timer.current), []);
|
||||
|
||||
function lookUp(value: string, caret: number) {
|
||||
window.clearTimeout(timer.current);
|
||||
const at = mentions ? mentionAt(value, caret) : null;
|
||||
if (!at) {
|
||||
setSuggest(null);
|
||||
return;
|
||||
}
|
||||
timer.current = window.setTimeout(() => {
|
||||
api<{ members: ForumAuthor[] }>(`/forum/members/search?q=${encodeURIComponent(at.query)}`)
|
||||
.then((res) => setSuggest(res.members.length ? { ...at, members: res.members } : null))
|
||||
.catch(() => setSuggest(null));
|
||||
}, 200);
|
||||
}
|
||||
|
||||
function pick(nickname: string) {
|
||||
if (!suggest) return;
|
||||
const el = area.current;
|
||||
const caret = el?.selectionStart ?? text.length;
|
||||
const inserted = `@${nickname} `;
|
||||
const next = text.slice(0, suggest.start) + inserted + text.slice(caret);
|
||||
setText(next);
|
||||
setSuggest(null);
|
||||
requestAnimationFrame(() => {
|
||||
el?.focus();
|
||||
const at = suggest.start + inserted.length;
|
||||
el?.setSelectionRange(at, at);
|
||||
});
|
||||
}
|
||||
|
||||
async function submit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!text.trim() || busy) return;
|
||||
const final = convertEmoticons(text, text.length, true).text;
|
||||
if (await onSubmit(final)) setText("");
|
||||
if (await onSubmit(final)) {
|
||||
setText("");
|
||||
setSuggest(null);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -50,17 +102,40 @@ export function Composer({
|
||||
</label>
|
||||
<textarea
|
||||
id={id}
|
||||
ref={area}
|
||||
className="fc-text"
|
||||
rows={rows}
|
||||
placeholder={placeholder}
|
||||
value={text}
|
||||
onChange={(e) => {
|
||||
withEmoji(e, setText);
|
||||
lookUp(e.target.value, e.target.selectionStart ?? e.target.value.length);
|
||||
onTyping?.();
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Escape") setSuggest(null);
|
||||
}}
|
||||
maxLength={10000}
|
||||
autoFocus={autoFocus}
|
||||
aria-autocomplete={mentions ? "list" : undefined}
|
||||
/>
|
||||
{suggest && (
|
||||
<div className="fc-suggest" role="listbox" aria-label="Tagok">
|
||||
{suggest.members.map((m) => (
|
||||
<button
|
||||
key={m.nickname}
|
||||
type="button"
|
||||
role="option"
|
||||
aria-selected="false"
|
||||
className="fc-suggest-item"
|
||||
onClick={() => pick(m.nickname)}
|
||||
>
|
||||
<Avatar avatar={m.avatar} size={24} online={m.online} />
|
||||
{m.nickname}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="fc-actions">
|
||||
<span className="fc-spacer" />
|
||||
{onCancel && (
|
||||
|
||||
Reference in New Issue
Block a user