Skip to content
Snippets Groups Projects
Unverified Commit 36c5cd16 authored by Sean Hatfield's avatar Sean Hatfield Committed by GitHub
Browse files

[REFACTOR] Refactor window path location for settings sidebar (#1856)

use useLocation hook instead of href for window location
parent 2f620163
No related branches found
No related tags found
No related merge requests found
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { CaretRight } from "@phosphor-icons/react"; import { CaretRight } from "@phosphor-icons/react";
import { Link } from "react-router-dom"; import { Link, useLocation } from "react-router-dom";
export default function MenuOption({ export default function MenuOption({
btnText, btnText,
...@@ -14,14 +14,14 @@ export default function MenuOption({ ...@@ -14,14 +14,14 @@ export default function MenuOption({
isChild = false, isChild = false,
}) { }) {
const storageKey = generateStorageKey({ key: btnText }); const storageKey = generateStorageKey({ key: btnText });
const location = window.location.pathname; const location = useLocation();
const hasChildren = childOptions.length > 0; const hasChildren = childOptions.length > 0;
const hasVisibleChildren = hasVisibleOptions(user, childOptions); const hasVisibleChildren = hasVisibleOptions(user, childOptions);
const { isExpanded, setIsExpanded } = useIsExpanded({ const { isExpanded, setIsExpanded } = useIsExpanded({
storageKey, storageKey,
hasVisibleChildren, hasVisibleChildren,
childOptions, childOptions,
location, location: location.pathname,
}); });
if (hidden) return null; if (hidden) return null;
...@@ -43,9 +43,10 @@ export default function MenuOption({ ...@@ -43,9 +43,10 @@ export default function MenuOption({
} }
const isActive = hasChildren const isActive = hasChildren
? (!isExpanded && childOptions.some((child) => child.href === location)) || ? (!isExpanded &&
location === href childOptions.some((child) => child.href === location.pathname)) ||
: location === href; location.pathname === href
: location.pathname === href;
const handleClick = (e) => { const handleClick = (e) => {
if (hasChildren) { if (hasChildren) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment