commit 4a4439e6c49a3dd7cd0cde6a51a60bb901a20ef3 Author: EGOIST Date: Mon May 2 20:43:47 2022 +0800 Remix! diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..71569754 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": ["@remix-run/eslint-config", "@remix-run/eslint-config/node"] +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..ec255bd5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +node_modules + +.cache +.env +.vercel +.output + +/build/ +/public/build +/api/index.js +/api/**/*.js.map diff --git a/.pnpmfile.cjs b/.pnpmfile.cjs new file mode 100644 index 00000000..584a016d --- /dev/null +++ b/.pnpmfile.cjs @@ -0,0 +1,13 @@ +function readPackage(pkg, context) { + if (pkg.dependencies["sort-package-json"]) { + pkg.dependencies["sort-package-json"] = "1.55.0" + } + + return pkg +} + +module.exports = { + hooks: { + readPackage, + }, +} diff --git a/README.md b/README.md new file mode 100644 index 00000000..2d17b4c8 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +## Development + +Follow the steps to run it locally. + +1. Copy `.env.example` to `.env` +2. Run `postgres` locally, the easiest way on mac is `brew install postgresql`, you can also use docker +3. Install dependencies: `pnpm i` +4. Initialize the database by running `pnpm prisma db push` +5. Start dev server: `pnpm dev` diff --git a/app/components/common/LoginModal.tsx b/app/components/common/LoginModal.tsx new file mode 100644 index 00000000..72146316 --- /dev/null +++ b/app/components/common/LoginModal.tsx @@ -0,0 +1,71 @@ +import { Button } from "~/components/ui/Button" +import { useStore } from "~/lib/store" +import { Dialog } from "@headlessui/react" +import { useEffect, useState } from "react" +import { useFetcher } from "@remix-run/react" + +export const LoginModal: React.FC = () => { + const [loginModalOpened, setLoginModalOpened] = useStore((store) => [ + store.loginModalOpened, + store.setLoginModalOpened, + ]) + const fetcher = useFetcher() + + return ( + setLoginModalOpened(false)} + className="fixed z-10 inset-0 overflow-y-auto" + > +
+ + +
+ + Continue with Email + + +
+ {fetcher.data && ( +
+ We just emailed you with a link to log in, please check your + inbox and spam folder in case you can't find it. +
+ )} + +
+ + +
+
+ +
+
+
+
+
+
+ ) +} + +export default LoginModal diff --git a/app/components/common/SubscribeModal.tsx b/app/components/common/SubscribeModal.tsx new file mode 100644 index 00000000..90811034 --- /dev/null +++ b/app/components/common/SubscribeModal.tsx @@ -0,0 +1,69 @@ +import { useFetcher } from "@remix-run/react" +import React from "react" +import { useStore } from "~/lib/store" +import { Badge } from "../ui/Badge" +import { Button } from "../ui/Button" +import { Modal } from "../ui/Modal" + +export const SubscribeModal: React.FC<{ + siteId: string + subscription?: { + telegram?: boolean + email?: boolean + } | null +}> = ({ siteId, subscription }) => { + const [open, setOpen] = useStore((store) => [ + store.subscribeModalOpened, + store.setSubscribeModalOpened, + ]) + const subscribeFetcher = useFetcher() + const unsubscribeFetcher = useFetcher() + + return ( + + +
+ +
+
+ +
+
+ + {subscription && ( + + + + )} +
+
+
+ ) +} diff --git a/app/components/dashboard/AvatarForm.tsx b/app/components/dashboard/AvatarForm.tsx new file mode 100644 index 00000000..470dc927 --- /dev/null +++ b/app/components/dashboard/AvatarForm.tsx @@ -0,0 +1,134 @@ +import { Dialog } from "@headlessui/react" +import { useEffect, useRef, useState } from "react" +import ReactAvatarEditor from "react-avatar-editor" +import { getUserContentsUrl } from "~/lib/user-contents" +import { Avatar } from "~/components/ui/Avatar" +import { Button } from "~/components/ui/Button" +import { useFetcher } from "@remix-run/react" +import toast from "react-hot-toast" + +const AvatarEditorModal: React.FC<{ + isOpen: boolean + image?: File | null + setIsOpen: (open: boolean) => void + site?: string +}> = ({ isOpen, setIsOpen, image, site }) => { + const editorRef = useRef(null) + const fetcher = useFetcher() + + const cropAndSave = async () => { + if (!editorRef.current) return + const canvas = editorRef.current.getImage() + const blob = await new Promise((resolve, reject) => { + canvas.toBlob((blob) => { + if (!blob) return reject(new Error("Canvas is empty")) + resolve(blob) + }) + }) + const form = new FormData() + if (site) { + form.append("site", site) + } + form.append("file", blob) + fetcher.submit(form, { + action: "/api/save-avatar", + method: "post", + encType: "multipart/form-data", + }) + } + + useEffect(() => { + if (fetcher.type === "done") { + setIsOpen(false) + toast.success("Updated!") + } + }, [fetcher.type, setIsOpen]) + + return ( + setIsOpen(false)} + className="fixed z-10 inset-0 overflow-y-auto" + > +
+ + +
+ + Adjust the picture + + +
+ {image && ( + + )} +
+ +
+ +
+
+
+
+ ) +} + +export const AvatarForm: React.FC<{ + filename: string | undefined + name: string + site?: string +}> = ({ filename, name, site }) => { + const [isOpen, setIsOpen] = useState(false) + const inputEl = useRef(null) + const [image, setImage] = useState(null) + + const onClick = () => { + inputEl.current?.click() + } + + const handleChange = (e: any) => { + const files = e.target.files as File[] + if (files.length > 0) { + setImage(files[0]) + setIsOpen(true) + } + } + + return ( + <> + + + + + ) +} diff --git a/app/components/dashboard/DashboardMain.tsx b/app/components/dashboard/DashboardMain.tsx new file mode 100644 index 00000000..b7d03576 --- /dev/null +++ b/app/components/dashboard/DashboardMain.tsx @@ -0,0 +1,18 @@ +import clsx from "clsx" + +export const DashboardMain: React.FC<{ + children: React.ReactNode + fullWidth?: boolean +}> = ({ children, fullWidth }) => { + return ( +
+
+ {children} +
+
+ ) +} diff --git a/app/components/dashboard/PagesManager.tsx b/app/components/dashboard/PagesManager.tsx new file mode 100644 index 00000000..b8c910f7 --- /dev/null +++ b/app/components/dashboard/PagesManager.tsx @@ -0,0 +1,243 @@ +import { Fragment, useMemo, useState } from "react" +import { getPageVisibility } from "~/lib/page-helpers" +import { formatDate } from "~/lib/date" +import { TabItem, Tabs } from "../ui/Tabs" +import { Menu } from "@headlessui/react" +import clsx from "clsx" +import { PageVisibilityEnum } from "~/lib/types" +import { Link, useFetcher, useLocation, useNavigate } from "@remix-run/react" +import { DashboardMain } from "./DashboardMain" + +export const PagesManager: React.FC<{ + isPost: boolean + subdomain: string + pages: { + id: string + title: string + published: boolean + publishedAt: Date + }[] +}> = ({ isPost, subdomain, pages }) => { + const navi = useNavigate() + const location = useLocation() + const query = useMemo( + () => Object.fromEntries(new URLSearchParams(location.search)), + [location.search] + ) + const visibility = useMemo( + () => + query.visibility + ? (query.visibility as PageVisibilityEnum) + : PageVisibilityEnum.All, + [query.visibility] + ) + + const deletePageFetcher = useFetcher() + + const tabItems: TabItem[] = [ + { + value: PageVisibilityEnum.All, + text: `All ${isPost ? "Posts" : "Pages"}`, + }, + { + value: PageVisibilityEnum.Published, + text: "Published", + }, + { + value: PageVisibilityEnum.Draft, + text: "Draft", + }, + { + value: PageVisibilityEnum.Scheduled, + text: "Scheduled", + }, + ].map((item) => ({ + text: item.text, + onClick: () => { + const newQuery: Record = { + ...query, + visibility: item.value, + } + if (item.value === PageVisibilityEnum.All) { + delete newQuery["visibility"] + } + const search = new URLSearchParams(newQuery).toString() + navi({ + search, + }) + }, + active: item.value === visibility, + })) + + const getPageEditLink = (page: { id: string }) => { + return `/dashboard/${subdomain}/editor?id=${page.id}&type=${ + isPost ? "post" : "page" + }` + } + + const getPageMenuItems = (page: { id: string }) => { + return [ + { + text: "Edit", + icon: ( + + + + + ), + onClick() { + navi(getPageEditLink(page)) + }, + }, + { + text: "Delete", + icon: ( + + + + + + + ), + onClick() { + deletePageFetcher.submit( + {}, + { method: "delete", action: `/api/pages/${page.id}` } + ) + }, + }, + ] + } + + const title = isPost ? "Posts" : "Pages" + + return ( + +
+

{title}

+ +
+ + +
+ {pages && pages.length === 0 && ( +
+ No {isPost ? "Posts" : "Pages"} Yet. +
+ )} + + {pages?.map((page) => { + return ( + +
+
+ {page.title} +
+
+ + {getPageVisibility(page).toLowerCase()} + + ยท + {formatDate(page.publishedAt)} +
+
+
+ + {({ open }) => ( + <> + + + + + {getPageMenuItems(page).map((item) => { + return ( + + + + ) + })} + + + )} + +
+ + ) + })} +
+
+ ) +} diff --git a/app/components/dashboard/SettingsLayout.tsx b/app/components/dashboard/SettingsLayout.tsx new file mode 100644 index 00000000..f1cf866c --- /dev/null +++ b/app/components/dashboard/SettingsLayout.tsx @@ -0,0 +1,24 @@ +import { Outlet } from "@remix-run/react" +import { type TabItem, Tabs } from "../ui/Tabs" +import { DashboardMain } from "./DashboardMain" + +export const SettingsLayout: React.FC<{ + title: string + tabItems: TabItem[] +}> = ({ title, tabItems }) => { + return ( + +
+
+

{title}

+
+
+ +
+ +
+
+
+
+ ) +} diff --git a/app/components/dashboard/SiteSwitcher.tsx b/app/components/dashboard/SiteSwitcher.tsx new file mode 100644 index 00000000..a9c0849f --- /dev/null +++ b/app/components/dashboard/SiteSwitcher.tsx @@ -0,0 +1,84 @@ +import { Popover } from "@headlessui/react" +import { Link } from "@remix-run/react" +import { getUserContentsUrl } from "~/lib/user-contents" +import { Avatar } from "../ui/Avatar" + +export const SiteSwitcher: React.FC<{ + subdomain: string + sites: { id: string; name: string; subdomain: string; icon?: string | null }[] + viewer: { email: string } +}> = ({ subdomain, sites, viewer }) => { + const activeSite = sites.find((s) => s.subdomain === subdomain) + return ( +
+ + +
+ + {activeSite?.name} +
+ + + + + + + +
+ +
+
+ {viewer.email} +
+
+ {sites?.map((site) => { + return ( + + {site.name} + {activeSite?.id === site.id && ( + + + + + + )} + + ) + })} +
+
+ + Create a new site + +
+
+
+
+
+ ) +} diff --git a/app/components/main/MainLayout.tsx b/app/components/main/MainLayout.tsx new file mode 100644 index 00000000..a6a23b6c --- /dev/null +++ b/app/components/main/MainLayout.tsx @@ -0,0 +1,82 @@ +import { Link } from "@remix-run/react" +import { logout } from "~/lib/auth.client" +import { useStore } from "~/lib/store" + +export function MainLayout({ + isLoggedIn, + appName, + children, +}: { + isLoggedIn: boolean + appName: string + children: React.ReactNode +}) { + const setLoginModalOpened = useStore((store) => store.setLoginModalOpened) + + const links: Array<{ text: string; href?: string; onClick?: () => void }> = + isLoggedIn + ? [ + { + text: "Dashboard", + href: "/dashboard", + }, + { + text: "Log out", + onClick() { + logout() + }, + }, + ] + : [ + { + text: "Log in", + onClick() { + setLoginModalOpened(true) + }, + }, + ] + return ( + <> +
+
+
+
+ + {appName} + +
+
+ ..is under beta testing +
+
+ {links.map((link) => { + if (link.href) { + return ( + + {link.text} + + ) + } + return ( + + ) + })} +
+
+
+
+ {children} + + ) +} diff --git a/app/components/site/SiteHome.tsx b/app/components/site/SiteHome.tsx new file mode 100644 index 00000000..18542aef --- /dev/null +++ b/app/components/site/SiteHome.tsx @@ -0,0 +1,30 @@ +import { Link } from "@remix-run/react" +import { formatDate } from "~/lib/date" +import { type PostOnSiteHome } from "~/lib/types" + +export const SiteHome: React.FC<{ + posts: PostOnSiteHome[] +}> = ({ posts }) => { + return ( +
+ {posts?.map((post) => { + return ( +
+

+ + {post.title} + +

+
+ {formatDate(post.publishedAt)} +
+
+ {post.excerpt} + {"..."} +
+
+ ) + })} +
+ ) +} diff --git a/app/components/site/SiteLayout.tsx b/app/components/site/SiteLayout.tsx new file mode 100644 index 00000000..e8377259 --- /dev/null +++ b/app/components/site/SiteLayout.tsx @@ -0,0 +1,173 @@ +import { useLocation } from "@remix-run/react" +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, OUR_DOMAIN } from "~/lib/config.shared" + +type MenuLink = { + text: string + href?: string + onClick?: () => void + hide?: boolean +} + +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 location = useLocation() + const setSubscribeModalOpened = useStore( + (store) => store.setSubscribeModalOpened + ) + return ( +
+
+
+
+ +
+
{siteName}
+ {description && ( +
{description}
+ )} +
+ +
+
+
+
+
+
+ {links.map((link, i) => { + const active = location.pathname === link.href + return ( + + {link.text} + + ) + })} +
+
+
+
+ ) +} + +export const SiteLayout: React.FC<{ + site: { + id: string + name: string + description: string + icon?: string | null + } + isLoggedIn: boolean + subscription?: { telegram?: boolean; email?: boolean } | null + children: React.ReactNode +}> = ({ site, isLoggedIn, subscription, children }) => { + const avatars = [getUserContentsUrl(site?.icon)] + const setLoginModalOpened = useStore((store) => store.setLoginModalOpened) + + const links: MenuLink[] = [ + { text: "Home", href: "/" }, + { + text: "About", + href: "/about", + }, + { text: "Archives", hide: true, href: "/archives" }, + !isLoggedIn && { + text: "Log in", + hide: true, + onClick() { + setLoginModalOpened(true) + }, + }, + isLoggedIn && { + text: "Dashboard", + hide: true, + href: `${IS_PROD ? "https" : "http"}://${OUR_DOMAIN}/dashboard`, + }, + isLoggedIn && { + text: "Log out", + hide: true, + onClick() { + logout() + }, + }, + ].filter(truthy) + + return ( + <> +
+
+
+ {children} +
+
+ {site.id && ( + + )} + + ) +} diff --git a/app/components/site/SitePage.tsx b/app/components/site/SitePage.tsx new file mode 100644 index 00000000..bbca6c82 --- /dev/null +++ b/app/components/site/SitePage.tsx @@ -0,0 +1,32 @@ +import type { PageType } from "@prisma/client" +import { formatDate } from "~/lib/date" + +export const SitePage: React.FC<{ + page: { + type: PageType + publishedAt: string + title: string + content: string + } +}> = ({ page }) => { + return ( + <> +
+ {page.type === "POST" ? ( +

{page.title}

+ ) : ( +

{page.title}

+ )} + {page.type === "POST" && ( +
+ {formatDate(page.publishedAt)} +
+ )} +
+
+ + ) +} diff --git a/app/components/ui/Avatar.tsx b/app/components/ui/Avatar.tsx new file mode 100644 index 00000000..f4b0ad34 --- /dev/null +++ b/app/components/ui/Avatar.tsx @@ -0,0 +1,72 @@ +import clsx from "clsx" +import React, { useMemo } from "react" + +export const Avatar: React.FC< + { + images: (string | null | undefined)[] + name?: string | null + size?: number + rounded?: boolean + } & React.HTMLAttributes +> = ({ images, size, name, className, rounded, ...props }) => { + size = size || 60 + + const fontSize = size * 0.5 + + const nameAbbr = (name || "") + .split(" ") + .slice(0, 2) + .map((word) => word[0]) + .join("") + + const image = useMemo(() => { + for (const image of images) { + if (image) return image + } + }, [images]) + + const borderRadius = rounded === false ? "rounded-lg" : "rounded-full" + + if (!image) { + return ( + + {nameAbbr} + + ) + } + + return ( + + {name + + ) +} diff --git a/app/components/ui/Badge.tsx b/app/components/ui/Badge.tsx new file mode 100644 index 00000000..501b66f6 --- /dev/null +++ b/app/components/ui/Badge.tsx @@ -0,0 +1,18 @@ +import clsx from "clsx" +import React from "react" + +export const Badge: React.FC<{ + children: React.ReactNode + className?: string +}> = ({ children, className }) => { + return ( + + {children} + + ) +} diff --git a/app/components/ui/Button.tsx b/app/components/ui/Button.tsx new file mode 100644 index 00000000..32dfa21b --- /dev/null +++ b/app/components/ui/Button.tsx @@ -0,0 +1,43 @@ +import React from "react" +import clsx from "clsx" + +export const Button: React.FC< + React.ButtonHTMLAttributes & { + isLoading?: boolean + isBlock?: boolean + variant?: "primary" | "secondary" | "text" + variantColor?: "green" | "red" + size?: "sm" + rounded?: "full" | "lg" + } +> = ({ + type, + children, + className, + isLoading, + isBlock, + variant, + variantColor, + size, + rounded, + ...props +}) => { + return ( + + ) +} diff --git a/app/components/ui/Editor.tsx b/app/components/ui/Editor.tsx new file mode 100644 index 00000000..fd757bff --- /dev/null +++ b/app/components/ui/Editor.tsx @@ -0,0 +1,72 @@ +import { useEffect, useRef, useState } from "react" +import { EditorState } from "@codemirror/state" +import { EditorView, keymap, ViewUpdate } from "@codemirror/view" +import { indentWithTab } from "@codemirror/commands" +import { markdown } from "@codemirror/lang-markdown" +import { history } from "@codemirror/history" + +const theme = EditorView.theme({ + ".cm-scroller": { + fontFamily: "var(--font-sans)", + fontSize: "1rem", + overflow: "auto", + }, + ".cm-content": { + minHeight: "400px", + }, + "&.cm-editor.cm-focused": { + outline: "none", + }, +}) + +export const Editor: React.FC<{ + value: string + onChange: (value: string) => void +}> = ({ value, onChange }) => { + const editorRef = useRef(null) + const [view, setView] = useState(null) + + useEffect(() => { + const updateListener = EditorView.updateListener.of((vu: ViewUpdate) => { + if (vu.docChanged && typeof onChange === "function") { + const doc = vu.state.doc + const value = doc.toString() + onChange(value) + } + }) + + const view = new EditorView({ + state: EditorState.create({ + doc: value, + extensions: [ + keymap.of([indentWithTab]), + markdown(), + history(), + updateListener, + EditorView.lineWrapping, + theme, + ], + }), + parent: editorRef.current!, + }) + + setView(view) + + return () => { + view.destroy() + setView(null) + } + }, []) + + // Update view state when `value` changed + useEffect(() => { + const currentValue = view ? view.state.doc.toString() : "" + if (view && value !== currentValue) { + view.dispatch({ + changes: { from: 0, to: currentValue.length, insert: value || "" }, + }) + } + }, [value, view]) + + return
+} diff --git a/app/components/ui/Input.tsx b/app/components/ui/Input.tsx new file mode 100644 index 00000000..05010e21 --- /dev/null +++ b/app/components/ui/Input.tsx @@ -0,0 +1,39 @@ +import clsx from "clsx" +import { DetailedHTMLProps, InputHTMLAttributes } from "react" + +export const Input: React.FC< + DetailedHTMLProps, HTMLInputElement> & { + label?: string + addon?: string + isBlock?: boolean + error?: string + } +> = ({ label, addon, className, isBlock, error, ...inputProps }) => { + const hasAddon = !!addon + return ( +
+ {label && ( + + )} +
+ + {addon && ( + + {addon} + + )} +
+ {error &&
{error}
} +
+ ) +} diff --git a/app/components/ui/Modal.tsx b/app/components/ui/Modal.tsx new file mode 100644 index 00000000..f875613a --- /dev/null +++ b/app/components/ui/Modal.tsx @@ -0,0 +1,51 @@ +import { Dialog } from "@headlessui/react" +import clsx from "clsx" +import React from "react" + +export const Modal: React.FC<{ + open: boolean + setOpen: (open: boolean) => void + children: React.ReactNode + title?: string + titleIcon?: React.ReactNode + size?: "md" | "lg" | "sm" +}> = ({ open, setOpen, children, title, titleIcon, size = "md" }) => { + return ( + setOpen(false)} + className="relative z-50" + > + {/* The backdrop, rendered as a fixed sibling to the panel container */} + + ) +} diff --git a/app/components/ui/Tabs.tsx b/app/components/ui/Tabs.tsx new file mode 100644 index 00000000..1915d974 --- /dev/null +++ b/app/components/ui/Tabs.tsx @@ -0,0 +1,34 @@ +import clsx from "clsx" +import React from "react" +import { UniLink } from "./UniLink" + +export type TabItem = { + text: string + href?: string + onClick?: () => void + active?: boolean +} + +export const Tabs: React.FC<{ items: TabItem[] }> = ({ items }) => { + return ( +
+ {items.map((item) => { + return ( + + {item.text} + + ) + })} +
+ ) +} diff --git a/app/components/ui/UniLink.tsx b/app/components/ui/UniLink.tsx new file mode 100644 index 00000000..771f1654 --- /dev/null +++ b/app/components/ui/UniLink.tsx @@ -0,0 +1,42 @@ +import { Link } from "@remix-run/react" + +export const UniLink: React.FC<{ + href?: string + onClick?: () => void + children: React.ReactNode + className?: string +}> = ({ href, onClick, children, className }) => { + if (onClick) { + return ( + + ) + } + + if (!href) { + console.error("missing href") + return null + } + + const isExternal = href && /^https?:\/\//.test(href) + + if (isExternal) { + return ( + + {children} + + ) + } + + return ( + + {children} + + ) +} diff --git a/app/controllers/site.controller.ts b/app/controllers/site.controller.ts new file mode 100644 index 00000000..22a4b57a --- /dev/null +++ b/app/controllers/site.controller.ts @@ -0,0 +1,311 @@ +import { prisma } from "~/lib/db.server" +import { + checkPageSlug, + checkSubdomain, + getSite, + getSitesByUser, +} from "~/models/site.model" +import { PageVisibilityEnum } from "~/lib/types" +import { isUUID } from "~/lib/uuid" +import { MembershipRole, PageType, Prisma } from "@prisma/client" +import { nanoid } from "nanoid" +import { z } from "zod" +import { type AuthUser } from "~/lib/auth.server" +import { createGate } from "~/lib/gate.server" + +export const siteController = { + async getSites(user: AuthUser | undefined | null) { + const gate = createGate({ user, requireAuth: true }) + const sites = await getSitesByUser({ userId: gate.user.id }) + return sites + }, + + async getSite(siteIdOrSubdomainOrDomain: string) { + const site = await getSite(siteIdOrSubdomainOrDomain) + return { site } + }, + + async getPages( + user: AuthUser | undefined | null, + input: { + site: string + type: "post" | "page" + visibility?: PageVisibilityEnum | null + take?: number | null + cursor?: string | null + } + ) { + const gate = createGate({ user }) + + const validated = z + .object({ + site: z.string(), + type: z.enum(["post", "page"]).default("post"), + visibility: z + .enum([ + PageVisibilityEnum.All, + PageVisibilityEnum.Published, + PageVisibilityEnum.Draft, + PageVisibilityEnum.Scheduled, + ]) + .nullish(), + take: z.number().default(30), + cursor: z.string().nullish(), + }) + .parse(input) + + const site = await getSite(validated.site) + + const visibility = validated.visibility || PageVisibilityEnum.Published + + if (!gate.allows({ type: "can-list-page", visibility, siteId: site.id })) { + throw gate.permissionError() + } + + const now = new Date() + + const where: Prisma.PageWhereInput = { + siteId: site.id, + deletedAt: null, + type: validated.type === "post" ? "POST" : "PAGE", + } + if (validated.visibility === PageVisibilityEnum.Published) { + where.published = true + where.publishedAt = { + lte: now, + } + } else if (validated.visibility === PageVisibilityEnum.Scheduled) { + where.published = true + where.publishedAt = { + gt: now, + } + } else if (validated.visibility === PageVisibilityEnum.Draft) { + where.published = false + } + + const [pages, total] = await Promise.all([ + prisma.page.findMany({ + where, + orderBy: { + createdAt: "desc", + }, + take: validated.take + 1, + cursor: validated.cursor + ? { + id: validated.cursor, + } + : undefined, + }), + await prisma.page.count({ + where: { + siteId: site.id, + }, + }), + ]) + + const hasMore = pages.length > validated.take + + return { + pages, + total, + hasMore, + } + }, + + async createOrUpdatePage( + user: AuthUser | null | undefined, + input: { + pageId?: string + siteId: string + slug?: string + title?: string + content?: string + published?: boolean + publishedAt?: Date + excerpt?: string + isPost?: boolean + } + ) { + const gate = createGate({ user }) + + const page = input.pageId + ? await prisma.page.findUnique({ + where: { + id: input.pageId, + }, + include: { + site: true, + }, + }) + : await prisma.page.create({ + data: { + title: "Untitled", + slug: `untitled-${nanoid(4)}`, + site: { + connect: { + id: input.siteId, + }, + }, + content: "", + excerpt: "", + }, + include: { + site: true, + }, + }) + + if (!page || page.deletedAt) { + throw new Error(`Page not found`) + } + + if (!gate.allows({ type: "can-create-page", siteId: page.siteId })) { + throw gate.permissionError() + } + + const slug = input.slug || page.slug + await checkPageSlug({ slug, excludePage: page.id, siteId: page.siteId }) + + const updated = await prisma.page.update({ + where: { + id: page.id, + }, + data: { + title: input.title, + content: input.content, + published: input.published, + publishedAt: input.publishedAt, + excerpt: input.excerpt, + slug, + type: input.isPost ? "POST" : "PAGE", + }, + }) + return { page: updated } + }, + + async getPage( + user: AuthUser | null | undefined, + input: { + /** page slug or id, `site` is needed when `page` is a slug */ + page: string + site: string + } + ) { + const gate = createGate({ user }) + + const site = input.site ? await getSite(input.site) : null + + if (input.site && !site) { + throw new Error(`site not found`) + } + + const isPageUUID = isUUID(input.page) + if (!isPageUUID && !input.site) { + throw new Error("missing input site") + } + + const page = isPageUUID + ? await prisma.page.findUnique({ + where: { + id: input.page, + }, + }) + : site + ? await prisma.page.findFirst({ + where: { siteId: site.id, slug: input.page }, + }) + : null + + if (!page || page.deletedAt) { + throw new Response(`page ${input.page} not found`, { + status: 404, + }) + } + + if (!gate.allows({ type: "can-read-page", page })) { + throw gate.permissionError() + } + + return page + }, + + async updateSite( + user: AuthUser | undefined | null, + payload: { + site: string + name?: string + description?: string + icon?: string | null + subdomain?: string + } + ) { + const gate = createGate({ user, requireAuth: true }) + const site = await getSite(payload.site) + + if (!gate.allows({ type: "can-update-site", site })) { + throw gate.permissionError() + } + + if (payload.subdomain) { + await checkSubdomain({ + subdomain: payload.subdomain, + updatingSiteId: site.id, + }) + } + + const updated = await prisma.site.update({ + where: { + id: site.id, + }, + data: { + name: payload.name, + subdomain: payload.subdomain, + description: payload.description, + icon: payload.icon, + }, + }) + + return { + site: updated, + subdomainUpdated: updated.subdomain !== site.subdomain, + } + }, + + async createSite( + user: AuthUser | null | undefined, + payload: { name: string; subdomain: string } + ) { + const gate = createGate({ user, requireAuth: true }) + + await checkSubdomain({ subdomain: payload.subdomain }) + + const site = await prisma.site.create({ + data: { + name: payload.name, + subdomain: payload.subdomain, + memberships: { + create: { + role: MembershipRole.OWNER, + user: { + connect: { + id: gate.user.id, + }, + }, + }, + }, + pages: { + create: { + title: "Aboute", + slug: "about", + excerpt: "", + content: `My name is ${payload.name} and I'm a new site.`, + published: true, + publishedAt: new Date(), + type: PageType.PAGE, + }, + }, + }, + }) + + return { site } + }, +} diff --git a/app/entry.client.tsx b/app/entry.client.tsx new file mode 100644 index 00000000..3eec1fd0 --- /dev/null +++ b/app/entry.client.tsx @@ -0,0 +1,4 @@ +import { RemixBrowser } from "@remix-run/react"; +import { hydrate } from "react-dom"; + +hydrate(, document); diff --git a/app/entry.server.tsx b/app/entry.server.tsx new file mode 100644 index 00000000..cdfe57a6 --- /dev/null +++ b/app/entry.server.tsx @@ -0,0 +1,21 @@ +import type { EntryContext } from "@remix-run/node" +import { RemixServer } from "@remix-run/react" +import { renderToString } from "react-dom/server" + +export default function handleRequest( + request: Request, + responseStatusCode: number, + responseHeaders: Headers, + remixContext: EntryContext +) { + let markup = renderToString( + + ) + + responseHeaders.set("Content-Type", "text/html") + + return new Response("" + markup, { + status: responseStatusCode, + headers: responseHeaders, + }) +} diff --git a/app/hooks/useRouteQuery.ts b/app/hooks/useRouteQuery.ts new file mode 100644 index 00000000..efa319ac --- /dev/null +++ b/app/hooks/useRouteQuery.ts @@ -0,0 +1,11 @@ +import { useLocation } from "@remix-run/react" +import { useMemo } from "react" + +export const useRouteQuery = () => { + const location = useLocation() + const query = useMemo(() => { + const search = new URLSearchParams(location.search) + return Object.fromEntries(search) + }, [location.search]) + return query +} diff --git a/app/lib/auth.client.ts b/app/lib/auth.client.ts new file mode 100644 index 00000000..952fc71f --- /dev/null +++ b/app/lib/auth.client.ts @@ -0,0 +1,10 @@ +export const logout = () => { + const url = new URL(`${location.protocol}//${ENV.OUR_DOMAIN}/api/logout`) + if (location.host !== ENV.OUR_DOMAIN) { + url.searchParams.set( + "next", + `${location.protocol}//${location.host}/api/logout` + ) + } + location.href = url.href +} diff --git a/app/lib/auth.server.ts b/app/lib/auth.server.ts new file mode 100644 index 00000000..827e96c0 --- /dev/null +++ b/app/lib/auth.server.ts @@ -0,0 +1,96 @@ +import type { User, Membership } from "@prisma/client" +import { AUTH_COOKIE_NAME } from "./config.server" +import { prisma } from "./db.server" +import dayjs from "dayjs" +import { type CookieSerializeOptions, createCookie } from "@remix-run/node" +import { IS_PROD, OUR_DOMAIN } from "./config.shared" + +export type AuthUser = User & { + memberships: Membership[] +} + +export const getAuthTokenFromRequest = async (request: Request) => { + let token = request.headers.get("authorization")?.replace(/[Bb]earer\s/, "") + if (!token) { + const cookie = createCookie(AUTH_COOKIE_NAME) + const cookieHeader = request.headers.get("cookie") + if (cookieHeader) { + const value = await cookie.parse(cookieHeader) + token = value + } + } + return token +} + +const findUserFromToken = async (token: string) => { + const accessToken = await prisma.accessToken.findUnique({ + where: { + token, + }, + include: { + user: { + include: { + memberships: true, + }, + }, + }, + }) + return accessToken?.user +} + +export const getAuthUser = async ( + request: Request, + requireAuth?: TRequireAuth +) => { + const token = await getAuthTokenFromRequest(request) + + let user: AuthUser | null | undefined = null + + if (token) { + user = await findUserFromToken(token) + } + + if (!user && requireAuth) { + throw new Error("require auth") + } + + return user as TRequireAuth extends true + ? AuthUser + : AuthUser | null | undefined +} + +export const getAuthCookieOptions = ({ + domain, + clearCookie, +}: { + domain?: string + clearCookie?: boolean +}): CookieSerializeOptions => { + return { + path: "/", + httpOnly: true, + sameSite: "lax", + expires: clearCookie ? new Date() : dayjs().add(6, "month").toDate(), + secure: IS_PROD, + domain: IS_PROD ? `.${domain || OUR_DOMAIN}` : undefined, + } +} + +export const generateCookie = ( + options: + | { type: "clear"; domain?: string } + | { type: "auth"; token: string; domain?: string } +) => { + const cookie = createCookie(AUTH_COOKIE_NAME) + + if (options.type === "clear") { + return cookie.serialize( + "", + getAuthCookieOptions({ domain: options.domain, clearCookie: true }) + ) + } + return cookie.serialize( + options.token, + getAuthCookieOptions({ domain: options.domain }) + ) +} diff --git a/app/lib/config.server.ts b/app/lib/config.server.ts new file mode 100644 index 00000000..ab1ff2f2 --- /dev/null +++ b/app/lib/config.server.ts @@ -0,0 +1,10 @@ +export const AUTH_COOKIE_NAME = process.env.AUTH_COOKIE_NAME +export const S3_REGION = process.env.S3_REGION +export const S3_ACCESS_KEY_ID = process.env.S3_ACCESS_KEY_ID +export const S3_SECRET_ACCESS_KEY = process.env.S3_SECRET_ACCESS_KEY + +export const S3_BUCKET_NAME = process.env.S3_BUCKET_NAME +export const S3_ENDPOINT = process.env.S3_ENDPOINT +export const MAILGUN_APIKEY = process.env.MAILGUN_APIKEY +export const MAILGUN_DOMAIN = process.env.MAILGUN_DOMAIN +export const MAILGUN_EU = process.env.MAILGUN_EU diff --git a/app/lib/config.shared.ts b/app/lib/config.shared.ts new file mode 100644 index 00000000..822be73f --- /dev/null +++ b/app/lib/config.shared.ts @@ -0,0 +1,8 @@ +export const IS_BROWSER = typeof window !== "undefined" + +export const IS_PROD = IS_BROWSER + ? !location.hostname.endsWith("localhost") + : process.env.NODE_ENV === "production" + +export const APP_NAME = IS_BROWSER ? ENV.APP_NAME : process.env.APP_NAME +export const OUR_DOMAIN = IS_BROWSER ? ENV.OUR_DOMAIN : process.env.OUR_DOMAIN diff --git a/app/lib/date.ts b/app/lib/date.ts new file mode 100644 index 00000000..aec167a0 --- /dev/null +++ b/app/lib/date.ts @@ -0,0 +1,5 @@ +import dayjs from "dayjs" + +export const formatDate = (date: string | Date) => { + return dayjs(date).format("MMM D, YYYY") +} diff --git a/app/lib/db.server.ts b/app/lib/db.server.ts new file mode 100644 index 00000000..7380b536 --- /dev/null +++ b/app/lib/db.server.ts @@ -0,0 +1,7 @@ +import { PrismaClient } from "@prisma/client" +import { singleton } from "./singleton.server" + +export const prisma = /* @__PURE__ */ singleton( + "prisma", + () => new PrismaClient() +) diff --git a/app/lib/gate.server.ts b/app/lib/gate.server.ts new file mode 100644 index 00000000..edecea4a --- /dev/null +++ b/app/lib/gate.server.ts @@ -0,0 +1,105 @@ +import { MembershipRole, type Site, type Page } from "@prisma/client" +import type { AuthUser } from "./auth.server" +import { PageVisibilityEnum } from "./types" + +type Action = + | { + type: "can-delete-page" + /** The site id this page belongs to */ + siteId: string + } + | { + type: "can-list-page" + visibility: PageVisibilityEnum + siteId: string + } + | { + type: "can-create-page" + siteId: string + } + | { + type: "can-read-page" + page: Page + } + | { + type: "can-update-site" + site: Site + } +export const createGate = ({ + user, + requireAuth, +}: { + user: AuthUser | null | undefined + requireAuth?: TRequiredAuth +}) => { + if (requireAuth && !user) { + throw new Error("require auth") + } + + const isSiteMember = (siteId: string, roles: MembershipRole[]) => { + if (!user) return false + return user.memberships.some( + (m) => m.siteId === siteId && roles.includes(m.role) + ) + } + + return { + user: user as TRequiredAuth extends true + ? AuthUser + : AuthUser | null | undefined, + allows(action: Action): boolean { + if (action.type === "can-delete-page") { + return isSiteMember(action.siteId, [ + MembershipRole.ADMIN, + MembershipRole.OWNER, + ]) + } + + if (action.type === "can-list-page") { + if (action.visibility === PageVisibilityEnum.Published) { + return true + } + return isSiteMember(action.siteId, [ + MembershipRole.ADMIN, + MembershipRole.OWNER, + ]) + } + + if (action.type === "can-create-page") { + return isSiteMember(action.siteId, [ + MembershipRole.ADMIN, + MembershipRole.OWNER, + ]) + } + + if (action.type === "can-read-page") { + const isPublished = + action.page.published && + action.page.publishedAt && + action.page.publishedAt <= new Date() + + return isPublished + ? !action.page.deletedAt + : !action.page.deletedAt && + isSiteMember(action.page.siteId, [ + MembershipRole.ADMIN, + MembershipRole.OWNER, + ]) + } + + if (action.type === "can-update-site") { + return isSiteMember(action.site.id, [ + MembershipRole.ADMIN, + MembershipRole.OWNER, + ]) + } + + return false + }, + permissionError(message = "not allowed") { + return new Error(message) + }, + } +} + +export type Gate = ReturnType diff --git a/app/lib/helpers.ts b/app/lib/helpers.ts new file mode 100644 index 00000000..cd0fb15d --- /dev/null +++ b/app/lib/helpers.ts @@ -0,0 +1,5 @@ +import { IS_PROD, OUR_DOMAIN } from "./config.shared" + +export const getSiteLink = ({ subdomain }: { subdomain: string }) => { + return `${IS_PROD ? "https" : "http"}://${subdomain}.${OUR_DOMAIN}` +} diff --git a/app/lib/mailgun.server.ts b/app/lib/mailgun.server.ts new file mode 100644 index 00000000..a571b2b8 --- /dev/null +++ b/app/lib/mailgun.server.ts @@ -0,0 +1,41 @@ +import Mailgun from "mailgun.js" +import FormData from "form-data" +import { singleton } from "./singleton.server" +import { MAILGUN_APIKEY, MAILGUN_DOMAIN, MAILGUN_EU } from "~/lib/config.server" +import type { MailgunMessageData } from "mailgun.js/interfaces/Messages" +import { APP_NAME, IS_PROD, OUR_DOMAIN } from "./config.shared" + +const getClient = () => + singleton("mailgun", () => { + const mg = new Mailgun(FormData) + const client = mg.client({ + username: "api", + key: MAILGUN_APIKEY, + url: MAILGUN_EU ? `https://api.eu.mailgun.net` : undefined, + }) + return client + }) + +export const sendLoginEmail = async (loginLink: string, email: string) => { + const message: MailgunMessageData = { + from: `${APP_NAME} `, + to: email, + subject: `Log in to ${APP_NAME}`, + html: `

Please use the link below to log in to ${APP_NAME}:

+ +login + +

This link will expire in 10 minutes.

+`, + } + + console.log(message) + + if (!IS_PROD) { + return + } + + const client = getClient() + + await client.messages.create(MAILGUN_DOMAIN, message).then(console.log) +} diff --git a/app/lib/markdown.server.ts b/app/lib/markdown.server.ts new file mode 100644 index 00000000..79570831 --- /dev/null +++ b/app/lib/markdown.server.ts @@ -0,0 +1,27 @@ +import Markdown from "markdown-it" + +export const renderPageContent = async (content: string) => { + const md = new Markdown({ + html: false, + linkify: true, + }) + const html = md.render(content) + return { html } +} + +const stripHTML = (html: string) => { + return html.replace(/<(?:.|\n)*?>/gm, "") +} + +export const getExcerpt = (content: string) => { + const indexOfMore = content.indexOf("") + const md = new Markdown({ + html: false, + linkify: true, + }) + if (indexOfMore > -1) { + content = content.substring(0, indexOfMore) + return stripHTML(md.render(content)) + } + return stripHTML(md.render(content)).slice(0, 200) +} diff --git a/app/lib/page-helpers.ts b/app/lib/page-helpers.ts new file mode 100644 index 00000000..61b33bc7 --- /dev/null +++ b/app/lib/page-helpers.ts @@ -0,0 +1,35 @@ +import dayjs from "dayjs" +import { useMemo } from "react" +import { PageVisibilityEnum } from "./types" + +export const usePageVisibility = ({ + published, + publishedAt, +}: { + published: boolean + publishedAt: string | Date | null +}) => { + const visibility = useMemo< + Omit + >(() => { + return getPageVisibility({ published, publishedAt }) + }, [published, publishedAt]) + + return visibility +} + +export const getPageVisibility = ({ + published, + publishedAt, +}: { + published: boolean + publishedAt: string | Date | null +}) => { + if (!published) { + return PageVisibilityEnum.Draft + } + if (published && publishedAt && dayjs(publishedAt).isBefore(new Date())) { + return PageVisibilityEnum.Published + } + return PageVisibilityEnum.Scheduled +} diff --git a/app/lib/s3.server.ts b/app/lib/s3.server.ts new file mode 100644 index 00000000..b9d135ea --- /dev/null +++ b/app/lib/s3.server.ts @@ -0,0 +1,37 @@ +import { + S3_REGION, + S3_ACCESS_KEY_ID, + S3_SECRET_ACCESS_KEY, + S3_BUCKET_NAME, + S3_ENDPOINT, +} from "~/lib/config.server" +import { + S3Client, + PutObjectCommand, + type PutObjectRequest, +} from "@aws-sdk/client-s3" +import { singleton } from "~/lib/singleton.server" + +export const s3 = singleton("s3-client", () => { + return new S3Client({ + endpoint: S3_ENDPOINT ? `https://${S3_ENDPOINT}` : undefined, + region: S3_REGION, + credentials: { + accessKeyId: S3_ACCESS_KEY_ID, + secretAccessKey: S3_SECRET_ACCESS_KEY, + }, + }) +}) + +export const s3uploadFile = async ( + filename: string, + file: PutObjectRequest["Body"] | string | Buffer +) => { + await s3.send( + new PutObjectCommand({ + Bucket: S3_BUCKET_NAME, + Key: filename, + Body: file, + }) + ) +} diff --git a/app/lib/singleton.server.ts b/app/lib/singleton.server.ts new file mode 100644 index 00000000..65da3885 --- /dev/null +++ b/app/lib/singleton.server.ts @@ -0,0 +1,43 @@ +// @ts-nocheck +globalThis._singletons = globalThis._singletons || {} + +export const singleton = (id: string, factory: () => T): T => { + if (!globalThis._singletons[id]) { + globalThis._singletons[id] = factory() + } + return globalThis._singletons[id] +} + +export const singletonAsync = ( + id: string, + factory: () => Promise, + singleton = true +): { readonly value: T; wait: Promise } => { + if (globalThis._singletons[id] && singleton) { + return { + wait: Promise.resolve(), + + get value() { + return globalThis._singletons[id] + }, + } + } + + let ready = false + + const wait = factory().then((value) => { + ready = true + globalThis._singletons[id] = value + }) + + return { + wait, + + get value() { + if (!ready) { + throw new Error(`please await .wait before using the value of '${id}'`) + } + return globalThis._singletons[id] + }, + } +} diff --git a/app/lib/store.ts b/app/lib/store.ts new file mode 100644 index 00000000..e6c3044e --- /dev/null +++ b/app/lib/store.ts @@ -0,0 +1,29 @@ +import create, { StoreApi } from "zustand" +import createContext from "zustand/context" + +export type Store = { + loginModalOpened: boolean + setLoginModalOpened: (open: boolean) => void + + subscribeModalOpened: boolean + setSubscribeModalOpened: (open: boolean) => void +} + +const { Provider, useStore } = createContext>() + +export { useStore } + +export const StoreProvider = Provider + +export const createStore = () => + create((set) => ({ + loginModalOpened: false, + setLoginModalOpened(open) { + set({ loginModalOpened: open }) + }, + + subscribeModalOpened: false, + setSubscribeModalOpened(open) { + set({ subscribeModalOpened: open }) + }, + })) diff --git a/app/lib/tenant.server.ts b/app/lib/tenant.server.ts new file mode 100644 index 00000000..81f735ce --- /dev/null +++ b/app/lib/tenant.server.ts @@ -0,0 +1,17 @@ +import { OUR_DOMAIN } from "./config.shared" + +export const getTenant = (request: Request) => { + const host = request.headers.get("host") + + const OUR_DOMAIN_SUFFIX = `.${OUR_DOMAIN}` + if (host) { + if (host.endsWith(OUR_DOMAIN_SUFFIX)) { + const subdomain = host.replace(OUR_DOMAIN_SUFFIX, "") + return subdomain + } + if (host !== OUR_DOMAIN) { + return host + } + } + return +} diff --git a/app/lib/types.ts b/app/lib/types.ts new file mode 100644 index 00000000..6e20e8c9 --- /dev/null +++ b/app/lib/types.ts @@ -0,0 +1,51 @@ +export type Site = { + id: string + name: string + subdomain: string + icon?: string | null +} + +export type SiteSubscription = { + email?: boolean + telegram?: boolean +} + +export type Viewer = { + id: string + name: string + username: string + email: string + avatar?: string | null +} + +export enum PageVisibilityEnum { + All = "all", + Published = "published", + Scheduled = "scheduled", + Draft = "draft", +} + +export type PostOnSiteHome = { + id: string + title: string + excerpt: string + slug: string + publishedAt: string | Date +} + +export type Page = { + id: string + title: string + contentHTML: string + excerpt: string + permalink: string + publishedAt: Date + published: boolean +} + +export type PostOnArchivesPage = { + id: string + title: string + slug: string + publishedAt: string | Date +} diff --git a/app/lib/upload.client.ts b/app/lib/upload.client.ts new file mode 100644 index 00000000..96b2c3c2 --- /dev/null +++ b/app/lib/upload.client.ts @@ -0,0 +1,15 @@ +export const uploadFileInBrowser = async (blob: Blob) => { + const form = new FormData() + form.append("file", blob) + form.append("type", "image") + const res = await fetch(`/api/upload`, { + credentials: "same-origin", + body: form, + method: "POST", + }) + if (!res.ok) { + throw new Error(`Upload failed: ${res.statusText}`) + } + const json = await res.json() + return json as { file: string } +} diff --git a/app/lib/user-contents.ts b/app/lib/user-contents.ts new file mode 100644 index 00000000..2ba430ea --- /dev/null +++ b/app/lib/user-contents.ts @@ -0,0 +1,16 @@ +import { IS_PROD, OUR_DOMAIN } from "./config.shared" + +export function getUserContentsUrl(filename: string): string +export function getUserContentsUrl(filename: undefined | null): undefined +export function getUserContentsUrl( + filename: T +): T +export function getUserContentsUrl(filename: string | undefined | null) { + if (!filename) return undefined + if (IS_PROD) { + return `https://usercontents.${OUR_DOMAIN}/${filename}` + } + return `/dev-s3-proxy?${new URLSearchParams({ + filename: filename, + }).toString()}` +} diff --git a/app/lib/utils.ts b/app/lib/utils.ts new file mode 100644 index 00000000..f6d94e54 --- /dev/null +++ b/app/lib/utils.ts @@ -0,0 +1,5 @@ +type Truthy = T extends false | "" | 0 | null | undefined ? never : T // from lodash + +export function truthy(value: T): value is Truthy { + return Boolean(value) +} diff --git a/app/lib/uuid.ts b/app/lib/uuid.ts new file mode 100644 index 00000000..494bfbcc --- /dev/null +++ b/app/lib/uuid.ts @@ -0,0 +1,3 @@ +import { validate } from "uuid" + +export const isUUID = (id: string) => validate(id) diff --git a/app/main.css b/app/main.css new file mode 100644 index 00000000..3be9ce49 --- /dev/null +++ b/app/main.css @@ -0,0 +1,1754 @@ +:root { + --border-color: #eee; + --font-fans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; + --shadow-color-button: #d1d5db; + --accent-color: #6366f1; + /* Accent color for form controls */ + accent-color: var(--accent-color); +} + +/* ! tailwindcss v3.0.24 | MIT License | https://tailwindcss.com */ + +/* +1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4) +2. Allow adding a border to an element by just adding a border-width. (https://github.com/tailwindcss/tailwindcss/pull/116) +*/ + +*, +::before, +::after { + box-sizing: border-box; + /* 1 */ + border-width: 0; + /* 2 */ + border-style: solid; + /* 2 */ + border-color: #e5e7eb; + /* 2 */ +} + +::before, +::after { + --tw-content: ''; +} + +/* +1. Use a consistent sensible line-height in all browsers. +2. Prevent adjustments of font size after orientation changes in iOS. +3. Use a more readable tab size. +4. Use the user's configured `sans` font-family by default. +*/ + +html { + line-height: 1.5; + /* 1 */ + -webkit-text-size-adjust: 100%; + /* 2 */ + -moz-tab-size: 4; + /* 3 */ + -o-tab-size: 4; + tab-size: 4; + /* 3 */ + font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; + /* 4 */ +} + +/* +1. Remove the margin in all browsers. +2. Inherit line-height from `html` so users can set them as a class directly on the `html` element. +*/ + +body { + margin: 0; + /* 1 */ + line-height: inherit; + /* 2 */ +} + +/* +1. Add the correct height in Firefox. +2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655) +3. Ensure horizontal rules are visible by default. +*/ + +hr { + height: 0; + /* 1 */ + color: inherit; + /* 2 */ + border-top-width: 1px; + /* 3 */ +} + +/* +Add the correct text decoration in Chrome, Edge, and Safari. +*/ + +abbr:where([title]) { + -webkit-text-decoration: underline dotted; + text-decoration: underline dotted; +} + +/* +Remove the default font size and weight for headings. +*/ + +h1, +h2, +h3, +h4, +h5, +h6 { + font-size: inherit; + font-weight: inherit; +} + +/* +Reset links to optimize for opt-in styling instead of opt-out. +*/ + +a { + color: inherit; + text-decoration: inherit; +} + +/* +Add the correct font weight in Edge and Safari. +*/ + +b, +strong { + font-weight: bolder; +} + +/* +1. Use the user's configured `mono` font family by default. +2. Correct the odd `em` font sizing in all browsers. +*/ + +code, +kbd, +samp, +pre { + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; + /* 1 */ + font-size: 1em; + /* 2 */ +} + +/* +Add the correct font size in all browsers. +*/ + +small { + font-size: 80%; +} + +/* +Prevent `sub` and `sup` elements from affecting the line height in all browsers. +*/ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sub { + bottom: -0.25em; +} + +sup { + top: -0.5em; +} + +/* +1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297) +2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016) +3. Remove gaps between table borders by default. +*/ + +table { + text-indent: 0; + /* 1 */ + border-color: inherit; + /* 2 */ + border-collapse: collapse; + /* 3 */ +} + +/* +1. Change the font styles in all browsers. +2. Remove the margin in Firefox and Safari. +3. Remove default padding in all browsers. +*/ + +button, +input, +optgroup, +select, +textarea { + font-family: inherit; + /* 1 */ + font-size: 100%; + /* 1 */ + line-height: inherit; + /* 1 */ + color: inherit; + /* 1 */ + margin: 0; + /* 2 */ + padding: 0; + /* 3 */ +} + +/* +Remove the inheritance of text transform in Edge and Firefox. +*/ + +button, +select { + text-transform: none; +} + +/* +1. Correct the inability to style clickable types in iOS and Safari. +2. Remove default button styles. +*/ + +button, +[type='button'], +[type='reset'], +[type='submit'] { + -webkit-appearance: button; + /* 1 */ + background-color: transparent; + /* 2 */ + background-image: none; + /* 2 */ +} + +/* +Use the modern Firefox focus style for all focusable elements. +*/ + +:-moz-focusring { + outline: auto; +} + +/* +Remove the additional `:invalid` styles in Firefox. (https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737) +*/ + +:-moz-ui-invalid { + box-shadow: none; +} + +/* +Add the correct vertical alignment in Chrome and Firefox. +*/ + +progress { + vertical-align: baseline; +} + +/* +Correct the cursor style of increment and decrement buttons in Safari. +*/ + +::-webkit-inner-spin-button, +::-webkit-outer-spin-button { + height: auto; +} + +/* +1. Correct the odd appearance in Chrome and Safari. +2. Correct the outline style in Safari. +*/ + +[type='search'] { + -webkit-appearance: textfield; + /* 1 */ + outline-offset: -2px; + /* 2 */ +} + +/* +Remove the inner padding in Chrome and Safari on macOS. +*/ + +::-webkit-search-decoration { + -webkit-appearance: none; +} + +/* +1. Correct the inability to style clickable types in iOS and Safari. +2. Change font properties to `inherit` in Safari. +*/ + +::-webkit-file-upload-button { + -webkit-appearance: button; + /* 1 */ + font: inherit; + /* 2 */ +} + +/* +Add the correct display in Chrome and Safari. +*/ + +summary { + display: list-item; +} + +/* +Removes the default spacing and border for appropriate elements. +*/ + +blockquote, +dl, +dd, +h1, +h2, +h3, +h4, +h5, +h6, +hr, +figure, +p, +pre { + margin: 0; +} + +fieldset { + margin: 0; + padding: 0; +} + +legend { + padding: 0; +} + +ol, +ul, +menu { + list-style: none; + margin: 0; + padding: 0; +} + +/* +Prevent resizing textareas horizontally by default. +*/ + +textarea { + resize: vertical; +} + +/* +1. Reset the default placeholder opacity in Firefox. (https://github.com/tailwindlabs/tailwindcss/issues/3300) +2. Set the default placeholder color to the user's configured gray 400 color. +*/ + +input::-moz-placeholder, textarea::-moz-placeholder { + opacity: 1; + /* 1 */ + color: #9ca3af; + /* 2 */ +} + +input:-ms-input-placeholder, textarea:-ms-input-placeholder { + opacity: 1; + /* 1 */ + color: #9ca3af; + /* 2 */ +} + +input::placeholder, +textarea::placeholder { + opacity: 1; + /* 1 */ + color: #9ca3af; + /* 2 */ +} + +/* +Set the default cursor for buttons. +*/ + +button, +[role="button"] { + cursor: pointer; +} + +/* +Make sure disabled buttons don't get the pointer cursor. +*/ + +:disabled { + cursor: default; +} + +/* +1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14) +2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210) + This can trigger a poorly considered lint error in some tools but is included by design. +*/ + +img, +svg, +video, +canvas, +audio, +iframe, +embed, +object { + display: block; + /* 1 */ + vertical-align: middle; + /* 2 */ +} + +/* +Constrain images and videos to the parent width and preserve their intrinsic aspect ratio. (https://github.com/mozdevs/cssremedy/issues/14) +*/ + +img, +video { + max-width: 100%; + height: auto; +} + +/* +Ensure the default browser behavior of the `hidden` attribute. +*/ + +[hidden] { + display: none; +} + +*, ::before, ::after { + --tw-translate-x: 0; + --tw-translate-y: 0; + --tw-rotate: 0; + --tw-skew-x: 0; + --tw-skew-y: 0; + --tw-scale-x: 1; + --tw-scale-y: 1; + --tw-pan-x: ; + --tw-pan-y: ; + --tw-pinch-zoom: ; + --tw-scroll-snap-strictness: proximity; + --tw-ordinal: ; + --tw-slashed-zero: ; + --tw-numeric-figure: ; + --tw-numeric-spacing: ; + --tw-numeric-fraction: ; + --tw-ring-inset: ; + --tw-ring-offset-width: 0px; + --tw-ring-offset-color: #fff; + --tw-ring-color: rgb(59 130 246 / 0.5); + --tw-ring-offset-shadow: 0 0 #0000; + --tw-ring-shadow: 0 0 #0000; + --tw-shadow: 0 0 #0000; + --tw-shadow-colored: 0 0 #0000; + --tw-blur: ; + --tw-brightness: ; + --tw-contrast: ; + --tw-grayscale: ; + --tw-hue-rotate: ; + --tw-invert: ; + --tw-saturate: ; + --tw-sepia: ; + --tw-drop-shadow: ; + --tw-backdrop-blur: ; + --tw-backdrop-brightness: ; + --tw-backdrop-contrast: ; + --tw-backdrop-grayscale: ; + --tw-backdrop-hue-rotate: ; + --tw-backdrop-invert: ; + --tw-backdrop-opacity: ; + --tw-backdrop-saturate: ; + --tw-backdrop-sepia: ; +} + +.container { + width: 100%; +} + +@media (min-width: 640px) { + .container { + max-width: 640px; + } +} + +@media (min-width: 768px) { + .container { + max-width: 768px; + } +} + +@media (min-width: 1024px) { + .container { + max-width: 1024px; + } +} + +@media (min-width: 1280px) { + .container { + max-width: 1280px; + } +} + +@media (min-width: 1536px) { + .container { + max-width: 1536px; + } +} + +.invisible { + visibility: hidden; +} + +.fixed { + position: fixed; +} + +.absolute { + position: absolute; +} + +.relative { + position: relative; +} + +.inset-0 { + top: 0px; + right: 0px; + bottom: 0px; + left: 0px; +} + +.right-0 { + right: 0px; +} + +.left-0 { + left: 0px; +} + +.top-0 { + top: 0px; +} + +.bottom-0 { + bottom: 0px; +} + +.z-10 { + z-index: 10; +} + +.z-50 { + z-index: 50; +} + +.z-20 { + z-index: 20; +} + +.-z-10 { + z-index: -10; +} + +.z-40 { + z-index: 40; +} + +.mx-auto { + margin-left: auto; + margin-right: auto; +} + +.my-20 { + margin-top: 5rem; + margin-bottom: 5rem; +} + +.-mx-3 { + margin-left: -0.75rem; + margin-right: -0.75rem; +} + +.mx-2 { + margin-left: 0.5rem; + margin-right: 0.5rem; +} + +.my-8 { + margin-top: 2rem; + margin-bottom: 2rem; +} + +.mt-5 { + margin-top: 1.25rem; +} + +.mr-3 { + margin-right: 0.75rem; +} + +.mb-5 { + margin-bottom: 1.25rem; +} + +.mb-1 { + margin-bottom: 0.25rem; +} + +.mr-1 { + margin-right: 0.25rem; +} + +.mb-8 { + margin-bottom: 2rem; +} + +.-mt-3 { + margin-top: -0.75rem; +} + +.mt-1 { + margin-top: 0.25rem; +} + +.-mt-20 { + margin-top: -5rem; +} + +.mt-10 { + margin-top: 2.5rem; +} + +.mt-3 { + margin-top: 0.75rem; +} + +.-ml-1 { + margin-left: -0.25rem; +} + +.mr-\[2px\] { + margin-right: 2px; +} + +.mt-2 { + margin-top: 0.5rem; +} + +.-mt-40 { + margin-top: -10rem; +} + +.mb-2 { + margin-bottom: 0.5rem; +} + +.mr-2 { + margin-right: 0.5rem; +} + +.mt-20 { + margin-top: 5rem; +} + +.mb-10 { + margin-bottom: 2.5rem; +} + +.ml-1 { + margin-left: 0.25rem; +} + +.mt-14 { + margin-top: 3.5rem; +} + +.block { + display: block; +} + +.inline-block { + display: inline-block; +} + +.inline { + display: inline; +} + +.flex { + display: flex; +} + +.inline-flex { + display: inline-flex; +} + +.hidden { + display: none; +} + +.h-12 { + height: 3rem; +} + +.h-16 { + height: 4rem; +} + +.h-4 { + height: 1rem; +} + +.h-9 { + height: 2.25rem; +} + +.h-5 { + height: 1.25rem; +} + +.h-8 { + height: 2rem; +} + +.h-10 { + height: 2.5rem; +} + +.h-screen { + height: 100vh; +} + +.h-14 { + height: 3.5rem; +} + +.h-20 { + height: 5rem; +} + +.h-full { + height: 100%; +} + +.min-h-screen { + min-height: 100vh; +} + +.w-full { + width: 100%; +} + +.w-4 { + width: 1rem; +} + +.w-5 { + width: 1.25rem; +} + +.w-10 { + width: 2.5rem; +} + +.w-8 { + width: 2rem; +} + +.w-64 { + width: 16rem; +} + +.w-8\/12 { + width: 66.666667%; +} + +.w-sidebar { + width: 240px; +} + +.w-\[1px\] { + width: 1px; +} + +.w-\[280px\] { + width: 280px; +} + +.w-28 { + width: 7rem; +} + +.min-w-\[280px\] { + min-width: 280px; +} + +.min-w-\[240px\] { + min-width: 240px; +} + +.max-w-sm { + max-width: 24rem; +} + +.max-w-md { + max-width: 28rem; +} + +.max-w-screen-xl { + max-width: 1280px; +} + +.max-w-screen-md { + max-width: 768px; +} + +.max-w-lg { + max-width: 32rem; +} + +.flex-shrink-0 { + flex-shrink: 0; +} + +.transform { + transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y)); +} + +.cursor-default { + cursor: default; +} + +.select-none { + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.items-start { + align-items: flex-start; +} + +.items-center { + align-items: center; +} + +.justify-center { + justify-content: center; +} + +.justify-between { + justify-content: space-between; +} + +.space-y-5 > :not([hidden]) ~ :not([hidden]) { + --tw-space-y-reverse: 0; + margin-top: calc(1.25rem * calc(1 - var(--tw-space-y-reverse))); + margin-bottom: calc(1.25rem * var(--tw-space-y-reverse)); +} + +.space-x-1 > :not([hidden]) ~ :not([hidden]) { + --tw-space-x-reverse: 0; + margin-right: calc(0.25rem * var(--tw-space-x-reverse)); + margin-left: calc(0.25rem * calc(1 - var(--tw-space-x-reverse))); +} + +.space-x-3 > :not([hidden]) ~ :not([hidden]) { + --tw-space-x-reverse: 0; + margin-right: calc(0.75rem * var(--tw-space-x-reverse)); + margin-left: calc(0.75rem * calc(1 - var(--tw-space-x-reverse))); +} + +.space-x-2 > :not([hidden]) ~ :not([hidden]) { + --tw-space-x-reverse: 0; + margin-right: calc(0.5rem * var(--tw-space-x-reverse)); + margin-left: calc(0.5rem * calc(1 - var(--tw-space-x-reverse))); +} + +.space-x-5 > :not([hidden]) ~ :not([hidden]) { + --tw-space-x-reverse: 0; + margin-right: calc(1.25rem * var(--tw-space-x-reverse)); + margin-left: calc(1.25rem * calc(1 - var(--tw-space-x-reverse))); +} + +.space-y-14 > :not([hidden]) ~ :not([hidden]) { + --tw-space-y-reverse: 0; + margin-top: calc(3.5rem * calc(1 - var(--tw-space-y-reverse))); + margin-bottom: calc(3.5rem * var(--tw-space-y-reverse)); +} + +.space-x-6 > :not([hidden]) ~ :not([hidden]) { + --tw-space-x-reverse: 0; + margin-right: calc(1.5rem * var(--tw-space-x-reverse)); + margin-left: calc(1.5rem * calc(1 - var(--tw-space-x-reverse))); +} + +.space-y-\[2px\] > :not([hidden]) ~ :not([hidden]) { + --tw-space-y-reverse: 0; + margin-top: calc(2px * calc(1 - var(--tw-space-y-reverse))); + margin-bottom: calc(2px * var(--tw-space-y-reverse)); +} + +.space-y-3 > :not([hidden]) ~ :not([hidden]) { + --tw-space-y-reverse: 0; + margin-top: calc(0.75rem * calc(1 - var(--tw-space-y-reverse))); + margin-bottom: calc(0.75rem * var(--tw-space-y-reverse)); +} + +.overflow-auto { + overflow: auto; +} + +.overflow-hidden { + overflow: hidden; +} + +.overflow-y-auto { + overflow-y: auto; +} + +.truncate { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.rounded-lg { + border-radius: 0.5rem; +} + +.rounded { + border-radius: 0.25rem; +} + +.rounded-full { + border-radius: 9999px; +} + +.rounded-r-lg { + border-top-right-radius: 0.5rem; + border-bottom-right-radius: 0.5rem; +} + +.border { + border-width: 1px; +} + +.border-b { + border-bottom-width: 1px; +} + +.border-t { + border-top-width: 1px; +} + +.border-b-2 { + border-bottom-width: 2px; +} + +.border-l-0 { + border-left-width: 0px; +} + +.border-l { + border-left-width: 1px; +} + +.border-none { + border-style: none; +} + +.border-accent { + border-color: var(--accent-color); +} + +.border-transparent { + border-color: transparent; +} + +.border-gray-200 { + --tw-border-opacity: 1; + border-color: rgb(229 231 235 / var(--tw-border-opacity)); +} + +.bg-white { + --tw-bg-opacity: 1; + background-color: rgb(255 255 255 / var(--tw-bg-opacity)); +} + +.bg-zinc-200 { + --tw-bg-opacity: 1; + background-color: rgb(228 228 231 / var(--tw-bg-opacity)); +} + +.bg-black { + --tw-bg-opacity: 1; + background-color: rgb(0 0 0 / var(--tw-bg-opacity)); +} + +.bg-pink-500 { + --tw-bg-opacity: 1; + background-color: rgb(236 72 153 / var(--tw-bg-opacity)); +} + +.bg-blue-500 { + --tw-bg-opacity: 1; + background-color: rgb(59 130 246 / var(--tw-bg-opacity)); +} + +.bg-gray-200 { + --tw-bg-opacity: 1; + background-color: rgb(229 231 235 / var(--tw-bg-opacity)); +} + +.bg-zinc-100 { + --tw-bg-opacity: 1; + background-color: rgb(244 244 245 / var(--tw-bg-opacity)); +} + +.bg-indigo-600 { + --tw-bg-opacity: 1; + background-color: rgb(79 70 229 / var(--tw-bg-opacity)); +} + +.bg-pink-400 { + --tw-bg-opacity: 1; + background-color: rgb(244 114 182 / var(--tw-bg-opacity)); +} + +.bg-yellow-400 { + --tw-bg-opacity: 1; + background-color: rgb(250 204 21 / var(--tw-bg-opacity)); +} + +.bg-gray-50 { + --tw-bg-opacity: 1; + background-color: rgb(249 250 251 / var(--tw-bg-opacity)); +} + +.bg-black\/30 { + background-color: rgb(0 0 0 / 0.3); +} + +.bg-zinc-50 { + --tw-bg-opacity: 1; + background-color: rgb(250 250 250 / var(--tw-bg-opacity)); +} + +.bg-border { + background-color: var(--border-color); +} + +.bg-gray-100 { + --tw-bg-opacity: 1; + background-color: rgb(243 244 246 / var(--tw-bg-opacity)); +} + +.p-8 { + padding: 2rem; +} + +.p-5 { + padding: 1.25rem; +} + +.p-2 { + padding: 0.5rem; +} + +.p-4 { + padding: 1rem; +} + +.px-3 { + padding-left: 0.75rem; + padding-right: 0.75rem; +} + +.px-5 { + padding-left: 1.25rem; + padding-right: 1.25rem; +} + +.py-5 { + padding-top: 1.25rem; + padding-bottom: 1.25rem; +} + +.py-3 { + padding-top: 0.75rem; + padding-bottom: 0.75rem; +} + +.py-2 { + padding-top: 0.5rem; + padding-bottom: 0.5rem; +} + +.px-2 { + padding-left: 0.5rem; + padding-right: 0.5rem; +} + +.px-4 { + padding-left: 1rem; + padding-right: 1rem; +} + +.py-10 { + padding-top: 2.5rem; + padding-bottom: 2.5rem; +} + +.px-1 { + padding-left: 0.25rem; + padding-right: 0.25rem; +} + +.pt-3 { + padding-top: 0.75rem; +} + +.pb-2 { + padding-bottom: 0.5rem; +} + +.pt-1 { + padding-top: 0.25rem; +} + +.pb-12 { + padding-bottom: 3rem; +} + +.pt-12 { + padding-top: 3rem; +} + +.pt-2 { + padding-top: 0.5rem; +} + +.pt-14 { + padding-top: 3.5rem; +} + +.pt-8 { + padding-top: 2rem; +} + +.text-center { + text-align: center; +} + +.text-xl { + font-size: 1.25rem; + line-height: 1.75rem; +} + +.text-sm { + font-size: 0.875rem; + line-height: 1.25rem; +} + +.text-2xl { + font-size: 1.5rem; + line-height: 2rem; +} + +.text-3xl { + font-size: 1.875rem; + line-height: 2.25rem; +} + +.text-xs { + font-size: 0.75rem; + line-height: 1rem; +} + +.text-4xl { + font-size: 2.25rem; + line-height: 2.5rem; +} + +.text-lg { + font-size: 1.125rem; + line-height: 1.75rem; +} + +.font-bold { + font-weight: 700; +} + +.font-medium { + font-weight: 500; +} + +.font-semibold { + font-weight: 600; +} + +.uppercase { + text-transform: uppercase; +} + +.capitalize { + text-transform: capitalize; +} + +.italic { + font-style: italic; +} + +.text-zinc-400 { + --tw-text-opacity: 1; + color: rgb(161 161 170 / var(--tw-text-opacity)); +} + +.text-accent { + color: var(--accent-color); +} + +.text-zinc-600 { + --tw-text-opacity: 1; + color: rgb(82 82 91 / var(--tw-text-opacity)); +} + +.text-white { + --tw-text-opacity: 1; + color: rgb(255 255 255 / var(--tw-text-opacity)); +} + +.text-gray-400 { + --tw-text-opacity: 1; + color: rgb(156 163 175 / var(--tw-text-opacity)); +} + +.text-zinc-500 { + --tw-text-opacity: 1; + color: rgb(113 113 122 / var(--tw-text-opacity)); +} + +.text-gray-500 { + --tw-text-opacity: 1; + color: rgb(107 114 128 / var(--tw-text-opacity)); +} + +.text-indigo-700 { + --tw-text-opacity: 1; + color: rgb(67 56 202 / var(--tw-text-opacity)); +} + +.text-gray-600 { + --tw-text-opacity: 1; + color: rgb(75 85 99 / var(--tw-text-opacity)); +} + +.text-red-500 { + --tw-text-opacity: 1; + color: rgb(239 68 68 / var(--tw-text-opacity)); +} + +.text-black { + --tw-text-opacity: 1; + color: rgb(0 0 0 / var(--tw-text-opacity)); +} + +.text-gray-800 { + --tw-text-opacity: 1; + color: rgb(31 41 55 / var(--tw-text-opacity)); +} + +.text-zinc-300 { + --tw-text-opacity: 1; + color: rgb(212 212 216 / var(--tw-text-opacity)); +} + +.underline { + -webkit-text-decoration-line: underline; + text-decoration-line: underline; +} + +.opacity-75 { + opacity: 0.75; +} + +.opacity-30 { + opacity: 0.3; +} + +.shadow-modal { + --tw-shadow: rgb(0 0 0 / 20%) 0px 0px 1px, rgb(0 0 0 / 20%) 0px 20px 40px; + --tw-shadow-colored: 0px 0px 1px var(--tw-shadow-color), 0px 20px 40px var(--tw-shadow-color); + box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow); +} + +.outline { + outline-style: solid; +} + +.ring-zinc-200 { + --tw-ring-opacity: 1; + --tw-ring-color: rgb(228 228 231 / var(--tw-ring-opacity)); +} + +.ring-offset-1 { + --tw-ring-offset-width: 1px; +} + +.filter { + filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow); +} + +.transition-colors { + transition-property: color, background-color, border-color, fill, stroke, -webkit-text-decoration-color; + transition-property: color, background-color, border-color, text-decoration-color, fill, stroke; + transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, -webkit-text-decoration-color; + transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); + transition-duration: 150ms; +} + +.transition { + transition-property: color, background-color, border-color, fill, stroke, opacity, box-shadow, transform, filter, -webkit-text-decoration-color, -webkit-backdrop-filter; + transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter; + transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter, -webkit-text-decoration-color, -webkit-backdrop-filter; + transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); + transition-duration: 150ms; +} + +*, +*:after, +*:before { + border-color: var(--border-color); +} + +.container { + max-width: 1280px; + margin-left: auto; + margin-right: auto; +} + +.button { + display: inline-flex; + align-items: center; + justify-content: center; + height: 2rem; + padding-left: 0.75rem; + padding-right: 0.75rem; + min-width: 100px; + --tw-shadow: 0 1.5px 1px var(--shadow-color-button); + --tw-shadow-colored: 0 1.5px 1px var(--tw-shadow-color); + box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow); + white-space: nowrap; + font-weight: 500; + transition-property: color, background-color, border-color, fill, stroke, -webkit-text-decoration-color; + transition-property: color, background-color, border-color, text-decoration-color, fill, stroke; + transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, -webkit-text-decoration-color; + transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); + transition-duration: 150ms; +} + +.button.is-loading { + opacity: 0.5; +} + +.button.is-loading:before { + margin-right: 0.5rem; + height: 1rem; + width: 1rem; + border-radius: 9999px; + border-width: 2px; + content: ""; + border-top-color: transparent; + border-left-color: transparent; + border-bottom-color: currentColor; + border-right-color: currentColor; +} + +@-webkit-keyframes spin { + to { + transform: rotate(360deg); + } +} + +@keyframes spin { + to { + transform: rotate(360deg); + } +} + +.button.is-loading:before { + -webkit-animation: spin 1s linear infinite; + animation: spin 1s linear infinite; +} + +.button.is-block { + width: 100%; +} + +.button.is-primary { + --shadow-color-button: #4338ca; + --tw-bg-opacity: 1; + background-color: rgb(99 102 241 / var(--tw-bg-opacity)); +} + +.button.is-primary:hover { + --tw-bg-opacity: 1; + background-color: rgb(79 70 229 / var(--tw-bg-opacity)); +} + +.button.is-primary:focus { + --tw-bg-opacity: 1; + background-color: rgb(67 56 202 / var(--tw-bg-opacity)); +} + +.button.is-primary { + --tw-text-opacity: 1; + color: rgb(255 255 255 / var(--tw-text-opacity)); +} + +.button.is-secondary { + --tw-bg-opacity: 1; + background-color: rgb(249 250 251 / var(--tw-bg-opacity)); +} + +.button.is-secondary:hover { + --tw-bg-opacity: 1; + background-color: rgb(243 244 246 / var(--tw-bg-opacity)); +} + +.button.is-secondary:focus { + --tw-bg-opacity: 1; + background-color: rgb(229 231 235 / var(--tw-bg-opacity)); +} + +.button.is-secondary { + --tw-text-opacity: 1; + color: rgb(107 114 128 / var(--tw-text-opacity)); +} + +.button.is-text { + --tw-shadow: 0 0 #0000; + --tw-shadow-colored: 0 0 #0000; + box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow); + --tw-text-opacity: 1; + color: rgb(107 114 128 / var(--tw-text-opacity)); +} + +.button.is-text:hover { + --tw-bg-opacity: 1; + background-color: rgb(249 250 251 / var(--tw-bg-opacity)); +} + +.button.is-text:focus { + --tw-bg-opacity: 1; + background-color: rgb(243 244 246 / var(--tw-bg-opacity)); +} + +.button.is-green { + --shadow-color-button: #15803d; + --tw-bg-opacity: 1; + background-color: rgb(34 197 94 / var(--tw-bg-opacity)); +} + +.button.is-green:hover { + --tw-bg-opacity: 1; + background-color: rgb(22 163 74 / var(--tw-bg-opacity)); +} + +.button.is-green:focus { + --tw-bg-opacity: 1; + background-color: rgb(21 128 61 / var(--tw-bg-opacity)); +} + +.button.is-red { + --shadow-color-button: #b91c1c; + --tw-bg-opacity: 1; + background-color: rgb(239 68 68 / var(--tw-bg-opacity)); +} + +.button.is-red:hover { + --tw-bg-opacity: 1; + background-color: rgb(220 38 38 / var(--tw-bg-opacity)); +} + +.button.is-red:focus { + --tw-bg-opacity: 1; + background-color: rgb(185 28 28 / var(--tw-bg-opacity)); +} + +.button.is-sm { + height: 1.75rem; + padding-left: 0.5rem; + padding-right: 0.5rem; + font-size: 0.875rem; + line-height: 1.25rem; +} + +.input { + border-width: 1px; + outline: 2px solid transparent; + outline-offset: 2px; + border-radius: 0.5rem; + padding-left: 0.75rem; + padding-right: 0.75rem; + height: 2.5rem; + display: inline-flex; + align-items: center; +} + +.input:focus { + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); + --tw-ring-opacity: 1; + --tw-ring-color: rgb(129 140 248 / var(--tw-ring-opacity)); + --tw-border-opacity: 1; + border-color: rgb(129 140 248 / var(--tw-border-opacity)); +} + +.input.is-block { + width: 100%; +} + +.input.has-addon { + border-top-right-radius: 0px; + border-bottom-right-radius: 0px; +} + +textarea.input { + height: auto; + padding-top: 0.75rem; + padding-bottom: 0.75rem; + padding-left: 0.75rem; + padding-right: 0.75rem; +} + +.label { + display: block; + margin-bottom: 0.5rem; + font-size: 0.875rem; + line-height: 1.25rem; + font-weight: 700; + --tw-text-opacity: 1; + color: rgb(55 65 81 / var(--tw-text-opacity)); +} + +.post-status-circle { + height: 15px; + width: 15px; + --tw-bg-opacity: 1; + background-color: rgb(34 197 94 / var(--tw-bg-opacity)); + display: inline-block; + border-radius: 9999px; + position: relative; +} + +.post-status-circle:before { + content: ""; + position: absolute; + left: 50%; + top: 50%; + --tw-bg-opacity: 1; + background-color: rgb(255 255 255 / var(--tw-bg-opacity)); + height: 10px; + width: 10px; + border-radius: 9999px; + --tw-translate-x: -50%; + --tw-translate-y: -50%; + transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y)); +} + +.post-status-circle.is-draft { + --tw-bg-opacity: 1; + background-color: rgb(209 213 219 / var(--tw-bg-opacity)); +} + +.post-status-circle.is-scheduled { + --tw-bg-opacity: 1; + background-color: rgb(234 179 8 / var(--tw-bg-opacity)); +} + +.page-title { + position: relative; + font-size: 1.875rem; + line-height: 2.25rem; + font-weight: 800; +} + +.prose > p { + margin-top: 1.25rem; + margin-bottom: 1.25rem; +} + +.prose > *:first-child { + margin-top: 0px; +} + +.prose { + font-size: 1.125rem; + line-height: 1.75rem; +} + +.prose h2 { + font-size: 1.875rem; + line-height: 2.25rem; + font-weight: 600; + margin-top: 1.25rem; + margin-bottom: 1.25rem; +} + +.prose h3 { + font-size: 1.5rem; + line-height: 2rem; + font-weight: 600; +} + +.prose h4 { + font-size: 1.25rem; + line-height: 1.75rem; + font-weight: 600; +} + +.prose blockquote { + border-left-width: 4px; + --tw-border-opacity: 1; + border-color: rgb(165 180 252 / var(--tw-border-opacity)); + padding-left: 1rem; + font-style: italic; + --tw-text-opacity: 1; + color: rgb(82 82 91 / var(--tw-text-opacity)); +} + +.prose ul { + list-style-type: disc; + padding-left: 1.25rem; +} + +.prose ol { + list-style-type: decimal; + padding-left: 1.25rem; +} + +.prose > ul, .prose > ol { + margin-top: 1.25rem; + margin-bottom: 1.25rem; +} + +.prose a { + --tw-text-opacity: 1; + color: rgb(79 70 229 / var(--tw-text-opacity)); + -webkit-text-decoration-line: underline; + text-decoration-line: underline; +} + +.prose pre { + overflow: auto; +} + +.hover\:border-gray-500:hover { + --tw-border-opacity: 1; + border-color: rgb(107 114 128 / var(--tw-border-opacity)); +} + +.hover\:border-gray-300:hover { + --tw-border-opacity: 1; + border-color: rgb(209 213 219 / var(--tw-border-opacity)); +} + +.hover\:border-indigo-300:hover { + --tw-border-opacity: 1; + border-color: rgb(165 180 252 / var(--tw-border-opacity)); +} + +.hover\:bg-zinc-100:hover { + --tw-bg-opacity: 1; + background-color: rgb(244 244 245 / var(--tw-bg-opacity)); +} + +.hover\:bg-gray-200:hover { + --tw-bg-opacity: 1; + background-color: rgb(229 231 235 / var(--tw-bg-opacity)); +} + +.hover\:bg-gray-100:hover { + --tw-bg-opacity: 1; + background-color: rgb(243 244 246 / var(--tw-bg-opacity)); +} + +.hover\:bg-indigo-100:hover { + --tw-bg-opacity: 1; + background-color: rgb(224 231 255 / var(--tw-bg-opacity)); +} + +.hover\:bg-opacity-50:hover { + --tw-bg-opacity: 0.5; +} + +.hover\:text-indigo-500:hover { + --tw-text-opacity: 1; + color: rgb(99 102 241 / var(--tw-text-opacity)); +} + +.hover\:text-gray-700:hover { + --tw-text-opacity: 1; + color: rgb(55 65 81 / var(--tw-text-opacity)); +} + +.hover\:underline:hover { + -webkit-text-decoration-line: underline; + text-decoration-line: underline; +} + +.focus\:outline-none:focus { + outline: 2px solid transparent; + outline-offset: 2px; +} + +.focus\:ring-2:focus { + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); +} + +.group:hover .group-hover\:visible { + visibility: visible; +} + +@media (min-width: 768px) { + .md\:px-10 { + padding-left: 2.5rem; + padding-right: 2.5rem; + } + + .md\:px-14 { + padding-left: 3.5rem; + padding-right: 3.5rem; + } + + .md\:pl-sidebar { + padding-left: 240px; + } +} + +@media (min-width: 1024px) { + .lg\:text-7xl { + font-size: 4.5rem; + line-height: 1; + } +} diff --git a/app/models/site.model.ts b/app/models/site.model.ts new file mode 100644 index 00000000..2d2a294c --- /dev/null +++ b/app/models/site.model.ts @@ -0,0 +1,157 @@ +import { prisma } from "~/lib/db.server" +import { isUUID } from "~/lib/uuid" +import { MembershipRole } from "@prisma/client" + +export const checkSubdomain = async ({ + subdomain, + updatingSiteId, +}: { + subdomain: string + updatingSiteId?: string +}) => { + const existingSite = await prisma.site.findUnique({ + where: { + subdomain, + }, + }) + + if (existingSite?.deletedAt) { + // Actuall delete the site so that the subdomain can be used again + await prisma.site.delete({ + where: { + id: existingSite.id, + }, + }) + return + } + + if (existingSite && (!updatingSiteId || existingSite.id !== updatingSiteId)) { + throw new Error(`Subdomain already taken`) + } +} + +export const getUserLastActiveSite = async (userId: string) => { + const memberships = await prisma.membership.findMany({ + where: { + userId, + role: { + in: [MembershipRole.OWNER, MembershipRole.ADMIN], + }, + }, + include: { + site: true, + }, + orderBy: { + lastSwitchedTo: "desc", + }, + }) + + const site = memberships[0]?.site + + if (!site || site.deletedAt) return null + + return site +} + +export const getSite = async (input: string) => { + const site = isUUID(input) + ? await prisma.site.findUnique({ + where: { + id: input, + }, + }) + : await prisma.site.findUnique({ + where: { + subdomain: input, + }, + }) + + if (!site || site.deletedAt) { + throw new Error(`Site not found`) + } + + return site +} + +export const getMembership = async (data: { + siteId: string + userId: string + role: MembershipRole +}) => { + const first = await prisma.membership.findFirst({ + where: { + role: data.role, + userId: data.userId, + siteId: data.siteId, + }, + }) + + return first +} + +export const getSitesByUser = async ({ userId }: { userId: string }) => { + const memberships = await prisma.membership.findMany({ + where: { + userId, + role: { + in: [MembershipRole.ADMIN, MembershipRole.OWNER], + }, + }, + include: { + site: true, + }, + }) + return memberships.map((m) => m.site) +} + +export const checkPageSlug = async ({ + slug, + excludePage, + siteId, +}: { + slug: string + excludePage?: string + siteId: string +}) => { + if (!slug) { + throw new Error("Missing page slug") + } + const page = await prisma.page.findFirst({ + where: { + siteId, + slug, + id: excludePage && { + not: excludePage, + }, + }, + }) + if (!page) return + + if (page.deletedAt) { + await prisma.page.delete({ + where: { + id: page.id, + }, + }) + return + } + + throw new Error("Page slug already used") +} + +export const getSubscription = async (data: { + userId: string + siteId: string +}) => { + const membership = await getMembership({ + ...data, + role: MembershipRole.SUBSCRIBER, + }) + const config = membership?.config as any + return { + config: config && { + telegram: config.telegram, + email: config.email, + }, + } +} diff --git a/app/models/user.model.ts b/app/models/user.model.ts new file mode 100644 index 00000000..96e5e6bd --- /dev/null +++ b/app/models/user.model.ts @@ -0,0 +1,56 @@ +import { type AuthUser } from "~/lib/auth.server" +import { prisma } from "~/lib/db.server" +import { createGate } from "~/lib/gate.server" + +export const userModel = { + async updateProfile( + user: AuthUser | null | undefined, + payload: { + name?: string + username?: string + avatar?: string + bio?: string + email?: string + } + ) { + const gate = createGate({ user, requireAuth: true }) + if (payload.email) { + const userByEmail = await prisma.user.findUnique({ + where: { + email: payload.email, + }, + }) + if (userByEmail && userByEmail.id !== gate.user.id) { + throw new Error("email already in use") + } + } + + if (payload.username) { + const userByUsername = await prisma.user.findUnique({ + where: { + username: payload.username, + }, + }) + if (userByUsername && userByUsername.id !== gate.user.id) { + throw new Error("username already in use") + } + } + + const updated = await prisma.user.update({ + where: { + id: gate.user.id, + }, + data: { + name: payload.name, + avatar: payload.avatar, + username: payload.username, + email: payload.email, + emailVerified: payload.email !== gate.user.email ? null : undefined, + }, + }) + + return { + updated, + } + }, +} diff --git a/app/root.tsx b/app/root.tsx new file mode 100644 index 00000000..fbf832fa --- /dev/null +++ b/app/root.tsx @@ -0,0 +1,168 @@ +import { + json, + type LinksFunction, + type LoaderFunction, + type MetaFunction, +} from "@remix-run/node" +import { + Links, + LiveReload, + Meta, + Outlet, + Scripts, + ScrollRestoration, + useLoaderData, +} from "@remix-run/react" +import LoginModal from "~/components/common/LoginModal" +import { createStore, StoreProvider } from "./lib/store" +import { Toaster } from "react-hot-toast" +import css from "./main.css" +import { getAuthUser } from "./lib/auth.server" +import { getTenant } from "./lib/tenant.server" +import { siteController } from "./controllers/site.controller" +import { getSubscription } from "./models/site.model" +import { APP_NAME } from "./lib/config.shared" +import { SiteLayout } from "./components/site/SiteLayout" +import { MainLayout } from "./components/main/MainLayout" + +export const meta: MetaFunction = () => { + return { + charset: "utf-8", + title: APP_NAME, + viewport: "width=device-width,initial-scale=1", + } +} + +export const links: LinksFunction = () => { + return [{ href: css, rel: "stylesheet", type: "text/css" }] +} + +type LoaderData = + | { + type: "main" + appName: string + isLoggedIn: boolean + ENV: Record + } + | { + type: "tenant" + isLoggedIn: boolean + appName: string + tenant?: string + site: { + id: string + name: string + description: string + icon?: string | null + } + subscription?: { + telegram?: boolean + email?: boolean + } | null + ENV: Record + } + | { + type: "dashboard" + ENV: Record + } + +export const loader: LoaderFunction = async ({ request }) => { + const user = await getAuthUser(request) + const tenant = getTenant(request) + const env = { + APP_NAME: process.env.APP_NAME, + OUR_DOMAIN: process.env.OUR_DOMAIN, + } + + const isLoggedIn = !!user + const url = new URL(request.url) + const isDashboard = + url.pathname === "/dashboard" || url.pathname.startsWith("/dashboard") + + if (tenant) { + if (isDashboard) { + throw new Response("not found", { status: 404 }) + } + + const { site } = await siteController.getSite(tenant) + const subscription = + user && + (await getSubscription({ + siteId: site.id, + userId: user.id, + })) + + return json({ + type: "tenant", + isLoggedIn, + appName: APP_NAME, + tenant, + site: { + id: site.id, + name: site.name, + description: site.description || "", + icon: site.icon, + }, + subscription: subscription?.config, + ENV: env, + }) + } + + if (isDashboard) { + return json({ + type: "dashboard", + ENV: env, + }) + } + + return json({ + type: "main", + isLoggedIn, + appName: APP_NAME, + ENV: env, + }) +} + +export default function App() { + const data = useLoaderData() + + return ( + + + + + + + + {data.type === "tenant" ? ( + + + + ) : data.type === "dashboard" ? ( + + ) : ( + + + + )} + + + + + + +