diff --git a/src/components/site/SiteArchives.tsx b/src/components/site/SiteArchives.tsx index f2dac551..2e8ad3ad 100644 --- a/src/components/site/SiteArchives.tsx +++ b/src/components/site/SiteArchives.tsx @@ -2,18 +2,17 @@ import Link from "next/link" import { useMemo } from "react" import { formatDate } from "~/lib/date" import { EmptyState } from "../ui/EmptyState" - -type Post = { id: string; publishedAt: string; slug: string; title: string } +import { Notes, Note } from "~/lib/types" export const SiteArchives: React.FC<{ - posts: Post[] | undefined + posts: Notes }> = ({ posts }) => { - const groupedByYear = useMemo>(() => { + const groupedByYear = useMemo>(() => { const map = new Map() if (posts) { - for (const post of posts) { - const year = formatDate(post.publishedAt, "YYYY") + for (const post of posts.list) { + const year = formatDate(post.date_published, "YYYY") const items = map.get(year) || [] items.push(post) map.set(year, items) @@ -28,12 +27,12 @@ export const SiteArchives: React.FC<{ return ( <>

Archives

- {posts.length === 0 && ( + {posts.list.length === 0 && (
)} - {posts.length > 0 && ( + {posts.list.length > 0 && (
{[...groupedByYear.keys()].map((year) => { const posts = groupedByYear.get(year)! @@ -48,7 +47,7 @@ export const SiteArchives: React.FC<{ {post.title} - {formatDate(post.publishedAt, "MMM D")} + {formatDate(post.date_published, "MMM D")} diff --git a/src/components/ui/Avatar.tsx b/src/components/ui/Avatar.tsx index 2f6b706b..9835b4ae 100644 --- a/src/components/ui/Avatar.tsx +++ b/src/components/ui/Avatar.tsx @@ -32,7 +32,7 @@ export const Avatar: React.FC< { - const user = await getAuthUser(ctx.req) - const viewer = getViewer(user) const domainOrSubdomain = ctx.params!.site as string - - const trpcContext = await getTRPCContext(ctx) - const ssg = createSSGHelpers({ router: appRouter, ctx: trpcContext }) - - await Promise.all([ - ssg.fetchQuery("site", { site: domainOrSubdomain }), - ssg.fetchQuery("site.pages", { site: domainOrSubdomain, take: 1000 }), - ssg.fetchQuery("site.subscription", { site: domainOrSubdomain }), + + const [site, posts] = await Promise.all([ + getSite(domainOrSubdomain), + getPagesBySite({ + site: domainOrSubdomain, + take: 1000, + type: "post", + visibility: PageVisibilityEnum.Published, + }), ]) return { props: { - viewer, + site, + posts, domainOrSubdomain, - trpcState: ssg.dehydrate(), }, } } ) function SiteArchivesPage({ - viewer, - domainOrSubdomain, + site, + posts, }: { - viewer: Viewer | null + site: Profile, + posts: Notes, domainOrSubdomain: string }) { - const siteResult = trpc.useQuery(["site", { site: domainOrSubdomain }], {}) - const subscriptionResult = trpc.useQuery([ - "site.subscription", - { site: domainOrSubdomain }, - ]) - const postsResult = trpc.useQuery([ - "site.pages", - { site: domainOrSubdomain, take: 1000 }, - ]) - - const site = siteResult.data - const subscription = subscriptionResult.data - const posts = postsResult.data?.nodes - return ( diff --git a/src/pages/_site/[site]/index.tsx b/src/pages/_site/[site]/index.tsx index ef378aba..70a9c61b 100644 --- a/src/pages/_site/[site]/index.tsx +++ b/src/pages/_site/[site]/index.tsx @@ -5,21 +5,17 @@ import { trpc } from "~/lib/trpc" import { createSSGHelpers } from "@trpc/react/ssg" import { appRouter } from "~/router" import { getTRPCContext } from "~/lib/trpc.server" -import { Viewer } from "~/lib/types" +import { Viewer, Profile, Notes } from "~/lib/types" import { getViewer } from "~/lib/viewer" import { useAccount } from 'wagmi' import { useEffect, useState } from 'react' import { getUserSites, getSite } from "~/models/site.model" import { getPagesBySite } from "~/models/page.model" -import { Profile, Notes } from "unidata.js" import { PageVisibilityEnum } from "~/lib/types" export const getServerSideProps: GetServerSideProps = async (ctx) => { const domainOrSubdomain = ctx.params!.site as string - const trpcContext = await getTRPCContext(ctx) - const ssg = createSSGHelpers({ router: appRouter, ctx: trpcContext }) - const [site, posts] = await Promise.all([ getSite(domainOrSubdomain), getPagesBySite({ @@ -35,7 +31,6 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { site, posts, domainOrSubdomain, - trpcState: ssg.dehydrate(), }, } }