feat: crossbell renovation - archives page

This commit is contained in:
DIYgod
2022-06-30 14:36:46 +01:00
parent 3bed9051e5
commit d7d8a80fad
4 changed files with 30 additions and 49 deletions
+8 -9
View File
@@ -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<Map<string, Post[]>>(() => {
const groupedByYear = useMemo<Map<string, Note[]>>(() => {
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 (
<>
<h2 className="text-xl font-bold page-title">Archives</h2>
{posts.length === 0 && (
{posts.list.length === 0 && (
<div className="mt-5">
<EmptyState />
</div>
)}
{posts.length > 0 && (
{posts.list.length > 0 && (
<div className="mt-5 space-y-5">
{[...groupedByYear.keys()].map((year) => {
const posts = groupedByYear.get(year)!
@@ -48,7 +47,7 @@ export const SiteArchives: React.FC<{
{post.title}
</span>
<span className="text-zinc-400 mr-3 font-medium whitespace-nowrap">
{formatDate(post.publishedAt, "MMM D")}
{formatDate(post.date_published, "MMM D")}
</span>
</a>
</Link>
+2 -2
View File
@@ -32,7 +32,7 @@ export const Avatar: React.FC<
<span
{...props}
className={clsx(
`inline-flex text-white bg-pink-400 items-center justify-center text-xl font-medium uppercase flex-shrink-0`,
`inline-flex text-white bg-gray-400 items-center justify-center text-xl font-medium uppercase flex-shrink-0`,
borderRadius,
className
)}
@@ -51,7 +51,7 @@ export const Avatar: React.FC<
<span
{...props}
className={clsx(
`inline-flex text-zinc-500 bg-pink-400 flex-shrink-0 items-center justify-center text-xl font-medium uppercase`,
`inline-flex text-zinc-500 bg-gray-400 flex-shrink-0 items-center justify-center text-xl font-medium uppercase`,
borderRadius,
className
)}
+19 -32
View File
@@ -8,60 +8,47 @@ import { getTRPCContext } from "~/lib/trpc.server"
import { serverSidePropsHandler } from "~/lib/server-side-props"
import { SiteArchives } from "~/components/site/SiteArchives"
import { getViewer } from "~/lib/viewer"
import { Viewer } from "~/lib/types"
import { Viewer, Profile, Notes } from "~/lib/types"
import { getSite } from "~/models/site.model"
import { getPagesBySite } from "~/models/page.model"
import { PageVisibilityEnum } from "~/lib/types"
export const getServerSideProps: GetServerSideProps = serverSidePropsHandler(
async (ctx) => {
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 (
<SiteLayout
site={site!}
title="Archives"
viewer={viewer}
subscription={subscription}
>
<SiteArchives posts={posts} />
</SiteLayout>
+1 -6
View File
@@ -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(),
},
}
}