refactor: switch posts to barrel export

This commit is contained in:
James Xylight committed 2025-09-07 10:20:04 -07:00
1 parent 0281e6f56a
commit bb30a86dc4
47 files changed
+424 -528

No files matched your search

+22 -23
View File
@@ -1,28 +1,27 @@
import { profile, type ProfileInfo } from '$lib/auth.svelte'
import { getClient } from '$lib/client/lemmy.svelte'
import { trycatch } from '$lib/util.svelte'
import { client } from '$lib/client/lemmy.svelte'
import type { Community, MyUserInfo } from '$lib/client/types'
// TODO obliterate this file
export const blockUser = async (block: boolean, id: number) => {
export async function blockUser(block: boolean, id: number) {
const auth = profile.current?.jwt
if (!auth) throw new Error('Unauthorized')
await getClient().blockPerson({
await client().blockPerson({
block: block,
person_id: id,
})
}
export const isBlocked = (me: MyUserInfo, user: number) =>
me.person_blocks.map((b) => b.target.id).includes(user)
export function isBlocked(me: MyUserInfo, user: number) {
return me.person_blocks.map((b) => b.target.id).includes(user)
}
export const addSubscription = (
export function addSubscription(
community: Community,
subscribe: boolean = true,
) => {
) {
const index = profile.current.user?.follows
.map((f) => f.community.id)
.indexOf(community.id)
@@ -37,19 +36,19 @@ export const addSubscription = (
}
}
export const addAdmin = async (handle: string, added: boolean) =>
trycatch(async () => {
const user = await getClient().resolveObject({
q: handle,
})
if (!user.person) throw new Error('No user found')
return await getClient().addAdmin({
added: added,
person_id: user.person.person.id,
})
export async function addAdmin(handle: string, added: boolean) {
const user = await client().resolveObject({
q: handle,
})
export const hasFavorite = (profile: ProfileInfo, id: number): boolean =>
profile.favorites?.map((i) => i.id).includes(id) ?? false
if (!user.person) throw new Error('No user found')
return await client().addAdmin({
added: added,
person_id: user.person.person.id,
})
}
export function hasFavorite(profile: ProfileInfo, id: number): boolean {
return profile.favorites?.map((i) => i.id).includes(id) ?? false
}