Skip to content

Commit

Permalink
Fix sorting when both sortBy and sortDir change
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Mar 22, 2023
1 parent 67e5ab0 commit 167738d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/web-app-files/src/composables/sort/useSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ref, Ref, computed, unref, isRef } from 'vue'
import { MaybeRef, ReadOnlyRef } from 'web-pkg/src/utils'
import { useRouteName, useRouteQueryPersisted, QueryValue } from 'web-pkg/src/composables'
import { SortConstants } from './constants'
import { useRouter } from 'vue-router'

export interface SortableItem {
type?: string
Expand Down Expand Up @@ -37,6 +38,7 @@ export interface SortResult<T> {
}

export function useSort<T extends SortableItem>(options: SortOptions<T>): SortResult<T> {
const router = useRouter()
const sortByRef = createSortByQueryRef(options)
const sortDirRef = createSortDirQueryRef(options)

Expand All @@ -63,8 +65,13 @@ export function useSort<T extends SortableItem>(options: SortOptions<T>): SortRe
})

const handleSort = ({ sortBy, sortDir }: { sortBy: string; sortDir: SortDir }) => {
sortByRef.value = sortBy
sortDirRef.value = sortDir
return router.replace({
query: {
...unref(router.currentRoute).query,
'sort-by': sortBy,
'sort-dir': sortDir
}
})
}

return {
Expand Down

0 comments on commit 167738d

Please sign in to comment.