Fix showing password prompt for unauthed protected posts

This commit is contained in:
Max Leiter 2023-01-07 15:42:11 -08:00
parent a6c8c8c825
commit 6b0a6bf3b6
5 changed files with 13 additions and 10 deletions

View file

@ -133,7 +133,6 @@ const Auth = ({
{isGithubEnabled ? ( {isGithubEnabled ? (
<Button <Button
type="submit" type="submit"
buttonType="primary"
width="100%" width="100%"
style={{ style={{
color: "var(--fg)" color: "var(--fg)"

View file

@ -4,7 +4,7 @@ import DocumentComponent from "./view-document"
import { useEffect, useState } from "react" import { useEffect, useState } from "react"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import PasswordModalPage from "./password-modal-wrapper" import PasswordModalWrapper from "./password-modal-wrapper"
import { PostWithFilesAndAuthor } from "@lib/server/prisma" import { PostWithFilesAndAuthor } from "@lib/server/prisma"
type Props = { type Props = {
@ -45,9 +45,10 @@ const PostFiles = ({ post: _initialPost }: Props) => {
const isProtected = post?.visibility === "protected" const isProtected = post?.visibility === "protected"
const hasFetched = post?.files !== undefined const hasFetched = post?.files !== undefined
console.log({ isProtected, hasFetched })
if (isProtected && !hasFetched) { if (isProtected && !hasFetched) {
return ( return (
<PasswordModalPage <PasswordModalWrapper
authorId={post.authorId} authorId={post.authorId}
setPost={setPost} setPost={setPost}
postId={post.id} postId={post.id}

View file

@ -13,7 +13,7 @@ type Props = {
authorId: Post["authorId"] authorId: Post["authorId"]
} }
const PasswordModalPage = ({ setPost, postId, authorId }: Props) => { const PasswordModalWrapper = ({ setPost, postId, authorId }: Props) => {
const router = useRouter() const router = useRouter()
const { setToast } = useToasts() const { setToast } = useToasts()
const { data: session, status } = useSession() const { data: session, status } = useSession()
@ -68,7 +68,7 @@ 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) { } else {
setIsPasswordModalOpen(true) setIsPasswordModalOpen(true)
} }
}, [isAuthor, onSubmit, setToast]) }, [isAuthor, onSubmit, setToast])
@ -83,4 +83,4 @@ const PasswordModalPage = ({ setPost, postId, authorId }: Props) => {
) )
} }
export default PasswordModalPage export default PasswordModalWrapper

View file

@ -5,15 +5,18 @@ const FadeIn = ({
duration = 300, duration = 300,
delay = 0, delay = 0,
children, children,
as,
...delegated ...delegated
}: { }: {
duration?: number duration?: number
delay?: number delay?: number
children: React.ReactNode children: React.ReactNode
as?: React.ElementType
[key: string]: any [key: string]: any
}) => { }) => {
const Element = as || "div"
return ( return (
<div <Element
{...delegated} {...delegated}
className={styles.fadeIn} className={styles.fadeIn}
style={{ style={{
@ -23,7 +26,7 @@ const FadeIn = ({
}} }}
> >
{children} {children}
</div> </Element>
) )
} }

View file

@ -66,8 +66,8 @@ const ListItem = ({
} }
return ( return (
<FadeIn> <FadeIn as="li" key={post.id}>
<li key={post.id}> <li>
<Card style={{ overflowY: "scroll" }}> <Card style={{ overflowY: "scroll" }}>
<> <>
<div className={styles.title}> <div className={styles.title}>