use search queries

This commit is contained in:
SrGooglo 2024-09-15 17:26:52 +00:00
parent 31fe482c1c
commit bf58669117
2 changed files with 5 additions and 5 deletions

View File

@ -48,7 +48,7 @@ export const Panel = (props) => {
export class PagePanelWithNavMenu extends React.Component {
state = {
activeTab: new URLSearchParams(window.location.hash.replace("#", "?")).get("type") ?? this.props.defaultTab ?? this.props.tabs[0].key,
activeTab: new URLSearchParams(window.location.search).get("type") ?? this.props.defaultTab ?? this.props.tabs[0].key,
renders: [],
}
@ -157,7 +157,7 @@ export class PagePanelWithNavMenu extends React.Component {
}
replaceQueryTypeToCurrentTab = (key) => {
document.location.hash = `type=${key ?? this.state.activeTab}`
history.pushState(undefined, "", `?type=${key ?? this.state.activeTab}`)
}
tabChange = async (key) => {

View File

@ -4,15 +4,15 @@ export default ({
defaultKey = "0",
queryKey = "key",
}) => {
const [activeKey, setActiveKey] = React.useState(new URLSearchParams(window.location.hash.replace("#", "?")).get(queryKey) ?? defaultKey)
const [activeKey, setActiveKey] = React.useState(new URLSearchParams(window.location.search).get(queryKey) ?? defaultKey)
const replaceQueryTypeToCurrentTab = (key) => {
if (!key) {
// delete query
return document.location.hash = null
return history.pushState(undefined, "", window.location.pathname)
}
return document.location.hash = `${queryKey}=${key}`
return history.pushState(undefined, "", `?${queryKey}=${key}`)
}
const changeActiveKey = (key) => {