feat: add profile reordering

This commit is contained in:
Xyphyn committed 2023-08-19 17:48:55 -07:00
1 parent 8182fa09e7
commit 5ae9894ec5
4 files changed
+55 -8

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "photon-lemmy",
"version": "0.9.12",
"version": "0.9.13",
"private": true,
"scripts": {
"dev": "vite dev",
+15 -5
View File
@@ -4,6 +4,7 @@ import { DEFAULT_INSTANCE_URL, instance } from '$lib/instance.js'
import { getClient, site } from '$lib/lemmy.js'
import { getInbox, getInboxItemPublished } from '$lib/lemmy/inbox.js'
import { userSettings } from '$lib/settings.js'
import { moveItem } from '$lib/util.js'
import type { GetSiteResponse, MyUserInfo } from 'lemmy-js-client'
import { get, writable } from 'svelte/store'
@@ -200,6 +201,20 @@ export function setUserID(id: number) {
return prof
}
export function moveProfile(id: number, up: boolean) {
const pd = get(profileData)
try {
const index = pd.profiles.findIndex((i) => i.id == id)
profileData.set({
...pd,
profiles: moveItem(pd.profiles, index, index + (up ? -1 : 1)),
})
} catch (err) {
// we dont care
}
}
const getNotificationCount = async (jwt: string, mod: boolean) => {
const unreads = await getClient().getUnreadCount({
auth: jwt,
@@ -279,8 +294,3 @@ export async function getInboxNotifications(dontUpdate: boolean = false) {
localStorage.setItem('seenUntil', Date.now().toString())
}
setInterval(
async () => getInboxNotifications(),
get(userSettings).notifications.notifRate || 30 * 1000
)
+25
View File
@@ -56,3 +56,28 @@ export const placeholders = {
: ''
},
}
export function moveItem<T>(
array: T[],
currentIndex: number,
newIndex: number
): T[] {
if (
currentIndex < 0 ||
currentIndex >= array.length ||
newIndex < 0 ||
newIndex >= array.length
) {
throw new Error('Invalid index')
}
const newArray = [...array]
// Remove the item from the current index
const [item] = newArray.splice(currentIndex, 1)
// Insert the item at the new index
newArray.splice(newIndex, 0, item)
return newArray
}
+14 -2
View File
@@ -5,6 +5,7 @@
profile as currentProfile,
resetProfile,
deleteProfile,
moveProfile,
} from '$lib/auth.js'
import Button from '$lib/components/input/Button.svelte'
import TextInput from '$lib/components/input/TextInput.svelte'
@@ -22,6 +23,8 @@
import {
ArrowLeftOnRectangle,
ArrowUturnLeft,
ChevronDown,
ChevronUp,
EllipsisHorizontal,
Icon,
PaintBrush,
@@ -29,6 +32,7 @@
Trash,
} from 'svelte-hero-icons'
import { flip } from 'svelte/animate'
import { expoInOut, expoOut } from 'svelte/easing'
let newInstance: string = $profileData.defaultInstance ?? DEFAULT_INSTANCE_URL
let loading = false
@@ -124,7 +128,7 @@
{#each $profileData.profiles as profile, index (profile.id)}
<div
class="flex flex-row gap-2 items-center py-4"
animate:flip={{ duration: 250 }}
animate:flip={{ duration: 250, easing: expoOut }}
>
<div class="flex items-center gap-2">
<div class="relative group flex-col items-center">
@@ -160,12 +164,20 @@
<Button on:click={toggleOpen} size="square-md" slot="button">
<Icon src={EllipsisHorizontal} mini size="16" slot="icon" />
</Button>
<MenuButton on:click={() => moveProfile(profile.id, true)}>
<Icon src={ChevronUp} size="16" mini slot="icon" />
Move Up
</MenuButton>
<MenuButton on:click={() => moveProfile(profile.id, false)}>
<Icon src={ChevronDown} size="16" mini slot="icon" />
Move Down
</MenuButton>
<MenuButton
disabled={!profile.color}
on:click={() => (profile.color = undefined)}
>
<Icon src={ArrowUturnLeft} size="16" mini slot="icon" />
Reset color
Reset Color
</MenuButton>
</Menu>
<Button