mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
use search queries
This commit is contained in:
parent
31fe482c1c
commit
bf58669117
@ -48,7 +48,7 @@ export const Panel = (props) => {
|
|||||||
|
|
||||||
export class PagePanelWithNavMenu extends React.Component {
|
export class PagePanelWithNavMenu extends React.Component {
|
||||||
state = {
|
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: [],
|
renders: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ export class PagePanelWithNavMenu extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
replaceQueryTypeToCurrentTab = (key) => {
|
replaceQueryTypeToCurrentTab = (key) => {
|
||||||
document.location.hash = `type=${key ?? this.state.activeTab}`
|
history.pushState(undefined, "", `?type=${key ?? this.state.activeTab}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
tabChange = async (key) => {
|
tabChange = async (key) => {
|
||||||
|
@ -4,15 +4,15 @@ export default ({
|
|||||||
defaultKey = "0",
|
defaultKey = "0",
|
||||||
queryKey = "key",
|
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) => {
|
const replaceQueryTypeToCurrentTab = (key) => {
|
||||||
if (!key) {
|
if (!key) {
|
||||||
// delete query
|
// 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) => {
|
const changeActiveKey = (key) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user