feat: add profile recoloring

This commit is contained in:
Xyphyn committed 2023-08-19 17:40:16 -07:00
1 parent 343e3cf78a
commit 8182fa09e7
4 files changed
+83 -16

No files matched your search

+2 -1
View File
@@ -25,13 +25,14 @@ function setFromStorage(key: string, item: any, stringify: boolean = true) {
return localStorage.setItem(key, stringify ? JSON.stringify(item) : item)
}
interface Profile {
export interface Profile {
id: number
instance: string
jwt?: string
user?: PersonData
username?: string
favorites?: number[]
color?: string
}
/**
+5 -7
View File
@@ -17,6 +17,7 @@
import { slide } from 'svelte/transition'
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
import CommunityList from '$lib/components/ui/sidebar/CommunityList.svelte'
import ProfileAvatar from '$lib/lemmy/ProfileAvatar.svelte'
</script>
<nav
@@ -68,13 +69,10 @@
? ''
: '!p-1.5'} {$profile?.id == prof.id ? 'font-bold' : ''}"
>
<Icon
src={UserCircle}
mini={$profile?.id == prof.id}
size="20"
title={prof.username}
class="text-blue-500"
style="filter: hue-rotate({index * 50}deg)"
<ProfileAvatar
profile={prof}
{index}
selected={$profile?.id == prof.id}
/>
<span
class:hidden={!$userSettings.expandSidebar}
+22
View File
@@ -0,0 +1,22 @@
<script lang="ts">
import type { Profile } from '$lib/auth.js'
import { Icon, UserCircle } from 'svelte-hero-icons'
export let profile: Profile | undefined = undefined
export let selected: boolean = false
export let index: number = 0
export let size: number = 20
</script>
{#if profile}
<Icon
src={UserCircle}
mini={selected}
size={`${size}`}
title={profile.username}
class="text-blue-500"
style={profile.color
? `color: ${profile.color}`
: `filter: hue-rotate(${index * 50}deg)`}
/>
{/if}
+54 -8
View File
@@ -9,6 +9,8 @@
import Button from '$lib/components/input/Button.svelte'
import TextInput from '$lib/components/input/TextInput.svelte'
import EditableList from '$lib/components/ui/list/EditableList.svelte'
import Menu from '$lib/components/ui/menu/Menu.svelte'
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
import { toast } from '$lib/components/ui/toasts/toasts.js'
import {
DEFAULT_INSTANCE_URL,
@@ -16,7 +18,16 @@
instance,
} from '$lib/instance.js'
import { validateInstance } from '$lib/lemmy.js'
import { ArrowLeftOnRectangle, Icon, Plus, Trash } from 'svelte-hero-icons'
import ProfileAvatar from '$lib/lemmy/ProfileAvatar.svelte'
import {
ArrowLeftOnRectangle,
ArrowUturnLeft,
EllipsisHorizontal,
Icon,
PaintBrush,
Plus,
Trash,
} from 'svelte-hero-icons'
import { flip } from 'svelte/animate'
let newInstance: string = $profileData.defaultInstance ?? DEFAULT_INSTANCE_URL
@@ -110,18 +121,53 @@
}}
let:action
>
{#each $profileData.profiles as profile (profile.id)}
{#each $profileData.profiles as profile, index (profile.id)}
<div
class="flex flex-row gap-4 items-center py-4"
class="flex flex-row gap-2 items-center py-4"
animate:flip={{ duration: 250 }}
>
<div class="flex flex-col">
<span class="font-bold">{profile.username}</span>
<span class="text-sm text-slate-600 dark:text-zinc-400">
{profile.instance}
</span>
<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
bg-slate-200 dark:bg-zinc-900 border border-slate-300 dark:border-zinc-800 rounded-full
transition-all"
>
<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-bold">{profile.username}</span>
<span class="text-sm text-slate-600 dark:text-zinc-400">
{profile.instance}
</span>
</div>
</div>
<div class="ml-auto" />
<Menu let:toggleOpen alignment="bottom-right">
<Button on:click={toggleOpen} size="square-md" slot="button">
<Icon src={EllipsisHorizontal} mini size="16" slot="icon" />
</Button>
<MenuButton
disabled={!profile.color}
on:click={() => (profile.color = undefined)}
>
<Icon src={ArrowUturnLeft} size="16" mini slot="icon" />
Reset color
</MenuButton>
</Menu>
<Button
on:click={() => {
if (profile.id == $currentProfile?.id) {