diff --git a/bun.lockb b/bun.lockb index bbc32c90..e799413b 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 1569ea4c..efa461d6 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -19,6 +19,7 @@ import { writable, type Readable, type Writable, + type Updater, } from 'svelte/store' import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js' import { browser } from '$app/environment' @@ -102,9 +103,31 @@ let fetchUser = { prevProfile: -1, } -export let profile: Readable = derived( - profileData, - (pd, set, update) => { +function profileStore( + data: Writable, + fn: ( + values: ProfileData, + set: (value: Profile) => void, + update: (fn: Updater) => void + ) => any +) { + const derive: Readable = derived(data, fn) + const { subscribe } = derive + + return { + subscribe, + set: (value: Profile) => { + data.update((data) => { + let index = data.profiles.findIndex((t) => t.id == value.id) + data.profiles[index] = value + return data + }) + }, + } +} + +export let profile: Readable & { set: (v: Profile) => void } = + profileStore(profileData, (pd, set, update) => { const profile = pd.profiles.find((p) => p.id == pd.profile) ?? getDefaultProfile() @@ -154,8 +177,7 @@ export let profile: Readable = derived( fetchUser.loading = false } } - } -) + }) export let notifications = writable({ applications: 0, diff --git a/src/lib/components/lemmy/community/CommunityForm.svelte b/src/lib/components/lemmy/community/CommunityForm.svelte index 9e17f6c9..f725d052 100644 --- a/src/lib/components/lemmy/community/CommunityForm.svelte +++ b/src/lib/components/lemmy/community/CommunityForm.svelte @@ -75,15 +75,25 @@ }) if ($profile.user) { - $profile.user = { - ...$profile.user, - moderates: [ - ...$profile.user.moderates, - { - community: res.community_view.community, - moderator: $profile.user.local_user_view.person, - }, - ], + const c = $profile.user.moderates + .map((m) => m.community.id) + .indexOf(res.community_view.community.id) + if (c != -1) { + $profile.user.moderates[c] = { + community: res.community_view.community, + moderator: $profile.user.local_user_view.person, + } + } else { + $profile.user = { + ...$profile.user, + moderates: [ + ...$profile.user.moderates, + { + community: res.community_view.community, + moderator: $profile.user.local_user_view.person, + }, + ], + } } addSubscription(res.community_view.community, true) @@ -106,7 +116,10 @@ } -
+
{$t('routes.createCommunity')}
diff --git a/src/lib/components/lemmy/dropdowns/Sort.svelte b/src/lib/components/lemmy/dropdowns/Sort.svelte index bf6c23f6..ecd10b1d 100644 --- a/src/lib/components/lemmy/dropdowns/Sort.svelte +++ b/src/lib/components/lemmy/dropdowns/Sort.svelte @@ -15,9 +15,9 @@ export let navigate: boolean = true export let changeDefault: boolean = false - let sort: string = selected.startsWith('Top') ? 'TopAll' : selected + let sort: string = selected?.startsWith('Top') ? 'TopAll' : selected $: if (selected) { - sort = selected.startsWith('Top') ? 'TopAll' : selected + sort = selected?.startsWith('Top') ? 'TopAll' : selected } const setSelected = () => (selected = sort) $: changeDefault diff --git a/src/lib/components/lemmy/post/PostActions.svelte b/src/lib/components/lemmy/post/PostActions.svelte index b4c6a5d4..c281c934 100644 --- a/src/lib/components/lemmy/post/PostActions.svelte +++ b/src/lib/components/lemmy/post/PostActions.svelte @@ -148,7 +148,7 @@ - + {#if !LINKED_INSTANCE_URL} + + {/if}