feat: make admin adding and removal consistent with mods

This commit is contained in:
Xyphyn committed 2023-08-28 16:28:44 -07:00
1 parent 9d0694f138
commit 98eeadab42
4 files changed
+92 -14

No files matched your search

+17
View File
@@ -1,5 +1,6 @@
import { profile } from '$lib/auth.js'
import { getClient } from '$lib/lemmy.js'
import { trycatch } from '$lib/util.js'
import type { Community, MyUserInfo, PersonView } from 'lemmy-js-client'
import { get } from 'svelte/store'
@@ -48,3 +49,19 @@ export const addSubscription = (
profile.set(p)
}
}
export const addAdmin = async (handle: string, added: boolean, jwt: string) =>
trycatch(async () => {
const user = await getClient().resolveObject({
auth: jwt,
q: handle,
})
if (!user.person) throw new Error('No user found')
return await getClient().addAdmin({
auth: jwt,
added: true,
person_id: user.person.person.id,
})
})
+4
View File
@@ -94,3 +94,7 @@ export const trycatch = <T>(func: () => T): Maybe<T> => {
})
}
}
export const removeItem = <T>(array: T[], predicate: (item: T) => boolean) => {
array.splice(array.findIndex(predicate), 1)
}