diff --git a/client/app/(posts)/components/file-tree/index.tsx b/client/app/(posts)/components/file-tree/index.tsx index c6cf04e1..79ea376d 100644 --- a/client/app/(posts)/components/file-tree/index.tsx +++ b/client/app/(posts)/components/file-tree/index.tsx @@ -1,4 +1,4 @@ -import { File } from "@lib/types" +import { File } from "@lib/server/prisma" import FileIcon from "@geist-ui/icons/fileText" import CodeIcon from "@geist-ui/icons/fileLambda" import styles from "./file-tree.module.css" diff --git a/client/app/(posts)/components/preview/index.tsx b/client/app/(posts)/components/preview/index.tsx index 7eb8a0d3..d9a30610 100644 --- a/client/app/(posts)/components/preview/index.tsx +++ b/client/app/(posts)/components/preview/index.tsx @@ -2,7 +2,6 @@ import { memo, useEffect, useState } from "react" import styles from "./preview.module.css" import "@styles/markdown.css" import "@styles/syntax.css" -import Skeleton from "@components/skeleton" import { Spinner } from "@geist-ui/core/dist" type Props = { diff --git a/client/app/(posts)/new/components/drag-and-drop/index.tsx b/client/app/(posts)/new/components/drag-and-drop/index.tsx index 85654b12..6a77cd60 100644 --- a/client/app/(posts)/new/components/drag-and-drop/index.tsx +++ b/client/app/(posts)/new/components/drag-and-drop/index.tsx @@ -1,8 +1,6 @@ import { Text, useMediaQuery, useTheme, useToasts } from "@geist-ui/core/dist" -import { memo } from "react" import { useDropzone } from "react-dropzone" import styles from "./drag-and-drop.module.css" -import type { Document } from "@lib/types" import generateUUID from "@lib/generate-uuid" import { allowedFileTypes, @@ -10,6 +8,7 @@ import { allowedFileExtensions } from "@lib/constants" import byteToMB from "@lib/byte-to-mb" +import type { Document } from "../new" function FileDropzone({ setDocs }: { setDocs: (docs: Document[]) => void }) { const { palette } = useTheme() diff --git a/client/app/(posts)/new/components/edit-document-list/index.tsx b/client/app/(posts)/new/components/edit-document-list/index.tsx index d51b8cb3..55af34b3 100644 --- a/client/app/(posts)/new/components/edit-document-list/index.tsx +++ b/client/app/(posts)/new/components/edit-document-list/index.tsx @@ -1,4 +1,4 @@ -import type { Document } from "@lib/types" +import type { Document } from "../new" import DocumentComponent from "./edit-document" import { ChangeEvent, memo, useCallback } from "react" diff --git a/client/app/(posts)/new/components/new.tsx b/client/app/(posts)/new/components/new.tsx index 4150ef94..ccfe277e 100644 --- a/client/app/(posts)/new/components/new.tsx +++ b/client/app/(posts)/new/components/new.tsx @@ -5,7 +5,6 @@ import { useRouter } from "next/navigation" import { useCallback, useState } from "react" import generateUUID from "@lib/generate-uuid" import styles from "./post.module.css" -import type { PostVisibility, Document as DocumentType } from "@lib/types" import EditDocumentList from "./edit-document-list" import { ChangeEvent } from "react" import DatePicker from "react-datepicker" @@ -21,6 +20,12 @@ const emptyDoc = { id: generateUUID() } +export type Document = { + title: string + content: string + id: string +} + const Post = ({ initialPost, newPostParent @@ -36,7 +41,7 @@ const Post = ({ const [description, setDescription] = useState(initialPost?.description || "") const [expiresAt, setExpiresAt] = useState(initialPost?.expiresAt) - const defaultDocs: DocumentType[] = initialPost + const defaultDocs: Document[] = initialPost ? initialPost.files?.map((doc) => ({ title: doc.title, content: doc.content, @@ -53,9 +58,9 @@ const Post = ({ url: string, data: { expiresAt: Date | null - visibility?: PostVisibility + visibility?: string title?: string - files?: DocumentType[] + files?: Document[] password?: string parentId?: string } @@ -93,7 +98,7 @@ const Post = ({ const [isSubmitting, setSubmitting] = useState(false) const onSubmit = useCallback( - async (visibility: PostVisibility, password?: string) => { + async (visibility: string, password?: string) => { if (visibility === "protected" && !password) { setPasswordModalVisible(true) return @@ -155,30 +160,23 @@ const Post = ({ const submitPassword = (password: string) => onSubmit("protected", password) - const onChangeExpiration = useCallback((date: Date) => setExpiresAt(date), []) + const onChangeExpiration = (date: Date) => setExpiresAt(date) - const onChangeTitle = useCallback( + const onChangeTitle = (e: ChangeEvent) => { setTitle(e.target.value) - }, - [setTitle] - ) + } - const onChangeDescription = useCallback( + const onChangeDescription = (e: ChangeEvent) => { setDescription(e.target.value) - }, - [setDescription] - ) + } - const updateDocTitle = useCallback( - (i: number) => (title: string) => { + const updateDocTitle = (i: number) => (title: string) => { setDocs((docs) => docs.map((doc, index) => (i === index ? { ...doc, title } : doc)) ) - }, - [setDocs] - ) + } const updateDocContent = (i: number) => (content: string) => { setDocs((docs) => @@ -190,7 +188,7 @@ const Post = ({ setDocs((docs) => docs.filter((_, index) => i !== index)) } - const uploadDocs = (files: DocumentType[]) => { + const uploadDocs = (files: Document[]) => { // if no title is set and the only document is empty, const isFirstDocEmpty = docs.length <= 1 && (docs.length ? docs[0].title === "" : true) diff --git a/client/app/(posts)/new/from/[id]/page.tsx b/client/app/(posts)/new/from/[id]/page.tsx index f9c16f59..fb782c65 100644 --- a/client/app/(posts)/new/from/[id]/page.tsx +++ b/client/app/(posts)/new/from/[id]/page.tsx @@ -17,6 +17,7 @@ const NewFromExisting = async ({ const post = await getPostById(id, { withFiles: true, + withAuthor: false }) return diff --git a/client/app/(posts)/post/[id]/components/post-page/password-modal-wrapper.tsx b/client/app/(posts)/post/[id]/components/post-page/password-modal-wrapper.tsx index 905ce89f..2bb962c8 100644 --- a/client/app/(posts)/post/[id]/components/post-page/password-modal-wrapper.tsx +++ b/client/app/(posts)/post/[id]/components/post-page/password-modal-wrapper.tsx @@ -1,12 +1,12 @@ import { useToasts } from "@geist-ui/core/dist" -import { PostWithFiles } from "@lib/server/prisma" +import { Post, PostWithFilesAndAuthor } from "@lib/server/prisma" import PasswordModal from "@components/password-modal" import { useRouter } from "next/navigation" import { useState } from "react" type Props = { - setPost: (post: PostWithFiles) => void - postId: PostWithFiles["id"] + setPost: (post: PostWithFilesAndAuthor) => void + postId: Post["id"] } const PasswordModalPage = ({ setPost, postId }: Props) => { diff --git a/client/app/(posts)/post/[id]/page.tsx b/client/app/(posts)/post/[id]/page.tsx index e559c3a3..64cce68d 100644 --- a/client/app/(posts)/post/[id]/page.tsx +++ b/client/app/(posts)/post/[id]/page.tsx @@ -1,7 +1,6 @@ -import type { Post } from "@lib/types" import PostPage from "app/(posts)/post/[id]/components/post-page" import { notFound } from "next/navigation" -import { getAllPosts, getPostById } from "@lib/server/prisma" +import { getPostById, Post } from "@lib/server/prisma" import { getCurrentUser } from "@lib/server/session" export type PostProps = { @@ -24,7 +23,7 @@ export type PostProps = { const getPost = async (id: string) => { const post = await getPostById(id, { withFiles: true, - withAuthor: true, + withAuthor: true }) const user = await getCurrentUser() @@ -58,7 +57,6 @@ const getPost = async (id: string) => { } } - // if expired if (post.expiresAt && !isAuthorOrAdmin) { const expirationDate = new Date(post.expiresAt) diff --git a/client/app/styles/markdown.css b/client/app/styles/markdown.css index 89bc9fd1..5fe3c20d 100644 --- a/client/app/styles/markdown.css +++ b/client/app/styles/markdown.css @@ -113,3 +113,18 @@ article pre { padding: 1rem; font-size: 0.875rem; } + + +table { + border-collapse: collapse; +} + +table th { + font-weight: 500; +} + +table th, +table td { + padding: 0.5rem 1rem; + border: 1px solid var(--light-gray); +} diff --git a/client/app/styles/syntax.css b/client/app/styles/syntax.css index 77fbcf56..7765e289 100644 --- a/client/app/styles/syntax.css +++ b/client/app/styles/syntax.css @@ -22,4 +22,3 @@ .token.attr-name { color: var(--name); } - diff --git a/client/lib/server/get-html-from-drift-file.ts b/client/lib/server/get-html-from-drift-file.ts index 111a29b6..f3558ae3 100644 --- a/client/lib/server/get-html-from-drift-file.ts +++ b/client/lib/server/get-html-from-drift-file.ts @@ -36,6 +36,8 @@ ${content} contentToRender = "\n" + content } - const html = markdown(contentToRender) + const html = markdown(contentToRender, { + showLineNumbers: false + }) return html } diff --git a/client/pages/api/post/[id].ts b/client/pages/api/post/[id].ts index 3a99f239..5a90191b 100644 --- a/client/pages/api/post/[id].ts +++ b/client/pages/api/post/[id].ts @@ -79,7 +79,7 @@ async function handlePut(req: NextApiRequest, res: NextApiResponse) { return res.status(400).json({ error: "Missing id" }) } - const post = await getPostById(id, false) + const post = await getPostById(id) if (!post) { return res.status(404).json({ message: "Post not found" }) @@ -126,7 +126,7 @@ async function handleDelete(req: NextApiRequest, res: NextApiResponse) { return res.status(400).json({ error: "Missing id" }) } - const post = await getPostById(id, false) + const post = await getPostById(id) if (!post) { return res.status(404).json({ message: "Post not found" })