client: don't flash page after it's expired
This commit is contained in:
parent
222b020e9a
commit
8291010f26
1 changed files with 14 additions and 10 deletions
|
@ -26,8 +26,17 @@ const PostPage = ({ post }: Props) => {
|
||||||
|
|
||||||
const isMobile = useMediaQuery("mobile")
|
const isMobile = useMediaQuery("mobile")
|
||||||
const [isExpired, setIsExpired] = useState(post.expiresAt ? new Date(post.expiresAt) < new Date() : null)
|
const [isExpired, setIsExpired] = useState(post.expiresAt ? new Date(post.expiresAt) < new Date() : null)
|
||||||
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const isOwner = post.users ? post.users[0].id === Cookies.get("drift-userid") : false
|
||||||
|
|
||||||
|
const expirationDate = new Date(post.expiresAt ? post.expiresAt : "")
|
||||||
|
if (!isOwner && expirationDate < new Date()) {
|
||||||
|
router.push("/expired")
|
||||||
|
} else {
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
|
||||||
let interval: NodeJS.Timer | null = null;
|
let interval: NodeJS.Timer | null = null;
|
||||||
if (post.expiresAt) {
|
if (post.expiresAt) {
|
||||||
interval = setInterval(() => {
|
interval = setInterval(() => {
|
||||||
|
@ -38,16 +47,8 @@ const PostPage = ({ post }: Props) => {
|
||||||
return () => {
|
return () => {
|
||||||
if (interval) clearInterval(interval)
|
if (interval) clearInterval(interval)
|
||||||
}
|
}
|
||||||
}, [post.expiresAt])
|
}, [post.expiresAt, post.users, router])
|
||||||
|
|
||||||
const onExpires = useCallback(() => {
|
|
||||||
const isOwner = post.users ? post.users[0].id === Cookies.get("drift-userid") : false
|
|
||||||
|
|
||||||
if (isExpired && !isOwner) {
|
|
||||||
router.push("/expired")
|
|
||||||
return <></>
|
|
||||||
}
|
|
||||||
}, [isExpired, post.users, router])
|
|
||||||
|
|
||||||
const download = async () => {
|
const download = async () => {
|
||||||
const downloadZip = (await import("client-zip")).downloadZip
|
const downloadZip = (await import("client-zip")).downloadZip
|
||||||
|
@ -65,6 +66,9 @@ const PostPage = ({ post }: Props) => {
|
||||||
link.remove()
|
link.remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return <></>
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page width={"100%"}>
|
<Page width={"100%"}>
|
||||||
|
|
Loading…
Reference in a new issue