client: don't flash page after it's expired

This commit is contained in:
Max Leiter 2022-03-30 23:27:09 -07:00
parent 222b020e9a
commit 8291010f26
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: A3512F2F2F17EBDA

View file

@ -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%"}>