many improvements
This commit is contained in:
@@ -23,6 +23,7 @@ model User {
|
||||
deletedAt DateTime?
|
||||
memberships Membership[]
|
||||
accessTokens AccessToken[]
|
||||
authoredPages Page[]
|
||||
|
||||
@@map("users")
|
||||
}
|
||||
@@ -32,7 +33,7 @@ model LoginToken {
|
||||
email String
|
||||
expiresAt DateTime
|
||||
// When the login token is creating by submitting the `subscribe` form
|
||||
// We store extra info here, like `{email: true,telegram: true}`
|
||||
// We store extra info here, like `{email: true}`
|
||||
subscribeForm Json?
|
||||
|
||||
@@map("login_tokens")
|
||||
@@ -119,6 +120,7 @@ model Page {
|
||||
siteId String
|
||||
deletedAt DateTime?
|
||||
subscribersNotifiedAt DateTime?
|
||||
authors User[]
|
||||
|
||||
@@unique([siteId, slug])
|
||||
@@map("pages")
|
||||
|
||||
@@ -10,7 +10,6 @@ import { useForm } from "react-hook-form"
|
||||
export const SubscribeModal: React.FC<{
|
||||
siteId: string
|
||||
subscription?: {
|
||||
telegram?: boolean
|
||||
email?: boolean
|
||||
} | null
|
||||
isLoggedIn: boolean
|
||||
@@ -27,7 +26,6 @@ export const SubscribeModal: React.FC<{
|
||||
defaultValues: {
|
||||
newUserEmail: "",
|
||||
email: subscription?.email ?? true,
|
||||
telegram: subscription?.telegram ?? false,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -35,7 +33,6 @@ export const SubscribeModal: React.FC<{
|
||||
subscribe.mutate({
|
||||
siteId,
|
||||
email: values.email,
|
||||
telegram: values.telegram,
|
||||
newUser: isLoggedIn
|
||||
? undefined
|
||||
: {
|
||||
@@ -90,12 +87,6 @@ export const SubscribeModal: React.FC<{
|
||||
<span>Receive updates via Email</span>
|
||||
</label>
|
||||
</div>
|
||||
<div className="">
|
||||
<label className="select-none flex items-center space-x-1">
|
||||
<input type="checkbox" {...subscribeForm.register("telegram")} />
|
||||
<span>Receive updates via Telegram</span>
|
||||
</label>
|
||||
</div>
|
||||
<div className="mt-5 space-x-3 flex items-center">
|
||||
<Button type="submit" isLoading={subscribe.isLoading}>
|
||||
<span>{subscription ? "Update" : "Subscribe"}</span>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useRouter } from "next/router"
|
||||
import React from "react"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { trpc } from "~/lib/trpc"
|
||||
import { DashboardIcon } from "../icons/DashboardIcon"
|
||||
import { UniLink } from "../ui/UniLink"
|
||||
import { DashboardSidebar } from "./DashboardSidebar"
|
||||
import { SiteSwitcher } from "./SiteSwitcher"
|
||||
@@ -30,18 +31,7 @@ export function DashboardLayout({ children }: { children: React.ReactNode }) {
|
||||
{
|
||||
href: `/dashboard/${subdomain}`,
|
||||
isActive: ({ href, pathname }) => href === pathname,
|
||||
icon: (
|
||||
<svg width="1em" height="1em" viewBox="0 0 24 24">
|
||||
<path
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="2"
|
||||
d="M3 3h7v9H3zm11 0h7v5h-7zm0 9h7v9h-7zM3 16h7v5H3z"
|
||||
></path>
|
||||
</svg>
|
||||
),
|
||||
icon: <DashboardIcon />,
|
||||
text: "Dashboard",
|
||||
},
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ import { useRouter } from "next/router"
|
||||
import { trpc } from "~/lib/trpc"
|
||||
import Link from "next/link"
|
||||
import toast from "react-hot-toast"
|
||||
import { EmptyState } from "../ui/EmptyState"
|
||||
|
||||
export const PagesManager: React.FC<{
|
||||
isPost: boolean
|
||||
@@ -24,7 +25,7 @@ export const PagesManager: React.FC<{
|
||||
: PageVisibilityEnum.All,
|
||||
[router.query.visibility]
|
||||
)
|
||||
const deletePage = trpc.useMutation("site.deletePage")
|
||||
const deletePage = trpc.useMutation("page.delete")
|
||||
const trpcContext = trpc.useContext()
|
||||
|
||||
useEffect(() => {
|
||||
@@ -177,9 +178,7 @@ export const PagesManager: React.FC<{
|
||||
|
||||
<div className="-mt-3">
|
||||
{pages && pages.length === 0 && (
|
||||
<div className="my-20 text-center text-3xl text-zinc-400">
|
||||
No {isPost ? "Posts" : "Pages"} Yet.
|
||||
</div>
|
||||
<EmptyState resource={isPost ? "posts" : "pages"} />
|
||||
)}
|
||||
|
||||
{pages?.map((page) => {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import React from "react"
|
||||
|
||||
export const DashboardIcon: React.FC<React.ComponentPropsWithoutRef<"svg">> = (
|
||||
props
|
||||
) => {
|
||||
return (
|
||||
<svg width="1em" height="1em" viewBox="0 0 24 24" {...props}>
|
||||
<path
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth="2"
|
||||
d="M3 3h7v9H3zm11 0h7v5h-7zm0 9h7v9h-7zM3 16h7v5H3z"
|
||||
></path>
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
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 }
|
||||
|
||||
@@ -27,30 +28,37 @@ export const SiteArchives: React.FC<{
|
||||
return (
|
||||
<>
|
||||
<h2 className="text-xl font-bold page-title">Archives</h2>
|
||||
<div className="mt-5 space-y-5">
|
||||
{[...groupedByYear.keys()].map((year) => {
|
||||
const posts = groupedByYear.get(year)!
|
||||
return (
|
||||
<div key={year}>
|
||||
<h3 className="text-lg font-bold mb-1 text-zinc-700">{year}</h3>
|
||||
{posts.map((post) => {
|
||||
return (
|
||||
<Link key={post.id} href={`/${post.slug}`}>
|
||||
<a className="flex justify-between items-center p-1 px-2 rounded-lg -mx-2 hover:bg-zinc-50">
|
||||
<span className="text-accent font-medium">
|
||||
{post.title}
|
||||
</span>
|
||||
<span className="text-zinc-400 mr-3 font-medium whitespace-nowrap">
|
||||
{formatDate(post.publishedAt, "MMM D")}
|
||||
</span>
|
||||
</a>
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
{posts.length === 0 && (
|
||||
<div className="mt-5">
|
||||
<EmptyState />
|
||||
</div>
|
||||
)}
|
||||
{posts.length > 0 && (
|
||||
<div className="mt-5 space-y-5">
|
||||
{[...groupedByYear.keys()].map((year) => {
|
||||
const posts = groupedByYear.get(year)!
|
||||
return (
|
||||
<div key={year}>
|
||||
<h3 className="text-lg font-bold mb-1 text-zinc-700">{year}</h3>
|
||||
{posts.map((post) => {
|
||||
return (
|
||||
<Link key={post.id} href={`/${post.slug}`}>
|
||||
<a className="flex justify-between items-center p-1 px-2 rounded-lg -mx-2 hover:bg-zinc-50">
|
||||
<span className="text-accent font-medium">
|
||||
{post.title}
|
||||
</span>
|
||||
<span className="text-zinc-400 mr-3 font-medium whitespace-nowrap">
|
||||
{formatDate(post.publishedAt, "MMM D")}
|
||||
</span>
|
||||
</a>
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ import { UniLink } from "../ui/UniLink"
|
||||
|
||||
export const SiteFooter: React.FC<{ site: { name: string } }> = ({ site }) => {
|
||||
return (
|
||||
<footer className="bg-indigo-50/50 text-zinc-500">
|
||||
<div className="max-w-screen-md mx-auto px-5 py-32">
|
||||
<footer className="text-zinc-500 border-t">
|
||||
<div className="max-w-screen-md mx-auto px-5 py-16">
|
||||
<span className="font-medium">
|
||||
©{" "}
|
||||
<UniLink href="/" className="hover:text-indigo-500">
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
import clsx from "clsx"
|
||||
import { useRouter } from "next/router"
|
||||
import { logout } from "~/lib/auth.client"
|
||||
import { IS_PROD } from "~/lib/constants"
|
||||
import { OUR_DOMAIN } from "~/lib/env"
|
||||
import { useStore } from "~/lib/store"
|
||||
import { Viewer } from "~/lib/types"
|
||||
import { getUserContentsUrl } from "~/lib/user-contents"
|
||||
import { truthy } from "~/lib/utils"
|
||||
import { DashboardIcon } from "../icons/DashboardIcon"
|
||||
import { Avatar } from "../ui/Avatar"
|
||||
import { Button } from "../ui/Button"
|
||||
import { UniLink } from "../ui/UniLink"
|
||||
|
||||
export type HeaderLinkType = {
|
||||
icon?: React.ReactNode
|
||||
label: string
|
||||
url?: string
|
||||
onClick?: () => void
|
||||
}
|
||||
|
||||
const HeaderLink: React.FC<{ link: HeaderLinkType }> = ({ link }) => {
|
||||
const router = useRouter()
|
||||
const active = router.asPath === link.url
|
||||
return (
|
||||
<UniLink
|
||||
href={link.url}
|
||||
onClick={link.onClick}
|
||||
className={clsx(
|
||||
`h-10 flex items-center border-b-2 space-x-1 hover:border-gray-500 hover:text-gray-700`,
|
||||
active ? `text-indigo-700 border-accent` : `border-transparent`
|
||||
)}
|
||||
>
|
||||
{link.icon && <span>{link.icon}</span>}
|
||||
<span>{link.label}</span>
|
||||
</UniLink>
|
||||
)
|
||||
}
|
||||
|
||||
export const SiteHeader: React.FC<{
|
||||
siteName: string | undefined
|
||||
description: string | undefined | null
|
||||
icon: string | null | undefined
|
||||
navigation?: HeaderLinkType[]
|
||||
subscribed?: boolean
|
||||
viewer: Viewer | null
|
||||
}> = ({ siteName, description, icon, navigation, subscribed, viewer }) => {
|
||||
const setSubscribeModalOpened = useStore(
|
||||
(store) => store.setSubscribeModalOpened
|
||||
)
|
||||
const setLoginModalOpened = useStore((store) => store.setLoginModalOpened)
|
||||
|
||||
const handleClickSubscribe = () => {
|
||||
setSubscribeModalOpened(true)
|
||||
}
|
||||
|
||||
const leftLinks: HeaderLinkType[] = [
|
||||
{ label: "Home", url: "/" },
|
||||
...(navigation || []),
|
||||
]
|
||||
|
||||
const dropdownLinks: HeaderLinkType[] = [
|
||||
{
|
||||
icon: <DashboardIcon />,
|
||||
label: "Dashboard",
|
||||
url: `${IS_PROD ? "https" : "http"}://${OUR_DOMAIN}/dashboard`,
|
||||
},
|
||||
{
|
||||
label: "Sign out",
|
||||
onClick() {
|
||||
if (!confirm(`Are you sure you want to log out?`)) {
|
||||
return
|
||||
}
|
||||
logout()
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
<header className="border-b">
|
||||
<div className="px-5 max-w-screen-md mx-auto">
|
||||
<div className="flex py-10">
|
||||
<div className="flex space-x-6 items-center">
|
||||
{icon && (
|
||||
<Avatar
|
||||
images={[getUserContentsUrl(icon)]}
|
||||
size={100}
|
||||
name={siteName}
|
||||
/>
|
||||
)}
|
||||
<div>
|
||||
<div className="text-2xl font-bold">{siteName}</div>
|
||||
{description && (
|
||||
<div className="text-gray-500 text-sm">{description}</div>
|
||||
)}
|
||||
<div className="mt-3 text-sm">
|
||||
<Button
|
||||
rounded="full"
|
||||
size="sm"
|
||||
variant={subscribed ? "secondary" : "primary"}
|
||||
onClick={handleClickSubscribe}
|
||||
className="space-x-1"
|
||||
>
|
||||
<span className="pl-1">
|
||||
{subscribed ? (
|
||||
<svg className="w-4 h-4" viewBox="0 0 24 24">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="m23.5 17l-5 5l-3.5-3.5l1.5-1.5l2 2l3.5-3.5l1.5 1.5M13 18H3V8l8 5l8-5v5h2V6c0-1.1-.9-2-2-2H3c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h10v-2m6-12l-8 5l-8-5h16Z"
|
||||
></path>
|
||||
</svg>
|
||||
) : (
|
||||
<svg className="w-4 h-4" viewBox="0 0 24 24">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M19 15v3h-3v2h3v3h2v-3h3v-2h-3v-3h-2m-5 3H3V8l8 5l8-5v5h2V6c0-1.1-.9-2-2-2H3c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h11v-2m5-12l-8 5l-8-5h16Z"
|
||||
></path>
|
||||
</svg>
|
||||
)}
|
||||
</span>
|
||||
<span className="pr-1">
|
||||
{subscribed ? "Subscribed" : "Subscribe"}
|
||||
</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-sm text-gray-400 flex items-center justify-between">
|
||||
<div className="flex items-center space-x-5">
|
||||
{leftLinks.map((link, i) => {
|
||||
return <HeaderLink link={link} key={`${link.label}${i}`} />
|
||||
})}
|
||||
</div>
|
||||
{viewer ? (
|
||||
<div className="relative group">
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex space-x-2 items-center h-10"
|
||||
>
|
||||
<Avatar
|
||||
images={[getUserContentsUrl(viewer.avatar)]}
|
||||
name={viewer.name}
|
||||
size={24}
|
||||
/>
|
||||
<span>{viewer.name}</span>
|
||||
</button>
|
||||
<div className="absolute hidden right-0 pt-1 group-hover:block">
|
||||
<div className="bg-white rounded-lg ring-1 ring-zinc-100 min-w-[140px] shadow-md py-2">
|
||||
{dropdownLinks.map((link, i) => {
|
||||
return (
|
||||
<UniLink
|
||||
key={i}
|
||||
href={link.url}
|
||||
onClick={link.onClick}
|
||||
className="px-4 h-8 flex items-center w-full hover:bg-zinc-100"
|
||||
>
|
||||
{link.label}
|
||||
</UniLink>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<button type="button" onClick={() => setLoginModalOpened(true)}>
|
||||
Sign In
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
)
|
||||
}
|
||||
@@ -1,32 +1,39 @@
|
||||
import Link from "next/link"
|
||||
import { formatDate } from "~/lib/date"
|
||||
import { Paginated, type PostOnSiteHome } from "~/lib/types"
|
||||
import { EmptyState } from "../ui/EmptyState"
|
||||
|
||||
export const SiteHome: React.FC<{
|
||||
posts?: Paginated<PostOnSiteHome>
|
||||
}> = ({ posts }) => {
|
||||
if (!posts) return null
|
||||
|
||||
return (
|
||||
<div className="space-y-14">
|
||||
{posts.nodes.map((post) => {
|
||||
const excerpt = post.excerpt || post.autoExcerpt
|
||||
return (
|
||||
<div key={post.id} className="block">
|
||||
<h3 className="text-2xl font-medium">
|
||||
<Link href={`/${post.slug}`}>
|
||||
<a className="hover:text-indigo-500">{post.title}</a>
|
||||
</Link>
|
||||
</h3>
|
||||
<div className="text-sm text-zinc-400 mt-1">
|
||||
{formatDate(post.publishedAt)}
|
||||
</div>
|
||||
<div className="mt-3 text-zinc-500">
|
||||
{excerpt}
|
||||
{excerpt && "..."}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
<div className="">
|
||||
{posts.total === 0 && <EmptyState />}
|
||||
{posts.total > 0 && (
|
||||
<div className="space-y-14">
|
||||
{posts.nodes.map((post) => {
|
||||
const excerpt = post.excerpt || post.autoExcerpt
|
||||
return (
|
||||
<div key={post.id} className="block">
|
||||
<h3 className="text-2xl font-bold">
|
||||
<Link href={`/${post.slug}`}>
|
||||
<a className="hover:text-indigo-500">{post.title}</a>
|
||||
</Link>
|
||||
</h3>
|
||||
<div className="text-sm text-zinc-400 mt-1">
|
||||
{formatDate(post.publishedAt)}
|
||||
</div>
|
||||
<div className="mt-3 text-zinc-500">
|
||||
{excerpt}
|
||||
{excerpt && "..."}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,120 +1,11 @@
|
||||
import clsx from "clsx"
|
||||
import React from "react"
|
||||
import { truthy } from "~/lib/utils"
|
||||
import { logout } from "~/lib/auth.client"
|
||||
import { useStore } from "~/lib/store"
|
||||
import { getUserContentsUrl } from "~/lib/user-contents"
|
||||
import { SubscribeModal } from "../common/SubscribeModal"
|
||||
import { Avatar } from "../ui/Avatar"
|
||||
import { Button } from "../ui/Button"
|
||||
import { UniLink } from "../ui/UniLink"
|
||||
import { IS_PROD } from "~/lib/constants"
|
||||
import { OUR_DOMAIN } from "~/lib/env"
|
||||
import { useRouter } from "next/router"
|
||||
import { SEOHead } from "../common/SEOHead"
|
||||
import { SiteNavigationItem } from "~/lib/types"
|
||||
import { SiteNavigationItem, Viewer } from "~/lib/types"
|
||||
import { SiteFooter } from "./SiteFooter"
|
||||
|
||||
type MenuLink = {
|
||||
label: string
|
||||
url?: string
|
||||
onClick?: () => void
|
||||
}
|
||||
|
||||
const Header: React.FC<{
|
||||
siteName: string | undefined
|
||||
description: string | undefined | null
|
||||
avatars: (string | null | undefined)[]
|
||||
links: MenuLink[]
|
||||
subscribed?: boolean
|
||||
}> = ({ siteName, description, avatars, links, subscribed }) => {
|
||||
const setSubscribeModalOpened = useStore(
|
||||
(store) => store.setSubscribeModalOpened
|
||||
)
|
||||
const router = useRouter()
|
||||
const handleClickSubscribe = () => {
|
||||
setSubscribeModalOpened(true)
|
||||
}
|
||||
|
||||
return (
|
||||
<header className="border-b">
|
||||
<div className="px-5 max-w-screen-md mx-auto">
|
||||
<div className="flex py-10">
|
||||
<div className="flex space-x-6 items-center">
|
||||
<Avatar images={avatars} size={100} name={siteName} />
|
||||
<div>
|
||||
<div className="text-2xl font-bold">{siteName}</div>
|
||||
{description && (
|
||||
<div className="text-gray-500 text-sm">{description}</div>
|
||||
)}
|
||||
<div className="mt-3 text-sm">
|
||||
<Button
|
||||
rounded="full"
|
||||
size="sm"
|
||||
variant={subscribed ? "secondary" : "primary"}
|
||||
onClick={handleClickSubscribe}
|
||||
>
|
||||
<span className="-ml-1">
|
||||
{subscribed ? (
|
||||
<svg
|
||||
className="w-4 h-4 mr-[2px]"
|
||||
fill="currentColor"
|
||||
viewBox="0 0 20 20"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
fillRule="evenodd"
|
||||
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
|
||||
clipRule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
) : (
|
||||
<svg
|
||||
className="w-5 h-5"
|
||||
fill="currentColor"
|
||||
viewBox="0 0 20 20"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
fillRule="evenodd"
|
||||
d="M10 5a1 1 0 011 1v3h3a1 1 0 110 2h-3v3a1 1 0 11-2 0v-3H6a1 1 0 110-2h3V6a1 1 0 011-1z"
|
||||
clipRule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
</span>
|
||||
<span>{subscribed ? "Subscribed" : "Subscribe"}</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-sm text-gray-400">
|
||||
<div className="flex items-center space-x-5">
|
||||
{links.map((link, i) => {
|
||||
const active = router.asPath === link.url
|
||||
return (
|
||||
<UniLink
|
||||
key={`${link.label}${i}`}
|
||||
href={link.url}
|
||||
onClick={link.onClick}
|
||||
className={clsx(
|
||||
`h-10 flex items-center border-b-2 hover:border-gray-500 hover:text-gray-700`,
|
||||
active
|
||||
? `text-indigo-700 border-accent`
|
||||
: `border-transparent`
|
||||
)}
|
||||
>
|
||||
{link.label}
|
||||
</UniLink>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
)
|
||||
}
|
||||
import { SiteHeader } from "./SiteHeader"
|
||||
|
||||
export type SiteLayoutProps = {
|
||||
site: {
|
||||
@@ -124,43 +15,19 @@ export type SiteLayoutProps = {
|
||||
icon?: string | null
|
||||
navigation?: SiteNavigationItem[] | null
|
||||
}
|
||||
isLoggedIn: boolean
|
||||
subscription?: { telegram?: boolean; email?: boolean } | null
|
||||
viewer: Viewer | null
|
||||
subscription?: { email?: boolean } | null
|
||||
children: React.ReactNode
|
||||
title?: string | null
|
||||
}
|
||||
|
||||
export const SiteLayout: React.FC<SiteLayoutProps> = ({
|
||||
site,
|
||||
isLoggedIn,
|
||||
viewer,
|
||||
subscription,
|
||||
children,
|
||||
title,
|
||||
}) => {
|
||||
const avatars = [getUserContentsUrl(site?.icon)]
|
||||
const setLoginModalOpened = useStore((store) => store.setLoginModalOpened)
|
||||
|
||||
const links: MenuLink[] = [
|
||||
{ label: "Home", url: "/" },
|
||||
...(site.navigation || []),
|
||||
!isLoggedIn && {
|
||||
label: "Log in",
|
||||
onClick() {
|
||||
setLoginModalOpened(true)
|
||||
},
|
||||
},
|
||||
isLoggedIn && {
|
||||
label: "Dashboard",
|
||||
url: `${IS_PROD ? "https" : "http"}://${OUR_DOMAIN}/dashboard`,
|
||||
},
|
||||
isLoggedIn && {
|
||||
label: "Log out",
|
||||
onClick() {
|
||||
logout()
|
||||
},
|
||||
},
|
||||
].filter(truthy)
|
||||
|
||||
const docTitle = title ? `${title} - ${site.name}` : site.name
|
||||
|
||||
return (
|
||||
@@ -170,12 +37,13 @@ export const SiteLayout: React.FC<SiteLayoutProps> = ({
|
||||
description={site.description}
|
||||
image={getUserContentsUrl(site.icon)}
|
||||
/>
|
||||
<Header
|
||||
links={links}
|
||||
<SiteHeader
|
||||
navigation={site!.navigation || []}
|
||||
siteName={site!.name}
|
||||
description={site?.description}
|
||||
avatars={avatars}
|
||||
icon={site!.icon}
|
||||
subscribed={!!subscription}
|
||||
viewer={viewer}
|
||||
/>
|
||||
<div className={clsx(`max-w-screen-md mx-auto px-5 pb-12`, `pt-12`)}>
|
||||
{children}
|
||||
@@ -185,7 +53,7 @@ export const SiteLayout: React.FC<SiteLayoutProps> = ({
|
||||
<SubscribeModal
|
||||
siteId={site.id}
|
||||
subscription={subscription}
|
||||
isLoggedIn={isLoggedIn}
|
||||
isLoggedIn={!!viewer}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { PageType } from "~/lib/db.server"
|
||||
import { formatDate } from "~/lib/date"
|
||||
import { Rendered } from "~/markdown"
|
||||
import { Avatar } from "../ui/Avatar"
|
||||
import { getUserContentsUrl } from "~/lib/user-contents"
|
||||
|
||||
export const SitePage: React.FC<{
|
||||
page: {
|
||||
@@ -8,6 +10,7 @@ export const SitePage: React.FC<{
|
||||
publishedAt: string
|
||||
title: string
|
||||
rendered: Rendered | null
|
||||
authors?: { id: string; name: string; avatar: string | null }[]
|
||||
}
|
||||
}> = ({ page }) => {
|
||||
return (
|
||||
@@ -19,8 +22,22 @@ export const SitePage: React.FC<{
|
||||
<h2 className="text-xl font-bold page-title">{page.title}</h2>
|
||||
)}
|
||||
{page.type === "POST" && (
|
||||
<div className="text-zinc-400 italic mt-2">
|
||||
{formatDate(page.publishedAt)}
|
||||
<div className="text-zinc-400 mt-2 flex items-center">
|
||||
<span>{formatDate(page.publishedAt)}</span>
|
||||
<div className="flex items-center ml-5">
|
||||
{page.authors?.map((author) => {
|
||||
return (
|
||||
<span key={author.id} className="flex items-center space-x-2">
|
||||
<Avatar
|
||||
size={24}
|
||||
images={[getUserContentsUrl(author.avatar)]}
|
||||
name={author.name}
|
||||
/>
|
||||
<span>{author.name}</span>
|
||||
</span>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -60,6 +60,7 @@ export const Avatar: React.FC<
|
||||
height: `${size}px`,
|
||||
}}
|
||||
>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
className={borderRadius}
|
||||
src={image}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
export const EmptyState: React.FC<{ resource?: string }> = ({ resource }) => {
|
||||
return (
|
||||
<div className="text-center py-10 mb-10 text-2xl text-zinc-500 flex justify-center flex-col items-center">
|
||||
<svg className="w-12 h-12" viewBox="0 0 24 24">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M12 2a9 9 0 0 0-9 9v11l3-3l3 3l3-3l3 3l3-3l3 3V11a9 9 0 0 0-9-9M9 8a2 2 0 0 1 2 2a2 2 0 0 1-2 2a2 2 0 0 1-2-2a2 2 0 0 1 2-2m6 0a2 2 0 0 1 2 2a2 2 0 0 1-2 2a2 2 0 0 1-2-2a2 2 0 0 1 2-2Z"
|
||||
></path>
|
||||
</svg>
|
||||
<div className="text-zinc-400">
|
||||
{" "}
|
||||
No <span className="capitalize">{resource || "posts"}</span> Yet.
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -7,7 +7,6 @@ export type Site = {
|
||||
|
||||
export type SiteSubscription = {
|
||||
email?: boolean
|
||||
telegram?: boolean
|
||||
}
|
||||
|
||||
export type Viewer = {
|
||||
@@ -61,7 +60,6 @@ export type PostOnArchivesPage = {
|
||||
*/
|
||||
export type SubscribeFormData = {
|
||||
email?: boolean
|
||||
telegram?: boolean
|
||||
siteId: string
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { AuthUser } from "./auth.server"
|
||||
import { Viewer } from "./types"
|
||||
|
||||
export const getViewer = (user: AuthUser | null | undefined): Viewer | null => {
|
||||
if (!user) return null
|
||||
return {
|
||||
id: user.id,
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
avatar: user.avatar,
|
||||
username: user.username,
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
prismaRead,
|
||||
PageType,
|
||||
MembershipRole,
|
||||
Page,
|
||||
} from "~/lib/db.server"
|
||||
import { type Gate } from "~/lib/gate.server"
|
||||
import { sendEmailForNewPost } from "~/lib/mailgun.server"
|
||||
@@ -66,6 +65,7 @@ export async function createOrUpdatePage(
|
||||
isPost?: boolean
|
||||
}
|
||||
) {
|
||||
const user = gate.getUser(true)
|
||||
const page = input.pageId
|
||||
? await prismaPrimary.page.findUnique({
|
||||
where: {
|
||||
@@ -86,6 +86,11 @@ export async function createOrUpdatePage(
|
||||
},
|
||||
content: "",
|
||||
excerpt: "",
|
||||
authors: {
|
||||
connect: {
|
||||
id: user.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
site: true,
|
||||
@@ -189,9 +194,7 @@ export async function getPagesBySite(
|
||||
: undefined,
|
||||
}),
|
||||
await prismaRead.page.count({
|
||||
where: {
|
||||
siteId: site.id,
|
||||
},
|
||||
where,
|
||||
}),
|
||||
])
|
||||
|
||||
@@ -206,7 +209,7 @@ export async function getPagesBySite(
|
||||
}
|
||||
})
|
||||
)
|
||||
console.log(nodesRendered)
|
||||
|
||||
return {
|
||||
nodes: nodesRendered,
|
||||
total,
|
||||
@@ -246,6 +249,7 @@ export async function getPage<TRender extends boolean = false>(
|
||||
page: string
|
||||
site?: string
|
||||
render?: TRender
|
||||
includeAuthors?: boolean
|
||||
}
|
||||
) {
|
||||
const site = input.site ? await getSite(input.site) : null
|
||||
@@ -264,10 +268,16 @@ export async function getPage<TRender extends boolean = false>(
|
||||
where: {
|
||||
id: input.page,
|
||||
},
|
||||
include: {
|
||||
authors: input.includeAuthors,
|
||||
},
|
||||
})
|
||||
: site
|
||||
? await prismaRead.page.findFirst({
|
||||
where: { siteId: site.id, slug: input.page },
|
||||
include: {
|
||||
authors: input.includeAuthors,
|
||||
},
|
||||
})
|
||||
: null
|
||||
|
||||
|
||||
@@ -97,7 +97,6 @@ export const getSubscription = async (data: {
|
||||
return {
|
||||
...membership,
|
||||
config: config && {
|
||||
telegram: config.telegram,
|
||||
email: config.email,
|
||||
},
|
||||
}
|
||||
@@ -202,7 +201,6 @@ export async function subscribeToSite(
|
||||
input: {
|
||||
siteId: string
|
||||
email?: boolean
|
||||
telegram?: boolean
|
||||
newUser?: {
|
||||
email: string
|
||||
url: string
|
||||
@@ -214,7 +212,6 @@ export async function subscribeToSite(
|
||||
// Create the login token instead
|
||||
const subscribeFormData: SubscribeFormData = {
|
||||
email: input.email,
|
||||
telegram: input.telegram,
|
||||
siteId: input.siteId,
|
||||
}
|
||||
const loginToken = await prismaPrimary.loginToken.create({
|
||||
@@ -256,7 +253,6 @@ export async function subscribeToSite(
|
||||
},
|
||||
config: {
|
||||
email: input.email,
|
||||
telegram: input.telegram,
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -268,7 +264,6 @@ export async function subscribeToSite(
|
||||
data: {
|
||||
config: {
|
||||
email: input.email,
|
||||
telegram: input.telegram,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -7,11 +7,13 @@ import { appRouter } from "~/router"
|
||||
import { getTRPCContext } from "~/lib/trpc.server"
|
||||
import { SitePage } from "~/components/site/SitePage"
|
||||
import { serverSidePropsHandler } from "~/lib/server-side-props"
|
||||
import { getViewer } from "~/lib/viewer"
|
||||
import { Viewer } from "~/lib/types"
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = serverSidePropsHandler(
|
||||
async (ctx) => {
|
||||
const user = await getAuthUser(ctx.req)
|
||||
const isLoggedIn = !!user
|
||||
const viewer = getViewer(user)
|
||||
const domainOrSubdomain = ctx.params!.site as string
|
||||
const pageSlug = ctx.params!.page as string
|
||||
|
||||
@@ -24,6 +26,7 @@ export const getServerSideProps: GetServerSideProps = serverSidePropsHandler(
|
||||
site: domainOrSubdomain,
|
||||
page: pageSlug,
|
||||
render: true,
|
||||
includeAuthors: true,
|
||||
}),
|
||||
ssg.fetchQuery("site.subscription", { site: domainOrSubdomain }),
|
||||
])
|
||||
@@ -32,7 +35,7 @@ export const getServerSideProps: GetServerSideProps = serverSidePropsHandler(
|
||||
|
||||
return {
|
||||
props: {
|
||||
isLoggedIn,
|
||||
viewer,
|
||||
domainOrSubdomain,
|
||||
pageSlug,
|
||||
trpcState,
|
||||
@@ -42,36 +45,40 @@ export const getServerSideProps: GetServerSideProps = serverSidePropsHandler(
|
||||
)
|
||||
|
||||
function SitePagePage({
|
||||
isLoggedIn,
|
||||
viewer,
|
||||
domainOrSubdomain,
|
||||
pageSlug,
|
||||
}: {
|
||||
isLoggedIn: boolean
|
||||
viewer: Viewer | null
|
||||
domainOrSubdomain: string
|
||||
pageSlug: string
|
||||
}) {
|
||||
const siteResult = trpc.useQuery(["site", { site: domainOrSubdomain }], {})
|
||||
const subscriptionResult = trpc.useQuery([
|
||||
const { data: site } = trpc.useQuery(
|
||||
["site", { site: domainOrSubdomain }],
|
||||
{}
|
||||
)
|
||||
const { data: subscription } = trpc.useQuery([
|
||||
"site.subscription",
|
||||
{ site: domainOrSubdomain },
|
||||
])
|
||||
const pageResult = trpc.useQuery([
|
||||
const { data: page } = trpc.useQuery([
|
||||
"site.page",
|
||||
{ site: domainOrSubdomain, page: pageSlug, render: true },
|
||||
{
|
||||
site: domainOrSubdomain,
|
||||
page: pageSlug,
|
||||
render: true,
|
||||
includeAuthors: true,
|
||||
},
|
||||
])
|
||||
|
||||
const site = siteResult.data
|
||||
const subscription = subscriptionResult.data
|
||||
const page = pageResult.data!
|
||||
|
||||
return (
|
||||
<SiteLayout
|
||||
site={site!}
|
||||
title={page.title}
|
||||
isLoggedIn={isLoggedIn}
|
||||
title={page!.title}
|
||||
viewer={viewer}
|
||||
subscription={subscription}
|
||||
>
|
||||
<SitePage page={page} />
|
||||
<SitePage page={page!} />
|
||||
</SiteLayout>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,23 +6,26 @@ 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 { getViewer } from "~/lib/viewer"
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const user = await getAuthUser(ctx.req)
|
||||
const isLoggedIn = !!user
|
||||
const domainOrSubdomain = ctx.params!.site as string
|
||||
|
||||
const viewer = getViewer(user)
|
||||
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 }),
|
||||
ssg.fetchQuery("site.subscription", { site: domainOrSubdomain }),
|
||||
])
|
||||
|
||||
return {
|
||||
props: {
|
||||
isLoggedIn,
|
||||
viewer,
|
||||
domainOrSubdomain,
|
||||
trpcState: ssg.dehydrate(),
|
||||
},
|
||||
@@ -30,30 +33,27 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
}
|
||||
|
||||
function SiteIndexPage({
|
||||
isLoggedIn,
|
||||
viewer,
|
||||
domainOrSubdomain,
|
||||
}: {
|
||||
isLoggedIn: boolean
|
||||
viewer: Viewer | null
|
||||
domainOrSubdomain: string
|
||||
}) {
|
||||
const siteResult = trpc.useQuery(["site", { site: domainOrSubdomain }], {})
|
||||
|
||||
const subscriptionResult = trpc.useQuery([
|
||||
const { data: site } = trpc.useQuery(
|
||||
["site", { site: domainOrSubdomain }],
|
||||
{}
|
||||
)
|
||||
const { data: subscription } = trpc.useQuery([
|
||||
"site.subscription",
|
||||
{ site: domainOrSubdomain },
|
||||
])
|
||||
const postsResult = trpc.useQuery(["site.pages", { site: domainOrSubdomain }])
|
||||
|
||||
const site = siteResult.data
|
||||
const subscription = subscriptionResult.data
|
||||
const posts = postsResult.data
|
||||
const { data: posts } = trpc.useQuery([
|
||||
"site.pages",
|
||||
{ site: domainOrSubdomain },
|
||||
])
|
||||
|
||||
return (
|
||||
<SiteLayout
|
||||
site={site!}
|
||||
isLoggedIn={isLoggedIn}
|
||||
subscription={subscription}
|
||||
>
|
||||
<SiteLayout site={site!} viewer={viewer} subscription={subscription}>
|
||||
<SiteHome posts={posts} />
|
||||
</SiteLayout>
|
||||
)
|
||||
|
||||
@@ -20,7 +20,6 @@ const handler: NextApiHandler = async (req, res) => {
|
||||
.object({
|
||||
siteId: z.string(),
|
||||
email: z.boolean().optional(),
|
||||
telegram: z.boolean().optional(),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
@@ -74,7 +73,6 @@ const handler: NextApiHandler = async (req, res) => {
|
||||
await subscribeToSite(gate, {
|
||||
siteId: data.subscribe.siteId,
|
||||
email: data.subscribe.email,
|
||||
telegram: data.subscribe.telegram,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ export default function SubdomainEditor() {
|
||||
data: createOrUpdatePageResult,
|
||||
error: createOrUpdatePageError,
|
||||
reset: resetCreateOrUpdatePage,
|
||||
} = trpc.useMutation("site.createOrUpdatePage")
|
||||
} = trpc.useMutation("page.createOrUpdate")
|
||||
const uploadFile = useUploadFile()
|
||||
|
||||
const [values, setValues] = useState({
|
||||
|
||||
@@ -5,6 +5,7 @@ import { TRPCContext } from "~/lib/trpc.server"
|
||||
import { getSite } from "~/models/site.model"
|
||||
import { authRouter } from "./auth"
|
||||
import { membershipRouter } from "./membership"
|
||||
import { pageRouter } from "./page"
|
||||
import { siteRouter } from "./site"
|
||||
import { userRouter } from "./user"
|
||||
|
||||
@@ -39,6 +40,7 @@ export const appRouter = trpc
|
||||
.merge("site.", siteRouter)
|
||||
.merge("user.", userRouter)
|
||||
.merge("membership.", membershipRouter)
|
||||
.merge("page.", pageRouter)
|
||||
.formatError(({ error, shape }) => {
|
||||
return {
|
||||
...shape,
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { z } from "zod"
|
||||
import { createRouter } from "~/lib/trpc.server"
|
||||
import { createOrUpdatePage, deletePage } from "~/models/page.model"
|
||||
|
||||
export const pageRouter = createRouter()
|
||||
.query("authors", {
|
||||
resolve() {},
|
||||
})
|
||||
.mutation("createOrUpdate", {
|
||||
input: z.object({
|
||||
siteId: z.string(),
|
||||
pageId: z.string().optional(),
|
||||
title: z.string().optional(),
|
||||
content: z.string().optional(),
|
||||
published: z.boolean().optional(),
|
||||
publishedAt: z.string().optional(),
|
||||
excerpt: z.string().optional(),
|
||||
isPost: z.boolean(),
|
||||
slug: z.string().optional(),
|
||||
}),
|
||||
output: z.object({
|
||||
id: z.string(),
|
||||
}),
|
||||
async resolve({ input, ctx }) {
|
||||
const { page } = await createOrUpdatePage(ctx.gate, input)
|
||||
return page
|
||||
},
|
||||
})
|
||||
.mutation("delete", {
|
||||
input: z.object({
|
||||
pageId: z.string(),
|
||||
}),
|
||||
async resolve({ ctx, input }) {
|
||||
await deletePage(ctx.gate, { id: input.pageId })
|
||||
},
|
||||
})
|
||||
+11
-30
@@ -41,7 +41,6 @@ export const siteRouter = createRouter()
|
||||
output: z
|
||||
.object({
|
||||
email: z.boolean().optional(),
|
||||
telegram: z.boolean().optional(),
|
||||
})
|
||||
.nullable(),
|
||||
async resolve({ input, ctx }) {
|
||||
@@ -96,6 +95,7 @@ export const siteRouter = createRouter()
|
||||
site: z.string(),
|
||||
page: z.string(),
|
||||
render: z.boolean(),
|
||||
includeAuthors: z.boolean().optional(),
|
||||
}),
|
||||
output: z.object({
|
||||
id: z.string(),
|
||||
@@ -112,6 +112,15 @@ export const siteRouter = createRouter()
|
||||
contentHTML: z.string(),
|
||||
})
|
||||
.nullable(),
|
||||
authors: z
|
||||
.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
avatar: z.string().nullable(),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
}),
|
||||
async resolve({ input, ctx }) {
|
||||
const page = await getPage(ctx.gate, input)
|
||||
@@ -156,26 +165,7 @@ export const siteRouter = createRouter()
|
||||
}
|
||||
},
|
||||
})
|
||||
.mutation("createOrUpdatePage", {
|
||||
input: z.object({
|
||||
siteId: z.string(),
|
||||
pageId: z.string().optional(),
|
||||
title: z.string().optional(),
|
||||
content: z.string().optional(),
|
||||
published: z.boolean().optional(),
|
||||
publishedAt: z.string().optional(),
|
||||
excerpt: z.string().optional(),
|
||||
isPost: z.boolean(),
|
||||
slug: z.string().optional(),
|
||||
}),
|
||||
output: z.object({
|
||||
id: z.string(),
|
||||
}),
|
||||
async resolve({ input, ctx }) {
|
||||
const { page } = await createOrUpdatePage(ctx.gate, input)
|
||||
return page
|
||||
},
|
||||
})
|
||||
|
||||
.mutation("create", {
|
||||
input: z.object({
|
||||
name: z.string(),
|
||||
@@ -190,18 +180,9 @@ export const siteRouter = createRouter()
|
||||
return site
|
||||
},
|
||||
})
|
||||
.mutation("deletePage", {
|
||||
input: z.object({
|
||||
pageId: z.string(),
|
||||
}),
|
||||
async resolve({ ctx, input }) {
|
||||
await deletePage(ctx.gate, { id: input.pageId })
|
||||
},
|
||||
})
|
||||
.mutation("subscribe", {
|
||||
input: z.object({
|
||||
email: z.boolean().optional(),
|
||||
telegram: z.boolean().optional(),
|
||||
siteId: z.string(),
|
||||
newUser: z
|
||||
.object({
|
||||
|
||||
Reference in New Issue
Block a user