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 { useWindowSize } from "../../libs/view " ;
56import LabelControl from "./labelControl" ;
67import LabelsControl from "./labelsControl" ;
78import NoteControl from "./noteControl" ;
@@ -14,6 +15,24 @@ export default function JottingsControl(props) {
1415 const [ tasks , setTasks ] = useState ( null ) ;
1516 const [ labels , setLabels ] = useState ( null ) ;
1617
18+ const { width } = useWindowSize ( ) ;
19+ const [ activeList , setActiveList ] = useState ( 'labels' ) ;
20+
21+ const router = useRouter ( ) ;
22+
23+ useEffect ( ( ) => {
24+ if ( width >= 800 ) {
25+ setActiveList ( 'all' ) ;
26+ } else {
27+ setActiveList ( 'labels' ) ;
28+ }
29+ } , [ width ] ) ;
30+
31+ useEffect ( ( ) => {
32+ setActiveList ( router . query . list || 'labels' ) ;
33+
34+ } , [ router . query ] ) ;
35+
1736 const getJotsToShow = ( response , jotType ) => {
1837 if (
1938 response [ 1 ] . status === "rejected" &&
@@ -92,15 +111,15 @@ export default function JottingsControl(props) {
92111 makeJottingsRequests ( ) ;
93112 } , [ ] ) ;
94113
95- return (
96- < >
97- < LabelsControl labelsState = { [ labels , setLabels ] } />
98- < NotesControl notesState = { [ notes , setNotes ] } />
99- < TasksControl tasksState = { [ tasks , setTasks ] } />
100-
101- < NoteControl notes = { notes } />
102- < TaskControl tasks = { tasks } />
103- < LabelControl labels = { labels } />
104- </ >
105- ) ;
114+ return (
115+ < >
116+ < LabelsControl active = { [ 'labels' , 'all' ] . includes ( activeList ) } labelsState = { [ labels , setLabels ] } />
117+ < NotesControl active = { [ 'notes' , 'all' ] . includes ( activeList ) } notesState = { [ notes , setNotes ] } />
118+ < TasksControl active = { [ 'tasks' , 'all' ] . includes ( activeList ) } tasksState = { [ tasks , setTasks ] } />
119+
120+ < NoteControl notes = { notes } />
121+ < TaskControl tasks = { tasks } />
122+ < LabelControl labels = { labels } />
123+ </ >
124+ ) ;
106125}
0 commit comments