docs: support multiple sidebars in a project (#11768)
* changed to new sidebar across projects except resources * finalize multi sidebar support * clean up * remove redundant property * small changes * fixes * generate * fix error * fix initial open
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import { ExpandedDocument, SecuritySchemeObject } from "@/types/openapi"
|
||||
import { ReactNode, createContext, useContext, useEffect, useMemo } from "react"
|
||||
import { SidebarItem, SidebarItemSections } from "types"
|
||||
import { Sidebar } from "types"
|
||||
import getSectionId from "../utils/get-section-id"
|
||||
import getTagChildSidebarItems from "../utils/get-tag-child-sidebar-items"
|
||||
import { useRouter } from "next/navigation"
|
||||
@@ -22,7 +22,8 @@ type BaseSpecsProviderProps = {
|
||||
|
||||
const BaseSpecsProvider = ({ children, baseSpecs }: BaseSpecsProviderProps) => {
|
||||
const router = useRouter()
|
||||
const { activePath, addItems, setActivePath, resetItems } = useSidebar()
|
||||
const { activePath, addItems, setActivePath, resetItems, shownSidebar } =
|
||||
useSidebar()
|
||||
|
||||
const getSecuritySchema = (
|
||||
securityName: string
|
||||
@@ -48,7 +49,7 @@ const BaseSpecsProvider = ({ children, baseSpecs }: BaseSpecsProviderProps) => {
|
||||
return []
|
||||
}
|
||||
|
||||
const itemsToAdd: SidebarItem[] = [
|
||||
const itemsToAdd: Sidebar.SidebarItem[] = [
|
||||
{
|
||||
type: "separator",
|
||||
},
|
||||
@@ -67,6 +68,7 @@ const BaseSpecsProvider = ({ children, baseSpecs }: BaseSpecsProviderProps) => {
|
||||
children: childItems,
|
||||
loaded: childItems.length > 0,
|
||||
showLoadingIfEmpty: true,
|
||||
initialOpen: false,
|
||||
onOpen: () => {
|
||||
if (location.hash !== tagPathName) {
|
||||
router.push(`#${tagPathName}`, {
|
||||
@@ -84,14 +86,14 @@ const BaseSpecsProvider = ({ children, baseSpecs }: BaseSpecsProviderProps) => {
|
||||
}, [baseSpecs])
|
||||
|
||||
useEffect(() => {
|
||||
if (!itemsToAdd.length) {
|
||||
if (!itemsToAdd.length || !shownSidebar) {
|
||||
return
|
||||
}
|
||||
|
||||
addItems(itemsToAdd, {
|
||||
section: SidebarItemSections.DEFAULT,
|
||||
sidebar_id: shownSidebar.sidebar_id,
|
||||
})
|
||||
}, [itemsToAdd])
|
||||
}, [itemsToAdd, shownSidebar?.sidebar_id])
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
|
||||
Reference in New Issue
Block a user