diff --git a/package.json b/package.json index 98db39d2..f3a1cd10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "photon-lemmy", - "version": "0.9.12", + "version": "0.9.13", "private": true, "scripts": { "dev": "vite dev", diff --git a/src/lib/auth.ts b/src/lib/auth.ts index b4834885..a28ca64d 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -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 -) diff --git a/src/lib/util.ts b/src/lib/util.ts index fbe52719..ccc13d35 100644 --- a/src/lib/util.ts +++ b/src/lib/util.ts @@ -56,3 +56,28 @@ export const placeholders = { : '' }, } + +export function moveItem( + 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 +} diff --git a/src/routes/accounts/+page.svelte b/src/routes/accounts/+page.svelte index f3618274..e04758ff 100644 --- a/src/routes/accounts/+page.svelte +++ b/src/routes/accounts/+page.svelte @@ -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)}
@@ -160,12 +164,20 @@ + moveProfile(profile.id, true)}> + + Move Up + + moveProfile(profile.id, false)}> + + Move Down + (profile.color = undefined)} > - Reset color + Reset Color