Skip to content

Commit

Permalink
fix: remember sort order for competitors page
Browse files Browse the repository at this point in the history
  • Loading branch information
brownben committed Jun 23, 2024
1 parent d378273 commit 523f247
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions frontend/components/Table/Competitors.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import type { PropType } from 'vue'
import type { Filters } from '~/utils/filter'
import type { CompetitorWithAgeGender } from '~~/utils/ageClass'
const route = useRoute()
const router = useRouter()
const props = defineProps({
competitors: {
type: Array as PropType<CompetitorWithAgeGender[]>,
Expand All @@ -13,8 +16,10 @@ const props = defineProps({
})
type Column = keyof CompetitorWithAgeGender
const ascending = ref(false)
const activeColumn = ref<Column>('id')
const ascending = ref(route.query.ascending === 'true')
const activeColumn = ref<Column>(
(queryToString(route.query.sort_by) as Column) || 'id',
)
const sortedResults = computed(() =>
props.competitors
Expand All @@ -33,6 +38,16 @@ const ariaSorted = computed(
[activeColumn.value]: ascending.value ? 'descending' : 'ascending',
}),
)
watch([activeColumn, ascending], () => {
router.replace({
query: {
...route.query,
sort_by: activeColumn.value,
ascending: ascending.value ? 'true' : 'false',
},
})
})
</script>
<template>
<table v-if="sortedResults.length > 0" class="w-full">
Expand Down

0 comments on commit 523f247

Please sign in to comment.