Skip to content

Commit

Permalink
add asc desc ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
stevie.hartog committed Jun 20, 2024
1 parent 0ae30f5 commit 73a4f88
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { storeToRefs } from 'pinia'
import { useWorkoutsStore } from '@/stores/workouts'
import { useI18n } from 'vue-i18n'
const { workoutsCommunityFilter, workoutsCommunity } = storeToRefs(useWorkoutsStore())
const { workoutsCommunity, workoutsCommunityFilter, workoutsCommunityFilterDirection } =
storeToRefs(useWorkoutsStore())
const { fetchCommunityWorkouts } = useWorkoutsStore()
Expand All @@ -20,6 +21,13 @@ const items: { filter: string; value: string }[] = [
{ filter: 'Level', value: 'level' }
]
const toggleDirection = () => {
workoutsCommunityFilterDirection.value =
workoutsCommunityFilterDirection.value === 'asc' ? 'desc' : 'asc'
workoutsCommunity.value = []
fetchCommunityWorkouts()
}
watch(
workoutsCommunityFilter,
async (newFilter, oldFilter) => {
Expand All @@ -30,8 +38,6 @@ watch(
},
{ deep: true }
)
// const sortOrder = ref('desc')
</script>

<template>
Expand All @@ -51,7 +57,7 @@ watch(
<v-container>
<v-row>
<v-col cols="12">
<div class="d-flex flex-column">
<div class="d-flex align-center justify-center">
<v-select
v-model="workoutsCommunityFilter"
:items="items"
Expand All @@ -60,8 +66,14 @@ watch(
item-value="value"
single-line
return-object
>
</v-select>
class="mr-2"
/>
<v-btn
variant="text"
class="mb-4"
@click="toggleDirection"
:icon="workoutsCommunityFilterDirection === 'asc' ? '$arrowUp' : '$arrowDown'"
/>
</div>
</v-col>
</v-row>
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/vuetify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
mdiAccountMultiple,
mdiAccountVoice,
mdiApple,
mdiArrowDown,
mdiArrowLeft,
mdiArrowUp,
mdiBellOutline,
mdiBluetooth,
mdiBluetoothOff,
Expand Down Expand Up @@ -108,7 +110,9 @@ export default createVuetify({
accountMultiple: mdiAccountMultiple,
accountVoice: mdiAccountVoice,
apple: mdiApple,
arrowDown: mdiArrowDown,
arrowLeft: mdiArrowLeft,
arrowUp: mdiArrowUp,
bellOutline: mdiBellOutline,
bluetooth: mdiBluetooth,
bluetoothOff: mdiBluetoothOff,
Expand Down
4 changes: 3 additions & 1 deletion src/stores/workouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const useWorkoutsStore = defineStore('workouts', () => {
filter: 'Last Modified',
value: 'updateTimestamp'
})
const workoutsCommunityFilterDirection = ref<'desc' | 'asc'>('desc')
const leaderboards = ref<Leaderboard[]>([])

// Actions
Expand Down Expand Up @@ -59,7 +60,7 @@ export const useWorkoutsStore = defineStore('workouts', () => {
const newWorkouts = await usersWorkoutsDb.readAll(
constraints,
workoutsCommunityFilter.value.value,
'desc',
workoutsCommunityFilterDirection.value,
20,
// @ts-expect-error DocumentSnapshot
lastVisible
Expand Down Expand Up @@ -215,6 +216,7 @@ export const useWorkoutsStore = defineStore('workouts', () => {
workouts,
workoutsCommunity,
workoutsCommunityFilter,
workoutsCommunityFilterDirection,
leaderboards,
fetchUserWorkouts,
fetchCommunityWorkouts,
Expand Down

0 comments on commit 73a4f88

Please sign in to comment.