From a14b5786ee837267cc74736da4c0d90cb6c064a3 Mon Sep 17 00:00:00 2001 From: Xylight Date: Sun, 7 Jul 2024 19:00:55 -0700 Subject: [PATCH] fix: subscribe error --- src/lib/lemmy/item.ts | 6 ------ src/lib/lemmy/user.ts | 21 +++++---------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/lib/lemmy/item.ts b/src/lib/lemmy/item.ts index b06b64b6..008a3e9d 100644 --- a/src/lib/lemmy/item.ts +++ b/src/lib/lemmy/item.ts @@ -96,10 +96,4 @@ export function addFavorite(item: Community, add: boolean = true) { } p.favorites = favs profileData.update(() => pd) - profile.update((p) => ({ - ...p, - favorites: favs, - id: p!.id, - instance: p!.instance, - })) } diff --git a/src/lib/lemmy/user.ts b/src/lib/lemmy/user.ts index 953aa6f3..3dab12e9 100644 --- a/src/lib/lemmy/user.ts +++ b/src/lib/lemmy/user.ts @@ -1,4 +1,4 @@ -import { profile, type Profile } from '$lib/auth.js' +import { profile, profileData, type 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' @@ -22,30 +22,19 @@ export const addSubscription = ( community: Community, subscribe: boolean = true ) => { - const p = get(profile) + const pd = get(profileData) + const p = pd.profiles.find((p) => p.id == pd.profile) if (!p?.user) return if (subscribe) { - profile.set({ - ...p, - user: { - ...p.user, - follows: [ - ...p.user.follows, - { - community: community, - follower: p.user.local_user_view.person, - }, - ], - }, - }) + profileData.set(pd) } else { p.user.follows.splice( p.user.follows.findIndex((i) => i.community.id == community.id), 1 ) - profile.set(p) + profileData.set(pd) } }