client: redirect on page expiration if not author
This commit is contained in:
parent
76e7bb8013
commit
88d14a40b1
2 changed files with 29 additions and 17 deletions
|
@ -30,10 +30,11 @@ const ExpirationBadge = ({
|
||||||
}, [expirationDate])
|
}, [expirationDate])
|
||||||
|
|
||||||
const isExpired = useMemo(() => {
|
const isExpired = useMemo(() => {
|
||||||
return expirationDate && new Date(expirationDate) < new Date()
|
return timeUntilString && timeUntilString === "in 0 seconds"
|
||||||
}, [expirationDate])
|
}, [timeUntilString])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// check if expired every
|
||||||
if (isExpired) {
|
if (isExpired) {
|
||||||
if (onExpires) {
|
if (onExpires) {
|
||||||
onExpires();
|
onExpires();
|
||||||
|
|
|
@ -23,6 +23,32 @@ type Props = {
|
||||||
|
|
||||||
const PostPage = ({ post }: Props) => {
|
const PostPage = ({ post }: Props) => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
|
const isMobile = useMediaQuery("mobile")
|
||||||
|
const [isExpired, setIsExpired] = useState(post.expiresAt ? new Date(post.expiresAt) < new Date() : null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let interval: NodeJS.Timer | null = null;
|
||||||
|
if (post.expiresAt) {
|
||||||
|
interval = setInterval(() => {
|
||||||
|
const expirationDate = new Date(post.expiresAt ? post.expiresAt : "")
|
||||||
|
setIsExpired(expirationDate < new Date())
|
||||||
|
}, 4000)
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
if (interval) clearInterval(interval)
|
||||||
|
}
|
||||||
|
}, [post.expiresAt])
|
||||||
|
|
||||||
|
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
|
||||||
const blob = await downloadZip(post.files.map((file: any) => {
|
const blob = await downloadZip(post.files.map((file: any) => {
|
||||||
|
@ -40,21 +66,6 @@ const PostPage = ({ post }: Props) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const isMobile = useMediaQuery("mobile")
|
|
||||||
|
|
||||||
const isExpired = useMemo(() => {
|
|
||||||
return post.expiresAt && new Date(post.expiresAt) < new Date()
|
|
||||||
}, [post.expiresAt])
|
|
||||||
|
|
||||||
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])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page width={"100%"}>
|
<Page width={"100%"}>
|
||||||
<PageSeo
|
<PageSeo
|
||||||
|
|
Loading…
Reference in a new issue