From 1206b97cb38f6e309674715fe697ec750c57bc0b Mon Sep 17 00:00:00 2001 From: Kalle Fagerberg Date: Sat, 17 Sep 2022 21:44:44 +0200 Subject: [PATCH] Added basic sorting --- src/views/PersonalSettingsPage.vue | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/views/PersonalSettingsPage.vue b/src/views/PersonalSettingsPage.vue index 2e2c528..0713db2 100644 --- a/src/views/PersonalSettingsPage.vue +++ b/src/views/PersonalSettingsPage.vue @@ -3,6 +3,16 @@
+
+ + +
    import EmptyContent from '@nextcloud/vue/dist/Components/EmptyContent' +import Multiselect from '@nextcloud/vue/dist/Components/Multiselect' import SettingsSection from '@nextcloud/vue/dist/Components/SettingsSection' import SubscriptionListItem from '../components/SubscriptionListItem.vue' @@ -37,10 +48,16 @@ import { generateUrl } from '@nextcloud/router' import axios from '@nextcloud/axios' import { showError } from '@nextcloud/dialogs' +const sortingOptions = [ + { label: 'Listened time (desc)', compare: (a, b) => a?.listenedSeconds < b?.listenedSeconds }, + { label: 'Listened time (asc)', compare: (a, b) => a?.listenedSeconds > b?.listenedSeconds }, +] + export default { name: 'PersonalSettingsPage', components: { EmptyContent, + Multiselect, Podcast, SettingsSection, SubscriptionListItem, @@ -49,6 +66,8 @@ export default { return { subscriptions: [], isLoading: true, + sortBy: sortingOptions[0], + sortingOptions, } }, async mounted() { @@ -58,6 +77,7 @@ export default { throw new Error('expected subscriptions array in metrics response') } this.subscriptions = resp.data.subscriptions + this.subscriptions.sort(this.sortBy.compare); } catch (e) { console.error(e) showError(t('gpoddersync', 'Could not fetch podcast synchronization stats')) @@ -78,6 +98,9 @@ export default { } return `(${hours}h ${modMinutes}min listened)` }, + updateSorting(sorting) { + this.subscriptions.sort(sorting.compare) + }, }, }