2026-11-26 10:29:49 +00:00
"use client" ;
import Link from "next/link" ;
import { useCallback , useEffect , useMemo , useRef , useState } from "react" ;
import { api , errorText } from "@/lib/api" ;
2026-11-26 12:20:17 +00:00
import { type ForumPost , INTENTS , REACTIONS , type ReactionKind , type ThreadPage , ago , memberHref } from "@/lib/forum" ;
2026-11-26 10:29:49 +00:00
2026-11-26 12:20:17 +00:00
import { signGlyphs } from "./AuthorLine" ;
2026-11-26 10:29:49 +00:00
import { Avatar } from "./Avatar" ;
import { Composer } from "./Composer" ;
import { PostBody } from "./PostBody" ;
2026-11-26 11:41:45 +00:00
import type { LiveNotice } from "./ForumNav" ;
2026-11-26 12:20:17 +00:00
import { ReactionIcon } from "./ReactionIcon" ;
import { ReportForm } from "./ReportButton" ;
2026-11-26 16:26:37 +00:00
import { LinkPreviews } from "./LinkPreviews" ;
2026-11-27 00:34:59 +00:00
import { PostPhotos } from "./Photos" ;
2026-11-26 14:52:00 +00:00
import { ShareCard } from "./ShareCard" ;
2026-11-26 11:50:09 +00:00
import { TypingLine , useTypingSender , useTypingWatch } from "./typing" ;
2026-11-26 13:02:38 +00:00
import { Badge , RankBadge } from "./Badges" ;
2026-11-27 00:34:59 +00:00
import { askDialog , confirmDialog } from "@/components/Dialogs" ;
2026-11-26 10:29:49 +00:00
/** How often the open thread looks for new replies (while the page is in front). */
const POLL_MS = 30 _000 ;
type Actions = {
busy : boolean ;
react : ( post : ForumPost , kind : ReactionKind | "down" ) => void ;
replyTo : ( post : ForumPost ) => void ;
edit : ( post : ForumPost , body : string ) => Promise < boolean >;
remove : ( post : ForumPost ) => void ;
restore : ( post : ForumPost ) => void ;
helped : ( post : ForumPost ) => void ;
2026-11-26 14:52:00 +00:00
/** The author takes the shared chart off their question. */
detachShare : ( post : ForumPost ) => void ;
2026-11-26 14:31:05 +00:00
/** Mute or unmute the post's author. */
mute : ( post : ForumPost ) => void ;
2026-11-26 10:29:49 +00:00
};
function ReactionRow ({
post ,
enabled ,
canDownvote ,
onReact ,
} : {
post : ForumPost ;
enabled : boolean ;
canDownvote : boolean ;
onReact : Actions [ "react" ];
}) {
const [ open , setOpen ] = useState ( false );
const given = REACTIONS . filter (( r ) => post . reactions [ r . kind ] > 0 || post . mine === r . kind );
return (
< div className = "fr-row" role = "group" aria-label = "Reakciók" >
{ given . map (( r ) => (
< button
key = { r . kind }
type = "button"
className = "fr-chip"
aria-pressed = { post . mine === r . kind }
2026-11-26 12:20:17 +00:00
aria-label = { ` ${ r . label } , ${ post . reactions [ r . kind ] }${ post . mine === r . kind ? ", a tiéd" : "" } ` }
title = { r . label }
2026-11-26 10:29:49 +00:00
disabled = { ! enabled }
onClick = {() => onReact ( post , r . kind )}
>
2026-11-26 12:20:17 +00:00
< ReactionIcon kind = { r . kind } filled = { post . mine === r . kind } />
{ post . reactions [ r . kind ]}
2026-11-26 10:29:49 +00:00
</ button >
))}
{ enabled && (
2026-11-26 12:20:17 +00:00
< Popover
open = { open }
onClose = {() => setOpen ( false )}
button = {
< button
type = "button"
className = "fr-chip fr-add"
aria-label = "Reakció hozzáadása"
aria-expanded = { open }
onClick = {() => setOpen (( o ) => ! o )}
>
< svg viewBox = "0 0 24 24" aria-hidden = "true" >
< path d = "M12 6v12M6 12h12" />
</ svg >
</ button >
}
>
{ REACTIONS . map (( r ) => (
< button
key = { r . kind }
type = "button"
role = "menuitem"
className = "fpop-item"
aria-pressed = { post . mine === r . kind }
onClick = {() => {
setOpen ( false );
onReact ( post , r . kind );
}}
>
< ReactionIcon kind = { r . kind } size = { 18 } filled = { post . mine === r . kind } />
{ r . label }
</ button >
))}
</ Popover >
2026-11-26 10:29:49 +00:00
)}
{ canDownvote && enabled && (
< button
type = "button"
className = "fr-chip fr-down"
aria-pressed = { post . mine === "down" }
aria-label = "Nem visz előre"
title = "Nem visz előre"
onClick = {() => onReact ( post , "down" )}
>
2026-11-26 12:20:17 +00:00
< svg viewBox = "0 0 24 24" aria-hidden = "true" >
< path d = "M7 10l5 5 5-5" />
</ svg >
2026-11-26 10:29:49 +00:00
</ button >
)}
</ div >
);
}
2026-11-26 12:20:17 +00:00
/** A small menu under a button (closes on a click elsewhere or Escape). */
function Popover ({
open ,
onClose ,
button ,
children ,
align = "left" ,
} : {
open : boolean ;
onClose : () => void ;
button : React.ReactNode ;
children : React.ReactNode ;
align ?: "left" | "right" ;
}) {
const box = useRef < HTMLSpanElement >( null );
useEffect (() => {
if ( ! open ) return ;
const outside = ( e : MouseEvent ) => {
if ( box . current && ! box . current . contains ( e . target as Node )) onClose ();
};
const escape = ( e : KeyboardEvent ) => {
if ( e . key === "Escape" ) onClose ();
};
document . addEventListener ( "mousedown" , outside );
document . addEventListener ( "keydown" , escape );
return () => {
document . removeEventListener ( "mousedown" , outside );
document . removeEventListener ( "keydown" , escape );
};
}, [ open , onClose ]);
2026-11-26 10:29:49 +00:00
return (
2026-11-26 12:20:17 +00:00
< span className = "fpop-wrap" ref = { box }>
{ button }
{ open && (
< span className = { align === "right" ? "fpop fpop-right" : "fpop" } role = "menu" >
{ children }
2026-11-26 10:29:49 +00:00
</ span >
)}
2026-11-26 12:20:17 +00:00
</ span >
2026-11-26 10:29:49 +00:00
);
}
2026-11-26 13:02:38 +00:00
/** The site's own mark as an avatar (the daily sky thread). */
function SiteMark ({ size } : { size : number }) {
return (
< span className = "av av-site" style = {{ width : size , height : size }}>
< svg viewBox = "0 0 64 64" width = { size } height = { size } aria-hidden = "true" >
< circle cx = "32" cy = "32" r = "32" className = "av-bg" />
< g fill = "none" strokeWidth = "4.5" strokeLinecap = "round" className = "av-site-mark" >
< circle cx = "32" cy = "32" r = "18" />
< path d = "M15 43 C 26 42, 30 25, 42 21" />
</ g >
</ svg >
</ span >
);
}
2026-11-26 10:29:49 +00:00
function PostCard ({
post ,
page ,
actions ,
isNew ,
2026-11-26 12:20:17 +00:00
nested = false ,
2026-11-26 10:29:49 +00:00
} : {
post : ForumPost ;
page : ThreadPage ;
actions : Actions ;
isNew : boolean ;
2026-11-26 12:20:17 +00:00
nested? : boolean ;
2026-11-26 10:29:49 +00:00
}) {
const [ editing , setEditing ] = useState ( false );
2026-11-26 12:20:17 +00:00
const [ reporting , setReporting ] = useState ( false );
const [ menu , setMenu ] = useState ( false );
2026-11-26 10:29:49 +00:00
const [ showCollapsed , setShowCollapsed ] = useState ( false );
2026-11-26 14:31:05 +00:00
const [ showMuted , setShowMuted ] = useState ( false );
2026-11-26 10:29:49 +00:00
const { viewer , thread , access } = page ;
const writer = viewer . member !== null && ! viewer . member . banned ;
const starter = post . author !== null && post . author . nickname === thread . author ? . nickname ;
const canReact = writer && ! post . own && ! post . deleted && ! thread . locked ;
2026-11-26 12:20:17 +00:00
const author = post . author ;
const glyphs = signGlyphs ( author ? . signs );
const size = post . is_opening ? 40 : nested ? 26 : 32 ;
2026-11-26 10:29:49 +00:00
if ( post . deleted && ! viewer . moderator ) {
return (
< article className = "fp fp-removed" id = { `h ${ post . id } ` }>
< span >
{ post . deleted . by_moderator
? "A moderátor eltávolította ezt a hozzászólást."
: "A szerző törölte ezt a hozzászólást." }
</ span >
{ post . deleted . reason && < span className = "hint" > Ok : { post . deleted . reason }</ span >}
</ article >
);
}
2026-11-26 14:31:05 +00:00
// A muted member's post folds up; one click shows it.
if ( post . muted && ! showMuted ) {
return (
< article className = { nested ? "fp fp-muted fp-nested" : "fp fp-muted" } id = { `h ${ post . id } ` }>
< button type = "button" className = "fp-collapsed" onClick = {() => setShowMuted ( true )}>
{ author ? . nickname ?? "Egy tag" } hozzászólása · elnémítottad · Megjelenítés
</ button >
</ article >
);
}
2026-11-26 12:20:17 +00:00
const menuItems : { label : string ; run : () => void ; danger? : boolean }[] = [];
if ( ! post . deleted ) {
if ( access ? . is_thread_author && ! post . is_opening && ! post . own && writer ) {
menuItems . push ({ label : post.helped ? "Mégsem segített" : "Ez segített" , run : () => actions . helped ( post ) });
}
if ( post . own && writer && ! thread . locked ) menuItems . push ({ label : "Szerkesztés" , run : () => setEditing ( true ) });
2026-11-26 14:52:00 +00:00
if ( post . own && post . share && ! post . share . revoked )
menuItems . push ({ label : "Képlet levétele" , run : () => actions . detachShare ( post ) });
2026-11-26 12:20:17 +00:00
if ( post . own ) menuItems . push ({ label : "Törlés" , run : () => actions . remove ( post ), danger : true });
if ( viewer . logged_in && ! post . own ) menuItems . push ({ label : "Jelentés" , run : () => setReporting ( true ) });
2026-11-26 14:31:05 +00:00
if ( viewer . member && ! post . own && author && ! post . system )
menuItems . push ({
label : post.muted ? ` ${ author . nickname } némításának feloldása` : ` ${ author . nickname } némítása` ,
run : () => actions . mute ( post ),
});
2026-11-26 12:20:17 +00:00
if ( viewer . moderator && ! post . own )
menuItems . push ({ label : "Eltávolítás" , run : () => actions . remove ( post ), danger : true });
} else if ( viewer . moderator ) {
menuItems . push ({ label : "Visszaállítás (admin)" , run : () => actions . restore ( post ) });
}
const classes = [ "fp" , post . is_opening && "fp-opening" , nested && "fp-nested" ]. filter ( Boolean ). join ( " " );
2026-11-26 10:29:49 +00:00
return (
2026-11-26 12:20:17 +00:00
< article className = { classes } id = { `h ${ post . id } ` }>
< span className = "fp-av" >
2026-11-26 13:02:38 +00:00
{ post . system ? (
< SiteMark size = { size } />
) : author ? (
2026-11-26 12:20:17 +00:00
< Link href = { memberHref ( author . nickname )} tabIndex = { - 1 } aria-hidden = "true" >
< Avatar avatar = { author . avatar } size = { size } online = { author . online } />
</ Link >
) : (
< Avatar avatar = { null } size = { size } />
)}
</ span >
< div className = "fp-head" >
< span className = "fp-names" >
2026-11-26 13:02:38 +00:00
{ post . system ? (
< span className = "fa-name" > Sorsfonalak </ span >
) : author ? (
2026-11-26 12:20:17 +00:00
< Link href = { memberHref ( author . nickname )} className = "fa-name" >
{ author . nickname }
</ Link >
) : (
< span className = "fa-name muted" > Törölt tag </ span >
)}
2026-11-26 13:02:38 +00:00
{ post . reply_to ? . nickname && nested && (
< span className = "fp-replyto" title = { `Válasz neki: ${ post . reply_to . nickname } ` }>
< svg viewBox = "0 0 24 24" aria-hidden = "true" >
< path d = "M9 14L4 9l5-5" />
< path d = "M4 9h10a6 6 0 0 1 6 6v4" />
</ svg >
< span className = "sr-only" > válasz neki : </ span >
{ post . reply_to . nickname }
</ span >
)}
2026-11-26 12:20:17 +00:00
{ author ? . online && < span className = "sr-only" >( online )</ span >}
2026-11-26 13:02:38 +00:00
{ author && < RankBadge rank = { author . rank } name = { author . rank_name } />}
{ post . system && < Badge kind = "sky" />}
{ author ? . moderator && < Badge kind = "mod" />}
2026-11-26 15:43:24 +00:00
{ author ? . founder && ! nested && < Badge kind = "founder" />}
2026-11-26 13:02:38 +00:00
{ author ? . listener && < Badge kind = "listener" />}
{ author ? . supporter && < Badge kind = "supporter" />}
{ starter && ! post . is_opening && < Badge kind = "starter" />}
2026-11-26 10:29:49 +00:00
{ isNew && < span className = "fa-badge fa-badge-new" > ú j </ span >}
2026-11-26 12:20:17 +00:00
{ glyphs && ! nested && (
< span className = "fp-signs sym" title = { glyphs . title }>
{ glyphs . text }
</ span >
)}
</ span >
< time
className = "fp-time"
suppressHydrationWarning
dateTime = { post . created_at }
title = { new Date ( post . created_at ). toLocaleString ( "hu-HU" , { timeZone : "Europe/Budapest" })}
>
{ ago ( post . created_at )}
{ post . edited_at && " · szerkesztve" }
</ time >
</ div >
< div className = "fp-content" >
2026-11-26 10:29:49 +00:00
{ post . deleted && (
< p className = "fp-mod-note" >
Eltávolítva { post . deleted . reason ? ` (ok: ${ post . deleted . reason } )` : " a szerző által" }. Csak a moderátorok
látják .
</ p >
)}
{ post . collapsed && ! showCollapsed ? (
< button type = "button" className = "fp-collapsed" onClick = {() => setShowCollapsed ( true )}>
Sokan jelezték , hogy ez nem visz előre . Megjelenítés
</ button >
) : editing ? (
< Composer
2026-11-26 13:02:38 +00:00
mentions
2026-11-26 10:29:49 +00:00
id = { `szerk- ${ post . id } ` }
label = "Hozzászólás szerkesztése"
initial = { post . body ?? "" }
submitLabel = "Mentés"
busy = { actions . busy }
autoFocus
onCancel = {() => setEditing ( false )}
onSubmit = { async ( text ) => {
const ok = await actions . edit ( post , text );
if ( ok ) setEditing ( false );
return ok ;
}}
/>
) : (
2026-11-26 14:52:00 +00:00
post . body !== null && (
<>
2026-11-26 16:26:37 +00:00
< PostBody text = { post . body } mentions = { post . mentions } hide = { post . links ? . map (( l ) => l . url ) ?? []} />
2026-11-27 00:34:59 +00:00
{ post . photos && post . photos . length > 0 && < PostPhotos photos = { post . photos } />}
2026-11-26 16:26:37 +00:00
{ post . links && post . links . length > 0 && < LinkPreviews links = { post . links } />}
2026-11-26 14:52:00 +00:00
{ post . share && < ShareCard share = { post . share } />}
</>
)
2026-11-26 10:29:49 +00:00
)}
2026-11-26 12:20:17 +00:00
</ div >
{ ! editing && ( ! post . deleted || menuItems . length > 0 ) && (
< div className = "fp-actions" >
{ post . helped && (
< span className = "fp-helped" title = { ` ${ thread . author ? . nickname ?? "A szál indítója" } szerint ez segített` }>
< svg viewBox = "0 0 24 24" aria-hidden = "true" >
< path d = "M5 12.5l4.5 4.5L19 7.5" />
</ svg >
Segített
</ span >
)}
{ ! post . deleted && (
< ReactionRow
post = { post }
enabled = { canReact }
canDownvote = { access ? . can_downvote ?? false }
onReact = { actions . react }
/>
)}
< span className = "fp-spacer" />
{ viewer . moderator && typeof post . down === "number" && post . down > 0 && (
< span className = "hint" title = "Nem visz előre jelzések (csak moderátoroknak)" >
⌄ { post . down }
</ span >
)}
{ ! post . deleted && access ? . can_reply && writer && ! post . is_opening && (
< button type = "button" className = "fp-reply" onClick = {() => actions . replyTo ( post )}>
< svg viewBox = "0 0 24 24" aria-hidden = "true" >
< path d = "M9 14L4 9l5-5" />
< path d = "M4 9h10a6 6 0 0 1 6 6v4" />
</ svg >
Válasz
</ button >
)}
{ menuItems . length > 0 && (
< Popover
open = { menu }
onClose = {() => setMenu ( false )}
align = "right"
button = {
2026-11-26 10:29:49 +00:00
< button
type = "button"
2026-11-26 12:20:17 +00:00
className = "fp-more"
aria-label = "Továbbiak"
aria-expanded = { menu }
onClick = {() => setMenu (( m ) => ! m )}
2026-11-26 10:29:49 +00:00
>
2026-11-26 12:20:17 +00:00
< svg viewBox = "0 0 24 24" aria-hidden = "true" >
< circle cx = "5.5" cy = "12" r = "1.6" />
< circle cx = "12" cy = "12" r = "1.6" />
< circle cx = "18.5" cy = "12" r = "1.6" />
</ svg >
2026-11-26 10:29:49 +00:00
</ button >
2026-11-26 12:20:17 +00:00
}
>
{ menuItems . map (( item ) => (
< button
key = { item . label }
type = "button"
role = "menuitem"
className = { item . danger ? "fpop-item fpop-danger" : "fpop-item" }
onClick = {() => {
setMenu ( false );
item . run ();
}}
>
{ item . label }
2026-11-26 10:29:49 +00:00
</ button >
2026-11-26 12:20:17 +00:00
))}
</ Popover >
)}
</ div >
)}
{ reporting && (
< div className = "fp-report" >
< ReportForm path = { `/forum/posts/ ${ post . id } /report` } onClose = {() => setReporting ( false )} />
</ div >
)}
2026-11-26 10:29:49 +00:00
</ article >
);
}
/** The thread page: posts, reactions, replies, read marks, new replies while open. */
export function ThreadView ({ initial } : { initial : ThreadPage }) {
const [ page , setPage ] = useState ( initial );
const [ incoming , setIncoming ] = useState < ThreadPage | null >( null );
const [ replyTo , setReplyTo ] = useState < ForumPost | null >( null );
const [ busy , setBusy ] = useState ( false );
const [ error , setError ] = useState < string | null >( null );
// Where the visitor stopped reading when they opened the page.
const [ readUpTo ] = useState ( initial . access ? . last_read_post_id ?? null );
2026-11-26 11:50:09 +00:00
const typingNow = useTypingWatch ( "thread" , initial . thread . id );
const imTyping = useTypingSender ( "thread" , initial . thread . id );
2026-11-26 10:29:49 +00:00
const composer = useRef < HTMLDivElement >( null );
2026-11-26 13:31:00 +00:00
// Replying to a post: the box opens at the bottom of its branch (the
// first-level post and the replies under it); what was typed moves along.
const inline = useRef < HTMLDivElement >( null );
const draft = useRef ( "" );
const replyBranch = replyTo ? ( replyTo . parent_id ?? replyTo . id ) : null ;
useEffect (() => {
if ( replyBranch === null ) return ;
const box = inline . current ;
box ? . scrollIntoView ({ behavior : "smooth" , block : "center" });
box ? . querySelector ( "textarea" ) ? . focus ({ preventScroll : true });
}, [ replyBranch , replyTo ]);
2026-11-26 10:29:49 +00:00
const { viewer , thread , access } = page ;
const member = viewer . member !== null ;
const base = `/forum/threads/ ${ thread . id } ` ;
const lastId = page . posts . length ? page . posts [ page . posts . length - 1 ]. id : 0 ;
// Mark read up to the newest post shown.
useEffect (() => {
if ( ! member || lastId === 0 ) return ;
2026-11-26 13:31:00 +00:00
api ( ` ${ base } /read` , { body : { post_id : lastId } })
// The answers read here leave the count on the "Válaszok" tab.
. then (() => window . dispatchEvent ( new Event ( "forum:nav" )))
. catch (() => {});
2026-11-26 10:29:49 +00:00
}, [ member , lastId , base ]);
// New replies while the page is open: offered, not pushed into the text being read.
const poll = useCallback ( async () => {
if ( document . visibilityState !== "visible" || thread . deleted ) return ;
try {
const fresh = await api < ThreadPage >( base );
const freshLast = fresh . posts . length ? fresh . posts [ fresh . posts . length - 1 ]. id : 0 ;
if ( freshLast > lastId ) setIncoming ( fresh );
} catch {
/* a missed poll is retried later */
}
}, [ base , lastId , thread . deleted ]);
useEffect (() => {
const timer = window . setInterval ( poll , POLL_MS );
2026-11-26 11:41:45 +00:00
// The live connection rings for this thread: look at once.
const live = ( e : Event ) => {
const notice = ( e as CustomEvent < LiveNotice >). detail ;
if ( notice . t === "thread" && notice . id === thread . id ) void poll ();
};
window . addEventListener ( "forum:live" , live );
return () => {
window . clearInterval ( timer );
window . removeEventListener ( "forum:live" , live );
};
}, [ poll , thread . id ]);
2026-11-26 10:29:49 +00:00
const newCount = incoming ? incoming . posts . filter (( p ) => p . id > lastId && ! p . own ). length : 0 ;
async function run < T >( work : () => Promise < T >) : Promise < T | null > {
setBusy ( true );
setError ( null );
try {
return await work ();
} catch ( e ) {
setError ( errorText ( e ));
return null ;
} finally {
setBusy ( false );
}
}
const replacePost = useCallback (( post : ForumPost ) => {
setPage (( p ) => ({ ... p , posts : p.posts.map (( x ) => ( x . id === post . id ? post : x )) }));
}, []);
const reload = useCallback ( async () => {
const fresh = await api < ThreadPage >( base );
setPage ( fresh );
setIncoming ( null );
}, [ base ]);
const actions : Actions = {
busy ,
react : ( post , kind ) =>
void run ( async () => {
const updated =
post . mine === kind
? await api < ForumPost >( `/forum/posts/ ${ post . id } /reaction` , { method : "DELETE" })
: await api < ForumPost >( `/forum/posts/ ${ post . id } /reaction` , { method : "PUT" , body : { kind } });
replacePost ( updated );
}),
2026-11-26 13:31:00 +00:00
replyTo : ( post ) => setReplyTo ( post ),
2026-11-26 10:29:49 +00:00
edit : async ( post , body ) => {
const updated = await run (() => api < ForumPost >( `/forum/posts/ ${ post . id } ` , { method : "PATCH" , body : { body } }));
if ( updated ) replacePost ( updated );
return updated !== null ;
},
2026-11-27 00:34:59 +00:00
remove : async ( post ) => {
2026-11-26 10:29:49 +00:00
let reason : string | null = null ;
if ( post . own ) {
2026-11-27 00:34:59 +00:00
const ok = await confirmDialog ({ title : "Törlöd a hozzászólásodat?" , confirm : "Törlés" , danger : true });
if ( ! ok ) return ;
2026-11-26 10:29:49 +00:00
} else {
2026-11-27 00:34:59 +00:00
reason = await askDialog ({
title : "Eltávolítod a hozzászólást?" ,
text : "Az indoklás a hozzászólás helyén látszik." ,
label : "Miért távolítod el?" ,
required : true ,
confirm : "Eltávolítás" ,
danger : true ,
});
2026-11-26 10:29:49 +00:00
if ( ! reason ) return ;
}
void run ( async () => {
await api ( `/forum/posts/ ${ post . id } ` , { method : "DELETE" , body : { reason } });
await reload ();
});
},
restore : ( post ) =>
void run ( async () => {
await api ( `/forum/posts/ ${ post . id } /restore` , { method : "POST" });
await reload ();
}),
2026-11-27 00:34:59 +00:00
detachShare : async ( post ) => {
const ok = await confirmDialog ({
title : "Leveszed a csatolt képletet?" ,
text : "A kártya eltűnik, és a link sem működik többé." ,
confirm : "Levétel" ,
danger : true ,
});
if ( ! ok ) return ;
2026-11-26 14:52:00 +00:00
void run ( async () => {
await api ( `/forum/posts/ ${ post . id } /share` , { method : "DELETE" });
await reload ();
});
},
2026-11-27 00:34:59 +00:00
mute : async ( post ) => {
2026-11-26 14:31:05 +00:00
const nickname = post . author ? . nickname ;
if ( ! nickname ) return ;
if (
! post . muted &&
2026-11-27 00:34:59 +00:00
! ( await confirmDialog ({
title : `Elnémítod ${ nickname } tagot?` ,
text : "A szálai eltűnnek a listáidból, a hozzászólásai összecsukva látszanak, és nem kapsz értesítést tőle. Ő erről nem tud. A beállításoknál bármikor feloldhatod." ,
confirm : "Elnémítás" ,
}))
2026-11-26 14:31:05 +00:00
)
return ;
void run ( async () => {
await api ( `/forum/members/ ${ encodeURIComponent ( nickname ) } /mute` , { method : post.muted ? "DELETE" : "PUT" });
await reload ();
});
},
2026-11-26 10:29:49 +00:00
helped : ( post ) =>
void run ( async () => {
const updated = await api < ForumPost >( `/forum/posts/ ${ post . id } /helped` , {
method : post.helped ? "DELETE" : "PUT" ,
});
replacePost ( updated );
}),
};
2026-11-26 13:31:00 +00:00
/** A first-level reply (the box at the bottom), or one to `replyTo` (the box in its branch). */
2026-11-27 00:34:59 +00:00
async function sendReply ( text : string , to : ForumPost | null , photos : string [] = []) : Promise < boolean > {
const post = await run (() =>
api < ForumPost >( ` ${ base } /posts` , { body : { body : text , parent_id : to?.id ?? null , photos } }),
);
2026-11-26 10:29:49 +00:00
if ( ! post ) return false ;
2026-11-26 13:31:00 +00:00
if ( to ) {
draft . current = "" ;
setReplyTo ( null );
}
2026-11-26 10:29:49 +00:00
await reload (). catch (() => setPage (( p ) => ({ ... p , posts : [... p . posts , post ] })));
requestAnimationFrame (() => document . getElementById ( `h ${ post . id } ` ) ? . scrollIntoView ({ block : "center" }));
return true ;
}
async function toggleFollow() {
const following = access ? . following ?? false ;
await run (() => api ( ` ${ base } /follow` , { method : following ? "DELETE" : "PUT" }));
setPage (( p ) => ( p . access ? { ... p , access : { ... p . access , following : ! following } } : p ));
}
async function moderateThread ( change : { locked? : boolean ; pinned? : boolean }) {
await run (() => api ( base , { method : "PATCH" , body : change }));
await reload ();
}
async function removeThread() {
2026-11-27 00:34:59 +00:00
const reason = await askDialog ({
title : "Eltávolítod az egész szálat?" ,
text : "Az indoklás látszik a szál helyén." ,
label : "Miért távolítod el?" ,
required : true ,
confirm : "Eltávolítás" ,
danger : true ,
});
2026-11-26 10:29:49 +00:00
if ( ! reason ) return ;
await run (() => api ( base , { method : "DELETE" , body : { reason } }));
await reload ();
}
const opening = page . posts . find (( p ) => p . is_opening );
const replies = useMemo (() => page . posts . filter (( p ) => ! p . is_opening ), [ page . posts ]);
const tops = replies . filter (( p ) => p . parent_id === null );
const childrenOf = ( id : number ) => replies . filter (( p ) => p . parent_id === id );
// "Itt hagytad abba": before the first post by someone else after the last visit.
const firstUnread = readUpTo !== null ? ( replies . find (( p ) => p . id > readUpTo && ! p . own ) ? . id ?? null ) : null ;
const unreadCount = firstUnread !== null ? replies . filter (( p ) => p . id >= firstUnread && ! p . own ). length : 0 ;
const topOf = ( id : number ) => {
const p = replies . find (( x ) => x . id === id );
return p ? . parent_id ?? id ;
};
const markerTop = firstUnread !== null ? topOf ( firstUnread ) : null ;
const intent = thread . intent ? INTENTS [ thread . intent ] : null ;
const starter = thread . author ? . nickname ?? "A szál indítója" ;
return (
< div className = "ftv" >
< nav className = "forum-crumbs" aria-label = "Morzsamenü" >
< Link href = "/forum" > Fórum </ Link >
< span aria-hidden = "true" > › </ span >
< Link href = { `/forum/ ${ thread . topic . slug } ` }>{ thread . topic . name }</ Link >
2026-11-26 13:02:38 +00:00
{ thread . topic . visibility !== "public" && (
< span
className = "ftv-private"
title = {
thread . topic . visibility === "members"
? "Csak belépett tagok látják, a keresők sem"
: "Zárt kör: csak a jóváhagyott tagok látják"
}
>
< svg viewBox = "0 0 24 24" aria-hidden = "true" >
< rect x = "5" y = "11" width = "14" height = "9" rx = "2" />
< path d = "M8 11V8a4 4 0 0 1 8 0v3" />
</ svg >
{ thread . topic . visibility === "members" ? "csak tagoknak" : "zárt kör" }
</ span >
)}
2026-11-26 10:29:49 +00:00
</ nav >
< div className = "ftv-toolbar" >
{ member && access && (
< button type = "button" className = "btn btn-sm" aria-pressed = { access . following } onClick = { toggleFollow }>
{ access . following ? "Követem ✓" : "Követem" }
</ button >
)}
{ viewer . moderator && ! thread . deleted && (
< details className = "ftv-mod" >
< summary className = "btn btn-sm btn-ghost" > Moderálás </ summary >
< div className = "ftv-mod-menu" >
< button type = "button" onClick = {() => moderateThread ({ locked : ! thread . locked })}>
{ thread . locked ? "Szál feloldása" : "Szál lezárása" }
</ button >
< button type = "button" onClick = {() => moderateThread ({ pinned : ! thread . pinned })}>
{ thread . pinned ? "Kitűzés levétele" : "Kitűzés" }
</ button >
< button type = "button" className = "danger" onClick = { removeThread }>
Szál eltávolítása
</ button >
</ div >
</ details >
)}
</ div >
{ thread . deleted ? (
< div className = "fp fp-removed" >
< span > A moderátor eltávolította ezt a szálat .</ span >
{ thread . deleted . reason && < span className = "hint" > Ok : { thread . deleted . reason }</ span >}
</ div >
) : null }
< h1 className = "ftv-title" >
{ thread . pinned && < span className = "ft-pin" > Kitűzve </ span >}
{ thread . locked && < span className = "ft-pin" > Lezárva </ span >}
{ thread . title }
</ h1 >
2026-11-26 12:20:17 +00:00
{ intent && (
< p className = "ftv-intent-line" >
< span className = { `ft-intent ft-intent- ${ thread . intent } ` }>{ intent . label }</ span >
{ thread . intent === "listen"
? "tanács helyett elég, ha jelen vagy, és leírod, ha veled is történt hasonló"
: ` ${ starter } kíváncsi a véleményetekre és a tapasztalataitokra` }
</ p >
)}
2026-11-26 10:29:49 +00:00
{ opening && < PostCard post = { opening } page = { page } actions = { actions } isNew = { false } />}
{( replies . length > 0 || ! thread . deleted ) && (
< div className = "ftv-count" >
< h2 >{ replies . filter (( p ) => ! p . deleted ). length } válasz </ h2 >
< span className = "hint" > időrendben </ span >
</ div >
)}
{ tops . map (( top ) => (
< div key = { top . id } className = "ftv-branch" >
{ markerTop === top . id && (
< div className = "ftv-marker" role = "separator" aria-label = { `Itt hagytad abba, ${ unreadCount } új` }>
< span > Itt hagytad abba · { unreadCount } ú j </ span >
</ div >
)}
< PostCard
post = { top }
page = { page }
actions = { actions }
isNew = { firstUnread !== null && top . id >= firstUnread && ! top . own }
/>
{ childrenOf ( top . id ). length > 0 && (
< div className = "ftv-children" >
{ childrenOf ( top . id ). map (( child ) => (
< PostCard
key = { child . id }
2026-11-26 12:20:17 +00:00
nested
2026-11-26 10:29:49 +00:00
post = { child }
page = { page }
actions = { actions }
isNew = { firstUnread !== null && child . id >= firstUnread && ! child . own }
/>
))}
</ div >
)}
2026-11-26 13:31:00 +00:00
{ replyTo && replyBranch === top . id && (
< div className = "ftv-inline" ref = { inline }>
< p className = "ftv-replyto" >
< svg viewBox = "0 0 24 24" aria-hidden = "true" >
< path d = "M9 14L4 9l5-5" />
< path d = "M4 9h10a6 6 0 0 1 6 6v4" />
</ svg >
Válasz neki : < strong >{ replyTo . author ? . nickname ?? "Törölt tag" }</ strong >
</ p >
< Composer
key = { top . id }
mentions
2026-11-27 00:34:59 +00:00
photos
2026-11-26 13:31:00 +00:00
onTyping = { imTyping }
id = { `valasz- ${ top . id } ` }
label = { `Válasz neki: ${ replyTo . author ? . nickname ?? "Törölt tag" } ` }
placeholder = "Írd meg a válaszod…"
initial = { draft . current }
onChange = {( text ) => {
draft . current = text ;
}}
busy = { busy }
2026-11-27 00:34:59 +00:00
onSubmit = {( text , photos ) => sendReply ( text , replyTo , photos )}
2026-11-26 13:31:00 +00:00
onCancel = {() => {
draft . current = "" ;
setReplyTo ( null );
}}
/>
</ div >
)}
2026-11-26 10:29:49 +00:00
</ div >
))}
{ newCount > 0 && (
< button
type = "button"
className = "ftv-incoming"
onClick = {() => incoming && ( setPage ( incoming ), setIncoming ( null ))}
>
{ newCount === 1 ? "1 új válasz érkezett" : ` ${ newCount } új válasz érkezett` }
</ button >
)}
{ error && (
< p className = "msg msg-error" role = "alert" >
{ error }
</ p >
)}
2026-11-26 11:50:09 +00:00
< TypingLine text = { typingNow } />
2026-11-26 10:29:49 +00:00
< div className = "ftv-compose" id = "valasz" ref = { composer }>
{ thread . deleted ? null : ! viewer . logged_in ? (
< p className = "ftv-gate" >
< Link href = { `/belepes?vissza=/forum/szal/ ${ thread . id } - ${ thread . slug } ` }> Lépj be </ Link >, hogy hozzászólhass .
</ p >
) : viewer . needs_nickname ? (
< p className = "ftv-gate" >
< Link href = { `/forum/beallitasok?vissza=/forum/szal/ ${ thread . id } - ${ thread . slug } ` }> Válassz á lnevet </ Link >,
hogy hozzászólhass .
</ p >
) : viewer . member ? . banned ? (
< p className = "ftv-gate" > Most nem í rhatsz a fórumba .</ p >
) : ! access ? . can_reply ? (
2026-11-26 14:31:05 +00:00
< p className = "ftv-gate" >
{ thread . topic . archived
? "Ez a téma archivált: olvasható, de új hozzászólás nem írható."
: "Ez a szál le van zárva, új hozzászólás nem írható." }
</ p >
2026-11-26 10:29:49 +00:00
) : (
<>
< Composer
2026-11-26 13:02:38 +00:00
mentions
2026-11-27 00:34:59 +00:00
photos
2026-11-26 11:50:09 +00:00
onTyping = { imTyping }
2026-11-26 10:29:49 +00:00
id = "valasz-szoveg"
label = "Válaszod"
placeholder = { thread . topic . listening ? "Írd le, ami benned van…" : "Írd meg a válaszod…" }
busy = { busy }
2026-11-27 00:34:59 +00:00
onSubmit = {( text , photos ) => sendReply ( text , null , photos )}
2026-11-26 10:29:49 +00:00
/>
</>
)}
</ div >
</ div >
);
}