fix(news): resolve null destructuring type errors in article page
.catch(() => null) unioned the query result with null, so destructuring the first row failed typecheck (TS2488). Return an empty array on failure instead and drop unused connection/desc imports.
This commit is contained in:
1 parent
dc8fb8a6ed
commit
694a24c791
1 file changed
+16
-18
@@ -1,5 +1,4 @@
|
|||||||
import { connection } from "next/server";
|
import { and, asc, eq, inArray } from "drizzle-orm";
|
||||||
import { and, asc, desc, eq, inArray } from "drizzle-orm";
|
|
||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
@@ -26,7 +25,6 @@ import { sanitize } from "@/lib/sanitize";
|
|||||||
// See: https://nextjs.org/docs/app/guides/migrating-to-cache-components
|
// See: https://nextjs.org/docs/app/guides/migrating-to-cache-components
|
||||||
export const instant = false;
|
export const instant = false;
|
||||||
|
|
||||||
|
|
||||||
type SearchParams = Promise<{
|
type SearchParams = Promise<{
|
||||||
comment?: string;
|
comment?: string;
|
||||||
reaction?: string;
|
reaction?: string;
|
||||||
@@ -64,7 +62,7 @@ export async function generateMetadata({
|
|||||||
.from(WebsiteArticles)
|
.from(WebsiteArticles)
|
||||||
.where(eq(WebsiteArticles.slug, slug))
|
.where(eq(WebsiteArticles.slug, slug))
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.catch(() => null);
|
.catch(() => []);
|
||||||
if (!article) return { title: "Article" };
|
if (!article) return { title: "Article" };
|
||||||
return {
|
return {
|
||||||
title: article.title,
|
title: article.title,
|
||||||
@@ -116,7 +114,7 @@ export default async function ArticlePage({
|
|||||||
.from(WebsiteArticles)
|
.from(WebsiteArticles)
|
||||||
.where(eq(WebsiteArticles.slug, slug))
|
.where(eq(WebsiteArticles.slug, slug))
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.catch(() => null);
|
.catch(() => []);
|
||||||
return row ?? null;
|
return row ?? null;
|
||||||
},
|
},
|
||||||
60,
|
60,
|
||||||
@@ -200,24 +198,24 @@ export default async function ArticlePage({
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main style={{ display: "grid", gap: "1.5rem" }}>
|
<main style={{ display: "grid", gap: "1.5rem" }}>
|
||||||
{comment === "posted" ? (
|
{comment === "posted" ? (
|
||||||
<div role="status" style={feedbackStyle("success")}>
|
<div role="status" style={feedbackStyle("success")}>
|
||||||
{t("success.posted")}
|
{t("success.posted")}
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
{reaction === "1" ? (
|
{reaction === "1" ? (
|
||||||
<div role="status" style={feedbackStyle("success")}>
|
<div role="status" style={feedbackStyle("success")}>
|
||||||
{t("success.reaction")}
|
{t("success.reaction")}
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
{errorMessage ? (
|
{errorMessage ? (
|
||||||
<div role="alert" style={feedbackStyle("error")}>
|
<div role="alert" style={feedbackStyle("error")}>
|
||||||
{errorMessage}
|
{errorMessage}
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
<ContentCard
|
<ContentCard
|
||||||
icon="📰"
|
icon="📰"
|
||||||
title={article.title}
|
title={article.title}
|
||||||
subtitle={
|
subtitle={
|
||||||
@@ -231,11 +229,11 @@ export default async function ArticlePage({
|
|||||||
>
|
>
|
||||||
{article.image ? (
|
{article.image ? (
|
||||||
// eslint-disable-next-line @next/next/no-img-element
|
// eslint-disable-next-line @next/next/no-img-element
|
||||||
(<img
|
<img
|
||||||
src={article.image}
|
src={article.image}
|
||||||
alt=""
|
alt=""
|
||||||
style={{ width: "100%", borderRadius: 10, margin: "0 0 1rem" }}
|
style={{ width: "100%", borderRadius: 10, margin: "0 0 1rem" }}
|
||||||
/>)
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
{/* Article body is rich HTML (atom uses TinyMCE) — sanitised server-side. */}
|
{/* Article body is rich HTML (atom uses TinyMCE) — sanitised server-side. */}
|
||||||
<SanitizedHtml
|
<SanitizedHtml
|
||||||
@@ -244,8 +242,8 @@ export default async function ArticlePage({
|
|||||||
/>
|
/>
|
||||||
</ContentCard>
|
</ContentCard>
|
||||||
|
|
||||||
{/* ── Reactions ─────────────────────────────────────────── */}
|
{/* ── Reactions ─────────────────────────────────────────── */}
|
||||||
<ContentCard
|
<ContentCard
|
||||||
icon="💬"
|
icon="💬"
|
||||||
title={t("reactionsTitle")}
|
title={t("reactionsTitle")}
|
||||||
subtitle={t("reactionsSubtitle")}
|
subtitle={t("reactionsSubtitle")}
|
||||||
@@ -319,8 +317,8 @@ export default async function ArticlePage({
|
|||||||
)}
|
)}
|
||||||
</ContentCard>
|
</ContentCard>
|
||||||
|
|
||||||
{/* ── Comments ──────────────────────────────────────────── */}
|
{/* ── Comments ──────────────────────────────────────────── */}
|
||||||
<ContentCard
|
<ContentCard
|
||||||
icon="🗨️"
|
icon="🗨️"
|
||||||
title={t("commentsTitle")}
|
title={t("commentsTitle")}
|
||||||
subtitle={
|
subtitle={
|
||||||
@@ -394,6 +392,6 @@ export default async function ArticlePage({
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</ContentCard>
|
</ContentCard>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user