UNPKG

react-garden

Version:

React + TypeScript + ThreeJS app using Material UI on NextJS, Apollo Client, GraphQL + WordPress REST APIs, for ThreeD web development.. a part of the threed.ai code family.

71 lines (63 loc) 1.58 kB
/** * Check for URL queries as well for matching * Current URL & Item Path * * @param item * @param activeItem */ export const handleURLQueries = (router, path) => { if (Object.keys(router.query).length && path) { const arr = Object.keys(router.query) return router.asPath.includes(path) && router.asPath.includes(router.query[arr[0]]) && path !== '/' } return false } /** * Check if the given item has the given url * in one of its children * * @param item * @param currentURL */ export const hasActiveChild = (item, currentURL) => { const { children } = item if (!children) { return false } for (const child of children) { if (child.children) { if (hasActiveChild(child, currentURL)) { return true } } const childPath = child.path // Check if the child has a link and is active if ( child && childPath && currentURL && (childPath === currentURL || (currentURL.includes(childPath) && childPath !== '/')) ) { return true } } return false } /** * Check if this is a children * of the given item * * @param children * @param openGroup * @param currentActiveGroup */ export const removeChildren = (children, openGroup, currentActiveGroup) => { children.forEach(child => { if (!currentActiveGroup.includes(child.title)) { const index = openGroup.indexOf(child.title) if (index > -1) openGroup.splice(index, 1) // @ts-ignore if (child.children) removeChildren(child.children, openGroup, currentActiveGroup) } }) }