fix(public): distinguish unavailable data from empty results and missing pages
This commit is contained in:
1 parent
db4acbb46e
commit
445ef13846
16 files changed
+608
-169
No files matched your search
@@ -3,9 +3,11 @@ import { notFound } from "next/navigation";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import type { CSSProperties } from "react";
|
||||
import Link from "@/components/link";
|
||||
import { PublicLoadError } from "@/components/public/load-error";
|
||||
import { ContentCard, EmptyState } from "@/components/public/ui";
|
||||
import { db, Guilds, GuildsForumsThreads, User } from "@/lib/db";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { publicReadFailure } from "@/lib/services/public-read";
|
||||
|
||||
type SearchParams = Promise<{ posted?: string }>;
|
||||
|
||||
@@ -49,7 +51,7 @@ export default async function GuildForumPage({
|
||||
const guildId = Number(id);
|
||||
if (!Number.isInteger(guildId) || guildId <= 0) notFound();
|
||||
|
||||
// Guild header (read-only). A DB hiccup degrades to notFound rather than 500.
|
||||
// Missing guilds and unavailable guild data have distinct outcomes.
|
||||
let guild: { id: number; name: string; badge: string } | null = null;
|
||||
try {
|
||||
const [row] = await db
|
||||
@@ -62,13 +64,22 @@ export default async function GuildForumPage({
|
||||
.where(eq(Guilds.id, guildId))
|
||||
.limit(1);
|
||||
guild = row ?? null;
|
||||
} catch {
|
||||
guild = null;
|
||||
} catch (error) {
|
||||
publicReadFailure("guild.forum")(error);
|
||||
return (
|
||||
<main className="page-grid">
|
||||
<ContentCard>
|
||||
<PublicLoadError href={`/guilds/${guildId}/forum`} />
|
||||
</ContentCard>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
if (!guild) notFound();
|
||||
|
||||
// Threads for this guild. Pinned first, then most-recently active.
|
||||
let threadsFailed = false;
|
||||
let authorsFailed = false;
|
||||
let threads: ThreadRow[] = [];
|
||||
try {
|
||||
threads = await db
|
||||
@@ -95,7 +106,9 @@ export default async function GuildForumPage({
|
||||
desc(GuildsForumsThreads.id),
|
||||
)
|
||||
.limit(100);
|
||||
} catch {
|
||||
} catch (error) {
|
||||
publicReadFailure("guild.threads")(error);
|
||||
threadsFailed = true;
|
||||
threads = [];
|
||||
}
|
||||
|
||||
@@ -113,7 +126,9 @@ export default async function GuildForumPage({
|
||||
.from(User)
|
||||
.where(inArray(User.id, openerIds))
|
||||
: [];
|
||||
} catch {
|
||||
} catch (error) {
|
||||
publicReadFailure("guild.thread-authors")(error);
|
||||
authorsFailed = true;
|
||||
users = [];
|
||||
}
|
||||
|
||||
@@ -134,7 +149,11 @@ export default async function GuildForumPage({
|
||||
<ContentCard
|
||||
icon="🗣️"
|
||||
title={t("forumTitle", { guild: guild.name || t("unnamedGuild") })}
|
||||
subtitle={`${threads.length} ${threads.length === 1 ? t("threadSingular") : t("threadPlural")}`}
|
||||
subtitle={
|
||||
threadsFailed
|
||||
? undefined
|
||||
: `${threads.length} ${threads.length === 1 ? t("threadSingular") : t("threadPlural")}`
|
||||
}
|
||||
action={
|
||||
<Link
|
||||
href={`/guilds/${guild.id}/forum/new`}
|
||||
@@ -145,8 +164,13 @@ export default async function GuildForumPage({
|
||||
}
|
||||
/>
|
||||
|
||||
<ContentCard padded={threads.length === 0}>
|
||||
{threads.length === 0 ? (
|
||||
<ContentCard padded={threads.length === 0 || authorsFailed}>
|
||||
{authorsFailed && (
|
||||
<PublicLoadError href={`/guilds/${guild.id}/forum`} />
|
||||
)}
|
||||
{threadsFailed ? (
|
||||
<PublicLoadError href={`/guilds/${guild.id}/forum`} />
|
||||
) : threads.length === 0 ? (
|
||||
<EmptyState icon="🗣️">{t("empty")}</EmptyState>
|
||||
) : (
|
||||
<table>
|
||||
|
||||
Reference in new issue
Block a user