feat: add sort options to accounts page
This commit is contained in:
1 parent
6a1635619e
commit
d9950f4c4e
2 files changed
+201
-135
No files matched your search
@@ -0,0 +1,63 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { Button } from 'mono-svelte'
|
||||||
|
import { Icon, XMark } from 'svelte-hero-icons'
|
||||||
|
import { expoOut } from 'svelte/easing'
|
||||||
|
import { fly, slide } from 'svelte/transition'
|
||||||
|
|
||||||
|
type T = $$Generic
|
||||||
|
|
||||||
|
export let items: T[]
|
||||||
|
export let id: (item: T) => string | number | symbol
|
||||||
|
|
||||||
|
let filters: Set<string | number | symbol> = new Set()
|
||||||
|
|
||||||
|
$: filteredItems =
|
||||||
|
filters.size > 0 ? items.filter((i) => filters.has(id(i))) : items
|
||||||
|
$: uniqueIds = new Set(items.map(id))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex flex-row overflow-auto space-x-2">
|
||||||
|
{#if filters.size > 0}
|
||||||
|
<div
|
||||||
|
in:slide={{ duration: 300, easing: expoOut, axis: 'x' }}
|
||||||
|
out:slide={{ duration: 300, easing: expoOut, axis: 'x', delay: 100 }}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
out:fly={{ duration: 300, easing: expoOut, y: 6 }}
|
||||||
|
in:fly={{ duration: 300, easing: expoOut, y: 6, delay: 100 }}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
on:click={() => {
|
||||||
|
filters.clear()
|
||||||
|
filters = filters
|
||||||
|
}}
|
||||||
|
color="ghost"
|
||||||
|
class="text-inherit dark:text-inherit text-xs aspect-square h-full"
|
||||||
|
rounding="pill"
|
||||||
|
size="square-sm"
|
||||||
|
>
|
||||||
|
<Icon src={XMark} size="14" micro />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{#each uniqueIds as identifier}
|
||||||
|
<Button
|
||||||
|
on:click={() => {
|
||||||
|
if (filters.has(identifier)) filters.delete(identifier)
|
||||||
|
else filters.add(identifier)
|
||||||
|
filters = filters
|
||||||
|
}}
|
||||||
|
color={filters.has(identifier) ? 'primary' : 'ghost'}
|
||||||
|
class="text-inherit dark:text-inherit text-xs px-2.5"
|
||||||
|
rounding="pill"
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
<slot name="identifier" string={identifier}>
|
||||||
|
{identifier}
|
||||||
|
</slot>
|
||||||
|
</Button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<slot items={filteredItems} />
|
||||||
+138
-135
@@ -9,14 +9,9 @@
|
|||||||
profile,
|
profile,
|
||||||
} from '$lib/auth.js'
|
} from '$lib/auth.js'
|
||||||
import EditableList from '$lib/components/ui/list/EditableList.svelte'
|
import EditableList from '$lib/components/ui/list/EditableList.svelte'
|
||||||
import { Menu, MenuButton, Modal, toast } from 'mono-svelte'
|
import { Menu, MenuButton, Modal } from 'mono-svelte'
|
||||||
import DebugObject from '$lib/components/util/debug/DebugObject.svelte'
|
import DebugObject from '$lib/components/util/debug/DebugObject.svelte'
|
||||||
import {
|
import { DEFAULT_INSTANCE_URL, LINKED_INSTANCE_URL } from '$lib/instance.js'
|
||||||
DEFAULT_INSTANCE_URL,
|
|
||||||
LINKED_INSTANCE_URL,
|
|
||||||
instance,
|
|
||||||
} from '$lib/instance.js'
|
|
||||||
import { validateInstance } from '$lib/lemmy.js'
|
|
||||||
import ProfileAvatar from '$lib/lemmy/ProfileAvatar.svelte'
|
import ProfileAvatar from '$lib/lemmy/ProfileAvatar.svelte'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
import { Button, TextInput } from 'mono-svelte'
|
import { Button, TextInput } from 'mono-svelte'
|
||||||
@@ -30,20 +25,17 @@
|
|||||||
ChevronDown,
|
ChevronDown,
|
||||||
ChevronUp,
|
ChevronUp,
|
||||||
EllipsisHorizontal,
|
EllipsisHorizontal,
|
||||||
ExclamationTriangle,
|
|
||||||
Icon,
|
Icon,
|
||||||
Identification,
|
Identification,
|
||||||
PaintBrush,
|
PaintBrush,
|
||||||
Plus,
|
Plus,
|
||||||
Trash,
|
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import { flip } from 'svelte/animate'
|
import { flip } from 'svelte/animate'
|
||||||
import { expoInOut, expoOut } from 'svelte/easing'
|
import { expoOut } from 'svelte/easing'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||||
|
import FilterTabs from '$lib/components/ui/tabs/FilterTabs.svelte'
|
||||||
let newInstance: string = $profileData.defaultInstance ?? DEFAULT_INSTANCE_URL
|
import { fly } from 'svelte/transition'
|
||||||
let loading = false
|
|
||||||
|
|
||||||
let debugging = false
|
let debugging = false
|
||||||
let debugProfile: Profile | undefined = undefined
|
let debugProfile: Profile | undefined = undefined
|
||||||
@@ -53,7 +45,7 @@
|
|||||||
account: undefined as Profile | undefined,
|
account: undefined as Profile | undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
let switching = -69
|
let switching = -2
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -136,136 +128,147 @@
|
|||||||
{:else}
|
{:else}
|
||||||
<div class="flex flex-col h-full gap-4">
|
<div class="flex flex-col h-full gap-4">
|
||||||
<div class="flex flex-row justify-between">
|
<div class="flex flex-row justify-between">
|
||||||
<Header>{$t('routes.accounts')}</Header>
|
<Header pageHeader>{$t('routes.accounts')}</Header>
|
||||||
</div>
|
</div>
|
||||||
<EditableList
|
<div class="flex">
|
||||||
on:action={(acc) => {
|
<div class="flex gap-2 mr-auto">
|
||||||
removing.account = acc.detail
|
<Button href="/login" size="lg" class="flex-1 px-8" color="primary">
|
||||||
removing.shown = !removing.shown
|
<Icon slot="prefix" src={ArrowLeftOnRectangle} size="16" mini />
|
||||||
}}
|
{$t('account.login')}
|
||||||
let:action
|
</Button>
|
||||||
>
|
{#if !LINKED_INSTANCE_URL}
|
||||||
{#each $profileData.profiles as profile, index (profile.id)}
|
<Button href="/login/guest" size="lg">
|
||||||
<div
|
<Icon slot="prefix" src={Plus} size="16" mini />
|
||||||
class="flex flex-row gap-2 items-center py-4"
|
{$t('account.addGuest')}
|
||||||
animate:flip={{ duration: 250, easing: expoOut }}
|
</Button>
|
||||||
>
|
{/if}
|
||||||
<div class="flex items-center gap-2">
|
</div>
|
||||||
<div class="relative group flex-col items-center">
|
</div>
|
||||||
<ProfileAvatar
|
<FilterTabs items={$profileData.profiles} id={(i) => i.instance} let:items>
|
||||||
{profile}
|
<EditableList
|
||||||
{index}
|
on:action={(acc) => {
|
||||||
selected={$currentProfile?.id == profile.id}
|
removing.account = acc.detail
|
||||||
size={24}
|
removing.shown = !removing.shown
|
||||||
/>
|
}}
|
||||||
<div
|
let:action
|
||||||
class="absolute top-0 left-0 w-full h-full opacity-0
|
>
|
||||||
|
{#each items as profile, index (profile.id)}
|
||||||
|
<div
|
||||||
|
class="flex flex-row gap-2 items-center py-3"
|
||||||
|
transition:fly={{ duration: 500, y: -12, easing: expoOut }}
|
||||||
|
animate:flip={{ duration: 500, easing: expoOut }}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
title={profile.id == $currentProfile?.id ? 'Switch' : 'Current'}
|
||||||
|
on:click={async () => {
|
||||||
|
if (profile.id != $currentProfile?.id) {
|
||||||
|
switching = profile.id
|
||||||
|
await setUserID(profile.id)
|
||||||
|
switching = -69
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
size="square-md"
|
||||||
|
color={profile.id == $currentProfile?.id ? 'primary' : 'ghost'}
|
||||||
|
loading={switching == profile.id}
|
||||||
|
disabled={switching == profile.id}
|
||||||
|
rounding="pill"
|
||||||
|
>
|
||||||
|
<svelte:fragment slot="prefix">
|
||||||
|
{#if profile.id == $currentProfile?.id}
|
||||||
|
<Icon src={Check} mini size="16" />
|
||||||
|
{:else}
|
||||||
|
<Icon src={ArrowsRightLeft} size="16" mini />
|
||||||
|
{/if}
|
||||||
|
</svelte:fragment>
|
||||||
|
</Button>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<div class="relative group flex-col items-center">
|
||||||
|
<ProfileAvatar
|
||||||
|
{profile}
|
||||||
|
{index}
|
||||||
|
selected={$currentProfile?.id == profile.id}
|
||||||
|
size={24}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
class="absolute top-0 left-0 w-full h-full opacity-0
|
||||||
grid group-hover:opacity-100 z-20 place-items-center
|
grid group-hover:opacity-100 z-20 place-items-center
|
||||||
bg-slate-200 dark:bg-zinc-900 border border-slate-300 dark:border-zinc-800 rounded-full
|
bg-slate-200 dark:bg-zinc-900 border border-slate-300 dark:border-zinc-800 rounded-full
|
||||||
transition-all"
|
transition-all"
|
||||||
>
|
>
|
||||||
<Icon src={PaintBrush} mini size="14" />
|
<Icon src={PaintBrush} mini size="14" />
|
||||||
|
</div>
|
||||||
|
<input
|
||||||
|
type="color"
|
||||||
|
class="opacity-0 absolute top-0 left-0 h-full w-full rounded-full cursor-pointer z-30"
|
||||||
|
bind:value={profile.color}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="font-medium">{profile.username}</span>
|
||||||
|
<span class="text-sm text-slate-600 dark:text-zinc-400">
|
||||||
|
{profile.instance}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<input
|
|
||||||
type="color"
|
|
||||||
class="opacity-0 absolute top-0 left-0 h-full w-full rounded-full cursor-pointer z-30"
|
|
||||||
bind:value={profile.color}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col">
|
<div class="ml-auto" />
|
||||||
<span class="font-medium">{profile.username}</span>
|
<Menu placement="bottom-end">
|
||||||
<span class="text-sm text-slate-600 dark:text-zinc-400">
|
<Button size="square-md" slot="target">
|
||||||
{profile.instance}
|
<Icon src={EllipsisHorizontal} mini size="16" slot="prefix" />
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="ml-auto" />
|
|
||||||
<Button
|
|
||||||
aria-label={profile.id == $currentProfile?.id
|
|
||||||
? 'Switch'
|
|
||||||
: 'Current'}
|
|
||||||
on:click={async () => {
|
|
||||||
if (profile.id != $currentProfile?.id) {
|
|
||||||
switching = profile.id
|
|
||||||
await setUserID(profile.id)
|
|
||||||
switching = -69
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
size="square-md"
|
|
||||||
color={profile.id == $currentProfile?.id ? 'primary' : 'ghost'}
|
|
||||||
loading={switching == profile.id}
|
|
||||||
disabled={switching == profile.id}
|
|
||||||
>
|
|
||||||
<svelte:fragment slot="prefix">
|
|
||||||
{#if profile.id == $currentProfile?.id}
|
|
||||||
<Icon src={Check} mini size="16" />
|
|
||||||
{:else}
|
|
||||||
<Icon src={ArrowsRightLeft} size="16" mini />
|
|
||||||
{/if}
|
|
||||||
</svelte:fragment>
|
|
||||||
</Button>
|
|
||||||
<Menu placement="bottom-end">
|
|
||||||
<Button size="square-md" slot="target">
|
|
||||||
<Icon src={EllipsisHorizontal} mini size="16" slot="prefix" />
|
|
||||||
</Button>
|
|
||||||
<div class="px-4 py-2 flex items-center gap-2">
|
|
||||||
<Button
|
|
||||||
size="square-md"
|
|
||||||
color="secondary"
|
|
||||||
title={$t('account.moveUp')}
|
|
||||||
on:click={() => moveProfile(profile.id, true)}
|
|
||||||
>
|
|
||||||
<Icon src={ChevronUp} size="16" mini slot="prefix" />
|
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<div class="px-4 py-2 flex items-center gap-2">
|
||||||
size="square-md"
|
<Button
|
||||||
color="secondary"
|
size="square-md"
|
||||||
title={$t('account.moveDown')}
|
color="secondary"
|
||||||
on:click={() => moveProfile(profile.id, false)}
|
title={$t('account.moveUp')}
|
||||||
>
|
on:click={() => moveProfile(profile.id, true)}
|
||||||
<Icon src={ChevronDown} size="16" mini slot="prefix" />
|
>
|
||||||
</Button>
|
<Icon src={ChevronUp} size="16" mini slot="prefix" />
|
||||||
</div>
|
</Button>
|
||||||
<MenuButton
|
<Button
|
||||||
disabled={!profile.color}
|
size="square-md"
|
||||||
on:click={() => (profile.color = undefined)}
|
color="secondary"
|
||||||
>
|
title={$t('account.moveDown')}
|
||||||
<Icon src={ArrowUturnLeft} size="16" mini slot="prefix" />
|
on:click={() => moveProfile(profile.id, false)}
|
||||||
{$t('account.resetColor')}
|
>
|
||||||
</MenuButton>
|
<Icon src={ChevronDown} size="16" mini slot="prefix" />
|
||||||
{#if $userSettings.debugInfo}
|
</Button>
|
||||||
|
</div>
|
||||||
<MenuButton
|
<MenuButton
|
||||||
on:click={() => {
|
disabled={!profile.color}
|
||||||
debugProfile = profile
|
on:click={() => (profile.color = undefined)}
|
||||||
debugging = !debugging
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Icon src={BugAnt} size="16" mini slot="prefix" />
|
<Icon src={ArrowUturnLeft} size="16" mini slot="prefix" />
|
||||||
{$t('common.debug')}
|
{$t('account.resetColor')}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{/if}
|
{#if $userSettings.debugInfo}
|
||||||
{#if !LINKED_INSTANCE_URL || profile.user}
|
<MenuButton
|
||||||
<MenuButton on:click={() => action(profile)} color="danger-subtle">
|
on:click={() => {
|
||||||
<Icon slot="prefix" src={ArrowRightOnRectangle} size="16" mini />
|
debugProfile = profile
|
||||||
{$t('account.logout')}
|
debugging = !debugging
|
||||||
</MenuButton>
|
}}
|
||||||
{/if}
|
>
|
||||||
</Menu>
|
<Icon src={BugAnt} size="16" mini slot="prefix" />
|
||||||
</div>
|
{$t('common.debug')}
|
||||||
{/each}
|
</MenuButton>
|
||||||
</EditableList>
|
{/if}
|
||||||
<div class="mt-auto" />
|
{#if !LINKED_INSTANCE_URL || profile.user}
|
||||||
<div class="flex items-center gap-2">
|
<MenuButton
|
||||||
<Button href="/login" size="lg" class="flex-1" color="primary">
|
on:click={() => action(profile)}
|
||||||
<Icon slot="prefix" src={ArrowLeftOnRectangle} size="16" mini />
|
color="danger-subtle"
|
||||||
{$t('account.login')}
|
>
|
||||||
</Button>
|
<Icon
|
||||||
{#if !LINKED_INSTANCE_URL}
|
slot="prefix"
|
||||||
<Button href="/login/guest" size="lg">
|
src={ArrowRightOnRectangle}
|
||||||
<Icon slot="prefix" src={Plus} size="16" mini />
|
size="16"
|
||||||
{$t('account.addGuest')}
|
mini
|
||||||
</Button>
|
/>
|
||||||
{/if}
|
{$t('account.logout')}
|
||||||
</div>
|
</MenuButton>
|
||||||
|
{/if}
|
||||||
|
</Menu>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</EditableList>
|
||||||
|
</FilterTabs>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
Reference in new issue
Block a user