Skip to content

Commit

Permalink
Updated URL for fullscreen posts
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Brady committed Sep 12, 2022
1 parent 7b56f86 commit dd623cb
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/components/FullscreenPosts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useEffect } from "react";
import React, { useEffect, useState } from "react";
import PropTypes from "prop-types";
import { useRouter } from "next/router";
import Redirects from "js/redirects";
import DesktopFullscreen from "./desktop";
import useMobile from "hooks/mobileHook";

FullscreenPosts.propTypes = {
loading: PropTypes.bool,
Expand All @@ -27,18 +27,29 @@ export default function FullscreenPosts({
index,
setIndex,
}) {
let isMobile = useMobile();

let router = useRouter();
let [initialUrl, setInitialUrl] = useState(router.asPath);

const post = posts[index];
const prevPost = posts[index - 1];
const nextPost = posts[index + 1];

useEffect(() => {
const postsRemaining = posts.length - (index + 1);
if (postsRemaining < 32) {
morePostsCallback();
}
}, [index, posts, morePostsCallback]);

const post = posts[index];
const prevPost = posts[index - 1];
const nextPost = posts[index + 1];
useEffect(() => {
let post = posts[index];
window.history.replaceState(null,null, Redirects.post(post.id))
}, [index, posts])

function exit() {
window.history.replaceState(null, null, initialUrl);
exitCallback()
}

function visitCallback() {
let link = Redirects.post(post.id);
Expand Down Expand Up @@ -68,7 +79,7 @@ export default function FullscreenPosts({
return (
<DesktopFullscreen
{...{
exitCallback,
exitCallback: exit,
visitCallback,
nextPostCallback,
prevPostCallback,
Expand Down

1 comment on commit dd623cb

@vercel
Copy link

@vercel vercel bot commented on dd623cb Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.