feat(dashboard): sort/filter by color

This commit is contained in:
Jake Fulmine 2023-01-21 20:47:40 +01:00
parent 65dea53c64
commit f22c23c5f1
3 changed files with 31 additions and 2 deletions

View File

@ -141,6 +141,7 @@ function resetPage() {
<option value="pronouns">Pronouns</option>
<option value="birthday">Birthday</option>
{/if}
<option value="color">Color</option>
{#if !pageOptions.isPublic}
<option value="created">Creation date</option>
{/if}
@ -391,6 +392,16 @@ function resetPage() {
</InputGroup>
</Col>
{/if}
<Col xs={12} md={6} lg={4} class="mb-2">
<InputGroup>
<InputGroupText>Color</InputGroupText>
<Input type="select" bind:value={options.filter.color} on:change={() => resetPage()}>
<option value="all">All</option>
<option value="include">With color</option>
<option value="exclude">Without color</option>
</Input>
</InputGroup>
</Col>
</Row>
{/if}
</CardBody>

View File

@ -121,6 +121,22 @@ function sort<T extends Member|Group>(list: T[], options: ListOptions): T[] {
return aa.localeCompare(bb);
});
} else if (options.sort === 'color') {
newList = [...list].sort((a, b) => {
let aa = Number("0x" + a.color);
let bb = Number("0x" + b.color);
if (a.color === null) return 1;
if (b.color === null) return -1;
if (aa === bb) return a.name.localeCompare(b.name);
if (Number.isNaN(aa)) return 1;
if (Number.isNaN(bb)) return -1;
if (aa > bb) return 1;
if (aa < bb) return -1;
})
}
return newList;
}

View File

@ -44,10 +44,11 @@ export interface ListOptions {
display_name: "all"|"include"|"exclude",
avatar_url: "all"|"include"|"exclude",
icon: "all"|"include"|"exclude",
color: "all"|"include"|"exclude",
}
// what it says on the tin
sort: 'name'|'description'|'birthday'|'pronouns'|'display_name'|'id'|'none'|'created',
sort: 'name'|'description'|'birthday'|'pronouns'|'display_name'|'id'|'none'|'created' | 'color',
order: "ascending"|"descending",
show: "all"|"private"|"public",
// so we can change the key for duplicate members on the randomize page
@ -109,7 +110,8 @@ export const defaultListOptions: ListOptions = {
description: 'all',
pronouns: 'all',
avatar_url: 'all',
icon: 'all'
icon: 'all',
color: 'all',
},
sort: 'name',