From 6b162c6eff3c67ac85484c548b194997d74bc06a Mon Sep 17 00:00:00 2001 From: gunshiz Date: Sun, 16 Aug 2026 02:56:06 +0700 Subject: [PATCH] feat: move share index to public route --- app/admin/share/page.tsx | 185 ------------------------------------- app/share/all/page.tsx | 182 ++++++++++++++++++++++++++++++++++++ app/share/layout.tsx | 8 +- components/admin-shell.tsx | 7 -- 4 files changed, 189 insertions(+), 193 deletions(-) delete mode 100644 app/admin/share/page.tsx create mode 100644 app/share/all/page.tsx diff --git a/app/admin/share/page.tsx b/app/admin/share/page.tsx deleted file mode 100644 index b393f29..0000000 --- a/app/admin/share/page.tsx +++ /dev/null @@ -1,185 +0,0 @@ -import Link from "next/link"; -import { desc, sql } from "drizzle-orm"; -import { ArrowUpRight, Plus } from "lucide-react"; -import { AdminShellServer } from "@/components/admin-shell-server"; -import { Badge } from "@/components/ui/badge"; -import { Button } from "@/components/ui/button"; -import { - Card, - CardContent, - CardDescription, - CardHeader, - CardTitle, -} from "@/components/ui/card"; -import { - Table, - TableBody, - TableCell, - TableHead, - TableHeader, - TableRow, -} from "@/components/ui/table"; -import { db } from "@/db"; -import { shareTexts } from "@/db/schema"; - -export const dynamic = "force-dynamic"; - -function formatBangkok(date: Date) { - return new Intl.DateTimeFormat("en-GB", { - dateStyle: "medium", - timeStyle: "short", - timeZone: "Asia/Bangkok", - }).format(date); -} - -export default async function AdminSharePage() { - const shares = await db - .select({ - id: shareTexts.id, - authorName: shareTexts.authorName, - source: shareTexts.source, - description: shareTexts.description, - contentPreview: sql`left(${shareTexts.content}, 160)`, - createdAt: shareTexts.createdAt, - }) - .from(shareTexts) - .orderBy(desc(shareTexts.createdAt)); - - return ( - -
-
-
-

Share

-

- {shares.length.toLocaleString("en-US")} published links -

-
- -
- - - - All shares - - Open a public page without loading the full text into this list. - - - -
- - - - Share - Preview - Author - Source - Created - Open - - - - {shares.length === 0 ? ( - - - No shares yet. - - - ) : ( - shares.map((share) => ( - - - - {share.id} - - - -

- {share.description || share.contentPreview} -

-
- {share.authorName} - - - {share.source === "bot" ? "Bot" : "Web"} - - - {formatBangkok(share.createdAt)} - - - -
- )) - )} -
-
-
- -
- {shares.length === 0 ? ( -

- No shares yet. -

- ) : ( - shares.map((share) => ( - - - - {share.id} - - - {share.authorName} · {formatBangkok(share.createdAt)} - - - -

- {share.description || share.contentPreview} -

-
- - {share.source === "bot" ? "Bot" : "Web"} - - -
-
-
- )) - )} -
-
-
-
-
- ); -} diff --git a/app/share/all/page.tsx b/app/share/all/page.tsx new file mode 100644 index 0000000..23615db --- /dev/null +++ b/app/share/all/page.tsx @@ -0,0 +1,182 @@ +import Link from "next/link"; +import { desc, sql } from "drizzle-orm"; +import { ArrowUpRight, Plus } from "lucide-react"; +import { Badge } from "@/components/ui/badge"; +import { Button } from "@/components/ui/button"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table"; +import { db } from "@/db"; +import { shareTexts } from "@/db/schema"; + +export const dynamic = "force-dynamic"; + +function formatBangkok(date: Date) { + return new Intl.DateTimeFormat("en-GB", { + dateStyle: "medium", + timeStyle: "short", + timeZone: "Asia/Bangkok", + }).format(date); +} + +export default async function AllSharesPage() { + const shares = await db + .select({ + id: shareTexts.id, + authorName: shareTexts.authorName, + source: shareTexts.source, + description: shareTexts.description, + contentPreview: sql`left(${shareTexts.content}, 160)`, + createdAt: shareTexts.createdAt, + }) + .from(shareTexts) + .orderBy(desc(shareTexts.createdAt)); + + return ( +
+
+
+

Share

+

+ {shares.length.toLocaleString("th-TH")} ลิงก์สาธารณะ +

+
+ +
+ + + + ข้อความที่แชร์ทั้งหมด + + เลือกข้อความเพื่อเปิดหน้าสาธารณะ + + + +
+ + + + Share + Preview + Author + Source + Created + Open + + + + {shares.length === 0 ? ( + + + ยังไม่มีข้อความที่แชร์ + + + ) : ( + shares.map((share) => ( + + + + {share.id} + + + +

+ {share.description || share.contentPreview} +

+
+ {share.authorName} + + + {share.source === "bot" ? "Bot" : "Web"} + + + {formatBangkok(share.createdAt)} + + + +
+ )) + )} +
+
+
+ +
+ {shares.length === 0 ? ( +

+ ยังไม่มีข้อความที่แชร์ +

+ ) : ( + shares.map((share) => ( + + + + {share.id} + + + {share.authorName} · {formatBangkok(share.createdAt)} + + + +

+ {share.description || share.contentPreview} +

+
+ + {share.source === "bot" ? "Bot" : "Web"} + + +
+
+
+ )) + )} +
+
+
+
+ ); +} diff --git a/app/share/layout.tsx b/app/share/layout.tsx index 51e1582..38111c1 100644 --- a/app/share/layout.tsx +++ b/app/share/layout.tsx @@ -1,7 +1,7 @@ import type { Metadata } from "next"; import Link from "next/link"; import { getServerSession } from "next-auth"; -import { ArrowLeft, Plus } from "lucide-react"; +import { ArrowLeft, List, Plus } from "lucide-react"; import { DropdownMenuAvatar } from "@/components/avatar"; import { Button } from "@/components/ui/button"; import { ThemeToggle } from "@/components/theme-toggle"; @@ -36,6 +36,12 @@ export default async function ShareLayout({ children }: { children: React.ReactN
+