Skip to content

Commit

Permalink
fix: Remove appending ?page=1
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarsen136 committed Apr 11, 2023
1 parent 5943df0 commit a1f7e44
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
6 changes: 3 additions & 3 deletions components/explore/ExploreChain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ const selected = computed(() =>
function onSwitchChain(chain) {
$store.dispatch('setUrlPrefix', chain)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { page, ...restQuery } = route.query
router.push({
params: {
prefix: chain,
},
query: {
...route.query,
page: '1',
...restQuery,
},
})
}
Expand Down
5 changes: 3 additions & 2 deletions components/explore/ExploreSort.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ const selectedSort = computed({
})
function onChange(selected) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { page, ...restQuery } = route.query
router.push({
path: route.fullPath,
query: {
...route.query,
page: '1',
...restQuery,
sort: removeDuplicateSortKeys(selected),
},
})
Expand Down
5 changes: 3 additions & 2 deletions components/search/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,15 @@ export default class Search extends mixins(
if (pathName && pathName !== this.$route.path) {
return
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { page, ...restQuery } = this.$route.query
this.$router
.replace({
path: this.isExplorePage
? String(this.$route.path)
: `/${this.urlPrefix}/explore/items`,
query: {
page: '1',
...this.$route.query,
...restQuery,
search: this.searchQuery || this.$route.query.search || undefined,
...queryCondition,
},
Expand Down
1 change: 0 additions & 1 deletion components/search/SearchSuggestion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ export default class SearchSuggestion extends mixins(PrefixMixin) {
.replace({
path: String(this.$route.path),
query: {
page: '1',
search: this.name,
},
})
Expand Down
11 changes: 8 additions & 3 deletions composables/useListInfiniteScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,19 @@ export default function ({
useScroll(window, { onScroll: updateCurrentPage, throttle: 1000 })
useResizeObserver(document.body, onResize)

const replaceUrlPage = (page: string) => {
if (page === route.query.page) {
const replaceUrlPage = (targetPage: string) => {
if (targetPage === route.query.page) {
return
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { page, ...restQuery } = route.query
router
.replace({
path: String(route.path),
query: { ...route.query, page },
query:
targetPage === '1'
? { ...restQuery }
: { ...restQuery, page: targetPage },
})
.catch($consola.warn)
}
Expand Down
4 changes: 3 additions & 1 deletion composables/useReplaceUrl.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { remove } from 'cypress/types/lodash'

export const replaceBooleanWithStrings = (
obj: Record<string, string | null | boolean | undefined | number>
): Record<string, string | null | undefined> => {
Expand Down Expand Up @@ -41,7 +43,7 @@ export default function (
...replaceBooleanWithStrings(queryCondition),
}
if (resetPage) {
query.page = '1'
delete query.page
}
router
.replace({
Expand Down

0 comments on commit a1f7e44

Please sign in to comment.