client: remove get-post-path and usage of it, fix view parent btn on post page not working due to SSR
This commit is contained in:
parent
683cad2a8d
commit
454ea303a6
6 changed files with 21 additions and 41 deletions
|
@ -17,6 +17,7 @@ const Description = ({ onChange, description }: props) => {
|
|||
label="Description"
|
||||
maxLength={256}
|
||||
width="100%"
|
||||
placeholder="A short description of your post"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
|
|
@ -2,9 +2,7 @@ import {
|
|||
Button,
|
||||
useToasts,
|
||||
ButtonDropdown,
|
||||
Toggle,
|
||||
Input,
|
||||
useClickAway
|
||||
} from "@geist-ui/core"
|
||||
import { useRouter } from "next/router"
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||
|
@ -19,7 +17,6 @@ import type {
|
|||
Document as DocumentType
|
||||
} from "@lib/types"
|
||||
import PasswordModal from "./password-modal"
|
||||
import getPostPath from "@lib/get-post-path"
|
||||
import EditDocumentList from "@components/edit-document-list"
|
||||
import { ChangeEvent } from "react"
|
||||
import DatePicker from "react-datepicker"
|
||||
|
@ -99,7 +96,7 @@ const Post = ({
|
|||
|
||||
if (res.ok) {
|
||||
const json = await res.json()
|
||||
router.push(getPostPath(json.visibility, json.id))
|
||||
router.push(`/post/${json.id}`)
|
||||
} else {
|
||||
const json = await res.json()
|
||||
setToast({
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import NextLink from "next/link"
|
||||
import VisibilityBadge from "../badges/visibility-badge"
|
||||
import getPostPath from "@lib/get-post-path"
|
||||
import {
|
||||
Link,
|
||||
Text,
|
||||
|
@ -36,6 +35,10 @@ const ListItem = ({
|
|||
router.push(`/new/from/${post.id}`)
|
||||
}
|
||||
|
||||
const viewParentClick = () => {
|
||||
router.push(`/post/${post.parent?.id}`)
|
||||
}
|
||||
|
||||
return (
|
||||
<FadeIn>
|
||||
<li key={post.id}>
|
||||
|
@ -44,7 +47,8 @@ const ListItem = ({
|
|||
<Text h3 className={styles.title}>
|
||||
<NextLink
|
||||
passHref={true}
|
||||
href={getPostPath(post.visibility, post.id)}
|
||||
href={`/post/[id]`}
|
||||
as={`/post/${post.id}`}
|
||||
>
|
||||
<Link color marginRight={"var(--gap)"}>
|
||||
{post.title}
|
||||
|
@ -57,14 +61,7 @@ const ListItem = ({
|
|||
<Button
|
||||
auto
|
||||
icon={<Parent />}
|
||||
onClick={() =>
|
||||
router.push(
|
||||
getPostPath(
|
||||
post.parent!.visibility,
|
||||
post.parent!.id
|
||||
)
|
||||
)
|
||||
}
|
||||
onClick={viewParentClick}
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
|
@ -102,9 +99,7 @@ const ListItem = ({
|
|||
<div key={file.id}>
|
||||
<Link
|
||||
color
|
||||
href={`${getPostPath(post.visibility, post.id)}#${
|
||||
file.title
|
||||
}`}
|
||||
href={`/post/${post.id}#${file.title}`}
|
||||
>
|
||||
{file.title || "Untitled file"}
|
||||
</Link>
|
||||
|
|
|
@ -16,7 +16,6 @@ import { useRouter } from "next/router"
|
|||
import ExpirationBadge from "@components/badges/expiration-badge"
|
||||
import CreatedAgoBadge from "@components/badges/created-ago-badge"
|
||||
import Cookies from "js-cookie"
|
||||
import getPostPath from "@lib/get-post-path"
|
||||
import PasswordModalPage from "./password-modal-wrapper"
|
||||
import VisibilityControl from "@components/badges/visibility-control"
|
||||
|
||||
|
@ -86,6 +85,12 @@ const PostPage = ({ post: initialPost, isProtected }: Props) => {
|
|||
router.push(`/new/from/${post.id}`)
|
||||
}
|
||||
|
||||
const viewParentClick = () => {
|
||||
router.push(
|
||||
`/post/${post.parent!.id}`
|
||||
)
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return <></>
|
||||
}
|
||||
|
@ -122,11 +127,7 @@ const PostPage = ({ post: initialPost, isProtected }: Props) => {
|
|||
<Button
|
||||
auto
|
||||
icon={<Parent />}
|
||||
onClick={() =>
|
||||
router.push(
|
||||
getPostPath(post.parent!.visibility, post.parent!.id)
|
||||
)
|
||||
}
|
||||
onClick={viewParentClick}
|
||||
>
|
||||
View Parent
|
||||
</Button>
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
import type { PostVisibility } from "./types"
|
||||
|
||||
export default function getPostPath(visibility: PostVisibility, id: string) {
|
||||
switch (visibility) {
|
||||
case "private":
|
||||
// return `/post/private/${id}`
|
||||
case "protected":
|
||||
// return `/post/protected/${id}`
|
||||
case "unlisted":
|
||||
case "public":
|
||||
return `/post/${id}`
|
||||
default:
|
||||
console.error(`Unknown visibility: ${visibility}`)
|
||||
return `/post/${id}`
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import type { GetServerSideProps, GetStaticPaths, GetStaticProps } from "next"
|
||||
import type { GetServerSideProps } from "next"
|
||||
|
||||
import type { Post } from "@lib/types"
|
||||
import PostPage from "@components/post-page"
|
||||
|
@ -69,9 +69,11 @@ export const getServerSideProps: GetServerSideProps = async ({
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
props: {
|
||||
post: json
|
||||
post: json,
|
||||
key: params?.id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue