mirror of
https://github.com/Buriburizaem0n/nezha-dash-v1.git
synced 2026-09-20 18:20:13 +00:00
feat: implement command context and provider for command handling; add search button component; enhance network chart with packet loss calculation and display; update translations for new features
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import { createContext } from "react"
|
||||
|
||||
export interface CommandContextType {
|
||||
isOpen: boolean
|
||||
openCommand: () => void
|
||||
closeCommand: () => void
|
||||
toggleCommand: () => void
|
||||
}
|
||||
|
||||
export const CommandContext = createContext<CommandContextType | undefined>(undefined)
|
||||
@@ -0,0 +1,24 @@
|
||||
import { ReactNode, useCallback, useState } from "react"
|
||||
|
||||
import { CommandContext } from "./command-context"
|
||||
|
||||
export function CommandProvider({ children }: { children: ReactNode }) {
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
|
||||
const openCommand = useCallback(() => setIsOpen(true), [])
|
||||
const closeCommand = useCallback(() => setIsOpen(false), [])
|
||||
const toggleCommand = useCallback(() => setIsOpen((prev) => !prev), [])
|
||||
|
||||
return (
|
||||
<CommandContext.Provider
|
||||
value={{
|
||||
isOpen,
|
||||
openCommand,
|
||||
closeCommand,
|
||||
toggleCommand,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</CommandContext.Provider>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user