This commit is contained in:
S-Reinhard 2026-05-06 13:51:20 +02:00 committed by GitHub
commit a1ef96bfe2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 5 deletions

View file

@ -4,8 +4,8 @@
<div id="bookshelf" class="w-full h-full px-1 py-4 md:p-8 relative overflow-y-auto">
<table class="tracksTable max-w-2xl mx-auto">
<tr>
<th class="text-left">{{ $strings.LabelName }}</th>
<th class="text-center w-24">{{ $strings.LabelBooks }}</th>
<th class="text-left cursor-pointer hover:underline" @click="sortNarratorsBy('name')">{{ $strings.LabelName }}<span class="no-underline inline-block">&nbsp;{{ sortingArrow('name') }}</span></th>
<th class="text-center w-24 cursor-pointer hover:underline" @click="sortNarratorsBy('numBooks')">{{ $strings.LabelBooks }}<span class="no-underline inline-block">&nbsp;{{ sortingArrow('numBooks') }}</span></th>
<th v-if="userCanUpdate" class="w-40"></th>
</tr>
<tr v-for="narrator in narrators" :key="narrator.id">
@ -63,7 +63,9 @@ export default {
loading: true,
narrators: [],
selectedNarrator: null,
newNarratorName: null
newNarratorName: null,
sortBy: 'name',
sortOrder: 'asc'
}
},
computed: {
@ -143,14 +145,38 @@ export default {
})
},
async init() {
await this.fetchNarrators()
},
async fetchNarrators() {
this.loading = true
this.narrators = await this.$axios
.$get(`/api/libraries/${this.currentLibraryId}/narrators`)
.$get(`/api/libraries/${this.currentLibraryId}/narrators`, {params: {sortOrder: this.sortOrder, sortBy: this.sortBy}})
.then((response) => response.narrators)
.catch((error) => {
console.error('Failed to load narrators', error)
return []
})
this.loading = false
},
async sortNarratorsBy(attribute) {
if (this.sortBy == attribute) {
if (this.sortOrder == 'asc') {
this.sortOrder = 'desc';
} else {
this.sortOrder = 'asc';
}
} else {
this.sortBy = attribute;
this.sortOrder = 'asc';
}
await this.fetchNarrators();
},
sortingArrow(attribute) {
if (this.sortBy == attribute) {
return this.sortOrder == 'asc'? '▲' : '▼';
} else {
return '';
}
}
},
mounted() {

View file

@ -1140,8 +1140,14 @@ class LibraryController {
})
}
// sorting
const key = req.query.sortBy === 'numBooks' ? 'numBooks' : 'name';
const order = req.query.sortOrder === 'desc' ? 'desc' : 'asc';
const narratorArr = Object.values(narrators);
const sorted = naturalSort(narratorArr)[order]((n) => n[key])
res.json({
narrators: naturalSort(Object.values(narrators)).asc((n) => n.name)
narrators: sorted
})
}