From 7ef45c28f06edf60d509abfc21e3ab34d2304d71 Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Sun, 4 Dec 2022 14:49:18 -0800 Subject: [PATCH] Add public post listing to home page --- .../components/file-dropdown/index.tsx | 12 +++- .../[id]/components/header/title/index.tsx | 6 +- .../post-page/view-document/index.tsx | 4 +- client/app/(posts)/post/[id]/page.tsx | 4 +- .../app/(posts)/post/[id]/styles.module.css | 7 +++ client/app/author/[username]/page.tsx | 2 +- client/app/components/home.module.css | 3 - client/app/components/home.tsx | 40 ------------- client/app/components/post-list/index.tsx | 10 ++-- client/app/page.tsx | 60 +++++++++++++++++-- client/next.config.mjs | 14 ++++- client/package.json | 2 +- client/pnpm-lock.yaml | 21 ++++--- 13 files changed, 115 insertions(+), 70 deletions(-) delete mode 100644 client/app/components/home.module.css delete mode 100644 client/app/components/home.tsx diff --git a/client/app/(posts)/components/file-dropdown/index.tsx b/client/app/(posts)/components/file-dropdown/index.tsx index 09d6ba01..add16498 100644 --- a/client/app/(posts)/components/file-dropdown/index.tsx +++ b/client/app/(posts)/components/file-dropdown/index.tsx @@ -19,7 +19,17 @@ const FileDropdown = ({ loading?: boolean }) => { if (loading) { - return + return ( + + +
+ +
+
+
+ ) } const items = files.map((file) => { diff --git a/client/app/(posts)/post/[id]/components/header/title/index.tsx b/client/app/(posts)/post/[id]/components/header/title/index.tsx index b7997037..a6b91d3d 100644 --- a/client/app/(posts)/post/[id]/components/header/title/index.tsx +++ b/client/app/(posts)/post/[id]/components/header/title/index.tsx @@ -26,13 +26,15 @@ export const PostTitle = ({ }: TitleProps) => { return ( -

+

{title}{" "} by{" "} {displayName || "anonymous"} -

+ {!loading && ( {visibility && } diff --git a/client/app/(posts)/post/[id]/components/post-page/view-document/index.tsx b/client/app/(posts)/post/[id]/components/post-page/view-document/index.tsx index 085248e9..8d1f9ecb 100644 --- a/client/app/(posts)/post/[id]/components/post-page/view-document/index.tsx +++ b/client/app/(posts)/post/[id]/components/post-page/view-document/index.tsx @@ -87,12 +87,14 @@ const Document = ({ height={"2rem"} style={{ borderRadius: 0 }} value={title || "Untitled"} + onChange={() => {}} disabled aria-label="Document title" />
- + {/* Not /api/ because of rewrites defined in next.config.mjs */} + +
)} - +
) } diff --git a/client/app/(posts)/post/[id]/styles.module.css b/client/app/(posts)/post/[id]/styles.module.css index 8494b004..a4f083b2 100644 --- a/client/app/(posts)/post/[id]/styles.module.css +++ b/client/app/(posts)/post/[id]/styles.module.css @@ -1,3 +1,10 @@ +.root { + padding-bottom: 200px; + display: flex; + flex-direction: column; + gap: var(--gap); +} + @media screen and (max-width: 900px) { .header { flex-direction: column; diff --git a/client/app/author/[username]/page.tsx b/client/app/author/[username]/page.tsx index 79d9d34b..0008d2a9 100644 --- a/client/app/author/[username]/page.tsx +++ b/client/app/author/[username]/page.tsx @@ -34,7 +34,7 @@ export default async function UserPage({ return ( <> -

{user?.displayName}'s public posts

+

Public posts by {user?.displayName || "Anonymous"}

}> {/* @ts-ignore because TS async JSX support is iffy */} diff --git a/client/app/components/home.module.css b/client/app/components/home.module.css deleted file mode 100644 index d52fd795..00000000 --- a/client/app/components/home.module.css +++ /dev/null @@ -1,3 +0,0 @@ -.textarea { - height: 100%; -} diff --git a/client/app/components/home.tsx b/client/app/components/home.tsx deleted file mode 100644 index 9ecdb5a9..00000000 --- a/client/app/components/home.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import Image from "next/image" -import Card from "./card" -import DocumentTabs from "app/(posts)/components/tabs" -const Home = ({ - introTitle, - introContent, - rendered -}: { - introTitle: string - introContent: string - rendered: string -}) => { - return ( - <> -
- -

{introTitle}

-
- - - - - ) -} - -export default Home diff --git a/client/app/components/post-list/index.tsx b/client/app/components/post-list/index.tsx index e8838c0d..2fabd677 100644 --- a/client/app/components/post-list/index.tsx +++ b/client/app/components/post-list/index.tsx @@ -5,8 +5,6 @@ import ListItem from "./list-item" import { ChangeEvent, useCallback, - useDeferredValue, - useEffect, useState } from "react" import Link from "@components/link" @@ -21,12 +19,14 @@ type Props = { initialPosts: string | PostWithFiles[] morePosts?: boolean userId?: string + hideSearch?: boolean } const PostList = ({ morePosts, initialPosts: initialPostsMaybeJSON, - userId + userId, + hideSearch }: Props) => { const initialPosts = typeof initialPostsMaybeJSON === "string" @@ -108,7 +108,7 @@ const PostList = ({ return (
-
+ {!hideSearch &&
-
+
} {!posts &&

Failed to load.

} {searching && (
    diff --git a/client/app/page.tsx b/client/app/page.tsx index d0eea24c..b8fe4a96 100644 --- a/client/app/page.tsx +++ b/client/app/page.tsx @@ -1,5 +1,9 @@ +import Image from "next/image" +import Card from "@components/card" import { getWelcomeContent } from "pages/api/welcome" -import Home from "./components/home" +import DocumentTabs from "./(posts)/components/tabs" +import { getAllPosts, Post } from "@lib/server/prisma" +import PostList from "@components/post-list" const getWelcomeData = async () => { const welcomeContent = await getWelcomeContent() @@ -8,12 +12,58 @@ const getWelcomeData = async () => { export default async function Page() { const { content, rendered, title } = await getWelcomeData() + const getPostsPromise = getAllPosts({ + where: { visibility: "public" } + }) return ( - +
    + +

    {title}

    +
    + + + +
    +

    Recent public posts

    + {/* @ts-ignore because of async RSC */} + +
    +
+ ) +} + +async function PublicPostList({ + getPostsPromise +}: { + getPostsPromise: Promise +}) { + const posts = await getPostsPromise + return ( + ) } + +export const revalidate = 60 diff --git a/client/next.config.mjs b/client/next.config.mjs index cc3e2d13..8957ef2c 100644 --- a/client/next.config.mjs +++ b/client/next.config.mjs @@ -4,10 +4,22 @@ import bundleAnalyzer from "@next/bundle-analyzer" const nextConfig = { reactStrictMode: true, experimental: { - // outputStandalone: true, // esmExternals: true, appDir: true }, + output: "standalone", + async rewrites() { + return [ + { + source: "/file/raw/:id", + destination: `/api/raw/:id` + }, + { + source: "/home", + destination: "/" + } + ] + } } diff --git a/client/package.json b/client/package.json index 7c0a70d6..b7e2cab1 100644 --- a/client/package.json +++ b/client/package.json @@ -40,7 +40,7 @@ "ts-jest": "^29.0.3" }, "devDependencies": { - "@next/bundle-analyzer": "12.1.6", + "@next/bundle-analyzer": "13.0.7-canary.1", "@types/bcrypt": "^5.0.0", "@types/lodash.debounce": "^4.0.7", "@types/node": "17.0.23", diff --git a/client/pnpm-lock.yaml b/client/pnpm-lock.yaml index 99934ec6..e8adae51 100644 --- a/client/pnpm-lock.yaml +++ b/client/pnpm-lock.yaml @@ -2,7 +2,7 @@ lockfileVersion: 5.4 specifiers: '@next-auth/prisma-adapter': ^1.0.5 - '@next/bundle-analyzer': 12.1.6 + '@next/bundle-analyzer': 13.0.7-canary.1 '@next/eslint-plugin-next': 13.0.5-canary.3 '@prisma/client': ^4.7.1 '@radix-ui/react-dialog': ^1.0.2 @@ -75,7 +75,7 @@ optionalDependencies: sharp: 0.31.2 devDependencies: - '@next/bundle-analyzer': 12.1.6 + '@next/bundle-analyzer': 13.0.7-canary.1 '@types/bcrypt': 5.0.0 '@types/lodash.debounce': 4.0.7 '@types/node': 17.0.23 @@ -799,10 +799,10 @@ packages: next-auth: 4.18.0_ihvxcpofhpc4k2aqfys2drrlkq dev: false - /@next/bundle-analyzer/12.1.6: - resolution: {integrity: sha512-WLydwytAeHoC/neXsiIgK+a6Me12PuSpwopnsZgX5JFNwXQ9MlwPeMGS3aTZkYsv8QmSm0Ns9Yh9FkgLKYaUuQ==} + /@next/bundle-analyzer/13.0.7-canary.1: + resolution: {integrity: sha512-3CKGOK1Fp5mhCQ001h/GIj/ceZa4IfljWAkxRkX4uAOUAyyQ9MNNLNUX9H95/+oO7k2YS/Z71wXRk/xDaxM3Jw==} dependencies: - webpack-bundle-analyzer: 4.3.0 + webpack-bundle-analyzer: 4.7.0 transitivePeerDependencies: - bufferutil - utf-8-validate @@ -2302,6 +2302,11 @@ packages: engines: {node: '>= 6'} dev: true + /commander/7.2.0: + resolution: {integrity: sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==} + engines: {node: '>= 10'} + dev: true + /commander/8.3.0: resolution: {integrity: sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==} engines: {node: '>= 12'} @@ -7181,15 +7186,15 @@ packages: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} dev: false - /webpack-bundle-analyzer/4.3.0: - resolution: {integrity: sha512-J3TPm54bPARx6QG8z4cKBszahnUglcv70+N+8gUqv2I5KOFHJbzBiLx+pAp606so0X004fxM7hqRu10MLjJifA==} + /webpack-bundle-analyzer/4.7.0: + resolution: {integrity: sha512-j9b8ynpJS4K+zfO5GGwsAcQX4ZHpWV+yRiHDiL+bE0XHJ8NiPYLTNVQdlFYWxtpg9lfAQNlwJg16J9AJtFSXRg==} engines: {node: '>= 10.13.0'} hasBin: true dependencies: acorn: 8.8.1 acorn-walk: 8.2.0 chalk: 4.1.2 - commander: 6.2.1 + commander: 7.2.0 gzip-size: 6.0.0 lodash: 4.17.21 opener: 1.5.2