Some styling fixes, potentially fix building w/ docker

This commit is contained in:
Max Leiter 2022-12-29 13:50:49 -05:00
parent 02695345cd
commit b9ab0df7c0
7 changed files with 52 additions and 23 deletions

View file

@ -21,7 +21,7 @@ const PostFiles = ({ post: _initialPost }: Props) => {
const [post, setPost] = useState<PostWithFilesAndAuthor>(initialPost) const [post, setPost] = useState<PostWithFilesAndAuthor>(initialPost)
const router = useRouter() const router = useRouter()
if (post.expiresAt) { if (post?.expiresAt) {
if (new Date(post.expiresAt) < new Date()) { if (new Date(post.expiresAt) < new Date()) {
router.push("/expired") router.push("/expired")
} }
@ -29,7 +29,7 @@ const PostFiles = ({ post: _initialPost }: Props) => {
useEffect(() => { useEffect(() => {
let interval: NodeJS.Timer | null = null let interval: NodeJS.Timer | null = null
if (post.expiresAt) { if (post?.expiresAt) {
interval = setInterval(() => { interval = setInterval(() => {
const expirationDate = new Date(post.expiresAt ? post.expiresAt : "") const expirationDate = new Date(post.expiresAt ? post.expiresAt : "")
if (expirationDate < new Date()) { if (expirationDate < new Date()) {
@ -41,10 +41,10 @@ const PostFiles = ({ post: _initialPost }: Props) => {
return () => { return () => {
if (interval) clearInterval(interval) if (interval) clearInterval(interval)
} }
}, [post.expiresAt, router]) }, [post?.expiresAt, router])
const isProtected = post.visibility === "protected" const isProtected = post?.visibility === "protected"
const hasFetched = post.files !== undefined const hasFetched = post?.files !== undefined
if (isProtected && !hasFetched) { if (isProtected && !hasFetched) {
return ( return (
<PasswordModalPage <PasswordModalPage
@ -63,7 +63,7 @@ const PostFiles = ({ post: _initialPost }: Props) => {
gap: "var(--gap-double)" gap: "var(--gap-double)"
}} }}
> >
{post.files?.map(({ id, content, title, html }) => ( {post?.files?.map(({ id, content, title, html }) => (
<DocumentComponent <DocumentComponent
skeleton={false} skeleton={false}
key={id} key={id}

View file

@ -21,8 +21,7 @@ const PasswordModalPage = ({ setPost, postId, authorId }: Props) => {
status === "loading" status === "loading"
? undefined ? undefined
: session?.user && session?.user?.id === authorId : session?.user && session?.user?.id === authorId
const [isPasswordModalOpen, setIsPasswordModalOpen] = useState(true) const [isPasswordModalOpen, setIsPasswordModalOpen] = useState(false)
const onSubmit = useCallback(async (password: string) => { const onSubmit = useCallback(async (password: string) => {
const res = await fetch(`/api/post/${postId}?password=${password}`, { const res = await fetch(`/api/post/${postId}?password=${password}`, {
method: "GET", method: "GET",
@ -48,7 +47,7 @@ const PasswordModalPage = ({ setPost, postId, authorId }: Props) => {
}) })
} else { } else {
setIsPasswordModalOpen(false) setIsPasswordModalOpen(false)
setPost(data) setPost(data.post)
} }
} }
}, [postId, setPost, setToast]) }, [postId, setPost, setToast])
@ -66,6 +65,8 @@ const PasswordModalPage = ({ setPost, postId, authorId }: Props) => {
"You're the author of this post, so you automatically have access to it.", "You're the author of this post, so you automatically have access to it.",
type: "default" type: "default"
}) })
} else if (isAuthor === false) {
setIsPasswordModalOpen(true)
} }
}, [isAuthor, onSubmit, setToast]) }, [isAuthor, onSubmit, setToast])

View file

@ -7,6 +7,7 @@ import Button from "@components/button"
import { useToasts } from "@components/toasts" import { useToasts } from "@components/toasts"
import { Spinner } from "@components/spinner" import { Spinner } from "@components/spinner"
import { useSession } from "next-auth/react" import { useSession } from "next-auth/react"
import { useRouter } from "next/navigation"
type Props = { type Props = {
authorId: string authorId: string
@ -22,6 +23,7 @@ const VisibilityControl = ({ authorId, postId, visibility: postVisibility }: Pro
const [isSubmitting, setSubmitting] = useState<string | null>() const [isSubmitting, setSubmitting] = useState<string | null>()
const [passwordModalVisible, setPasswordModalVisible] = useState(false) const [passwordModalVisible, setPasswordModalVisible] = useState(false)
const { setToast } = useToasts() const { setToast } = useToasts()
const router = useRouter();
const sendRequest = useCallback( const sendRequest = useCallback(
async (visibility: string, password?: string) => { async (visibility: string, password?: string) => {
@ -36,6 +38,7 @@ const VisibilityControl = ({ authorId, postId, visibility: postVisibility }: Pro
if (res.ok) { if (res.ok) {
const json = await res.json() const json = await res.json()
setVisibility(json.visibility) setVisibility(json.visibility)
router.refresh()
} else { } else {
setToast({ setToast({
message: "An error occurred", message: "An error occurred",

View file

@ -38,7 +38,7 @@
.header { .header {
transition: opacity 0.2s ease-in-out; transition: opacity 0.2s ease-in-out;
opacity: 0; opacity: .5;
} }
.header:not(.loading) { .header:not(.loading) {
@ -67,6 +67,10 @@
} }
@media only screen and (max-width: 768px) { @media only screen and (max-width: 768px) {
.header {
opacity: 1;
}
.wrapper [data-tab="github"] { .wrapper [data-tab="github"] {
display: none; display: none;
} }

View file

@ -7,3 +7,10 @@
height: auto; height: auto;
margin: 0 auto; margin: 0 auto;
} }
/* 55rem == --main-content */
@media screen and (max-width: 55rem) {
.page {
padding: 0 1rem;
}
}

View file

@ -66,7 +66,7 @@ export default async function Page() {
</Card> </Card>
<div> <div>
<h2>Recent public posts</h2> <h2>Recent public posts</h2>
{/* @ts-ignore because of async RSC */} {/* @ts-expect-error because of async RSC */}
<PublicPostList getPostsPromise={getPostsPromise} /> <PublicPostList getPostsPromise={getPostsPromise} />
</div> </div>
</div> </div>
@ -78,6 +78,7 @@ async function PublicPostList({
}: { }: {
getPostsPromise: Promise<Post[]> getPostsPromise: Promise<Post[]>
}) { }) {
try {
const posts = await getPostsPromise const posts = await getPostsPromise
return ( return (
<PostList <PostList
@ -88,6 +89,17 @@ async function PublicPostList({
hideSearch hideSearch
/> />
) )
} catch (error) {
return (
<PostList
userId={undefined}
morePosts={false}
initialPosts={[]}
hideActions
hideSearch
/>
)
}
} }
export const revalidate = 60 export const revalidate = 60

View file

@ -44,7 +44,8 @@ async function handleGet(req: NextApiRequest, res: NextApiResponse<unknown>) {
// the user can always go directly to their own post // the user can always go directly to their own post
if (session?.user.id === post.authorId) { if (session?.user.id === post.authorId) {
return res.json({ return res.json({
...post post: post,
password: undefined
}) })
} }
@ -58,7 +59,8 @@ async function handleGet(req: NextApiRequest, res: NextApiResponse<unknown>) {
if (hash === post.password) { if (hash === post.password) {
return res.json({ return res.json({
...post post,
password: undefined
}) })
} else { } else {
return res.json({ return res.json({