diff --git a/src/routes/(app)/admin/+page.svelte b/src/routes/(app)/admin/+page.svelte index 00a2c5fb5..858f5f82d 100644 --- a/src/routes/(app)/admin/+page.svelte +++ b/src/routes/(app)/admin/+page.svelte @@ -75,6 +75,17 @@ } loaded = true; }); + let sortKey = 'created_at'; // default sort key + let sortOrder = 'asc'; // default sort order + + function setSortKey(key) { + if (sortKey === key) { + sortOrder = sortOrder === 'asc' ? 'desc' : 'asc'; + } else { + sortKey = key; + sortOrder = 'asc'; + } + } {#key selectedUser} @@ -139,12 +150,46 @@ - - - - - - + + + + + @@ -159,6 +204,10 @@ const query = search.toLowerCase(); return name.includes(query); } + }).sort((a, b) => { + if (a[sortKey] < b[sortKey]) return sortOrder === 'asc' ? -1 : 1; + if (a[sortKey] > b[sortKey]) return sortOrder === 'asc' ? 1 : -1; + return 0; }) .slice((page - 1) * 20, page * 20) as user}
{$i18n.t('Role')} {$i18n.t('Name')} {$i18n.t('Email')} {$i18n.t('Last Active')} {$i18n.t('Created at')} setSortKey('role')}> + {$i18n.t('Role')} + {#if sortKey === 'role'} + {sortOrder === 'asc' ? '▲' : '▼'} + {:else} + + {/if} + setSortKey('name')}> + {$i18n.t('Name')} + {#if sortKey === 'name'} + {sortOrder === 'asc' ? '▲' : '▼'} + {:else} + + {/if} + setSortKey('email')}> + {$i18n.t('Email')} + {#if sortKey === 'email'} + {sortOrder === 'asc' ? '▲' : '▼'} + {:else} + + {/if} + setSortKey('last_active_at')}> + {$i18n.t('Last Active')} + {#if sortKey === 'last_active_at'} + {sortOrder === 'asc' ? '▲' : '▼'} + {:else} + + {/if} + setSortKey('created_at')}> + {$i18n.t('Created at')} + {#if sortKey === 'created_at'} + {sortOrder === 'asc' ? '▲' : '▼'} + {:else} + + {/if} +