Forum: answers to me as the only count, reply box in the branch, keyboard-safe inputs
- The "Követett" tab becomes "Válaszok": its count is the unread answers to the member (a reply to their post, a first-level reply in their thread, or a post naming them), listed on /forum/valaszok with "Mind olvasott"; the followed threads are its second view. The other counts are gone from the menu; listeners see the waiting threads on their card on the front page. - Replying to a post opens the box at the bottom of its branch and scrolls there; another branch moves it (with the text typed so far). - Phones: while typing, the forum's bottom menu and floating bars step aside and the box with its send button is scrolled above the keyboard (KeyboardSafe, site-wide; Android resizes the page for the keyboard). - The "Meghallgató" badge is now "Kísérő", with a new icon. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -406,7 +406,7 @@ fn forum_listener(payload: &Value, url: String) -> Result<Content, TemplateError
|
||||
unsubscribe: None,
|
||||
unsubscribe_post_url: None,
|
||||
};
|
||||
forum_footer(payload, content, "önkéntes meghallgatóként értesítést kértél a válasz nélküli szálakról")
|
||||
forum_footer(payload, content, "önkéntes kísérőként értesítést kértél a válasz nélküli szálakról")
|
||||
}
|
||||
|
||||
/// The weekly summary: the busiest threads, and those still waiting.
|
||||
|
||||
+5
-5
@@ -152,10 +152,10 @@ Jelölés: ami mellett **(javaslat)** áll, azt még nem hagytuk jóvá, a több
|
||||
### Ami elkészült (6. kör)
|
||||
|
||||
- **Új dizájn:** saját reakcióikonok, tömörebb hozzászólások, a kérdés (a nyitó hozzászólás) külön kártyán, a válaszok a lapon. A szövegdoboz feletti meghallgatós emlékeztető kikerült; a cím alatti „Csak meghallgatást kér” jelzés maradt.
|
||||
- **Jelvények ikonnal:** minden rangnak saját ikonja van (Vándor: ösvény, Kereső: iránytű, Fonó: orsó, Csillagfonó: csillag fonallal, Sorsfonó: a sorsfonal köre; a magasabb rangoké arany). Ikont kapott a Moderátor (pajzs), a Meghallgató (fül), a Támogató (drágakő), a Szálindító (toll) és a napi égbolt (holdsarló) is.
|
||||
- **Jelvények ikonnal:** minden rangnak saját ikonja van (Vándor: ösvény, Kereső: iránytű, Fonó: orsó, Csillagfonó: csillag fonallal, Sorsfonó: a sorsfonal köre; a magasabb rangoké arany). Ikont kapott a Moderátor (pajzs), a Kísérő (két alak), a Támogató (drágakő), a Szálindító (toll) és a napi égbolt (holdsarló) is.
|
||||
- **Kinek válaszolsz:** a válaszok legfeljebb két szint mélyek (az eredeti hozzászólás és alatta a válaszok). Ha valaki egy válaszra válaszol, az ugyanoda kerül, de a neve mellett látszik, kinek szól: „↪ Holdfény” (`posts.reply_to_id`, 0042).
|
||||
- **Napi „Mai égbolt” szál:** a worker reggel 5 órától nyitja meg az „Égbolt és képletek” témában, a backend nyilvános égboltjából (a Hold jegye és fázisa, jegyváltás, retrográd bolygók, a következő holdfázis), kötött magyar mondatokkal, AI nélkül. Egy napig ki van tűzve; a szerzője „Sorsfonalak”.
|
||||
- **Önkéntes meghallgatók** (a Kereső rangtól): „Meghallgató” jelvény; a Fórum fülön szám jelzi a válaszra váró meghallgatós szálakat; e-mail, ha egy szál két órája vár (ha kérik, legfeljebb hatóránként egy).
|
||||
- **Önkéntes kísérők** (a Kereső rangtól; eredetileg „meghallgató”, a felhasználó átnevezte): „Kísérő” jelvény; a fórum főoldalán, a saját kártyájukon látják, hány meghallgatást kérő szál vár válaszra; e-mail, ha egy szál két órája vár (ha kérik, legfeljebb hatóránként egy).
|
||||
- **Említés:** „@Holdfény” (szóközös álnévvel is). Az említett tag követni kezdi a szálat, élőben és (ha kéri) e-mailben is értesül. Gépelés közben ajánló segít, az említés link a profilra.
|
||||
- **Saját avatar** a Kereső rangtól: 256×256-os JPEG lesz belőle, a kép rejtett adatai (EXIF) nélkül, a backenddel közös tárolóban (`crates/object-storage`, `forum-avatars/`). A moderátor visszaállíthatja a kezdő avatart. A fiók törlésekor a kép is törlődik.
|
||||
- **„Támogató” jelvény:** csak vásárlóknak, és csak ha bekapcsolják. Rangot nem ad.
|
||||
@@ -220,7 +220,7 @@ Az **Ami a szívemen van** csak tagoknak szól, mert egy álnév kevésbé véd,
|
||||
## Meghallgatás (javaslat)
|
||||
|
||||
- **„Még senki nem válaszolt”** lista, a legrégebbi felül.
|
||||
- **Önkéntes meghallgatók:** szerepkör jelvénnyel, értesítést kapnak, ha egy szál néhány órája válasz nélkül áll.
|
||||
- **Önkéntes kísérők** (korábban „meghallgatók”): szerepkör jelvénnyel, értesítést kapnak, ha egy szál néhány órája válasz nélkül áll.
|
||||
|
||||
## Értékelés és reakciók
|
||||
|
||||
@@ -246,7 +246,7 @@ A rang egyben **jogosultsági szint** is: ettől függ, ki küldhet privát üze
|
||||
|
||||
**A kezdő (Vándor) is nyithat szálat és hozzászólhat**, mert lehet, hogy épp segítségre van szüksége. A hozzászólásai nem várnak moderátori jóváhagyásra. **Privát üzenetet viszont nem kezdeményezhet.** Ha valaki más kérést küld neki, azt elfogadhatja. (az elfogadás javaslat)
|
||||
|
||||
A **rang automatikus, a szerepkör kiosztott:** admin, moderátor, témamoderátor, meghallgató, támogató.
|
||||
A **rang automatikus, a szerepkör kiosztott:** admin, moderátor, témamoderátor, kísérő, támogató.
|
||||
|
||||
### Vásárlás és rang
|
||||
|
||||
@@ -313,7 +313,7 @@ Típusok és alapértékek (javaslat):
|
||||
| Válasz a hozzászólásomra | be | napi összesítő |
|
||||
| Új hozzászólás egy követett szálban | be | ki |
|
||||
| Megemlítettek (@álnév) | be | azonnal |
|
||||
| Válasz nélküli szál (meghallgatóknak) | be | ki |
|
||||
| Válasz nélküli szál (kísérőknek) | be | ki |
|
||||
| Heti összefoglaló | – | ki |
|
||||
| Hírlevél | – | ki |
|
||||
|
||||
|
||||
@@ -174,9 +174,20 @@ pub async fn home(state: St, viewer: Viewer) -> ApiResult<Json<Value>> {
|
||||
let people = super::authors(&state.db, present.iter().copied()).await?;
|
||||
let online: Vec<Value> = present.iter().filter_map(|id| people.get(id).cloned()).collect();
|
||||
|
||||
// Volunteer listeners: threads asking to be heard, still without a reply.
|
||||
let waiting = match &viewer.member {
|
||||
Some(m) if m.listener => Some(waiting_count(&state, &viewer).await?),
|
||||
_ => None,
|
||||
};
|
||||
let replies = match &viewer.member {
|
||||
Some(m) => Some(super::replies::unread_count(&state.db, &viewer, m.user_id).await?),
|
||||
None => None,
|
||||
};
|
||||
Ok(Json(json!({
|
||||
"viewer": viewer_json(&viewer),
|
||||
"followed": followed,
|
||||
"replies": replies,
|
||||
"waiting": waiting,
|
||||
"online": online,
|
||||
"topics": topics,
|
||||
"unanswered": cards_json(&state.db, unanswered).await?,
|
||||
@@ -234,17 +245,16 @@ pub async fn nav(state: St, viewer: Viewer) -> ApiResult<Json<Value>> {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
// Volunteer listeners: threads asking to be heard, still without a reply.
|
||||
let waiting = match &viewer.member {
|
||||
Some(m) if m.listener => Some(waiting_count(&state, &viewer).await?),
|
||||
_ => None,
|
||||
// The only count on the forum tab: unread answers to the member.
|
||||
let replies = match &viewer.member {
|
||||
Some(m) => Some(super::replies::unread_count(&state.db, &viewer, m.user_id).await?),
|
||||
None => None,
|
||||
};
|
||||
Ok(Json(json!({
|
||||
"viewer": viewer_json(&viewer),
|
||||
"followed": followed_counts(&state, &viewer).await?,
|
||||
"replies": replies,
|
||||
"messages": messages,
|
||||
"reports": reports,
|
||||
"waiting": waiting,
|
||||
})))
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ pub async fn save_me(
|
||||
if req.listener == Some(true) {
|
||||
let newcomer = viewer.member.as_ref().is_none_or(|m| m.rank(OffsetDateTime::now_utc()).is_newcomer());
|
||||
if newcomer && !viewer.is_moderator() {
|
||||
return Err(ApiError::Forbidden("Meghallgatónak a Kereső rangtól jelentkezhetsz.".into()));
|
||||
return Err(ApiError::Forbidden("Kísérőnek a Kereső rangtól jelentkezhetsz.".into()));
|
||||
}
|
||||
}
|
||||
if req.supporter_badge == Some(true) && !super::has_purchase(&state.db, user.id).await? {
|
||||
|
||||
@@ -12,6 +12,7 @@ mod mentions;
|
||||
mod messages;
|
||||
mod moderation;
|
||||
mod posts;
|
||||
mod replies;
|
||||
mod reports;
|
||||
mod threads;
|
||||
mod topics;
|
||||
@@ -48,6 +49,8 @@ pub fn router(state: Arc<AppState>) -> Router {
|
||||
.route("/v1/forum/topics/{slug}/join", post(topics::join).delete(topics::leave))
|
||||
.route("/v1/forum/mod/topic-requests", get(topics::requests).post(topics::decide))
|
||||
.route("/v1/forum/followed", get(home::followed))
|
||||
.route("/v1/forum/replies", get(replies::list))
|
||||
.route("/v1/forum/replies/read", post(replies::read_all))
|
||||
.route("/v1/forum/threads", post(threads::create))
|
||||
.route("/v1/forum/threads/{id}", get(threads::show).patch(threads::update).delete(threads::remove))
|
||||
.route("/v1/forum/threads/{id}/restore", post(threads::restore))
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
//! "Válaszok": what answers the member. A reply to one of their posts (also
|
||||
//! a reply to a reply of theirs, `reply_to_id`), a first-level reply in a
|
||||
//! thread they opened, or a post that names them ("@Holdfény"). One stays
|
||||
//! unread until the member has read that far in the thread; the forum menu
|
||||
//! shows only this count.
|
||||
|
||||
use axum::Json;
|
||||
use axum::extract::{Query, State};
|
||||
use axum::http::StatusCode;
|
||||
use axum_extra::extract::WithRejection;
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Value, json};
|
||||
use sqlx::PgPool;
|
||||
use time::OffsetDateTime;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::{St, rfc3339, visible_topics};
|
||||
use crate::auth::Viewer;
|
||||
use crate::error::{ApiError, ApiResult};
|
||||
|
||||
/// The posts that answer `$1`, from the threads the viewer may read.
|
||||
fn answers(viewer: &Viewer) -> String {
|
||||
format!(
|
||||
"FROM forum.posts p \
|
||||
JOIN forum.threads th ON th.id = p.thread_id \
|
||||
JOIN forum.topics tp ON tp.id = th.topic_id \
|
||||
LEFT JOIN forum.posts target ON target.id = COALESCE(p.reply_to_id, p.parent_id) \
|
||||
LEFT JOIN forum.reads r ON r.user_id = $1 AND r.thread_id = p.thread_id \
|
||||
WHERE p.deleted_at IS NULL AND th.deleted_at IS NULL AND NOT p.is_opening AND NOT p.system \
|
||||
AND p.author_id IS DISTINCT FROM $1 AND ({}) \
|
||||
AND (target.author_id = $1 \
|
||||
OR (p.parent_id IS NULL AND th.author_id = $1) \
|
||||
OR EXISTS (SELECT 1 FROM forum.mentions mn WHERE mn.post_id = p.id AND mn.user_id = $1))",
|
||||
visible_topics(viewer)
|
||||
)
|
||||
}
|
||||
|
||||
const UNREAD: &str = "p.id > COALESCE(r.last_post_id, 0)";
|
||||
|
||||
/// How many answers wait unread (for the menu), at most 100.
|
||||
pub async fn unread_count(db: &PgPool, viewer: &Viewer, me: Uuid) -> Result<i64, sqlx::Error> {
|
||||
sqlx::query_scalar(&format!("SELECT count(*) FROM (SELECT 1 {} AND {UNREAD} LIMIT 100) x", answers(viewer)))
|
||||
.bind(me)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ListQuery {
|
||||
#[serde(default)]
|
||||
page: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(sqlx::FromRow)]
|
||||
struct Row {
|
||||
id: i64,
|
||||
thread_id: i64,
|
||||
title: String,
|
||||
author_id: Option<Uuid>,
|
||||
body: String,
|
||||
created_at: OffsetDateTime,
|
||||
kind: String,
|
||||
unread: bool,
|
||||
}
|
||||
|
||||
const PAGE: i64 = 30;
|
||||
|
||||
/// The member's answers, newest first.
|
||||
pub async fn list(
|
||||
State(state): St,
|
||||
viewer: Viewer,
|
||||
WithRejection(Query(q), _): WithRejection<Query<ListQuery>, ApiError>,
|
||||
) -> ApiResult<Json<Value>> {
|
||||
let member = viewer.require_member()?;
|
||||
let page = q.page.unwrap_or(1).clamp(1, 1000);
|
||||
let rows: Vec<Row> = sqlx::query_as(&format!(
|
||||
"SELECT p.id, p.thread_id, th.title, p.author_id, p.body, p.created_at, \
|
||||
CASE WHEN target.author_id = $1 THEN 'reply' \
|
||||
WHEN p.parent_id IS NULL AND th.author_id = $1 THEN 'thread' \
|
||||
ELSE 'mention' END AS kind, \
|
||||
{UNREAD} AS unread \
|
||||
{} ORDER BY p.id DESC LIMIT {} OFFSET $2",
|
||||
answers(&viewer),
|
||||
PAGE + 1
|
||||
))
|
||||
.bind(member.user_id)
|
||||
.bind((page - 1) * PAGE)
|
||||
.fetch_all(&state.db)
|
||||
.await?;
|
||||
let more = rows.len() as i64 > PAGE;
|
||||
let rows = &rows[..rows.len().min(PAGE as usize)];
|
||||
let authors = super::authors(&state.db, rows.iter().filter_map(|r| r.author_id)).await?;
|
||||
let replies: Vec<Value> = rows
|
||||
.iter()
|
||||
.map(|r| {
|
||||
json!({
|
||||
"id": r.id,
|
||||
"thread": { "id": r.thread_id, "title": r.title, "slug": crate::text::slug(&r.title) },
|
||||
"author": r.author_id.and_then(|a| authors.get(&a).cloned()),
|
||||
"excerpt": excerpt(&r.body),
|
||||
"created_at": rfc3339(r.created_at),
|
||||
"kind": r.kind,
|
||||
"unread": r.unread,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
let unread = unread_count(&state.db, &viewer, member.user_id).await?;
|
||||
Ok(Json(json!({ "replies": replies, "unread": unread, "page": page, "more": more })))
|
||||
}
|
||||
|
||||
/// "Mind olvasott": the threads with unread answers count as read up to them.
|
||||
pub async fn read_all(State(state): St, viewer: Viewer) -> ApiResult<StatusCode> {
|
||||
let member = viewer.require_member()?;
|
||||
sqlx::query(&format!(
|
||||
"INSERT INTO forum.reads (user_id, thread_id, last_post_id) \
|
||||
SELECT $1, p.thread_id, max(p.id) {} AND {UNREAD} GROUP BY p.thread_id \
|
||||
ON CONFLICT (user_id, thread_id) DO UPDATE \
|
||||
SET last_post_id = GREATEST(forum.reads.last_post_id, EXCLUDED.last_post_id), read_at = now()",
|
||||
answers(&viewer)
|
||||
))
|
||||
.bind(member.user_id)
|
||||
.execute(&state.db)
|
||||
.await?;
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
}
|
||||
|
||||
/// The start of a post, on one line.
|
||||
fn excerpt(body: &str) -> String {
|
||||
let line = body.split_whitespace().collect::<Vec<_>>().join(" ");
|
||||
match line.char_indices().nth(160) {
|
||||
Some((at, _)) => format!("{}…", line[..at].trim_end()),
|
||||
None => line,
|
||||
}
|
||||
}
|
||||
@@ -1044,8 +1044,8 @@ async fn mentions_listeners_supporters_and_who_is_here(pool: PgPool) {
|
||||
.execute(&app.pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(app.get("/v1/forum/nav", Some(&bea)).await["waiting"], 1);
|
||||
assert!(app.get("/v1/forum/nav", Some(&cili)).await["waiting"].is_null());
|
||||
assert_eq!(app.get("/v1/forum/home", Some(&bea)).await["waiting"], 1);
|
||||
assert!(app.get("/v1/forum/home", Some(&cili)).await["waiting"].is_null());
|
||||
let shown = app.get(&format!("/v1/forum/threads/{thread}"), Some(&anna)).await;
|
||||
assert!(shown["posts"].as_array().unwrap().iter().all(|p| p["author"]["supporter"] == false));
|
||||
|
||||
@@ -1080,3 +1080,53 @@ async fn mentions_listeners_supporters_and_who_is_here(pool: PgPool) {
|
||||
.collect();
|
||||
assert!(here.contains(&"Zöldág".to_string()) && !here.contains(&"Csendesvíz".to_string()));
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
async fn answers_to_the_member(pool: PgPool) {
|
||||
let app = TestApp::new(pool);
|
||||
let anna = app.member("anna@example.com", "Csendesvíz", &["user"]).await;
|
||||
let bea = app.member("bea@example.com", "Holdfény", &["user"]).await;
|
||||
let cili = app.member("cili@example.com", "Zöldág", &["user"]).await;
|
||||
let answers = |v: Value| -> Vec<(i64, String, bool)> {
|
||||
v["replies"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|r| (r["id"].as_i64().unwrap(), r["kind"].as_str().unwrap().to_string(), r["unread"] == true))
|
||||
.collect()
|
||||
};
|
||||
|
||||
// Anna's thread: Bea replies to it, Anna answers, Cili answers Anna's answer
|
||||
// (on the second level, under Bea's post) and names Bea elsewhere.
|
||||
let thread = app.thread(&anna, "torzsasztal", "Téli levesek").await;
|
||||
let first = app.reply(&bea, thread, "Gulyás.", None).await["id"].as_i64().unwrap();
|
||||
let second = app.reply(&anna, thread, "Az jó ötlet.", Some(first)).await["id"].as_i64().unwrap();
|
||||
let third = app.reply(&cili, thread, "Szerintem is.", Some(second)).await["id"].as_i64().unwrap();
|
||||
let fourth = app.reply(&cili, thread, "@Holdfény, babbal?", None).await["id"].as_i64().unwrap();
|
||||
|
||||
// Anna: Bea's reply in her thread (read once she answered it), Cili's answer
|
||||
// to her, and Cili's first-level post in her thread.
|
||||
assert_eq!(
|
||||
answers(app.get("/v1/forum/replies", Some(&anna)).await),
|
||||
vec![(fourth, "thread".into(), true), (third, "reply".into(), true), (first, "thread".into(), false)]
|
||||
);
|
||||
assert_eq!(app.get("/v1/forum/nav", Some(&anna)).await["replies"], 2);
|
||||
// Bea: Anna answered her; Cili named her. Cili's answer was to Anna, not to her.
|
||||
assert_eq!(
|
||||
answers(app.get("/v1/forum/replies", Some(&bea)).await),
|
||||
vec![(fourth, "mention".into(), true), (second, "reply".into(), true)]
|
||||
);
|
||||
// Nothing for Cili; a visitor gets nothing.
|
||||
assert_eq!(app.get("/v1/forum/nav", Some(&cili)).await["replies"], 0);
|
||||
assert!(app.get("/v1/forum/nav", None).await["replies"].is_null());
|
||||
|
||||
// Reading the thread clears them; so does "Mind olvasott".
|
||||
let (status, _) =
|
||||
app.call("POST", &format!("/v1/forum/threads/{thread}/read"), Some(&anna), json!({ "post_id": fourth })).await;
|
||||
assert_eq!(status, StatusCode::NO_CONTENT);
|
||||
assert_eq!(app.get("/v1/forum/nav", Some(&anna)).await["replies"], 0);
|
||||
let (status, _) = app.call("POST", "/v1/forum/replies/read", Some(&bea), Value::Null).await;
|
||||
assert_eq!(status, StatusCode::NO_CONTENT);
|
||||
assert_eq!(app.get("/v1/forum/nav", Some(&bea)).await["replies"], 0);
|
||||
assert_eq!(answers(app.get("/v1/forum/replies", Some(&bea)).await).len(), 2, "the list stays");
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ export default async function PrivacyPage() {
|
||||
<td>
|
||||
Fórumprofilod: az álneved (a korábbiakat 90 napig, hogy más ne vehesse fel), az avatarod vagy a
|
||||
feltöltött saját képed (kicsinyítve, a kép rejtett adatai, például a helyszín nélkül), a
|
||||
bemutatkozásod, a képletedből megosztott jegyek, hogy önkéntes meghallgató vagy-e, a Támogató
|
||||
bemutatkozásod, a képletedből megosztott jegyek, hogy önkéntes kísérő vagy-e, a Támogató
|
||||
jelvény (ha bekapcsolod, mások látják, hogy vásároltál), a láthatatlan mód és az e-mail-értesítések
|
||||
beállítása
|
||||
</td>
|
||||
@@ -221,7 +221,7 @@ export default async function PrivacyPage() {
|
||||
<strong>Fórum:</strong> amit a nyilvános témákban írsz, bárki láthatja, a keresők is; a csak tagoknak szóló
|
||||
témákat csak belépett felhasználók látják, a zárt témákat csak a jóváhagyott tagjaik. A hozzászólásaid
|
||||
mellett az álneved, az avatarod, a rangod, az általad megosztott jegyek és a bekapcsolt jelvényeid
|
||||
(Meghallgató, Támogató) látszanak; a valódi neved, az e-mail-címed és a születési adataid nem, és a
|
||||
(Kísérő, Támogató) látszanak; a valódi neved, az e-mail-címed és a születési adataid nem, és a
|
||||
képletedből soha nem mutatunk fokokat. A privát üzeneteidet csak a beszélgetés két résztvevője látja; a
|
||||
moderátorok csak akkor, ha valaki egy üzenetet jelent, és akkor is csak a jelentett üzenetet és az előtte
|
||||
lévő néhányat. A moderátorok (az üzemeltető által kijelölt tagok) a valódi nevedet és az e-mail-címedet nem
|
||||
|
||||
@@ -248,10 +248,10 @@ export function ProfileForm({ me, back }: { me: ForumMe; back: string | null })
|
||||
<label className="fprof-check">
|
||||
<input type="checkbox" checked={listener} onChange={(e) => setListener(e.target.checked)} />
|
||||
<span>
|
||||
<strong>Önkéntes meghallgató vagyok</strong>
|
||||
<strong>Önkéntes kísérő vagyok</strong>
|
||||
<span className="hint">
|
||||
A nevem mellett megjelenik a „Meghallgató” jelvény, és a menü jelzi, ha egy meghallgatást kérő szál válasz
|
||||
nélkül vár. E-mailt is kérhetsz róla lent.
|
||||
Szívesen válaszolok azoknak, akik meghallgatást kérnek. A nevem mellett megjelenik a „Kísérő” jelvény, és
|
||||
a fórum főoldalán látom, hány ilyen szál vár válaszra. E-mailt is kérhetsz róla lent.
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
@@ -315,7 +315,9 @@ export function ProfileForm({ me, back }: { me: ForumMe; back: string | null })
|
||||
</select>
|
||||
{listener && (
|
||||
<>
|
||||
<label htmlFor="fprof-mail-listener">Meghallgatóként: ha egy szál két órája válasz nélkül vár</label>
|
||||
<label htmlFor="fprof-mail-listener">
|
||||
Kísérőként: ha egy meghallgatást kérő szál két órája válasz nélkül vár
|
||||
</label>
|
||||
<select
|
||||
id="fprof-mail-listener"
|
||||
className="inp"
|
||||
@@ -340,8 +342,8 @@ export function ProfileForm({ me, back }: { me: ForumMe; back: string | null })
|
||||
</span>
|
||||
</label>
|
||||
<span className="hint">
|
||||
Ha éppen itt vagy a fórumon, nem küldünk levelet: a menü jelzi az újdonságot. A privát üzenetek szövege nem
|
||||
kerül bele a levélbe.
|
||||
Ha éppen itt vagy a fórumon, nem küldünk levelet: a válaszokat a Válaszok fülön, az üzeneteket az Üzenetek
|
||||
fülön látod. A privát üzenetek szövege nem kerül bele a levélbe.
|
||||
</span>
|
||||
</fieldset>
|
||||
|
||||
|
||||
@@ -605,3 +605,42 @@ a.fh-online-item:hover { color: var(--gold); }
|
||||
.ftopic-private svg, .ftv-private svg { width: 15px; height: 15px; flex: none; margin-top: 2px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
|
||||
.ftv-private { display: inline-flex; align-items: center; gap: 4px; margin-left: 4px; font-size: 13px; color: var(--muted); }
|
||||
.ftv-private svg { margin-top: 0; width: 13px; height: 13px; }
|
||||
|
||||
/* --- "Válaszok": answers to the member --- */
|
||||
.frep-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
|
||||
.fanswers { list-style: none; margin: 0; padding: 0; }
|
||||
.fanswers li + li { border-top: 1px solid var(--line); }
|
||||
.fanswer {
|
||||
display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 12px; align-items: start;
|
||||
padding: 14px 16px; color: var(--ink); text-decoration: none;
|
||||
}
|
||||
.fanswer:hover { background: var(--f-hover); }
|
||||
.fanswer-new { background: var(--f-tint); }
|
||||
.fanswer-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
|
||||
.fanswer-who { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 15px; }
|
||||
.fanswer-thread { font-size: 14px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.fanswer-excerpt {
|
||||
font-size: 14px; color: var(--muted); overflow: hidden;
|
||||
display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
|
||||
}
|
||||
.fanswer-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
|
||||
.fh-me-waiting { font-size: 14px; color: var(--harmonic); text-decoration: none; }
|
||||
.fh-me-waiting:hover { text-decoration: underline; }
|
||||
|
||||
/* The reply box at the bottom of a branch, where the answers to that post go. */
|
||||
.ftv-inline {
|
||||
display: flex; flex-direction: column; gap: 6px; margin: 4px 0 8px 17px; padding: 8px 0 4px 14px;
|
||||
border-left: 2px solid var(--gold); scroll-margin: 96px 0 120px;
|
||||
}
|
||||
.ftv-inline .ftv-replyto { display: flex; align-items: center; gap: 5px; margin: 0; }
|
||||
.ftv-inline .ftv-replyto svg {
|
||||
width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
|
||||
}
|
||||
|
||||
/* Phones, while typing: the bottom menu and the floating button step aside
|
||||
for the keyboard (KeyboardSafe sets kb-open), and a focused box keeps room
|
||||
around it for its send button. */
|
||||
@media (max-width: 759px) {
|
||||
.kb-open .forum-nav, .kb-open .ftv-incoming { display: none; }
|
||||
}
|
||||
.forum textarea, .forum input { scroll-margin: 88px 0 96px; }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { RepliesTabs } from "@/components/forum/RepliesTabs";
|
||||
import { ThreadList } from "@/components/forum/ThreadList";
|
||||
import type { ForumViewer, ThreadCard } from "@/lib/forum";
|
||||
import { forumGet } from "@/lib/forumServer";
|
||||
@@ -13,7 +14,8 @@ export default async function FollowedPage() {
|
||||
const { threads } = res.data;
|
||||
return (
|
||||
<div className="fh">
|
||||
<h1 className="fpage-title">Követett szálak</h1>
|
||||
<h1 className="fpage-title">Válaszok</h1>
|
||||
<RepliesTabs current="followed" />
|
||||
<p className="muted">A saját szálaid, azok, amelyekhez hozzászóltál, és amelyeket követni kezdtél.</p>
|
||||
{threads.length === 0 ? (
|
||||
<p className="fh-card fh-empty">Még nem követsz egy szálat sem.</p>
|
||||
|
||||
@@ -42,10 +42,9 @@ export default async function ForumLayout({ children }: { children: React.ReactN
|
||||
member={viewer?.member?.nickname ?? null}
|
||||
loggedIn={viewer?.logged_in ?? false}
|
||||
initial={{
|
||||
unread: nav.ok ? (nav.data.followed?.new_replies ?? 0) : 0,
|
||||
replies: nav.ok ? (nav.data.replies ?? 0) : 0,
|
||||
messages: nav.ok ? (nav.data.messages ?? 0) : 0,
|
||||
reports: nav.ok ? (nav.data.reports ?? 0) : 0,
|
||||
waiting: nav.ok ? (nav.data.waiting ?? 0) : 0,
|
||||
}}
|
||||
wsUrl={process.env.FORUM_WS_URL || "/api/v1/forum/ws"}
|
||||
/>
|
||||
|
||||
@@ -87,7 +87,7 @@ function SkyCard({ sky }: { sky: SkyNow }) {
|
||||
export default async function ForumHomePage() {
|
||||
const [home, sky] = await Promise.all([forumGet<ForumHome>("/v1/forum/home"), loadSky()]);
|
||||
if (!home.ok) notFound();
|
||||
const { viewer, followed, topics, unanswered, hot } = home.data;
|
||||
const { viewer, replies, waiting, topics, unanswered, hot } = home.data;
|
||||
|
||||
return (
|
||||
<div className="fh fh-home">
|
||||
@@ -123,17 +123,17 @@ export default async function ForumHomePage() {
|
||||
</p>
|
||||
)}
|
||||
|
||||
{followed && followed.new_replies > 0 && (
|
||||
<Link href="/forum/kovetett" className="fh-banner o-2">
|
||||
{replies !== null && replies > 0 && (
|
||||
<Link href="/forum/valaszok" className="fh-banner o-2">
|
||||
<span>
|
||||
<strong>{followed.new_replies} új válasz</strong> a követett szálaidban
|
||||
<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" aria-labelledby="fh-waiting">
|
||||
<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>
|
||||
@@ -267,6 +267,13 @@ export default async function ForumHomePage() {
|
||||
<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
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
import { api } from "@/lib/api";
|
||||
|
||||
/** "Mind olvasott": the answers stay in the list, the count on the tab goes. */
|
||||
export function ReadAll() {
|
||||
const router = useRouter();
|
||||
const [busy, setBusy] = useState(false);
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-sm"
|
||||
disabled={busy}
|
||||
onClick={async () => {
|
||||
setBusy(true);
|
||||
try {
|
||||
await api("/forum/replies/read", { method: "POST" });
|
||||
window.dispatchEvent(new Event("forum:nav"));
|
||||
router.refresh();
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Mind olvasott
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { Avatar } from "@/components/forum/Avatar";
|
||||
import { RepliesTabs } from "@/components/forum/RepliesTabs";
|
||||
import { type ReplyEntry, ago, threadHref } from "@/lib/forum";
|
||||
import { forumGet } from "@/lib/forumServer";
|
||||
|
||||
import { ReadAll } from "./ReadAll";
|
||||
|
||||
export const metadata = { title: "Válaszok", robots: { index: false } };
|
||||
|
||||
const KIND: Record<ReplyEntry["kind"], string> = {
|
||||
reply: "válaszolt neked",
|
||||
thread: "válaszolt a száladban",
|
||||
mention: "megemlített",
|
||||
};
|
||||
|
||||
/** The answers to the member, newest first; the unread ones stand out. */
|
||||
export default async function RepliesPage({ searchParams }: { searchParams: Promise<{ oldal?: string }> }) {
|
||||
const page = Math.max(1, Number((await searchParams).oldal) || 1);
|
||||
const res = await forumGet<{ replies: ReplyEntry[]; unread: number; more: boolean }>(
|
||||
`/v1/forum/replies?page=${page}`,
|
||||
);
|
||||
if (!res.ok) redirect("/belepes?vissza=/forum/valaszok");
|
||||
const { replies, unread, more } = res.data;
|
||||
return (
|
||||
<div className="fh">
|
||||
<h1 className="fpage-title">Válaszok</h1>
|
||||
<div className="frep-head">
|
||||
<RepliesTabs current="replies" />
|
||||
{unread > 0 && <ReadAll />}
|
||||
</div>
|
||||
<p className="muted">
|
||||
Ha valaki a hozzászólásodra vagy a száladban válaszol, vagy megemlít. A menüben csak ezek száma látszik.
|
||||
</p>
|
||||
{replies.length === 0 ? (
|
||||
<p className="fh-card fh-empty">Még nem válaszolt neked senki. Ha valaki ír neked, itt látod.</p>
|
||||
) : (
|
||||
<ul className="fh-card fh-flush fanswers">
|
||||
{replies.map((r) => (
|
||||
<li key={r.id}>
|
||||
<Link href={threadHref(r.thread, r.id)} className={r.unread ? "fanswer fanswer-new" : "fanswer"}>
|
||||
<Avatar avatar={r.author?.avatar} size={36} online={r.author?.online} />
|
||||
<span className="fanswer-text">
|
||||
<span className="fanswer-who">
|
||||
<strong>{r.author?.nickname ?? "Törölt tag"}</strong> {KIND[r.kind]}
|
||||
{r.unread && <span className="fa-badge fa-badge-new">új</span>}
|
||||
</span>
|
||||
<span className="fanswer-thread">{r.thread.title}</span>
|
||||
<span className="fanswer-excerpt">{r.excerpt}</span>
|
||||
</span>
|
||||
<time className="fanswer-time" suppressHydrationWarning dateTime={r.created_at}>
|
||||
{ago(r.created_at)}
|
||||
</time>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{(page > 1 || more) && (
|
||||
<nav className="forum-pager" aria-label="Lapozás">
|
||||
{page > 1 ? <Link href={`/forum/valaszok?oldal=${page - 1}`}>‹ Újabbak</Link> : <span />}
|
||||
<span className="hint">{page}. oldal</span>
|
||||
{more ? <Link href={`/forum/valaszok?oldal=${page + 1}`}>Régebbiek ›</Link> : <span />}
|
||||
</nav>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -834,6 +834,9 @@ a.pair-row:hover strong { color: var(--gold); }
|
||||
.qdock-fab-label { display: none; }
|
||||
.qdock-dot { left: 42px; }
|
||||
.qdock-panel { inset: 0; width: 100%; height: 100dvh; border: 0; border-radius: 0; }
|
||||
/* While typing: only the part of the screen above the keyboard (KeyboardSafe). */
|
||||
.kb-open .qdock-panel { top: var(--vv-top, 0px); bottom: auto; height: var(--vv-height, 100dvh); }
|
||||
.kb-open .qdock-fab { display: none; }
|
||||
body.qdock-open { overflow: hidden; }
|
||||
}
|
||||
@media (max-width: 480px) {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { Metadata } from "next";
|
||||
import type { Metadata, Viewport } from "next";
|
||||
import { Cormorant_Garamond, Inter } from "next/font/google";
|
||||
import { Suspense } from "react";
|
||||
|
||||
import { KeyboardSafe } from "@/components/KeyboardSafe";
|
||||
import { NightSky } from "@/components/NightSky";
|
||||
import { NpsBanner } from "@/components/NpsBanner";
|
||||
import { PaymentReturn } from "@/components/PaymentReturn";
|
||||
@@ -30,6 +31,10 @@ export async function generateMetadata(): Promise<Metadata> {
|
||||
};
|
||||
}
|
||||
|
||||
// On Android the opening keyboard shrinks the page instead of covering it
|
||||
// (iOS ignores this; KeyboardSafe handles both).
|
||||
export const viewport: Viewport = { width: "device-width", initialScale: 1, interactiveWidget: "resizes-content" };
|
||||
|
||||
export default async function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
const me = await getMe();
|
||||
// The Moon today in the header (cached for five minutes).
|
||||
@@ -38,6 +43,7 @@ export default async function RootLayout({ children }: { children: React.ReactNo
|
||||
<html lang="hu" className={`${cormorant.variable} ${inter.variable}`}>
|
||||
<body>
|
||||
<NightSky />
|
||||
<KeyboardSafe />
|
||||
<ValidationMessages />
|
||||
{me && <SiteHeader me={me} sky={sky} />}
|
||||
{children}
|
||||
|
||||
@@ -85,7 +85,7 @@ const DATA: [string, string, string][] = [
|
||||
"Legitimate interest (Art. 6(1)(f))",
|
||||
],
|
||||
[
|
||||
"Your forum profile: your nickname (earlier ones for 90 days, so nobody else can take them), your avatar or the picture you uploaded (made smaller, without its hidden data such as the location), introduction, the signs of your chart you share, whether you are a volunteer listener, the Támogató (supporter) badge (if you switch it on, others see that you bought something), the invisible mode and your e-mail notification settings",
|
||||
"Your forum profile: your nickname (earlier ones for 90 days, so nobody else can take them), your avatar or the picture you uploaded (made smaller, without its hidden data such as the location), introduction, the signs of your chart you share, whether you are a volunteer companion (Kísérő), the Támogató (supporter) badge (if you switch it on, others see that you bought something), the invisible mode and your e-mail notification settings",
|
||||
"Taking part in the forum; sharing the signs and the badges is your choice",
|
||||
"Performance of the contract",
|
||||
],
|
||||
@@ -191,7 +191,7 @@ export default async function PrivacyPolicyPage() {
|
||||
<strong>Forum:</strong> what you write in the public topics can be seen by anyone, including search engines;
|
||||
the members-only topics are seen only by logged-in users, and the restricted ones only by their approved
|
||||
members. Next to your posts we show your nickname, avatar, rank, the signs you chose to share and the badges
|
||||
you switched on (Meghallgató – listener, Támogató – supporter); never your real name, e-mail address or birth data, and never the
|
||||
you switched on (Kísérő – companion, Támogató – supporter); never your real name, e-mail address or birth data, and never the
|
||||
degrees of your chart. Your private messages are seen only by the two people in the conversation; moderators
|
||||
see a message only when someone reports it, and then only that message and the few before it. Moderators
|
||||
(members appointed by the operator) do not see your real name or e-mail address. The forum rules are in
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
|
||||
const NOT_TYPED = new Set([
|
||||
"checkbox",
|
||||
"radio",
|
||||
"button",
|
||||
"submit",
|
||||
"reset",
|
||||
"range",
|
||||
"file",
|
||||
"color",
|
||||
"image",
|
||||
"hidden",
|
||||
]);
|
||||
|
||||
function typedInto(el: Element | null): el is HTMLElement {
|
||||
if (el instanceof HTMLTextAreaElement) return true;
|
||||
if (el instanceof HTMLInputElement) return !NOT_TYPED.has(el.type);
|
||||
return el instanceof HTMLElement && el.isContentEditable;
|
||||
}
|
||||
|
||||
/**
|
||||
* On phones the on-screen keyboard must not cover the box being typed in.
|
||||
* While a text field has the focus: `kb-open` on <html> (the forum's bottom
|
||||
* menu and other fixed bars step aside), `--vv-top` and `--vv-height` give
|
||||
* the part of the screen the keyboard leaves free (for full-screen panels),
|
||||
* and the field, with its send button when the form is small, is scrolled
|
||||
* into that part.
|
||||
*/
|
||||
export function KeyboardSafe() {
|
||||
useEffect(() => {
|
||||
if (!window.matchMedia("(pointer: coarse)").matches) return;
|
||||
const root = document.documentElement;
|
||||
const vv = window.visualViewport;
|
||||
let timer: number | undefined;
|
||||
let closing: number | undefined;
|
||||
|
||||
const measure = () => {
|
||||
root.style.setProperty("--vv-top", `${vv ? vv.offsetTop : 0}px`);
|
||||
root.style.setProperty("--vv-height", `${vv ? vv.height : window.innerHeight}px`);
|
||||
};
|
||||
|
||||
const reveal = () => {
|
||||
const el = document.activeElement;
|
||||
if (!typedInto(el)) return;
|
||||
measure();
|
||||
const top = vv ? vv.offsetTop : 0;
|
||||
const height = vv ? vv.height : window.innerHeight;
|
||||
const form = el.closest("form");
|
||||
const target = form && form.getBoundingClientRect().height < height * 0.6 ? form : el;
|
||||
const rect = target.getBoundingClientRect();
|
||||
const free = { top: top + 12, bottom: top + height - 12 };
|
||||
if (rect.bottom > free.bottom) {
|
||||
window.scrollBy({ top: Math.min(rect.bottom - free.bottom, rect.top - free.top), behavior: "smooth" });
|
||||
} else if (rect.top < free.top) {
|
||||
window.scrollBy({ top: rect.top - free.top, behavior: "smooth" });
|
||||
}
|
||||
};
|
||||
|
||||
// After the keyboard has slid up, and again whenever the free part changes.
|
||||
const later = (ms: number) => {
|
||||
window.clearTimeout(timer);
|
||||
timer = window.setTimeout(reveal, ms);
|
||||
};
|
||||
|
||||
const onFocusIn = (e: FocusEvent) => {
|
||||
if (!typedInto(e.target as Element)) return;
|
||||
window.clearTimeout(closing);
|
||||
root.classList.add("kb-open");
|
||||
measure();
|
||||
later(350);
|
||||
};
|
||||
const onFocusOut = () => {
|
||||
// Moving to another field keeps it open.
|
||||
window.clearTimeout(closing);
|
||||
closing = window.setTimeout(() => {
|
||||
if (!typedInto(document.activeElement)) root.classList.remove("kb-open");
|
||||
}, 150);
|
||||
};
|
||||
const onViewport = () => {
|
||||
if (!root.classList.contains("kb-open")) return;
|
||||
measure();
|
||||
later(120);
|
||||
};
|
||||
|
||||
document.addEventListener("focusin", onFocusIn);
|
||||
document.addEventListener("focusout", onFocusOut);
|
||||
vv?.addEventListener("resize", onViewport);
|
||||
vv?.addEventListener("scroll", measure);
|
||||
return () => {
|
||||
window.clearTimeout(timer);
|
||||
window.clearTimeout(closing);
|
||||
document.removeEventListener("focusin", onFocusIn);
|
||||
document.removeEventListener("focusout", onFocusOut);
|
||||
vv?.removeEventListener("resize", onViewport);
|
||||
vv?.removeEventListener("scroll", measure);
|
||||
root.classList.remove("kb-open");
|
||||
};
|
||||
}, []);
|
||||
return null;
|
||||
}
|
||||
@@ -57,14 +57,16 @@ const BADGES: Record<BadgeKind, { label: string; title: string; icon: React.Reac
|
||||
</>
|
||||
),
|
||||
},
|
||||
// An ear.
|
||||
// Two walking side by side.
|
||||
listener: {
|
||||
label: "Meghallgató",
|
||||
title: "Önkéntes meghallgató: szívesen meghallgat",
|
||||
label: "Kísérő",
|
||||
title: "Önkéntes kísérő: szívesen válaszol annak, aki meghallgatást kér",
|
||||
icon: (
|
||||
<>
|
||||
<path d="M7 9.5a5 5 0 0 1 10 0c0 3-2.5 4-3 6s-1.5 4-3.8 4A2.7 2.7 0 0 1 7.5 17" />
|
||||
<path d="M10 10a2 2 0 0 1 4 0c0 1.3-1.2 1.7-1.6 2.6" />
|
||||
<circle cx="8" cy="6.5" r="2.5" />
|
||||
<circle cx="16" cy="6.5" r="2.5" />
|
||||
<path d="M3.5 20v-3.5a4.5 4.5 0 0 1 9 0V20" />
|
||||
<path d="M11.5 20v-3.5a4.5 4.5 0 0 1 9 0V20" />
|
||||
</>
|
||||
),
|
||||
},
|
||||
@@ -116,7 +118,7 @@ export function RankBadge({ rank, name }: { rank: Rank; name: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
/** A badge (Moderátor, Meghallgató, Támogató, Szálindító, napi égbolt), with its icon. */
|
||||
/** A badge (Moderátor, Kísérő, Támogató, Szálindító, napi égbolt), with its icon. */
|
||||
export function Badge({ kind }: { kind: BadgeKind }) {
|
||||
const b = BADGES[kind];
|
||||
return (
|
||||
|
||||
@@ -21,6 +21,7 @@ function mentionAt(text: string, caret: number): { query: string; start: number
|
||||
* 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.
|
||||
* `onChange`: the text as it is typed (to keep a draft when the box moves).
|
||||
*/
|
||||
export function Composer({
|
||||
id,
|
||||
@@ -32,6 +33,7 @@ export function Composer({
|
||||
onSubmit,
|
||||
onCancel,
|
||||
onTyping,
|
||||
onChange,
|
||||
mentions = false,
|
||||
rows = 3,
|
||||
autoFocus = false,
|
||||
@@ -45,6 +47,7 @@ export function Composer({
|
||||
onSubmit: (text: string) => Promise<boolean>;
|
||||
onCancel?: () => void;
|
||||
onTyping?: () => void;
|
||||
onChange?: (text: string) => void;
|
||||
mentions?: boolean;
|
||||
rows?: number;
|
||||
autoFocus?: boolean;
|
||||
@@ -55,6 +58,9 @@ export function Composer({
|
||||
const timer = useRef<number | undefined>(undefined);
|
||||
|
||||
useEffect(() => () => window.clearTimeout(timer.current), []);
|
||||
useEffect(() => {
|
||||
onChange?.(text);
|
||||
}, [text, onChange]);
|
||||
|
||||
function lookUp(value: string, caret: number) {
|
||||
window.clearTimeout(timer.current);
|
||||
|
||||
@@ -9,11 +9,10 @@ import type { ForumNavData } from "@/lib/forum";
|
||||
|
||||
/** The menu's counts. */
|
||||
export interface NavCounts {
|
||||
unread: number;
|
||||
/** Unread answers to the member: the only count on the "Válaszok" tab. */
|
||||
replies: number;
|
||||
messages: number;
|
||||
reports: number;
|
||||
/** Listeners: threads waiting for a first reply. */
|
||||
waiting: number;
|
||||
}
|
||||
|
||||
/** The live notice a page listens to (`window` event `forum:live`). */
|
||||
@@ -29,12 +28,7 @@ export interface LiveNotice {
|
||||
const POLL_MS = 30_000;
|
||||
|
||||
function counts(data: ForumNavData): NavCounts {
|
||||
return {
|
||||
unread: data.followed?.new_replies ?? 0,
|
||||
messages: data.messages ?? 0,
|
||||
reports: data.reports ?? 0,
|
||||
waiting: data.waiting ?? 0,
|
||||
};
|
||||
return { replies: data.replies ?? 0, messages: data.messages ?? 0, reports: data.reports ?? 0 };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,7 +99,7 @@ function useLive(member: boolean, wsUrl: string, refresh: () => void) {
|
||||
}, [member, wsUrl, refresh]);
|
||||
}
|
||||
|
||||
function Icon({ name }: { name: "forum" | "followed" | "new" | "messages" | "profile" }) {
|
||||
function Icon({ name }: { name: "forum" | "replies" | "new" | "messages" | "profile" }) {
|
||||
return (
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true" className="fn-icon">
|
||||
{name === "forum" && (
|
||||
@@ -114,10 +108,11 @@ function Icon({ name }: { name: "forum" | "followed" | "new" | "messages" | "pro
|
||||
<path d="M20 9h1a1 1 0 0 1 1 1v8l-3-2h-6" />
|
||||
</>
|
||||
)}
|
||||
{name === "followed" && (
|
||||
{name === "replies" && (
|
||||
<>
|
||||
<path d="M6 16V11a6 6 0 0 1 12 0v5l1.5 2h-15z" />
|
||||
<path d="M10 20.5a2 2 0 0 0 4 0" />
|
||||
<path d="M10 8L5 12.5l5 4.5" />
|
||||
<path d="M5 12.5h9a5 5 0 0 1 5 5V19" />
|
||||
<path d="M14 4.5h5.5" />
|
||||
</>
|
||||
)}
|
||||
{name === "new" && (
|
||||
@@ -144,7 +139,8 @@ function Icon({ name }: { name: "forum" | "followed" | "new" | "messages" | "pro
|
||||
|
||||
/**
|
||||
* The forum's own menu: a bar at the bottom of the screen on phones, tabs
|
||||
* above the content on wider screens. `unread`: new replies in followed threads.
|
||||
* above the content on wider screens. The "Válaszok" tab counts the unread
|
||||
* answers to the member (a reply to them, in their thread, or naming them).
|
||||
*/
|
||||
export function ForumNav({
|
||||
member,
|
||||
@@ -158,13 +154,18 @@ export function ForumNav({
|
||||
wsUrl: string;
|
||||
}) {
|
||||
const path = usePathname();
|
||||
const [{ unread, messages, reports, waiting }, setCounts] = useState(initial);
|
||||
const [{ replies, messages, reports }, setCounts] = useState(initial);
|
||||
const refresh = useCallback(() => {
|
||||
api<ForumNavData>("/forum/nav")
|
||||
.then((data) => setCounts(counts(data)))
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
useLive(member !== null, wsUrl, refresh);
|
||||
// A page that changed what counts (read a thread, "Mind olvasott") asks for fresh counts.
|
||||
useEffect(() => {
|
||||
window.addEventListener("forum:nav", refresh);
|
||||
return () => window.removeEventListener("forum:nav", refresh);
|
||||
}, [refresh]);
|
||||
// The menu stays on screen between pages: fresh counts on every page.
|
||||
const first = useRef(true);
|
||||
useEffect(() => {
|
||||
@@ -180,15 +181,13 @@ export function ForumNav({
|
||||
label: "Fórum",
|
||||
icon: "forum" as const,
|
||||
current: path === "/forum" || path.startsWith("/forum/szal"),
|
||||
// Listeners: what waits for a first reply.
|
||||
badge: waiting,
|
||||
},
|
||||
{
|
||||
href: loggedIn ? "/forum/kovetett" : "/belepes?vissza=/forum/kovetett",
|
||||
label: "Követett",
|
||||
icon: "followed" as const,
|
||||
current: path.startsWith("/forum/kovetett"),
|
||||
badge: unread,
|
||||
href: loggedIn ? "/forum/valaszok" : "/belepes?vissza=/forum/valaszok",
|
||||
label: "Válaszok",
|
||||
icon: "replies" as const,
|
||||
current: path.startsWith("/forum/valaszok") || path.startsWith("/forum/kovetett"),
|
||||
badge: replies,
|
||||
},
|
||||
{
|
||||
href: loggedIn ? "/forum/uj" : "/belepes?vissza=/forum/uj",
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import Link from "next/link";
|
||||
|
||||
/** The two views of the "Válaszok" tab: answers to me, and the threads I follow. */
|
||||
export function RepliesTabs({ current }: { current: "replies" | "followed" }) {
|
||||
return (
|
||||
<nav className="fmod-tabs" aria-label="Válaszok">
|
||||
<Link href="/forum/valaszok" aria-current={current === "replies" ? "page" : undefined}>
|
||||
Nekem
|
||||
</Link>
|
||||
<Link href="/forum/kovetett" aria-current={current === "followed" ? "page" : undefined}>
|
||||
Követett szálak
|
||||
</Link>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
@@ -405,6 +405,17 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
|
||||
const typingNow = useTypingWatch("thread", initial.thread.id);
|
||||
const imTyping = useTypingSender("thread", initial.thread.id);
|
||||
const composer = useRef<HTMLDivElement>(null);
|
||||
// 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]);
|
||||
const { viewer, thread, access } = page;
|
||||
const member = viewer.member !== null;
|
||||
const base = `/forum/threads/${thread.id}`;
|
||||
@@ -414,7 +425,10 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
|
||||
// Mark read up to the newest post shown.
|
||||
useEffect(() => {
|
||||
if (!member || lastId === 0) return;
|
||||
api(`${base}/read`, { body: { post_id: lastId } }).catch(() => {});
|
||||
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(() => {});
|
||||
}, [member, lastId, base]);
|
||||
|
||||
// New replies while the page is open: offered, not pushed into the text being read.
|
||||
@@ -477,10 +491,7 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
|
||||
: await api<ForumPost>(`/forum/posts/${post.id}/reaction`, { method: "PUT", body: { kind } });
|
||||
replacePost(updated);
|
||||
}),
|
||||
replyTo: (post) => {
|
||||
setReplyTo(post);
|
||||
composer.current?.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||
},
|
||||
replyTo: (post) => setReplyTo(post),
|
||||
edit: async (post, body) => {
|
||||
const updated = await run(() => api<ForumPost>(`/forum/posts/${post.id}`, { method: "PATCH", body: { body } }));
|
||||
if (updated) replacePost(updated);
|
||||
@@ -513,12 +524,14 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
|
||||
}),
|
||||
};
|
||||
|
||||
async function sendReply(text: string): Promise<boolean> {
|
||||
const post = await run(() =>
|
||||
api<ForumPost>(`${base}/posts`, { body: { body: text, parent_id: replyTo?.id ?? null } }),
|
||||
);
|
||||
/** A first-level reply (the box at the bottom), or one to `replyTo` (the box in its branch). */
|
||||
async function sendReply(text: string, to: ForumPost | null): Promise<boolean> {
|
||||
const post = await run(() => api<ForumPost>(`${base}/posts`, { body: { body: text, parent_id: to?.id ?? null } }));
|
||||
if (!post) return false;
|
||||
setReplyTo(null);
|
||||
if (to) {
|
||||
draft.current = "";
|
||||
setReplyTo(null);
|
||||
}
|
||||
await reload().catch(() => setPage((p) => ({ ...p, posts: [...p.posts, post] })));
|
||||
requestAnimationFrame(() => document.getElementById(`h${post.id}`)?.scrollIntoView({ block: "center" }));
|
||||
return true;
|
||||
@@ -662,6 +675,35 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{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
|
||||
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}
|
||||
onSubmit={(text) => sendReply(text, replyTo)}
|
||||
onCancel={() => {
|
||||
draft.current = "";
|
||||
setReplyTo(null);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
|
||||
@@ -699,19 +741,6 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
|
||||
<p className="ftv-gate">Ez a szál le van zárva, új hozzászólás nem írható.</p>
|
||||
) : (
|
||||
<>
|
||||
{replyTo && (
|
||||
<p className="ftv-replyto">
|
||||
Válasz neki: <strong>{replyTo.author?.nickname ?? "Törölt tag"}</strong>
|
||||
<button
|
||||
type="button"
|
||||
className="fp-link"
|
||||
onClick={() => setReplyTo(null)}
|
||||
aria-label="Válasz visszavonása"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</p>
|
||||
)}
|
||||
<Composer
|
||||
mentions
|
||||
onTyping={imTyping}
|
||||
@@ -719,7 +748,7 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
|
||||
label="Válaszod"
|
||||
placeholder={thread.topic.listening ? "Írd le, ami benned van…" : "Írd meg a válaszod…"}
|
||||
busy={busy}
|
||||
onSubmit={sendReply}
|
||||
onSubmit={(text) => sendReply(text, null)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -19,7 +19,7 @@ export interface ForumAuthor {
|
||||
online: boolean;
|
||||
/** Planet (or `ascendant`) → sign, as the member chose to share. */
|
||||
signs: Record<string, string> | null;
|
||||
/** A volunteer listener ("Meghallgató"). */
|
||||
/** A volunteer companion ("Kísérő") for the threads asking to be heard. */
|
||||
listener?: boolean;
|
||||
/** Bought a package and shows the "Támogató" badge. */
|
||||
supporter?: boolean;
|
||||
@@ -71,6 +71,10 @@ export interface ThreadCard {
|
||||
export interface ForumHome {
|
||||
viewer: ForumViewer;
|
||||
followed: { new_replies: number; threads: number } | null;
|
||||
/** Unread answers to the member. */
|
||||
replies: number | null;
|
||||
/** Listeners: threads asking to be heard that wait for a reply. */
|
||||
waiting: number | null;
|
||||
/** "Most itt vannak". */
|
||||
online: ForumAuthor[];
|
||||
topics: ForumTopic[];
|
||||
@@ -348,12 +352,23 @@ export interface ReportEntry {
|
||||
/** The forum menu's counts. */
|
||||
export interface ForumNavData {
|
||||
viewer: ForumViewer;
|
||||
followed: { new_replies: number } | null;
|
||||
/** Unread answers to the member (a reply to them, in their thread, or naming them). */
|
||||
replies: number | null;
|
||||
messages: number | null;
|
||||
/** Moderators: open reports and requests to join restricted topics. */
|
||||
reports: number | null;
|
||||
/** Listeners: threads asking to be heard that wait for a reply. */
|
||||
waiting: number | null;
|
||||
}
|
||||
|
||||
/** An answer to the member, on the "Válaszok" page. */
|
||||
export interface ReplyEntry {
|
||||
id: number;
|
||||
thread: { id: number; title: string; slug: string };
|
||||
author: ForumAuthor | null;
|
||||
excerpt: string;
|
||||
created_at: string;
|
||||
/** `reply`: to one of their posts; `thread`: in their thread; `mention`: names them. */
|
||||
kind: "reply" | "thread" | "mention";
|
||||
unread: boolean;
|
||||
}
|
||||
|
||||
export interface TopicRequest {
|
||||
|
||||
Reference in New Issue
Block a user