- Text boxes say autocomplete="off" (the forum's in the markup, any other textarea when it gets the focus), so iOS Safari does not lay its AutoFill bar (passwords, cards, addresses) over them. - KeyboardSafe scrolls at once instead of smoothly (the browser's own scroll cut the smooth one short on iOS), once more when that has settled, and keeps a little more room above the keyboard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
105 lines
3.6 KiB
TypeScript
105 lines
3.6 KiB
TypeScript
import type { Metadata } from "next";
|
||
import Link from "next/link";
|
||
|
||
import { ago, threadHref } from "@/lib/forum";
|
||
import { forumGet } from "@/lib/forumServer";
|
||
|
||
export const metadata: Metadata = { title: "Keresés a fórumban", robots: { index: false, follow: true } };
|
||
|
||
interface SearchResult {
|
||
thread: { id: number; title: string; slug: string };
|
||
topic: { slug: string; name: string };
|
||
author: { nickname: string } | null;
|
||
last_post_at: string;
|
||
reply_count: number;
|
||
post_id: number | null;
|
||
/** The matching words between ⟦ and ⟧. */
|
||
snippet: string | null;
|
||
}
|
||
|
||
/** The words the search found, marked. */
|
||
function Marked({ text }: { text: string }) {
|
||
return (
|
||
<>
|
||
{text
|
||
.split(/(⟦[^⟧]*⟧)/)
|
||
.map((part, i) =>
|
||
part.startsWith("⟦") ? <mark key={i}>{part.slice(1, -1)}</mark> : <span key={i}>{part}</span>,
|
||
)}
|
||
</>
|
||
);
|
||
}
|
||
|
||
/** Search in the threads and posts the visitor may read. */
|
||
export default async function SearchPage({ searchParams }: { searchParams: Promise<{ q?: string; oldal?: string }> }) {
|
||
const params = await searchParams;
|
||
const q = (params.q ?? "").trim();
|
||
const page = Math.max(1, Number(params.oldal) || 1);
|
||
const res =
|
||
q.length >= 2
|
||
? await forumGet<{ results: SearchResult[]; more: boolean }>(
|
||
`/v1/forum/search?q=${encodeURIComponent(q)}&page=${page}`,
|
||
)
|
||
: null;
|
||
const results = res?.ok ? res.data.results : [];
|
||
const more = res?.ok ? res.data.more : false;
|
||
const link = (p: number) => `/forum/kereses?q=${encodeURIComponent(q)}&oldal=${p}`;
|
||
return (
|
||
<div className="fh">
|
||
<h1 className="fpage-title">Keresés</h1>
|
||
<form className="fsearch-form" action="/forum/kereses" role="search">
|
||
<label htmlFor="fsearch-q" className="sr-only">
|
||
Mit keresel?
|
||
</label>
|
||
<input
|
||
id="fsearch-q"
|
||
name="q"
|
||
type="search"
|
||
autoComplete="off"
|
||
className="inp"
|
||
defaultValue={q}
|
||
placeholder="Mit keresel? Például: alvás, telihold, gyász"
|
||
minLength={2}
|
||
maxLength={100}
|
||
autoFocus={!q}
|
||
/>
|
||
<button type="submit" className="btn btn-primary">
|
||
Keresés
|
||
</button>
|
||
</form>
|
||
{q.length >= 2 &&
|
||
(results.length === 0 ? (
|
||
<p className="fh-card fh-empty">Erre nincs találat. Próbáld más szóval, vagy rövidebben.</p>
|
||
) : (
|
||
<ul className="fh-card fh-flush fsearch-results">
|
||
{results.map((r) => (
|
||
<li key={r.thread.id}>
|
||
<Link href={threadHref(r.thread, r.post_id ?? undefined)} className="fsearch-hit">
|
||
<span className="fsearch-title">{r.thread.title}</span>
|
||
<span className="fsearch-meta">
|
||
{r.topic.name} · {r.author?.nickname ?? "Törölt tag"} · {r.reply_count} válasz · utoljára{" "}
|
||
<time suppressHydrationWarning dateTime={r.last_post_at}>
|
||
{ago(r.last_post_at)}
|
||
</time>
|
||
</span>
|
||
{r.snippet && (
|
||
<span className="fsearch-snippet">
|
||
<Marked text={r.snippet} />
|
||
</span>
|
||
)}
|
||
</Link>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
))}
|
||
{(page > 1 || more) && (
|
||
<nav className="forum-pager" aria-label="Lapozás">
|
||
{page > 1 ? <Link href={link(page - 1)}>‹ Előző</Link> : <span />}
|
||
<span className="hint">{page}. oldal</span>
|
||
{more ? <Link href={link(page + 1)}>Következő ›</Link> : <span />}
|
||
</nav>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|