Code-Review: tote Stellen entfernt, Umwege vereinfacht
- SQLite-Import, migrate.sh, notes/migrations.md und altes jQuery-Skript entfernt - Backend: scanEntry/queryEntries statt doppelter Scan-Liste, Feed-Queries direkt statt feedWhere, Thread ohne Map-Umweg, gemeinsame Helfer für Cookie-Löschen und Mediennamen, usernameTaken - Frontend: PostForm für Beitrag und Antwort, EntryCard in Deleted/LiveCard aufgeteilt, tote CSS-Regeln und Typen entfernt, Strich-Regeln zusammengelegt - Rechtstexte verlinken /stats; Kommentare ohne Vorgeschichte Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TiXsPUqw7oeomZ8wZrQW5q
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d1bd0f5f1d
commit
df0cfec132
@@ -2,9 +2,8 @@ import { useState, type FormEvent, type MouseEvent } from "react";
|
||||
import { api, errMsg } from "../api";
|
||||
import { useAuthChanged } from "../auth";
|
||||
|
||||
// AuthBox: Login und Registrierung im Wechsel. Die {" "} bilden die
|
||||
// Leerzeichen des alten Markups nach -- Überschrift, Inputs und Knöpfe sind
|
||||
// inline, der Abstand zwischen ihnen ist also sichtbar.
|
||||
// AuthBox: Login und Registrierung im Wechsel. Die {" "} sind Absicht:
|
||||
// Überschrift, Inputs und Knöpfe sind inline, der Abstand ist sichtbar.
|
||||
export function AuthBox() {
|
||||
const [mode, setMode] = useState<"login" | "register">("login");
|
||||
const [msg, setMsg] = useState("");
|
||||
|
||||
@@ -8,7 +8,7 @@ const nowSec = () => Math.floor(Date.now() / 1000);
|
||||
|
||||
// cooldownText ist der Hinweis in der Byline: Restzeit auf Stunden
|
||||
// aufgerundet (mindestens 1 -> nie "0h", solange Restzeit übrig ist).
|
||||
export function cooldownText(retryAfter: number): string {
|
||||
function cooldownText(retryAfter: number): string {
|
||||
return ` · Repost in ${Math.max(1, Math.ceil(retryAfter / 3600))}h`;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import { useState, type FormEvent } from "react";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { api, errMsg } from "../api";
|
||||
import { pasteImage } from "../paste";
|
||||
import type { CreatedEntry } from "../types";
|
||||
|
||||
// Compose: neuer Beitrag. Nach Erfolg springt der Feed zurück auf Seite 0,
|
||||
// damit der eigene Beitrag oben steht.
|
||||
export function Compose() {
|
||||
const qc = useQueryClient();
|
||||
const [pasteMsg, setPasteMsg] = useState("");
|
||||
const create = useMutation({
|
||||
mutationFn: (fd: FormData) => api.post<CreatedEntry>("/entry/create", fd),
|
||||
});
|
||||
|
||||
const onSubmit = (e: FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
const form = e.currentTarget;
|
||||
create.mutate(new FormData(form), {
|
||||
onSuccess: () => {
|
||||
form.reset();
|
||||
setPasteMsg("");
|
||||
qc.resetQueries({ queryKey: ["feed"] });
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<section id="compose">
|
||||
<form
|
||||
id="entry-form"
|
||||
onSubmit={onSubmit}
|
||||
onPaste={(e) => {
|
||||
if (pasteImage(e)) setPasteMsg("Bild aus Zwischenablage übernommen.");
|
||||
}}
|
||||
>
|
||||
<textarea name="content" rows={4} maxLength={1000} placeholder="Was gibt's Neues?"></textarea>{" "}
|
||||
<p className="muted" id="paste-msg">{pasteMsg}</p>{" "}
|
||||
<input name="file" type="file" accept="image/*" />{" "}
|
||||
<button type="submit" disabled={create.isPending}>Eintrag erstellen</button>
|
||||
</form>
|
||||
<p className="msg" id="entry-msg">{create.isError ? errMsg(create.error, "Beitrag fehlgeschlagen.") : ""}</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -14,28 +14,28 @@ function useOpenOnClick(pid: number) {
|
||||
};
|
||||
}
|
||||
|
||||
export function EntryCard({ entry: e }: { entry: Entry }) {
|
||||
const open = useOpenOnClick(e.pid);
|
||||
const when = formatTime(e.created_at);
|
||||
|
||||
// Soft-gelöschter Beitrag: nur Platzhalter, damit der Thread navigierbar bleibt.
|
||||
if (e.deleted) {
|
||||
return (
|
||||
<article className="card" onClick={open}>
|
||||
<div className="muted byline"><span>[deleted] · {when}</span></div>
|
||||
<div className="threadline-wrapper">
|
||||
<div className="threadline"></div>
|
||||
<div className="body">
|
||||
<div className="content">[deleted]</div>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
return <LiveCard entry={e} when={when} open={open} />;
|
||||
export function EntryCard({ entry }: { entry: Entry }) {
|
||||
return entry.deleted ? <DeletedCard entry={entry} /> : <LiveCard entry={entry} />;
|
||||
}
|
||||
|
||||
function LiveCard({ entry: e, when, open }: { entry: Entry; when: string; open: (ev: MouseEvent) => void }) {
|
||||
// Soft-gelöschter Beitrag: nur Platzhalter, damit der Thread navigierbar bleibt.
|
||||
function DeletedCard({ entry: e }: { entry: Entry }) {
|
||||
const open = useOpenOnClick(e.pid);
|
||||
return (
|
||||
<article className="card" onClick={open}>
|
||||
<div className="muted byline"><span>[deleted] · {formatTime(e.created_at)}</span></div>
|
||||
<div className="threadline-wrapper">
|
||||
<div className="threadline"></div>
|
||||
<div className="body">
|
||||
<div className="content">[deleted]</div>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
function LiveCard({ entry: e }: { entry: Entry }) {
|
||||
const open = useOpenOnClick(e.pid);
|
||||
const bump = useBump(e);
|
||||
const profile = `/u/${encodeURIComponent(e.username)}`;
|
||||
|
||||
@@ -46,7 +46,7 @@ function LiveCard({ entry: e, when, open }: { entry: Entry; when: string; open:
|
||||
<img className="avatar avatar-sm" src={avatarUrl(e.avatar)} alt="" loading="lazy" />
|
||||
</Link>
|
||||
<span>
|
||||
<Link to={profile}>{e.username}</Link> · {when}
|
||||
<Link to={profile}>{e.username}</Link> · {formatTime(e.created_at)}
|
||||
<span className="cooldown">{bump.cooldown}</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -10,8 +10,8 @@ const maxPage = 100;
|
||||
|
||||
// Feed lädt Seiten per Infinite-Scroll: queryKey identifiziert den Feed im
|
||||
// Cache (zum Invalidieren nach eigenen Beiträgen), urlFor(page) baut den
|
||||
// API-Pfad der Seite. as ist das Container-Element wie im alten Markup:
|
||||
// <section> auf der Startseite, <div> innerhalb des Profils.
|
||||
// API-Pfad der Seite. as ist das Container-Element: <section> auf der
|
||||
// Startseite, <div> innerhalb des Profils.
|
||||
export function Feed({ queryKey, urlFor, as: Container = "section" }: {
|
||||
queryKey: unknown[];
|
||||
urlFor: (page: number) => string;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { useState, type FormEvent } from "react";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { api, errMsg } from "../api";
|
||||
import { pasteImage } from "../paste";
|
||||
|
||||
// PostForm verfasst einen Beitrag, mit replyTo eine Antwort darauf.
|
||||
export function PostForm({ replyTo, rows, placeholder, submitLabel, fallback, onDone }: {
|
||||
replyTo?: string;
|
||||
rows: number;
|
||||
placeholder: string;
|
||||
submitLabel: string;
|
||||
fallback: string;
|
||||
onDone: () => void;
|
||||
}) {
|
||||
const [pasteMsg, setPasteMsg] = useState("");
|
||||
const create = useMutation({
|
||||
mutationFn: (fd: FormData) => api.post("/entry/create", fd),
|
||||
});
|
||||
|
||||
const onSubmit = (e: FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
const form = e.currentTarget;
|
||||
const fd = new FormData(form);
|
||||
if (replyTo) fd.append("reply_to", replyTo);
|
||||
create.mutate(fd, {
|
||||
onSuccess: () => {
|
||||
form.reset();
|
||||
setPasteMsg("");
|
||||
onDone();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<form
|
||||
onSubmit={onSubmit}
|
||||
onPaste={(e) => {
|
||||
if (pasteImage(e)) setPasteMsg("Bild aus Zwischenablage übernommen.");
|
||||
}}
|
||||
>
|
||||
<textarea name="content" rows={rows} maxLength={1000} placeholder={placeholder}></textarea>{" "}
|
||||
<p className="muted">{pasteMsg}</p>{" "}
|
||||
<input name="file" type="file" accept="image/*" />{" "}
|
||||
<button type="submit" disabled={create.isPending}>{submitLabel}</button>
|
||||
</form>
|
||||
<p className="msg">{create.isError ? errMsg(create.error, fallback) : ""}</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user