Skip to content

Commit 820ebb3

Browse files
committed
Use nextjs router to fix error (for real)
1 parent b54f674 commit 820ebb3

7 files changed

Lines changed: 24 additions & 18 deletions

File tree

components/JottingsControls/jottingsControl.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import { useRouter } from "next/router";
12
import { useEffect, useState } from "react";
23
import { compareArrays } from "../../libs/arrayExtensions";
34
import { getJottings, getLabels, getSharedJottings } from "../../libs/Datastore/requests";
4-
import { useInterval } from "../../libs/delay";
5-
import UrlService from "../../libs/UrlService";
65
import { useWindowSize } from "../../libs/view";
76
import LabelControl from "./labelControl";
87
import 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 (

components/JottingsControls/jottingsControl.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
}
44

55
.labelList, .ownNoteList, .ownTaskList {
6+
display: none;
67
grid-row: 2;
78
grid-column: 2 / -1;
89
}

components/JottingsControls/labelsControl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { useWindowSize } from "../../libs/view";
1313
* @param props.notesState[0] The value of notes
1414
* @param props.notesState[1] The Dispatch to set a new value to the notes state
1515
*/
16-
export default function LabelsControl({labelsState, active=true}) {
16+
export default function LabelsControl({labelsState, active}) {
1717
const [labels, setLabels] = labelsState;
1818

1919
return (

components/JottingsControls/notesControl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import jottingsControl from "./jottingsControl.module.css";
1212
* @param props.notesState[0] The value of notes
1313
* @param props.notesState[1] The Dispatch to set a new value to the notes state
1414
*/
15-
export default function NotesControl({notesState, active=true}) {
15+
export default function NotesControl({notesState, active}) {
1616
const [notes, setNotes] = notesState;
1717

1818
return (

components/MobileNav/MobileNav.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import Link from "next/link";
44
export default function MobileNav() {
55
return (
66
<nav className={mobileNav.mobileNav}>
7+
<Link href="#labels">Labels</Link>
78
<Link href="#notes">Notes</Link>
89
<Link href="#tasks">Tasks</Link>
9-
<Link href="#labels">Labels</Link>
1010
</nav>
1111
);
1212
}

components/MobileNav/mobileNav.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
padding: 1em;
1010
}
1111

12-
@media screen and (min-width: 830px) {
12+
@media screen and (min-width: 800px) {
1313
.mobileNav {
1414
display: none;
1515
}

pages/Home/home.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010
}
1111

12-
@media only screen and (min-width: 830px) {
12+
@media only screen and (min-width: 800px) {
1313
.main {
1414
grid-template-rows: auto 100px repeat(2, 200px) 30px;
1515
grid-template-columns: 255px repeat(6, 175px);

0 commit comments

Comments
 (0)