docs: fix search in api reference (#6578)
* docs: fix search in api reference * remove log messages
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
export * from "./use-copy"
|
export * from "./use-copy"
|
||||||
|
export * from "./use-is-browser"
|
||||||
export * from "./use-keyboard-shortcut"
|
export * from "./use-keyboard-shortcut"
|
||||||
export * from "./use-scroll-utils"
|
export * from "./use-scroll-utils"
|
||||||
export * from "./use-search-navigation"
|
export * from "./use-search-navigation"
|
||||||
|
|||||||
13
www/packages/docs-ui/src/hooks/use-is-browser/index.ts
Normal file
13
www/packages/docs-ui/src/hooks/use-is-browser/index.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
|
||||||
|
export const useIsBrowser = () => {
|
||||||
|
const [isBrowser, setIsBrowser] = useState(false)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setIsBrowser(typeof window !== "undefined")
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return isBrowser
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import React, {
|
|||||||
} from "react"
|
} from "react"
|
||||||
import { usePathname } from "next/navigation"
|
import { usePathname } from "next/navigation"
|
||||||
import { getScrolledTop } from "../../utils"
|
import { getScrolledTop } from "../../utils"
|
||||||
|
import { useIsBrowser } from "../../hooks"
|
||||||
|
|
||||||
export enum SidebarItemSections {
|
export enum SidebarItemSections {
|
||||||
TOP = "top",
|
TOP = "top",
|
||||||
@@ -179,6 +180,7 @@ export const SidebarProvider = ({
|
|||||||
const [mobileSidebarOpen, setMobileSidebarOpen] = useState<boolean>(false)
|
const [mobileSidebarOpen, setMobileSidebarOpen] = useState<boolean>(false)
|
||||||
const [desktopSidebarOpen, setDesktopSidebarOpen] = useState(true)
|
const [desktopSidebarOpen, setDesktopSidebarOpen] = useState(true)
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
|
const isBrowser = useIsBrowser()
|
||||||
const getResolvedScrollableElement = useCallback(() => {
|
const getResolvedScrollableElement = useCallback(() => {
|
||||||
return scrollableElement || window
|
return scrollableElement || window
|
||||||
}, [scrollableElement])
|
}, [scrollableElement])
|
||||||
@@ -239,14 +241,6 @@ export const SidebarProvider = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is mainly triggered by Algolia
|
|
||||||
const handleHashChange = useCallback(() => {
|
|
||||||
const currentPath = location.hash.replace("#", "")
|
|
||||||
if (currentPath !== activePath) {
|
|
||||||
setActivePath(currentPath)
|
|
||||||
}
|
|
||||||
}, [activePath])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (shouldHandleHashChange) {
|
if (shouldHandleHashChange) {
|
||||||
init()
|
init()
|
||||||
@@ -270,16 +264,31 @@ export const SidebarProvider = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
resolvedScrollableElement.addEventListener("scroll", handleScroll)
|
resolvedScrollableElement.addEventListener("scroll", handleScroll)
|
||||||
resolvedScrollableElement.addEventListener("hashchange", handleHashChange)
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
resolvedScrollableElement.removeEventListener("scroll", handleScroll)
|
resolvedScrollableElement.removeEventListener("scroll", handleScroll)
|
||||||
resolvedScrollableElement.removeEventListener(
|
|
||||||
"hashchange",
|
|
||||||
handleHashChange
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}, [handleHashChange, shouldHandleHashChange, getResolvedScrollableElement])
|
}, [shouldHandleHashChange, getResolvedScrollableElement])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!shouldHandleHashChange || !isBrowser) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is mainly triggered by Algolia
|
||||||
|
const handleHashChange = () => {
|
||||||
|
const currentPath = location.hash.replace("#", "")
|
||||||
|
if (currentPath !== activePath) {
|
||||||
|
setActivePath(currentPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("hashchange", handleHashChange)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("hashchange", handleHashChange)
|
||||||
|
}
|
||||||
|
}, [shouldHandleHashChange, isBrowser])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isLoading && items.top.length && items.bottom.length) {
|
if (isLoading && items.top.length && items.bottom.length) {
|
||||||
|
|||||||
Reference in New Issue
Block a user