a tool for shared writing and social publishing
1import { supabaseServerClient } from "supabase/serverClient";
2import Link from "next/link";
3import { SortedPublicationList } from "./SortedPublicationList";
4import { Metadata } from "next";
5import { DashboardLayout } from "components/PageLayouts/DashboardLayout";
6
7export const dynamic = "force-static";
8export const revalidate = 60;
9
10export type PublicationsList = Awaited<ReturnType<typeof getPublications>>;
11async function getPublications() {
12 let { data: publications, error } = await supabaseServerClient
13 .from("publications")
14 .select(
15 "*, documents_in_publications(*, documents(*)), publication_subscriptions(count)",
16 )
17 .or(
18 "record->preferences->showInDiscover.is.null,record->preferences->>showInDiscover.eq.true",
19 )
20 .order("indexed_at", {
21 referencedTable: "documents_in_publications",
22 ascending: false,
23 })
24 .limit(1, { referencedTable: "documents_in_publications" });
25 return publications;
26}
27
28export const metadata: Metadata = {
29 title: "Leaflet Discover",
30 description: "Explore publications on Leaflet ✨ Or make your own!",
31};
32
33export default async function Discover(props: {
34 searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
35}) {
36 let order = ((await props.searchParams).order as string) || "recentlyUpdated";
37 let publications = await getPublications();
38
39 return (
40 <div className="w-full h-full mx-auto bg-[#FDFCFA]">
41 <DashboardLayout
42 id="discover"
43 cardBorderHidden={false}
44 currentPage="discover"
45 defaultTab="default"
46 actions={null}
47 tabs={{
48 default: {
49 controls: null,
50 content: <DiscoverContent order={order} />,
51 },
52 }}
53 />
54 </div>
55 );
56}
57
58const DiscoverContent = async (props: { order: string }) => {
59 let publications = await getPublications();
60
61 return (
62 <div className="max-w-prose mx-auto w-full">
63 <div className="discoverHeader flex flex-col items-center text-center pt-2 px-4">
64 <h1>Discover</h1>
65 </div>
66 <SortedPublicationList publications={publications} order={props.order} />
67 </div>
68 );
69};