Skip to content

Commit

Permalink
Add support for clearing queryString in tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Aug 27, 2024
1 parent 452175a commit 7c4ae21
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
"recommendations": [
"Vue.volar"
]
}
6 changes: 4 additions & 2 deletions src/components/Tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ const props = withDefaults(defineProps<{
tabClass?: string
bodyClass?: string
url?:boolean
clearQuery?:boolean
}>(), {
id: 'tabs',
param: 'tab',
label: (tab:string) => humanize(tab),
bodyClass: 'p-4',
url: true
url:true,
clearQuery:false,
})
const tabNames = computed(() => Object.keys(props.tabs))
Expand All @@ -55,7 +57,7 @@ function select(tab:string) {
selected.value = tab
if (props.url) {
const firstTab = tabNames.value[0]
pushState({ tab: tab === firstTab ? undefined : tab })
pushState({ tab: tab === firstTab ? undefined : tab }, props.clearQuery)
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/use/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Ref } from "vue"
import { isRef, nextTick, unref } from "vue"
import type { ApiRequest, IReturn, TransitionRules } from "@/types"
import { ApiResult, appendQueryString, dateFmt, enc, JsonServiceClient, nameOf, omit, setQueryString, toTime } from "@servicestack/client"
import { ApiResult, appendQueryString, dateFmt, enc, JsonServiceClient, lastLeftPart, nameOf, omit, setQueryString, toTime } from "@servicestack/client"
import { assetsPathResolver } from "./config"
import { Sole } from "./config"

Expand Down Expand Up @@ -139,9 +139,11 @@ export function parseJson(json?:string|null) {
return typeof json == 'string' ? JSON.parse(json) : null
}

export function pushState(args:Record<string,any>) {
if (typeof history != 'undefined') {
const url = setQueryString(location.href, args)
export function pushState(args:Record<string,any>, clear?:boolean) {
if (typeof history != 'undefined') {
const url = clear
? setQueryString(location.href, args)
: appendQueryString(lastLeftPart(location.href,'?'), args)
history.pushState({}, '', url)
}
}
Expand Down

0 comments on commit 7c4ae21

Please sign in to comment.