1- import React , { useEffect } from "react" ;
1+ import React , { useEffect , useState } from "react" ;
22import PropTypes from "prop-types" ;
3+ import { useRouter } from "next/router" ;
34import Redirects from "js/redirects" ;
45import DesktopFullscreen from "./desktop" ;
5- import useMobile from "hooks/mobileHook" ;
66
77FullscreenPosts . propTypes = {
88 loading : PropTypes . bool ,
@@ -27,18 +27,29 @@ export default function FullscreenPosts({
2727 index,
2828 setIndex,
2929} ) {
30- let isMobile = useMobile ( ) ;
31-
30+ let router = useRouter ( ) ;
31+ let [ initialUrl , setInitialUrl ] = useState ( router . asPath ) ;
32+
33+ const post = posts [ index ] ;
34+ const prevPost = posts [ index - 1 ] ;
35+ const nextPost = posts [ index + 1 ] ;
36+
3237 useEffect ( ( ) => {
3338 const postsRemaining = posts . length - ( index + 1 ) ;
3439 if ( postsRemaining < 32 ) {
3540 morePostsCallback ( ) ;
3641 }
3742 } , [ index , posts , morePostsCallback ] ) ;
3843
39- const post = posts [ index ] ;
40- const prevPost = posts [ index - 1 ] ;
41- const nextPost = posts [ index + 1 ] ;
44+ useEffect ( ( ) => {
45+ let post = posts [ index ] ;
46+ window . history . replaceState ( null , null , Redirects . post ( post . id ) )
47+ } , [ index , posts ] )
48+
49+ function exit ( ) {
50+ window . history . replaceState ( null , null , initialUrl ) ;
51+ exitCallback ( )
52+ }
4253
4354 function visitCallback ( ) {
4455 let link = Redirects . post ( post . id ) ;
@@ -68,7 +79,7 @@ export default function FullscreenPosts({
6879 return (
6980 < DesktopFullscreen
7081 { ...{
71- exitCallback,
82+ exitCallback : exit ,
7283 visitCallback,
7384 nextPostCallback,
7485 prevPostCallback,
0 commit comments