feat: add profile reordering
This commit is contained in:
1 parent
8182fa09e7
commit
5ae9894ec5
4 files changed
+55
-8
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "photon-lemmy",
|
"name": "photon-lemmy",
|
||||||
"version": "0.9.12",
|
"version": "0.9.13",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|||||||
+15
-5
@@ -4,6 +4,7 @@ import { DEFAULT_INSTANCE_URL, instance } from '$lib/instance.js'
|
|||||||
import { getClient, site } from '$lib/lemmy.js'
|
import { getClient, site } from '$lib/lemmy.js'
|
||||||
import { getInbox, getInboxItemPublished } from '$lib/lemmy/inbox.js'
|
import { getInbox, getInboxItemPublished } from '$lib/lemmy/inbox.js'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
|
import { moveItem } from '$lib/util.js'
|
||||||
import type { GetSiteResponse, MyUserInfo } from 'lemmy-js-client'
|
import type { GetSiteResponse, MyUserInfo } from 'lemmy-js-client'
|
||||||
import { get, writable } from 'svelte/store'
|
import { get, writable } from 'svelte/store'
|
||||||
|
|
||||||
@@ -200,6 +201,20 @@ export function setUserID(id: number) {
|
|||||||
return prof
|
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 getNotificationCount = async (jwt: string, mod: boolean) => {
|
||||||
const unreads = await getClient().getUnreadCount({
|
const unreads = await getClient().getUnreadCount({
|
||||||
auth: jwt,
|
auth: jwt,
|
||||||
@@ -279,8 +294,3 @@ export async function getInboxNotifications(dontUpdate: boolean = false) {
|
|||||||
|
|
||||||
localStorage.setItem('seenUntil', Date.now().toString())
|
localStorage.setItem('seenUntil', Date.now().toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(
|
|
||||||
async () => getInboxNotifications(),
|
|
||||||
get(userSettings).notifications.notifRate || 30 * 1000
|
|
||||||
)
|
|
||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
profile as currentProfile,
|
profile as currentProfile,
|
||||||
resetProfile,
|
resetProfile,
|
||||||
deleteProfile,
|
deleteProfile,
|
||||||
|
moveProfile,
|
||||||
} from '$lib/auth.js'
|
} from '$lib/auth.js'
|
||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||||
@@ -22,6 +23,8 @@
|
|||||||
import {
|
import {
|
||||||
ArrowLeftOnRectangle,
|
ArrowLeftOnRectangle,
|
||||||
ArrowUturnLeft,
|
ArrowUturnLeft,
|
||||||
|
ChevronDown,
|
||||||
|
ChevronUp,
|
||||||
EllipsisHorizontal,
|
EllipsisHorizontal,
|
||||||
Icon,
|
Icon,
|
||||||
PaintBrush,
|
PaintBrush,
|
||||||
@@ -29,6 +32,7 @@
|
|||||||
Trash,
|
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'
|
||||||
|
|
||||||
let newInstance: string = $profileData.defaultInstance ?? DEFAULT_INSTANCE_URL
|
let newInstance: string = $profileData.defaultInstance ?? DEFAULT_INSTANCE_URL
|
||||||
let loading = false
|
let loading = false
|
||||||
@@ -124,7 +128,7 @@
|
|||||||
{#each $profileData.profiles as profile, index (profile.id)}
|
{#each $profileData.profiles as profile, index (profile.id)}
|
||||||
<div
|
<div
|
||||||
class="flex flex-row gap-2 items-center py-4"
|
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="flex items-center gap-2">
|
||||||
<div class="relative group flex-col items-center">
|
<div class="relative group flex-col items-center">
|
||||||
@@ -160,12 +164,20 @@
|
|||||||
<Button on:click={toggleOpen} size="square-md" slot="button">
|
<Button on:click={toggleOpen} size="square-md" slot="button">
|
||||||
<Icon src={EllipsisHorizontal} mini size="16" slot="icon" />
|
<Icon src={EllipsisHorizontal} mini size="16" slot="icon" />
|
||||||
</Button>
|
</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
|
<MenuButton
|
||||||
disabled={!profile.color}
|
disabled={!profile.color}
|
||||||
on:click={() => (profile.color = undefined)}
|
on:click={() => (profile.color = undefined)}
|
||||||
>
|
>
|
||||||
<Icon src={ArrowUturnLeft} size="16" mini slot="icon" />
|
<Icon src={ArrowUturnLeft} size="16" mini slot="icon" />
|
||||||
Reset color
|
Reset Color
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
</Menu>
|
</Menu>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
Reference in new issue
Block a user