From d7aeb70918e878e38ef4e6463567154bc3a836a5 Mon Sep 17 00:00:00 2001 From: Jake/Rads Date: Thu, 7 Jul 2022 19:53:24 +0200 Subject: [PATCH] feat(dashboard): more list sorting options --- dashboard/src/lib/list/ListControl.svelte | 62 ++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/dashboard/src/lib/list/ListControl.svelte b/dashboard/src/lib/list/ListControl.svelte index cb080f7d..bb9dc88c 100644 --- a/dashboard/src/lib/list/ListControl.svelte +++ b/dashboard/src/lib/list/ListControl.svelte @@ -4,6 +4,7 @@ import FaSearch from 'svelte-icons/fa/FaSearch.svelte' import Svelecte, { addFormatter } from 'svelecte'; import { Member, Group } from '../../api/types'; import { Link, useParams } from 'svelte-navigator'; +import moment from 'moment'; export let list: Member[] | Group[] = []; @@ -68,8 +69,9 @@ $: filteredList = searchedList.filter((item) => { let sortedList = []; $: if (filteredList) { + let alphabeticalList = filteredList.sort((a, b) => a.name.localeCompare(b.name)); switch (sortBy) { - case "name": sortedList = filteredList.sort((a, b) => a.name.localeCompare(b.name)); + case "name": sortedList = alphabeticalList; break; case "display name": sortedList = filteredList.sort((a, b) => { if (a.display_name && b.display_name) return a.display_name.localeCompare(b.display_name); @@ -84,6 +86,60 @@ $: if (filteredList) { break; case "ID": sortedList = filteredList.sort((a, b) => a.id.localeCompare(b.id)); break; + case "avatar": sortedList = alphabeticalList.sort((a, b) => { + if (a.icon === null || a.avatar_url === null) { + return 1; + }; + if (b.icon === null || b.avatar_url === null) { + return -1; + }; + if (a.icon === b.icon || a.avatar_url === b.avatar_url) { + return 0; + } + }); + break; + case "color": sortedList = alphabeticalList.sort((a, b) => { + if (a.color === null) { + return 1; + }; + if (b.color === null) { + return -1; + }; + if (a.color === b.color) { + return 0; + } + }); + break; + case "birthday": sortedList = alphabeticalList.sort((a, b) => { + if (a.birthday === null) { + return 1; + } + if (b.birthday === null) { + return -1; + } + let aBirthday = moment(a.birthday.slice(5, a.birthday.length), "MM-DD", true); + let bBirthday = moment(b.birthday.slice(5, b.birthday.length), "MM-DD", true); + if (aBirthday.isBefore(bBirthday)) { + return -1; + } + if (aBirthday.isAfter(bBirthday)) { + return 1; + } + if (aBirthday === bBirthday) { + return 0; + } + }); + break; + case "pronouns": sortedList = alphabeticalList.sort((a, b) => { + if (a.pronouns === null) { + return 1; + }; + if (b.pronouns === null) { + return -1; + }; + return 0; + }) + break; default: sortedList = filteredList.sort((a, b) => a.name.localeCompare(b.name)); break; } @@ -203,6 +259,10 @@ function capitalizeFirstLetter(string: string) { {#if !isPublic}{/if} + + + {#if itemType === "member"}{/if} + {#if itemType === "member"}{/if}