Files
sorsfonalak/services/frontend/src/app/forum/page.tsx
T

321 lines
13 KiB
TypeScript
Raw Normal View History

import Link from "next/link";
import { notFound } from "next/navigation";
import { Avatar } from "@/components/forum/Avatar";
import { RankBadge } from "@/components/forum/Badges";
import { JoinTopic } from "@/components/forum/JoinTopic";
import { ThreadList, WaitingCard } from "@/components/forum/ThreadList";
import { MoonPhaseIcon } from "@/components/MoonChip";
import { MOON_PHASES, SIGNS } from "@/lib/astro";
import { type ForumHome, ago, memberHref } from "@/lib/forum";
import { forumGet } from "@/lib/forumServer";
import { loadSky } from "@/lib/sky";
import { MOON_IN_SIGN, SIGN_IN, withArticle } from "@/lib/skyText";
import type { SkyNow } from "@/lib/types";
export const metadata = { title: { absolute: "Fórum · Sorsfonalak" } };
function TopicIcon({ slug }: { slug: string }) {
return (
<svg viewBox="0 0 24 24" aria-hidden="true" className="topic-icon">
{slug === "ami-a-szivemen-van" && (
<path d="M12 20s-7.5-4.6-7.5-10.2A4.2 4.2 0 0 1 12 7.3a4.2 4.2 0 0 1 7.5 2.5C19.5 15.4 12 20 12 20z" />
)}
{slug === "belso-utak" && (
<>
<path d="M12 12a1.2 1.2 0 1 0 1.2-1.2" />
<path d="M13.2 10.8A3.4 3.4 0 1 0 15.4 14" />
<path d="M15.4 14A5.6 5.6 0 1 1 12 6.4" />
<path d="M12 6.4a7.8 7.8 0 1 1-7.6 9.4" />
</>
)}
{slug === "egbolt-es-kepletek" && (
<>
<circle cx="12" cy="12" r="8.5" />
<path d="M12 7.5l1.2 3.3 3.3 1.2-3.3 1.2L12 16.5l-1.2-3.3L7.5 12l3.3-1.2z" />
</>
)}
{slug === "torzsasztal" && (
<>
<path d="M4.5 10h11v4.5a5 5 0 0 1-5 5h-1a5 5 0 0 1-5-5z" />
<path d="M15.5 11.5h1.3a2.4 2.4 0 0 1 0 4.8h-1.6" />
<path d="M8.5 3.5c0 1.4 1 1.6 1 3M12 3.5c0 1.4 1 1.6 1 3" />
</>
)}
{!["ami-a-szivemen-van", "belso-utak", "egbolt-es-kepletek", "torzsasztal"].includes(slug) && (
<circle cx="12" cy="12" r="8.5" />
)}
</svg>
);
}
/** "Mai égbolt": the Moon today, the same for everyone; never empty. */
function SkyCard({ sky }: { sky: SkyNow }) {
const moon = sky.moon;
const sign = moon.position.sign;
const date = new Date(sky.local_time.slice(0, 10) + "T12:00:00Z").toLocaleDateString("hu-HU", {
month: "long",
day: "numeric",
weekday: "long",
timeZone: "UTC",
});
return (
<section className="fh-card fh-sky" aria-labelledby="fh-sky-title">
<div className="fh-card-head">
<span className="eyebrow">Mai égbolt</span>
<span className="hint">{date}</span>
</div>
<div className="fh-sky-body">
<span className="fh-moon">
<MoonPhaseIcon illumination={moon.illumination} waxing={moon.waxing} />
</span>
<div className="fh-sky-text">
<h2 id="fh-sky-title">
{MOON_PHASES[moon.phase] ?? moon.phase}, <span className="sym">{SIGNS[sign]?.glyph}</span> Hold{" "}
{withArticle(SIGN_IN[sign] ?? sign)}
</h2>
<p>{MOON_IN_SIGN[sign]}</p>
</div>
</div>
<Link href="/holdnaptar" className="fh-sky-link">
Holdnaptár és a következő holdfázisok
</Link>
</section>
);
}
export default async function ForumHomePage() {
const [home, sky] = await Promise.all([forumGet<ForumHome>("/v1/forum/home"), loadSky()]);
if (!home.ok) notFound();
const { viewer, replies, waiting, topics, unanswered, hot } = home.data;
return (
<div className="fh fh-home">
<div className="fh-col fh-col-main">
{!viewer.logged_in && (
<section className="fh-card fh-intro o-1">
<h1>Fórum</h1>
<p>
Beszélgetés a spiritualitásról, az égboltról, az álmokról és arról, ami a szívedet nyomja. Itt mindenki
álnéven ír, a tempó nyugodt, és a meghallgatás fontosabb a vitánál.
</p>
<p className="hint">
Olvasni belépés nélkül is lehet. Hozzászólni és az „Ami a szívemen van” témát olvasni belépve.
</p>
<Link href="/belepes?vissza=/forum" className="btn btn-primary">
Belépés
</Link>
</section>
)}
{viewer.needs_nickname && (
<Link href="/forum/beallitasok" className="fh-banner o-2">
<span>
<strong>Válassz álnevet</strong>, hogy hozzászólhass. A valódi neved soha nem jelenik meg a fórumon.
</span>
<span aria-hidden="true">›</span>
</Link>
)}
{viewer.member?.banned && (
<p className="fh-banner fh-banner-warn o-2">
Most nem írhatsz a fórumba. A részleteket a beállításaidnál látod.
</p>
)}
{replies !== null && replies > 0 && (
<Link href="/forum/valaszok" className="fh-banner o-2">
<span>
<strong>{replies === 1 ? "1 új válasz" : `${replies} új válasz`}</strong> érkezett neked
</span>
<span aria-hidden="true">›</span>
</Link>
)}
{unanswered.length > 0 && (
<section className="fh-section o-4" id="varnak" aria-labelledby="fh-waiting">
<div className="fh-section-head">
<h2 id="fh-waiting">Várják a válaszod</h2>
<span className="hint">még senki nem válaszolt</span>
</div>
<div className="fh-waiting-grid">
{unanswered.map((t) => (
<WaitingCard key={t.id} thread={t} />
))}
</div>
</section>
)}
{hot.length > 0 && (
<section className="fh-section o-5" aria-labelledby="fh-hot">
<div className="fh-section-head">
<h2 id="fh-hot">Pörgős most</h2>
<span className="hint">az utóbbi 24 órában</span>
</div>
<div className="fh-card fh-flush">
<ThreadList threads={hot} />
</div>
</section>
)}
<section className="fh-section o-6" aria-labelledby="fh-topics">
<div className="fh-section-head">
<h2 id="fh-topics">Témák</h2>
</div>
<ul className="fh-card fh-flush fh-topics">
{topics.map((t) =>
t.visibility === "restricted" && !t.readable ? (
<li key={t.slug}>
<div className="fh-topic fh-topic-closed">
<span className="fh-topic-icon">
<TopicIcon slug={t.slug} />
</span>
<span className="fh-topic-text">
<span className="fh-topic-name">
{t.name}
<svg viewBox="0 0 24 24" className="fh-lock" role="img" aria-label="Zárt téma">
<rect x="5" y="11" width="14" height="9" rx="2" />
<path d="M8 11V8a4 4 0 0 1 8 0v3" />
</svg>
</span>
<span className="fh-topic-desc">{t.description}</span>
<span className="fh-topic-last">Zárt kör: jóváhagyás után olvasható</span>
</span>
{viewer.member && <JoinTopic slug={t.slug} pending={t.membership === "pending"} />}
</div>
</li>
) : (
<li key={t.slug}>
<Link
href={t.readable ? `/forum/${t.slug}` : `/belepes?vissza=/forum/${t.slug}`}
className="fh-topic"
>
<span className="fh-topic-icon">
<TopicIcon slug={t.slug} />
</span>
<span className="fh-topic-text">
<span className="fh-topic-name">
{t.name}
{t.visibility !== "public" && (
<svg viewBox="0 0 24 24" className="fh-lock" role="img" aria-label="Csak tagoknak">
<rect x="5" y="11" width="14" height="9" rx="2" />
<path d="M8 11V8a4 4 0 0 1 8 0v3" />
</svg>
)}
</span>
<span className="fh-topic-desc">{t.description}</span>
{t.readable && t.last && (
<span className="fh-topic-last">
{t.last.author && (
<Avatar avatar={t.last.author.avatar} size={18} online={t.last.author.online} />
)}
{t.last.author?.nickname ?? "Törölt tag"},{" "}
<time suppressHydrationWarning dateTime={t.last.at}>
{ago(t.last.at)}
</time>
</span>
)}
{!t.readable && <span className="fh-topic-last">Belépés után olvasható</span>}
</span>
{t.readable && (
<span className="fh-topic-count">
<strong>{t.thread_count ?? 0}</strong> szál
</span>
)}
{t.readable && t.new_count ? (
<span className="ft-new">{t.new_count > 99 ? "99+" : t.new_count} új</span>
) : null}
</Link>
</li>
),
)}
</ul>
</section>
</div>
<aside className="fh-col fh-col-side" aria-label="Oldalsáv">
{sky && (
<div className="o-3">
<SkyCard sky={sky} />
</div>
)}
{home.data.online.length > 0 && (
<section className="fh-card fh-online o-7" aria-labelledby="fh-online-title">
<h2 id="fh-online-title" className="fh-online-title">
Most itt vannak <span className="hint">({home.data.online.length})</span>
</h2>
<ul className="fh-online-list">
{home.data.online.map((m) => (
<li key={m.nickname}>
<Link href={memberHref(m.nickname)} className="fh-online-item">
<Avatar avatar={m.avatar} size={28} online />
<span>{m.nickname}</span>
</Link>
</li>
))}
</ul>
</section>
)}
{viewer.member && (
<section className="fh-card fh-me o-7" aria-label="Saját">
<div className="fh-me-head">
<Avatar avatar={viewer.member.avatar} size={48} />
<span className="fh-me-names">
<Link href={memberHref(viewer.member.nickname)} className="fa-name">
{viewer.member.nickname}
</Link>
<RankBadge rank={viewer.member.rank} name={viewer.member.rank_name} />
</span>
</div>
{waiting !== null && waiting > 0 && (
<Link href="#varnak" className="fh-me-waiting">
{waiting === 1
? "1 meghallgatást kérő szál vár válaszra"
: `${waiting} meghallgatást kérő szál vár válaszra`}
</Link>
)}
<div className="fh-me-actions">
<Link href="/forum/uj" className="btn btn-primary btn-sm">
Új szál
</Link>
<Link href="/forum/beallitasok" className="btn btn-sm">
Fórumprofil
</Link>
</div>
</section>
)}
2026-11-26 13:44:25 +00:00
<nav className="fh-card fh-flush fh-links o-8" aria-label="Továbbiak">
<Link href="/aszf#forum" className="fh-link">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M5 4.5h9.5a3 3 0 0 1 3 3v12h-9.5a3 3 0 0 1-3-3z" />
<path d="M8.5 9h5.5M8.5 12.5h5.5" />
</svg>
<span className="fh-link-text">
Házirend
<span className="hint">A fórum szabályai</span>
</span>
<span className="fh-link-arrow" aria-hidden="true">
›
</span>
</Link>
2026-11-26 13:44:25 +00:00
{viewer.moderator && (
<Link href="/forum/moderalas" className="fh-link">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M12 3.5l7 2.5v5.5c0 4.5-3 7.5-7 9-4-1.5-7-4.5-7-9V6z" />
<path d="M9 12l2.2 2.2L15.5 10" />
</svg>
<span className="fh-link-text">
Moderálás
<span className="hint">Jelentések, témák, napló</span>
</span>
<span className="fh-link-arrow" aria-hidden="true">
›
</span>
</Link>
)}
</nav>
</aside>
</div>
);
}