diff --git a/apps/docs/components/DocSearch.tsx b/apps/docs/components/DocSearch.tsx index d8bde374580..38c48a75396 100644 --- a/apps/docs/components/DocSearch.tsx +++ b/apps/docs/components/DocSearch.tsx @@ -1,4 +1,4 @@ -import { useState, useCallback, useRef, createContext, useContext, useEffect } from 'react' +import { useState, useCallback, useRef, createContext, useContext, useEffect, memo } from 'react' import { createPortal } from 'react-dom' import Link from 'next/link' import Head from 'next/head' @@ -16,7 +16,7 @@ const APP_ID = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID const SearchContext = createContext(null) -export function SearchProvider({ children }: any) { +function SearchProviderContent({ children }: any) { const router = useRouter() const [isOpen, setIsOpen] = useState(false) const [initialQuery, setInitialQuery] = useState(null) @@ -114,6 +114,10 @@ export function SearchProvider({ children }: any) { ) } +const SearchProvider = memo(SearchProviderContent) + +export { SearchProvider } + // @ts-ignore function Hit({ hit, children }) { return ( diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx index e40f2e99e53..ba106fdb574 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx @@ -22,7 +22,7 @@ import { flattenSections } from '~/lib/helpers' import NavigationMenuHome from './HomeMenu' // Filter libCommonSections for just the relevant sections in the current library -function generateAllowedClientLibKeys(sections, spec) { +export function generateAllowedClientLibKeys(sections, spec) { // Filter parent sections first const specIds = spec.functions.map((func) => { @@ -198,7 +198,7 @@ const SideNav = () => { active={isReference_Javascript_V1} commonSections={libCommonSections} lib="javascript" - allowedClientKeys={generateAllowedClientLibKeys(libCommonSections, spec_js_v1)} + spec={spec_js_v1} /> */} { active={isReference_Javascript_V2} commonSections={libCommonSections} lib="javascript" - allowedClientKeys={generateAllowedClientLibKeys(libCommonSections, spec_js_v2)} + spec={spec_js_v2} /> {/* { active={isReference_Dart_V0} commonSections={libCommonSections} lib="dart" - allowedClientKeys={generateAllowedClientLibKeys(libCommonSections, spec_dart_v0)} - /> */} - {/* + */} {/* // Tools */} {/* { active={isReference_Cli} commonSections={cliCommonSections} lib="cli" - /> */} - {/* + { active={isReference_Self_Hosting_Auth} commonSections={authServerCommonSections} lib="self-hosting-auth" - /> */} - {/* + */} - {/* + = ({ id, lib, commonSections, - allowedClientKeys, + active, + spec, }) => { // console.log(filterIds) // console.log(modifierIds) @@ -53,12 +43,7 @@ const NavigationMenuRefList: React.FC = ({ !active ? 'opacity-0 invisible absolute h-0 overflow-hidden' : '', ].join(' ')} > - + ) } diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx index bda02438afc..a0d45213e4f 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx @@ -13,6 +13,7 @@ import RevVersionDropdown from '~/components/RefVersionDropdown' import { RefIdOptions, RefKeyOptions } from './NavigationMenu' import React from 'react' +import { generateAllowedClientLibKeys } from '~/lib/refGenerator/helpers' const FunctionLink = ({ title, @@ -80,17 +81,15 @@ interface INavigationMenuRefList { // the keys of menu items that are allowed to be shown on the side menu // if undefined, we show all the menu items allowedClientKeys?: string[] + spec?: any } -const Content: React.FC = ({ - id, - lib, - commonSections, - allowedClientKeys, -}) => { +const Content: React.FC = ({ id, lib, commonSections, spec }) => { const router = useRouter() const { isDarkMode } = useTheme() + const allowedClientKeys = spec ? generateAllowedClientLibKeys(commonSections, spec) : undefined + console.log( id && 'id changed', lib && 'lib changed', diff --git a/apps/docs/lib/refGenerator/helpers.ts b/apps/docs/lib/refGenerator/helpers.ts index ed8f18f5e4e..db1bccd25dc 100644 --- a/apps/docs/lib/refGenerator/helpers.ts +++ b/apps/docs/lib/refGenerator/helpers.ts @@ -2,6 +2,7 @@ import { TsDoc } from '~/generator/legacy/definitions' import { values, mapValues } from 'lodash' import { OpenAPIV3 } from 'openapi-types' +import { flattenSections } from '../helpers' export function extractTsDocNode(nodeToFind: string, definition: any) { const nodePath = nodeToFind.split('.') @@ -283,3 +284,23 @@ export const toArrayWithKey = (obj: object, keyAs: string) => return value }) ) + +export function generateAllowedClientLibKeys(sections, spec) { + // Filter parent sections first + + const specIds = spec.functions.map((func) => { + return func.id + }) + + const newShape = flattenSections(sections).filter((section) => { + if (specIds.includes(section.id)) { + return section + } + }) + + const final = newShape.map((func) => { + return func.id + }) + + return final +}