mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
* refactor: extract shared useUrlParams hook and use push navigation for dialogs * Remove schedule badges and fix dialog safe area padding * fix: deduplicate server health toasts with stable IDs * fix: restore Enabled/Paused status badges on schedule jobs * refactor: consolidate url state hooks and add shared test utilities
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { useCallback, useEffect, useMemo, useRef } from 'react'
|
|
import { useLocation, useNavigate } from 'react-router-dom'
|
|
|
|
type UrlHistoryMode = 'push' | 'replace'
|
|
|
|
interface UseUrlParamsReturn {
|
|
search: string
|
|
searchParams: URLSearchParams
|
|
updateParams: (updater: (params: URLSearchParams) => void, mode?: UrlHistoryMode) => void
|
|
}
|
|
|
|
export function useUrlParams(): UseUrlParamsReturn {
|
|
const navigate = useNavigate()
|
|
const location = useLocation()
|
|
const searchRef = useRef(location.search)
|
|
|
|
useEffect(() => {
|
|
searchRef.current = location.search
|
|
}, [location.search])
|
|
|
|
const searchParams = useMemo(() => new URLSearchParams(location.search), [location.search])
|
|
|
|
const updateParams = useCallback(
|
|
(updater: (params: URLSearchParams) => void, mode: UrlHistoryMode = 'replace') => {
|
|
const params = new URLSearchParams(searchRef.current)
|
|
updater(params)
|
|
navigate({ search: params.toString() }, { replace: mode === 'replace' })
|
|
},
|
|
[navigate],
|
|
)
|
|
|
|
return { search: location.search, searchParams, updateParams }
|
|
}
|