Forum photos, a one-row bottom menu, and the site's own question windows
Photos in posts and replies: a "Fotó" button in the new thread form and the reply boxes. The browser makes the picture small before uploading it (1600 pixels at most, WebP, JPEG where WebP cannot be made); the forum checks it is a still picture, strips its metadata and makes a square preview (forum-photos/ in the storage). Five a member a day, five a post; one taken off before sending is deleted and does not count. Under the post a row of square previews; a click opens a viewer paged with arrows, swipes and keys. Seen by whoever may read the thread (long public cache only for public topics). Unsent photos go after a day, those of removed posts after a year; removed with the account and listed in the data export. Terms and privacy notice updated. The forum's bottom menu keeps its five items in one row (the fifth wrapped to a second row). On iPhones, when the keyboard goes away without the usual tap (a photo picker opening over it), the page is put back in place instead of the menu floating mid-screen over an empty strip. The browser's own confirm() and prompt() windows (23 places: deleting, revoking, blocking, muting, moderators' reasons, admin actions) are replaced by a question window in the site's look, following the forum's light or dark theme, with named buttons and a text box for reasons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,220 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useId, useRef, useState } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
|
||||
/**
|
||||
* Small question windows in the site's own look, instead of the browser's
|
||||
* grey confirm() and prompt(): `confirmDialog` (yes or no), `askDialog` (a
|
||||
* short text, e.g. a moderator's reason) and `copyDialog` (a link to copy by
|
||||
* hand). Each returns a promise; the one `DialogHost` (root layout) shows
|
||||
* them one after the other. In the forum the window is placed inside the
|
||||
* forum's part of the page, so it takes the forum's light or dark colours.
|
||||
*/
|
||||
|
||||
interface Question {
|
||||
title: string;
|
||||
/** A line or two under the title: what will happen. */
|
||||
text?: React.ReactNode;
|
||||
/** The button that goes ahead, named for what it does ("Törlés", "Letiltás"). */
|
||||
confirm?: string;
|
||||
cancel?: string;
|
||||
/** Something that removes or ends something: the button is red. */
|
||||
danger?: boolean;
|
||||
}
|
||||
|
||||
export interface AskQuestion extends Question {
|
||||
/** The label of the text box. */
|
||||
label: string;
|
||||
placeholder?: string;
|
||||
maxLength?: number;
|
||||
/** The button waits until something is typed. */
|
||||
required?: boolean;
|
||||
}
|
||||
|
||||
export interface CopyQuestion {
|
||||
title: string;
|
||||
text?: React.ReactNode;
|
||||
value: string;
|
||||
}
|
||||
|
||||
type Request = { id: number } & (
|
||||
| { kind: "confirm"; question: Question; resolve: (ok: boolean) => void }
|
||||
| { kind: "ask"; question: AskQuestion; resolve: (text: string | null) => void }
|
||||
| { kind: "copy"; question: CopyQuestion; resolve: () => void }
|
||||
);
|
||||
|
||||
type NewRequest = Request extends infer R ? (R extends Request ? Omit<R, "id"> : never) : never;
|
||||
|
||||
let enqueue: ((request: NewRequest) => void) | null = null;
|
||||
|
||||
/** Yes or no: true when the person goes ahead. */
|
||||
export function confirmDialog(question: Question): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
// The host is always on the page; the browser's own window only as a last resort.
|
||||
if (!enqueue) return resolve(window.confirm(question.title));
|
||||
enqueue({ kind: "confirm", question, resolve });
|
||||
});
|
||||
}
|
||||
|
||||
/** A short text (trimmed), or null when the person steps back. */
|
||||
export function askDialog(question: AskQuestion): Promise<string | null> {
|
||||
return new Promise((resolve) => {
|
||||
if (!enqueue) return resolve(window.prompt(question.label)?.trim() || null);
|
||||
enqueue({ kind: "ask", question, resolve });
|
||||
});
|
||||
}
|
||||
|
||||
/** Shows a value to copy by hand (when the clipboard is not allowed). */
|
||||
export function copyDialog(question: CopyQuestion): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
if (!enqueue) {
|
||||
window.prompt(question.title, question.value);
|
||||
return resolve();
|
||||
}
|
||||
enqueue({ kind: "copy", question, resolve });
|
||||
});
|
||||
}
|
||||
|
||||
export function DialogHost() {
|
||||
const [queue, setQueue] = useState<Request[]>([]);
|
||||
const counter = useRef(0);
|
||||
useEffect(() => {
|
||||
enqueue = (request) => setQueue((q) => [...q, { ...request, id: ++counter.current } as Request]);
|
||||
return () => {
|
||||
enqueue = null;
|
||||
};
|
||||
}, []);
|
||||
const current = queue[0];
|
||||
if (!current) return null;
|
||||
const place = document.querySelector<HTMLElement>(".forum") ?? document.body;
|
||||
return createPortal(
|
||||
<QuestionWindow key={current.id} request={current} onDone={() => setQueue((q) => q.slice(1))} />,
|
||||
place,
|
||||
);
|
||||
}
|
||||
|
||||
function QuestionWindow({ request, onDone }: { request: Request; onDone: () => void }) {
|
||||
const ref = useRef<HTMLDialogElement>(null);
|
||||
const first = useRef<HTMLButtonElement | HTMLTextAreaElement | HTMLInputElement | null>(null);
|
||||
const titleId = useId();
|
||||
const textId = useId();
|
||||
const [value, setValue] = useState("");
|
||||
const answered = useRef(false);
|
||||
const pressedBackdrop = useRef(false);
|
||||
const { question } = request;
|
||||
const ask = request.kind === "ask" ? request.question : null;
|
||||
const waiting = ask?.required === true && value.trim() === "";
|
||||
|
||||
const finish = (ok: boolean) => {
|
||||
if (answered.current) return;
|
||||
answered.current = true;
|
||||
if (request.kind === "confirm") request.resolve(ok);
|
||||
else if (request.kind === "ask") request.resolve(ok && value.trim() ? value.trim() : null);
|
||||
else request.resolve();
|
||||
onDone();
|
||||
};
|
||||
const goAhead = () => {
|
||||
if (!waiting) finish(true);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const dialog = ref.current;
|
||||
if (dialog && !dialog.open) dialog.showModal();
|
||||
// A text box, or for something that removes a thing the safe button, has the focus.
|
||||
first.current?.focus();
|
||||
if (first.current instanceof HTMLInputElement) first.current.select();
|
||||
}, []);
|
||||
|
||||
const danger = request.kind !== "copy" && request.question.danger;
|
||||
const confirmLabel = request.kind === "copy" ? "Bezárás" : (request.question.confirm ?? "Rendben");
|
||||
|
||||
return (
|
||||
<dialog
|
||||
ref={ref}
|
||||
className="modal modal-ask"
|
||||
aria-labelledby={titleId}
|
||||
aria-describedby={question.text ? textId : undefined}
|
||||
// Escape, or the window closing in any other way: stepping back.
|
||||
onClose={() => finish(false)}
|
||||
onPointerDown={(e) => {
|
||||
pressedBackdrop.current = e.target === ref.current;
|
||||
}}
|
||||
onClick={(e) => {
|
||||
const onBackdrop = pressedBackdrop.current && e.target === ref.current;
|
||||
pressedBackdrop.current = false;
|
||||
if (onBackdrop) finish(false);
|
||||
}}
|
||||
>
|
||||
<div className="modal-inner">
|
||||
<h2 id={titleId} className="modal-ask-title">
|
||||
{question.title}
|
||||
</h2>
|
||||
{question.text && (
|
||||
<div id={textId} className="modal-ask-text">
|
||||
{question.text}
|
||||
</div>
|
||||
)}
|
||||
{ask && (
|
||||
<label className="modal-ask-field">
|
||||
<span>{ask.label}</span>
|
||||
<textarea
|
||||
ref={(el) => {
|
||||
first.current = el;
|
||||
}}
|
||||
className="inp"
|
||||
rows={3}
|
||||
value={value}
|
||||
maxLength={ask.maxLength ?? 500}
|
||||
placeholder={ask.placeholder}
|
||||
onChange={(e) => setValue(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
||||
e.preventDefault();
|
||||
goAhead();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
{request.kind === "copy" && (
|
||||
<input
|
||||
ref={(el) => {
|
||||
first.current = el;
|
||||
}}
|
||||
className="inp"
|
||||
readOnly
|
||||
value={request.question.value}
|
||||
onFocus={(e) => e.target.select()}
|
||||
aria-label={request.question.title}
|
||||
/>
|
||||
)}
|
||||
<div className="modal-ask-actions">
|
||||
{request.kind !== "copy" && (
|
||||
<button
|
||||
ref={(el) => {
|
||||
if (danger && !ask) first.current = el;
|
||||
}}
|
||||
type="button"
|
||||
className="btn"
|
||||
onClick={() => finish(false)}
|
||||
>
|
||||
{request.question.cancel ?? "Mégse"}
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
ref={(el) => {
|
||||
if (!danger && !ask && request.kind !== "copy") first.current = el;
|
||||
}}
|
||||
type="button"
|
||||
className={danger ? "btn btn-danger-solid" : "btn btn-primary"}
|
||||
disabled={waiting}
|
||||
onClick={goAhead}
|
||||
>
|
||||
{confirmLabel}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
);
|
||||
}
|
||||
@@ -30,6 +30,11 @@ function typedInto(el: Element | null): el is HTMLElement {
|
||||
* into that part. A text box gets `autocomplete="off"` unless it says
|
||||
* otherwise, so iOS Safari does not lay its AutoFill bar (passwords, cards,
|
||||
* addresses) over it.
|
||||
*
|
||||
* iOS sometimes leaves the page scrolled past its end when the keyboard goes
|
||||
* away without the usual tap (a photo picker opening over it, for one): the
|
||||
* fixed bottom menu then floats mid-screen above an empty strip. When the
|
||||
* keyboard is gone, a one-pixel scroll puts the page back in place.
|
||||
*/
|
||||
export function KeyboardSafe() {
|
||||
useEffect(() => {
|
||||
@@ -39,6 +44,7 @@ export function KeyboardSafe() {
|
||||
let timer: number | undefined;
|
||||
let again: number | undefined;
|
||||
let closing: number | undefined;
|
||||
const settling: number[] = [];
|
||||
|
||||
const measure = () => {
|
||||
root.style.setProperty("--vv-top", `${vv ? vv.offsetTop : 0}px`);
|
||||
@@ -63,6 +69,21 @@ export function KeyboardSafe() {
|
||||
if (Math.abs(delta) > 2) window.scrollBy({ top: delta, behavior: "instant" });
|
||||
};
|
||||
|
||||
// The visible part has drifted below the page (iOS, keyboard gone): back.
|
||||
const settle = () => {
|
||||
if (!vv || root.classList.contains("kb-open")) return;
|
||||
if (Math.abs(vv.scale - 1) > 0.01 || vv.offsetTop < 2) return;
|
||||
const end = Math.max(0, document.documentElement.scrollHeight - vv.height);
|
||||
const top = Math.min(vv.pageTop, end);
|
||||
window.scrollTo({ top: Math.max(0, top - 1), behavior: "instant" });
|
||||
requestAnimationFrame(() => window.scrollTo({ top, behavior: "instant" }));
|
||||
};
|
||||
// Checked a few times while the keyboard slides down.
|
||||
const settleSoon = () => {
|
||||
settling.splice(0).forEach((t) => window.clearTimeout(t));
|
||||
for (const ms of [120, 450, 900]) settling.push(window.setTimeout(settle, ms));
|
||||
};
|
||||
|
||||
// After the keyboard has slid up (and once more when the browser's own
|
||||
// scrolling has settled), and whenever the free part changes.
|
||||
const later = (ms: number) => {
|
||||
@@ -87,20 +108,34 @@ export function KeyboardSafe() {
|
||||
// Moving to another field keeps it open.
|
||||
window.clearTimeout(closing);
|
||||
closing = window.setTimeout(() => {
|
||||
if (!typedInto(document.activeElement)) root.classList.remove("kb-open");
|
||||
if (typedInto(document.activeElement)) return;
|
||||
root.classList.remove("kb-open");
|
||||
settleSoon();
|
||||
}, 150);
|
||||
};
|
||||
const onViewport = () => {
|
||||
if (!root.classList.contains("kb-open")) return;
|
||||
if (!root.classList.contains("kb-open")) {
|
||||
settleSoon();
|
||||
return;
|
||||
}
|
||||
measure();
|
||||
later(150);
|
||||
};
|
||||
// Back from a picker (photos) or another app.
|
||||
const onReturn = () => {
|
||||
if (document.visibilityState === "visible") settleSoon();
|
||||
};
|
||||
|
||||
document.addEventListener("focusin", onFocusIn);
|
||||
document.addEventListener("focusout", onFocusOut);
|
||||
vv?.addEventListener("resize", onViewport);
|
||||
vv?.addEventListener("scroll", measure);
|
||||
window.addEventListener("focus", onReturn);
|
||||
document.addEventListener("visibilitychange", onReturn);
|
||||
return () => {
|
||||
settling.forEach((t) => window.clearTimeout(t));
|
||||
window.removeEventListener("focus", onReturn);
|
||||
document.removeEventListener("visibilitychange", onReturn);
|
||||
window.clearTimeout(timer);
|
||||
window.clearTimeout(again);
|
||||
window.clearTimeout(closing);
|
||||
|
||||
@@ -5,7 +5,8 @@ import { useEffect, useId, useRef } from "react";
|
||||
/**
|
||||
* A modal window (the browser's own <dialog>: focus stays inside, Escape
|
||||
* closes it). Shown while mounted; a click on the dimmed backdrop closes it.
|
||||
* `canClose`: asked first (e.g. about unsaved input); false keeps it open.
|
||||
* `canClose`: asked first (e.g. about unsaved input, maybe in a question
|
||||
* window); false keeps it open.
|
||||
*/
|
||||
export function Modal({
|
||||
title,
|
||||
@@ -17,7 +18,7 @@ export function Modal({
|
||||
title: string;
|
||||
subtitle?: React.ReactNode;
|
||||
onClose: () => void;
|
||||
canClose?: () => boolean;
|
||||
canClose?: () => boolean | Promise<boolean>;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const ref = useRef<HTMLDialogElement>(null);
|
||||
@@ -26,8 +27,8 @@ export function Modal({
|
||||
// it (not a text selection dragged out, nor a pick from a select's list that
|
||||
// hangs over the backdrop).
|
||||
const pressedBackdrop = useRef(false);
|
||||
const close = () => {
|
||||
if (!canClose || canClose()) onClose();
|
||||
const close = async () => {
|
||||
if (!canClose || (await canClose())) onClose();
|
||||
};
|
||||
|
||||
// No close() on unmount: that would fire onClose; a removed dialog is gone anyway.
|
||||
@@ -43,8 +44,10 @@ export function Modal({
|
||||
aria-labelledby={titleId}
|
||||
onClose={onClose}
|
||||
onCancel={(e) => {
|
||||
// Escape: the dialog would close by itself.
|
||||
if (canClose && !canClose()) e.preventDefault();
|
||||
// Escape: the dialog would close by itself; with a question first it waits for the answer.
|
||||
if (!canClose) return;
|
||||
e.preventDefault();
|
||||
void close();
|
||||
}}
|
||||
onPointerDown={(e) => {
|
||||
pressedBackdrop.current = e.target === ref.current;
|
||||
@@ -52,7 +55,7 @@ export function Modal({
|
||||
onClick={(e) => {
|
||||
const onBackdrop = pressedBackdrop.current && e.target === ref.current;
|
||||
pressedBackdrop.current = false;
|
||||
if (onBackdrop) close();
|
||||
if (onBackdrop) void close();
|
||||
}}
|
||||
>
|
||||
<div className="modal-inner">
|
||||
@@ -61,7 +64,7 @@ export function Modal({
|
||||
<h2 id={titleId}>{title}</h2>
|
||||
{subtitle && <div className="muted modal-sub">{subtitle}</div>}
|
||||
</div>
|
||||
<button type="button" className="modal-close" onClick={close} aria-label="Bezárás">
|
||||
<button type="button" className="modal-close" onClick={() => void close()} aria-label="Bezárás">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M6 6l12 12M18 6L6 18" />
|
||||
</svg>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { useCallback, useEffect, useState } from "react";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { formatDate } from "@/lib/astro";
|
||||
import type { PersonInvite } from "@/lib/types";
|
||||
import { confirmDialog } from "@/components/Dialogs";
|
||||
|
||||
/** The user's "how compatible are we?" invitations: waiting ones (revocable) and accepted ones. */
|
||||
export function PendingInvites() {
|
||||
@@ -25,7 +26,13 @@ export function PendingInvites() {
|
||||
}, [load]);
|
||||
|
||||
async function revoke(i: PersonInvite) {
|
||||
if (!window.confirm(`Visszavonod a meghívót${i.label ? ` (${i.label})` : ""}? A link nem fog működni.`)) return;
|
||||
const ok = await confirmDialog({
|
||||
title: "Visszavonod a meghívót?",
|
||||
text: `${i.label ? `${i.label}: ` : ""}a link ezután nem fog működni.`,
|
||||
confirm: "Visszavonás",
|
||||
danger: true,
|
||||
});
|
||||
if (!ok) return;
|
||||
try {
|
||||
await api(`/invites/${i.id}`, { method: "DELETE" });
|
||||
await load();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { confirmDialog } from "@/components/Dialogs";
|
||||
|
||||
interface Share {
|
||||
id: string;
|
||||
@@ -83,7 +84,14 @@ export function ShareChart({
|
||||
}
|
||||
|
||||
async function revoke() {
|
||||
if (!share || !window.confirm("Visszavonod a linket? Aki megkapta, többé nem tudja megnyitni.")) return;
|
||||
if (!share) return;
|
||||
const ok = await confirmDialog({
|
||||
title: "Visszavonod a linket?",
|
||||
text: "Aki megkapta, többé nem tudja megnyitni.",
|
||||
confirm: "Visszavonás",
|
||||
danger: true,
|
||||
});
|
||||
if (!ok) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await api(`/shares/${share.id}`, { method: "DELETE" });
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
import { api } from "@/lib/api";
|
||||
import { usePhotoUploads } from "@/lib/photos";
|
||||
import { convertEmoticons, withEmoji } from "@/lib/emoticons";
|
||||
import type { ForumAuthor } from "@/lib/forum";
|
||||
|
||||
import { Avatar } from "./Avatar";
|
||||
import { PhotoButton, PickedPhotos } from "./Photos";
|
||||
|
||||
/** "@Ho" right before the caret: what was typed after the "@", and where it starts. */
|
||||
function mentionAt(text: string, caret: number): { query: string; start: number } | null {
|
||||
@@ -22,6 +24,7 @@ function mentionAt(text: string, caret: number): { query: string; start: number
|
||||
* `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).
|
||||
* `photos`: a "Fotó" button; the uploaded photos' ids go with the text.
|
||||
*/
|
||||
export function Composer({
|
||||
id,
|
||||
@@ -35,6 +38,7 @@ export function Composer({
|
||||
onTyping,
|
||||
onChange,
|
||||
mentions = false,
|
||||
photos = false,
|
||||
rows = 3,
|
||||
autoFocus = false,
|
||||
}: {
|
||||
@@ -44,17 +48,19 @@ export function Composer({
|
||||
initial?: string;
|
||||
submitLabel?: string;
|
||||
busy: boolean;
|
||||
onSubmit: (text: string) => Promise<boolean>;
|
||||
onSubmit: (text: string, photos: string[]) => Promise<boolean>;
|
||||
onCancel?: () => void;
|
||||
onTyping?: () => void;
|
||||
onChange?: (text: string) => void;
|
||||
mentions?: boolean;
|
||||
photos?: boolean;
|
||||
rows?: number;
|
||||
autoFocus?: boolean;
|
||||
}) {
|
||||
const [text, setText] = useState(initial);
|
||||
const [suggest, setSuggest] = useState<{ query: string; start: number; members: ForumAuthor[] } | null>(null);
|
||||
const area = useRef<HTMLTextAreaElement>(null);
|
||||
const picked = usePhotoUploads();
|
||||
const timer = useRef<number | undefined>(undefined);
|
||||
|
||||
useEffect(() => () => window.clearTimeout(timer.current), []);
|
||||
@@ -92,11 +98,12 @@ export function Composer({
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
if (!text.trim() || busy) return;
|
||||
if (!text.trim() || busy || picked.busy) return;
|
||||
const final = convertEmoticons(text, text.length, true).text;
|
||||
if (await onSubmit(final)) {
|
||||
if (await onSubmit(final, picked.ids)) {
|
||||
setText("");
|
||||
setSuggest(null);
|
||||
picked.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +155,14 @@ export function Composer({
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{photos && <PickedPhotos items={picked.items} onRemove={picked.remove} />}
|
||||
{photos && picked.error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{picked.error}
|
||||
</p>
|
||||
)}
|
||||
<div className="fc-actions">
|
||||
{photos && <PhotoButton onFiles={(files) => void picked.add(files)} disabled={picked.full} />}
|
||||
<span className="fc-spacer" />
|
||||
{onCancel && (
|
||||
<button type="button" className="btn btn-ghost btn-sm" onClick={onCancel}>
|
||||
@@ -158,7 +172,7 @@ export function Composer({
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-sm"
|
||||
disabled={busy || !text.trim()}
|
||||
disabled={busy || picked.busy || !text.trim()}
|
||||
onClick={() => void submit()}
|
||||
>
|
||||
{busy ? "Küldés…" : submitLabel}
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
import type { ForumPhoto, PickedPhoto } from "@/lib/photos";
|
||||
|
||||
/** "Fotó": picks pictures from the phone or the computer. */
|
||||
export function PhotoButton({ onFiles, disabled }: { onFiles: (files: FileList) => void; disabled?: boolean }) {
|
||||
const input = useRef<HTMLInputElement>(null);
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-sm fphoto-btn"
|
||||
disabled={disabled}
|
||||
onClick={() => input.current?.click()}
|
||||
>
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<rect x="3" y="5" width="18" height="15" rx="2.5" />
|
||||
<circle cx="9" cy="10.5" r="2" />
|
||||
<path d="M21 16l-5-5-8 8" />
|
||||
</svg>
|
||||
Fotó
|
||||
</button>
|
||||
<input
|
||||
ref={input}
|
||||
type="file"
|
||||
accept="image/*"
|
||||
multiple
|
||||
className="sr-only"
|
||||
tabIndex={-1}
|
||||
onChange={(e) => {
|
||||
if (e.target.files?.length) onFiles(e.target.files);
|
||||
e.target.value = "";
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** The picked photos before sending: small squares, each removable. */
|
||||
export function PickedPhotos({ items, onRemove }: { items: PickedPhoto[]; onRemove: (key: string) => void }) {
|
||||
if (items.length === 0) return null;
|
||||
return (
|
||||
<ul className="fphoto-picked">
|
||||
{items.map((p) => (
|
||||
<li key={p.key} className={p.id ? "fphoto-chip" : "fphoto-chip fphoto-busy"}>
|
||||
{/* A local preview or the forum's square preview. */}
|
||||
<img src={p.preview} alt="" />
|
||||
{p.id ? (
|
||||
<button
|
||||
type="button"
|
||||
className="fphoto-remove"
|
||||
aria-label="Fotó eltávolítása"
|
||||
onClick={() => onRemove(p.key)}
|
||||
>
|
||||
×
|
||||
</button>
|
||||
) : (
|
||||
<span className="fphoto-spinner" aria-label="Feltöltés…" />
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
/** A post's photos: one row of square previews; a click opens the viewer. */
|
||||
export function PostPhotos({ photos }: { photos: ForumPhoto[] }) {
|
||||
const [open, setOpen] = useState<number | null>(null);
|
||||
return (
|
||||
<>
|
||||
<div className="fpics">
|
||||
{photos.map((p, i) => (
|
||||
<button
|
||||
key={p.id}
|
||||
type="button"
|
||||
className="fpic"
|
||||
onClick={() => setOpen(i)}
|
||||
aria-label={photos.length > 1 ? `${i + 1}. fotó megnyitása` : "Fotó megnyitása"}
|
||||
>
|
||||
<img src={p.thumb} alt="" width={360} height={360} loading="lazy" />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{open !== null && <Lightbox photos={photos} start={open} onClose={() => setOpen(null)} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** The photo viewer: one picture at a time; arrows, swiping and the keyboard turn the pages. */
|
||||
function Lightbox({ photos, start, onClose }: { photos: ForumPhoto[]; start: number; onClose: () => void }) {
|
||||
const [at, setAt] = useState(start);
|
||||
const dialog = useRef<HTMLDialogElement>(null);
|
||||
const touch = useRef<number | null>(null);
|
||||
const many = photos.length > 1;
|
||||
const go = (step: number) => setAt((i) => (i + step + photos.length) % photos.length);
|
||||
|
||||
useEffect(() => {
|
||||
const d = dialog.current;
|
||||
if (d && !d.open) d.showModal();
|
||||
}, []);
|
||||
// The neighbours load ahead.
|
||||
useEffect(() => {
|
||||
for (const step of [1, -1]) {
|
||||
const next = photos[(at + step + photos.length) % photos.length];
|
||||
if (next) new Image().src = next.url;
|
||||
}
|
||||
}, [at, photos]);
|
||||
|
||||
const photo = photos[at];
|
||||
return (
|
||||
<dialog
|
||||
ref={dialog}
|
||||
className="flight"
|
||||
aria-label="Fotók"
|
||||
onClose={onClose}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "ArrowRight" && many) go(1);
|
||||
if (e.key === "ArrowLeft" && many) go(-1);
|
||||
}}
|
||||
onClick={(e) => {
|
||||
if (e.target === e.currentTarget) onClose();
|
||||
}}
|
||||
onPointerDown={(e) => (touch.current = e.clientX)}
|
||||
onPointerUp={(e) => {
|
||||
if (touch.current === null || !many) return;
|
||||
const dx = e.clientX - touch.current;
|
||||
touch.current = null;
|
||||
if (Math.abs(dx) > 50) go(dx < 0 ? 1 : -1);
|
||||
}}
|
||||
>
|
||||
<figure className="flight-figure" onClick={(e) => e.target === e.currentTarget && onClose()}>
|
||||
{/* The photo itself (already made small by the browser that uploaded it). */}
|
||||
<img src={photo.url} alt="" className="flight-img" width={photo.width} height={photo.height} />
|
||||
</figure>
|
||||
<button type="button" className="flight-btn flight-close" aria-label="Bezárás" onClick={onClose}>
|
||||
×
|
||||
</button>
|
||||
{many && (
|
||||
<>
|
||||
<button type="button" className="flight-btn flight-prev" aria-label="Előző fotó" onClick={() => go(-1)}>
|
||||
‹
|
||||
</button>
|
||||
<button type="button" className="flight-btn flight-next" aria-label="Következő fotó" onClick={() => go(1)}>
|
||||
›
|
||||
</button>
|
||||
<span className="flight-count">
|
||||
{at + 1} / {photos.length}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</dialog>
|
||||
);
|
||||
}
|
||||
@@ -14,9 +14,11 @@ import type { LiveNotice } from "./ForumNav";
|
||||
import { ReactionIcon } from "./ReactionIcon";
|
||||
import { ReportForm } from "./ReportButton";
|
||||
import { LinkPreviews } from "./LinkPreviews";
|
||||
import { PostPhotos } from "./Photos";
|
||||
import { ShareCard } from "./ShareCard";
|
||||
import { TypingLine, useTypingSender, useTypingWatch } from "./typing";
|
||||
import { Badge, RankBadge } from "./Badges";
|
||||
import { askDialog, confirmDialog } from "@/components/Dialogs";
|
||||
|
||||
/** How often the open thread looks for new replies (while the page is in front). */
|
||||
const POLL_MS = 30_000;
|
||||
@@ -338,6 +340,7 @@ function PostCard({
|
||||
post.body !== null && (
|
||||
<>
|
||||
<PostBody text={post.body} mentions={post.mentions} hide={post.links?.map((l) => l.url) ?? []} />
|
||||
{post.photos && post.photos.length > 0 && <PostPhotos photos={post.photos} />}
|
||||
{post.links && post.links.length > 0 && <LinkPreviews links={post.links} />}
|
||||
{post.share && <ShareCard share={post.share} />}
|
||||
</>
|
||||
@@ -529,12 +532,20 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
|
||||
if (updated) replacePost(updated);
|
||||
return updated !== null;
|
||||
},
|
||||
remove: (post) => {
|
||||
remove: async (post) => {
|
||||
let reason: string | null = null;
|
||||
if (post.own) {
|
||||
if (!window.confirm("Biztosan törlöd a hozzászólásodat?")) return;
|
||||
const ok = await confirmDialog({ title: "Törlöd a hozzászólásodat?", confirm: "Törlés", danger: true });
|
||||
if (!ok) return;
|
||||
} else {
|
||||
reason = window.prompt("Miért távolítod el? Az indoklás a hozzászólás helyén látszik.");
|
||||
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,
|
||||
});
|
||||
if (!reason) return;
|
||||
}
|
||||
void run(async () => {
|
||||
@@ -547,21 +558,29 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
|
||||
await api(`/forum/posts/${post.id}/restore`, { method: "POST" });
|
||||
await reload();
|
||||
}),
|
||||
detachShare: (post) => {
|
||||
if (!window.confirm("Leveszed a csatolt képletet? A kártya eltűnik, és a link sem működik többé.")) return;
|
||||
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;
|
||||
void run(async () => {
|
||||
await api(`/forum/posts/${post.id}/share`, { method: "DELETE" });
|
||||
await reload();
|
||||
});
|
||||
},
|
||||
mute: (post) => {
|
||||
mute: async (post) => {
|
||||
const nickname = post.author?.nickname;
|
||||
if (!nickname) return;
|
||||
if (
|
||||
!post.muted &&
|
||||
!window.confirm(
|
||||
`Elnémítod ${nickname} tagot? 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.`,
|
||||
)
|
||||
!(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",
|
||||
}))
|
||||
)
|
||||
return;
|
||||
void run(async () => {
|
||||
@@ -579,8 +598,10 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
|
||||
};
|
||||
|
||||
/** 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 } }));
|
||||
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 } }),
|
||||
);
|
||||
if (!post) return false;
|
||||
if (to) {
|
||||
draft.current = "";
|
||||
@@ -603,7 +624,14 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
|
||||
}
|
||||
|
||||
async function removeThread() {
|
||||
const reason = window.prompt("Miért távolítod el az egész szálat? Az indoklás látszik a helyén.");
|
||||
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,
|
||||
});
|
||||
if (!reason) return;
|
||||
await run(() => api(base, { method: "DELETE", body: { reason } }));
|
||||
await reload();
|
||||
@@ -741,6 +769,7 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
|
||||
<Composer
|
||||
key={top.id}
|
||||
mentions
|
||||
photos
|
||||
onTyping={imTyping}
|
||||
id={`valasz-${top.id}`}
|
||||
label={`Válasz neki: ${replyTo.author?.nickname ?? "Törölt tag"}`}
|
||||
@@ -750,7 +779,7 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
|
||||
draft.current = text;
|
||||
}}
|
||||
busy={busy}
|
||||
onSubmit={(text) => sendReply(text, replyTo)}
|
||||
onSubmit={(text, photos) => sendReply(text, replyTo, photos)}
|
||||
onCancel={() => {
|
||||
draft.current = "";
|
||||
setReplyTo(null);
|
||||
@@ -801,12 +830,13 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
|
||||
<>
|
||||
<Composer
|
||||
mentions
|
||||
photos
|
||||
onTyping={imTyping}
|
||||
id="valasz-szoveg"
|
||||
label="Válaszod"
|
||||
placeholder={thread.topic.listening ? "Írd le, ami benned van…" : "Írd meg a válaszod…"}
|
||||
busy={busy}
|
||||
onSubmit={(text) => sendReply(text, null)}
|
||||
onSubmit={(text, photos) => sendReply(text, null, photos)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user