* initial implementation of search modal * added hit and search suggestions * added support for multiple indices * updated sample env * added close when click outside dropdown * test for mobile * added mobile design * added shortcut * dark mode fixes * added search to docs * added plugins filter * added React import * moved filters to configurations * handled error on page load * change suggestion text * removed hits limit * handle select all * open link in current tab * change highlight colors * added support for shortcuts + auto focus * change header and footer * redesigned search ui
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
"use client"
|
|
|
|
import type { Area } from "@/types/openapi"
|
|
import { createContext, useContext, useEffect, useState } from "react"
|
|
import { useSearch } from "./search"
|
|
|
|
type AreaContextType = {
|
|
area: Area
|
|
setArea: (value: Area) => void
|
|
}
|
|
|
|
const AreaContext = createContext<AreaContextType | null>(null)
|
|
|
|
type AreaProviderProps = {
|
|
area: Area
|
|
children: React.ReactNode
|
|
}
|
|
|
|
const AreaProvider = ({ area: passedArea, children }: AreaProviderProps) => {
|
|
const [area, setArea] = useState<Area>(passedArea)
|
|
const { defaultFilters, setDefaultFilters } = useSearch()
|
|
|
|
useEffect(() => {
|
|
if (!defaultFilters.includes(area)) {
|
|
setDefaultFilters([area])
|
|
}
|
|
}, [area, defaultFilters, setDefaultFilters])
|
|
|
|
return (
|
|
<AreaContext.Provider
|
|
value={{
|
|
area,
|
|
setArea,
|
|
}}
|
|
>
|
|
{children}
|
|
</AreaContext.Provider>
|
|
)
|
|
}
|
|
|
|
export default AreaProvider
|
|
|
|
export const useArea = (): AreaContextType => {
|
|
const context = useContext(AreaContext)
|
|
|
|
if (!context) {
|
|
throw new Error("useAreaProvider must be used inside an AreaProvider")
|
|
}
|
|
|
|
return context
|
|
}
|