md table styles, expiration post fixes, dont render linenumbers
This commit is contained in:
parent
2b36e3c58e
commit
c31b911c86
12 changed files with 47 additions and 36 deletions
|
@ -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"
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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<HTMLInputElement>) => {
|
||||
setTitle(e.target.value)
|
||||
},
|
||||
[setTitle]
|
||||
)
|
||||
}
|
||||
|
||||
const onChangeDescription = useCallback(
|
||||
const onChangeDescription =
|
||||
(e: ChangeEvent<HTMLInputElement>) => {
|
||||
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)
|
||||
|
|
|
@ -17,6 +17,7 @@ const NewFromExisting = async ({
|
|||
|
||||
const post = await getPostById(id, {
|
||||
withFiles: true,
|
||||
withAuthor: false
|
||||
})
|
||||
|
||||
return <NewPost initialPost={post} newPostParent={id} />
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -22,4 +22,3 @@
|
|||
.token.attr-name {
|
||||
color: var(--name);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@ ${content}
|
|||
contentToRender = "\n" + content
|
||||
}
|
||||
|
||||
const html = markdown(contentToRender)
|
||||
const html = markdown(contentToRender, {
|
||||
showLineNumbers: false
|
||||
})
|
||||
return html
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ async function handlePut(req: NextApiRequest, res: NextApiResponse<any>) {
|
|||
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<any>) {
|
|||
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" })
|
||||
|
|
Loading…
Reference in a new issue