md table styles, expiration post fixes, dont render linenumbers

This commit is contained in:
Max Leiter 2022-11-14 17:24:35 -08:00
parent 2b36e3c58e
commit c31b911c86
12 changed files with 47 additions and 36 deletions

View file

@ -1,4 +1,4 @@
import { File } from "@lib/types" import { File } from "@lib/server/prisma"
import FileIcon from "@geist-ui/icons/fileText" import FileIcon from "@geist-ui/icons/fileText"
import CodeIcon from "@geist-ui/icons/fileLambda" import CodeIcon from "@geist-ui/icons/fileLambda"
import styles from "./file-tree.module.css" import styles from "./file-tree.module.css"

View file

@ -2,7 +2,6 @@ import { memo, useEffect, useState } from "react"
import styles from "./preview.module.css" import styles from "./preview.module.css"
import "@styles/markdown.css" import "@styles/markdown.css"
import "@styles/syntax.css" import "@styles/syntax.css"
import Skeleton from "@components/skeleton"
import { Spinner } from "@geist-ui/core/dist" import { Spinner } from "@geist-ui/core/dist"
type Props = { type Props = {

View file

@ -1,8 +1,6 @@
import { Text, useMediaQuery, useTheme, useToasts } from "@geist-ui/core/dist" import { Text, useMediaQuery, useTheme, useToasts } from "@geist-ui/core/dist"
import { memo } from "react"
import { useDropzone } from "react-dropzone" import { useDropzone } from "react-dropzone"
import styles from "./drag-and-drop.module.css" import styles from "./drag-and-drop.module.css"
import type { Document } from "@lib/types"
import generateUUID from "@lib/generate-uuid" import generateUUID from "@lib/generate-uuid"
import { import {
allowedFileTypes, allowedFileTypes,
@ -10,6 +8,7 @@ import {
allowedFileExtensions allowedFileExtensions
} from "@lib/constants" } from "@lib/constants"
import byteToMB from "@lib/byte-to-mb" import byteToMB from "@lib/byte-to-mb"
import type { Document } from "../new"
function FileDropzone({ setDocs }: { setDocs: (docs: Document[]) => void }) { function FileDropzone({ setDocs }: { setDocs: (docs: Document[]) => void }) {
const { palette } = useTheme() const { palette } = useTheme()

View file

@ -1,4 +1,4 @@
import type { Document } from "@lib/types" import type { Document } from "../new"
import DocumentComponent from "./edit-document" import DocumentComponent from "./edit-document"
import { ChangeEvent, memo, useCallback } from "react" import { ChangeEvent, memo, useCallback } from "react"

View file

@ -5,7 +5,6 @@ import { useRouter } from "next/navigation"
import { useCallback, useState } from "react" import { useCallback, useState } from "react"
import generateUUID from "@lib/generate-uuid" import generateUUID from "@lib/generate-uuid"
import styles from "./post.module.css" import styles from "./post.module.css"
import type { PostVisibility, Document as DocumentType } from "@lib/types"
import EditDocumentList from "./edit-document-list" import EditDocumentList from "./edit-document-list"
import { ChangeEvent } from "react" import { ChangeEvent } from "react"
import DatePicker from "react-datepicker" import DatePicker from "react-datepicker"
@ -21,6 +20,12 @@ const emptyDoc = {
id: generateUUID() id: generateUUID()
} }
export type Document = {
title: string
content: string
id: string
}
const Post = ({ const Post = ({
initialPost, initialPost,
newPostParent newPostParent
@ -36,7 +41,7 @@ const Post = ({
const [description, setDescription] = useState(initialPost?.description || "") const [description, setDescription] = useState(initialPost?.description || "")
const [expiresAt, setExpiresAt] = useState(initialPost?.expiresAt) const [expiresAt, setExpiresAt] = useState(initialPost?.expiresAt)
const defaultDocs: DocumentType[] = initialPost const defaultDocs: Document[] = initialPost
? initialPost.files?.map((doc) => ({ ? initialPost.files?.map((doc) => ({
title: doc.title, title: doc.title,
content: doc.content, content: doc.content,
@ -53,9 +58,9 @@ const Post = ({
url: string, url: string,
data: { data: {
expiresAt: Date | null expiresAt: Date | null
visibility?: PostVisibility visibility?: string
title?: string title?: string
files?: DocumentType[] files?: Document[]
password?: string password?: string
parentId?: string parentId?: string
} }
@ -93,7 +98,7 @@ const Post = ({
const [isSubmitting, setSubmitting] = useState(false) const [isSubmitting, setSubmitting] = useState(false)
const onSubmit = useCallback( const onSubmit = useCallback(
async (visibility: PostVisibility, password?: string) => { async (visibility: string, password?: string) => {
if (visibility === "protected" && !password) { if (visibility === "protected" && !password) {
setPasswordModalVisible(true) setPasswordModalVisible(true)
return return
@ -155,30 +160,23 @@ const Post = ({
const submitPassword = (password: string) => onSubmit("protected", password) 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<HTMLInputElement>) => { (e: ChangeEvent<HTMLInputElement>) => {
setTitle(e.target.value) setTitle(e.target.value)
}, }
[setTitle]
)
const onChangeDescription = useCallback( const onChangeDescription =
(e: ChangeEvent<HTMLInputElement>) => { (e: ChangeEvent<HTMLInputElement>) => {
setDescription(e.target.value) setDescription(e.target.value)
}, }
[setDescription]
)
const updateDocTitle = useCallback( const updateDocTitle = (i: number) => (title: string) => {
(i: number) => (title: string) => {
setDocs((docs) => setDocs((docs) =>
docs.map((doc, index) => (i === index ? { ...doc, title } : doc)) docs.map((doc, index) => (i === index ? { ...doc, title } : doc))
) )
}, }
[setDocs]
)
const updateDocContent = (i: number) => (content: string) => { const updateDocContent = (i: number) => (content: string) => {
setDocs((docs) => setDocs((docs) =>
@ -190,7 +188,7 @@ const Post = ({
setDocs((docs) => docs.filter((_, index) => i !== index)) 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, // if no title is set and the only document is empty,
const isFirstDocEmpty = const isFirstDocEmpty =
docs.length <= 1 && (docs.length ? docs[0].title === "" : true) docs.length <= 1 && (docs.length ? docs[0].title === "" : true)

View file

@ -17,6 +17,7 @@ const NewFromExisting = async ({
const post = await getPostById(id, { const post = await getPostById(id, {
withFiles: true, withFiles: true,
withAuthor: false
}) })
return <NewPost initialPost={post} newPostParent={id} /> return <NewPost initialPost={post} newPostParent={id} />

View file

@ -1,12 +1,12 @@
import { useToasts } from "@geist-ui/core/dist" 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 PasswordModal from "@components/password-modal"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import { useState } from "react" import { useState } from "react"
type Props = { type Props = {
setPost: (post: PostWithFiles) => void setPost: (post: PostWithFilesAndAuthor) => void
postId: PostWithFiles["id"] postId: Post["id"]
} }
const PasswordModalPage = ({ setPost, postId }: Props) => { const PasswordModalPage = ({ setPost, postId }: Props) => {

View file

@ -1,7 +1,6 @@
import type { Post } from "@lib/types"
import PostPage from "app/(posts)/post/[id]/components/post-page" import PostPage from "app/(posts)/post/[id]/components/post-page"
import { notFound } from "next/navigation" 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" import { getCurrentUser } from "@lib/server/session"
export type PostProps = { export type PostProps = {
@ -24,7 +23,7 @@ export type PostProps = {
const getPost = async (id: string) => { const getPost = async (id: string) => {
const post = await getPostById(id, { const post = await getPostById(id, {
withFiles: true, withFiles: true,
withAuthor: true, withAuthor: true
}) })
const user = await getCurrentUser() const user = await getCurrentUser()
@ -58,7 +57,6 @@ const getPost = async (id: string) => {
} }
} }
// if expired // if expired
if (post.expiresAt && !isAuthorOrAdmin) { if (post.expiresAt && !isAuthorOrAdmin) {
const expirationDate = new Date(post.expiresAt) const expirationDate = new Date(post.expiresAt)

View file

@ -113,3 +113,18 @@ article pre {
padding: 1rem; padding: 1rem;
font-size: 0.875rem; 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);
}

View file

@ -22,4 +22,3 @@
.token.attr-name { .token.attr-name {
color: var(--name); color: var(--name);
} }

View file

@ -36,6 +36,8 @@ ${content}
contentToRender = "\n" + content contentToRender = "\n" + content
} }
const html = markdown(contentToRender) const html = markdown(contentToRender, {
showLineNumbers: false
})
return html return html
} }

View file

@ -79,7 +79,7 @@ async function handlePut(req: NextApiRequest, res: NextApiResponse<any>) {
return res.status(400).json({ error: "Missing id" }) return res.status(400).json({ error: "Missing id" })
} }
const post = await getPostById(id, false) const post = await getPostById(id)
if (!post) { if (!post) {
return res.status(404).json({ message: "Post not found" }) return res.status(404).json({ message: "Post not found" })
@ -126,7 +126,7 @@ async function handleDelete(req: NextApiRequest, res: NextApiResponse<any>) {
return res.status(400).json({ error: "Missing id" }) return res.status(400).json({ error: "Missing id" })
} }
const post = await getPostById(id, false) const post = await getPostById(id)
if (!post) { if (!post) {
return res.status(404).json({ message: "Post not found" }) return res.status(404).json({ message: "Post not found" })