1+ import { useRouter } from "next/router" ;
12import { useEffect , useState } from "react" ;
23import { compareArrays } from "../../libs/arrayExtensions" ;
34import { getJottings , getLabels , getSharedJottings } from "../../libs/Datastore/requests" ;
4- import { useInterval } from "../../libs/delay" ;
5- import UrlService from "../../libs/UrlService" ;
65import { useWindowSize } from "../../libs/view" ;
76import LabelControl from "./labelControl" ;
87import LabelsControl from "./labelsControl" ;
@@ -16,18 +15,24 @@ export default function JottingsControl(props) {
1615 const [ tasks , setTasks ] = useState ( null ) ;
1716 const [ labels , setLabels ] = useState ( null ) ;
1817
19- const { windowWidth } = useWindowSize ( ) ;
20- const [ activeList , setActiveList ] = useState ( windowWidth < 600 ? 'labels' : 'all' ) ;
18+ const { width } = useWindowSize ( ) ;
19+ const [ activeList , setActiveList ] = useState ( typeof width === 'undefined' || width < 800 ? 'labels' : 'all' ) ;
2120
22- useEffect ( ( ) => {
23- let isCancelled = false ;
24- console . log ( window . location . hash . substring ( 1 ) ) ;
25-
26- if ( ! isCancelled )
27- setActiveList ( window . location . hash . substring ( 1 ) ) ;
28-
29- return ( ) => { isCancelled = true } ;
30- } , [ window ?. location ?. hash ] ) ;
21+ const router = useRouter ( ) ;
22+
23+ useEffect ( ( ) => {
24+ const onHashChangeStart = ( url ) => {
25+ const newHash = url . split ( '#' ) [ 1 ] ;
26+ console . log ( `Path changing to ${ newHash } ` ) ;
27+ setActiveList ( newHash || 'labels' ) ;
28+ } ;
29+
30+ router . events . on ( "hashChangeStart" , onHashChangeStart ) ;
31+
32+ return ( ) => {
33+ router . events . off ( "hashChangeStart" , onHashChangeStart ) ;
34+ } ;
35+ } , [ router . events ] ) ;
3136
3237 const getJotsToShow = ( response , jotType ) => {
3338 if (
0 commit comments