diff --git a/src/lib/auth.svelte.ts b/src/lib/auth.svelte.ts index 7af3bc23..3dc7fc0d 100644 --- a/src/lib/auth.svelte.ts +++ b/src/lib/auth.svelte.ts @@ -92,27 +92,27 @@ export const profileData = $state( ) class CurrentProfile { - #data = $derived( + #current = $derived( profileData.profiles.find(i => i.id == profileData.profile) ?? getDefaultProfile(), ) - get data() { - return this.#data + get current() { + return this.#current } - set data(value) { + set current(value) { if (!value) return const index = profileData.profiles.findIndex(i => i.id == value?.id) profileData.profiles[index] = value } async fetchUserData() { - const startId = this.#data.id - if (this.#data.jwt) { + const startId = this.#current.id + if (this.#current.jwt) { site.data = undefined notifications.set({ applications: 0, inbox: 0, reports: 0 }) - const res = await userFromJwt(this.#data.jwt, this.#data.instance) + const res = await userFromJwt(this.#current.jwt, this.#current.instance) if (!res?.user) toast({ content: @@ -121,21 +121,21 @@ class CurrentProfile { }) // TODO update authentication handling to not be this dynamic - if (this.#data.id != startId) { + if (this.#current.id != startId) { console.error('profile was switched too fast, ID mismatch') return } site.data = res?.site - this.#data.user = res?.user - if (profile.data.user) { - this.#data.avatar = res?.user?.local_user_view.person.avatar - this.#data.username = res?.user?.local_user_view.person.name + this.#current.user = res?.user + if (profile.current.user) { + this.#current.avatar = res?.user?.local_user_view.person.avatar + this.#current.username = res?.user?.local_user_view.person.name } } else { if (browser) { site.data = undefined - client({ instanceURL: this.#data.instance }) + client({ instanceURL: this.#current.instance }) .getSite() .then(res => (site.data = res)) } @@ -174,7 +174,7 @@ $effect.root(() => { }) $effect(() => { - if (profile.data.id || profileData) + if (profile.current.id || profileData) profile.fetchUserData().then(() => { checkInbox() }) @@ -358,7 +358,7 @@ async function getNotificationCount(jwt: string, mod: boolean, admin: boolean) { } async function checkInbox() { - const { user, jwt } = profile.data + const { user, jwt } = profile.current if (!jwt || !user) return const notifs = await getNotificationCount( @@ -380,10 +380,11 @@ async function init() { // hacky way to check donation status setTimeout(() => { if ( - profile.data.user?.local_user_view.local_user.last_donation_notification + profile.current.user?.local_user_view.local_user + .last_donation_notification ) { const donationDate = publishedToDate( - profile.data.user?.local_user_view.local_user + profile.current.user?.local_user_view.local_user .last_donation_notification, ) if (Date.now() - donationDate.getTime() > 365 * 24 * 60 * 60 * 1000) { @@ -395,11 +396,11 @@ async function init() { // lemmy js client donation dialog is broken fetch( - `${instanceToURL(profile.data.instance)}/api/v3/user/donation_dialog_shown`, + `${instanceToURL(profile.current.instance)}/api/v3/user/donation_dialog_shown`, { method: 'POST', headers: { - authorization: `Bearer ${profile.data.jwt}`, + authorization: `Bearer ${profile.current.jwt}`, }, }, ) diff --git a/src/lib/components/lemmy/PictrsImage.svelte b/src/lib/components/lemmy/PictrsImage.svelte index 2ec0324e..d6568487 100644 --- a/src/lib/components/lemmy/PictrsImage.svelte +++ b/src/lib/components/lemmy/PictrsImage.svelte @@ -14,7 +14,7 @@ let loading = $state(false) async function deleteImage(image: LocalImage) { - if (!profile.data?.jwt) return + if (!profile.current?.jwt) return try { loading = true diff --git a/src/lib/components/lemmy/comment/Comment.svelte b/src/lib/components/lemmy/comment/Comment.svelte index e2e717a4..c61ce8d6 100644 --- a/src/lib/components/lemmy/comment/Comment.svelte +++ b/src/lib/components/lemmy/comment/Comment.svelte @@ -50,7 +50,7 @@ let editingLoad = $state(false) async function save(type: 'reply' | 'edit') { - if (!profile.data?.jwt || newComment.length <= 0) return + if (!profile.current?.jwt || newComment.length <= 0) return editingLoad = true diff --git a/src/lib/components/lemmy/comment/CommentActions.svelte b/src/lib/components/lemmy/comment/CommentActions.svelte index 78685723..3c04f8cf 100644 --- a/src/lib/components/lemmy/comment/CommentActions.svelte +++ b/src/lib/components/lemmy/comment/CommentActions.svelte @@ -60,7 +60,7 @@ {$t('comment.reply')} - {#if profile.data?.user && (amMod(profile.data?.user, comment.community) || isAdmin(profile.data.user))} + {#if profile.current?.user && (amMod(profile.current?.user, comment.community) || isAdmin(profile.current.user))} {/if} @@ -90,8 +90,8 @@
{$t('post.actions.more.share')}
- {#if profile.data?.jwt} - {#if comment.creator.id == profile.data.user?.local_user_view.person.id} + {#if profile.current?.jwt} + {#if comment.creator.id == profile.current.user?.local_user_view.person.id} onedit?.(comment)}> {$t('post.actions.more.edit')} @@ -99,7 +99,7 @@ {/if} { - if (profile.data?.jwt) + if (profile.current?.jwt) comment.saved = await save(comment, !comment.saved) }} > @@ -108,11 +108,11 @@ {comment.saved ? $t('post.actions.unsave') : $t('post.actions.save')} - {#if profile.data?.user && profile.data.jwt && profile.data.user.local_user_view.person.id == comment.creator.id} + {#if profile.current?.user && profile.current.jwt && profile.current.user.local_user_view.person.id == comment.creator.id} { - if (profile.data?.jwt) + if (profile.current?.jwt) comment.comment.deleted = await deleteItem( comment, !comment.comment.deleted, @@ -127,7 +127,7 @@ {/if} - {#if profile.data.jwt && profile.data.user?.local_user_view.person.id != comment.creator.id} + {#if profile.current.jwt && profile.current.user?.local_user_view.person.id != comment.creator.id} report(comment)} color="danger-subtle"> {$t('moderation.report')} diff --git a/src/lib/components/lemmy/comment/CommentForm.svelte b/src/lib/components/lemmy/comment/CommentForm.svelte index c27c7236..c4afdb62 100644 --- a/src/lib/components/lemmy/comment/CommentForm.svelte +++ b/src/lib/components/lemmy/comment/CommentForm.svelte @@ -51,7 +51,7 @@ let language: number | undefined = $state() async function submit() { - if (!profile.data?.user || !profile.data?.jwt || value == '') return + if (!profile.current?.user || !profile.current?.jwt || value == '') return loading = true diff --git a/src/lib/components/lemmy/comment/CommentVote.svelte b/src/lib/components/lemmy/comment/CommentVote.svelte index 4cb300ce..b30fcc37 100644 --- a/src/lib/components/lemmy/comment/CommentVote.svelte +++ b/src/lib/components/lemmy/comment/CommentVote.svelte @@ -24,7 +24,7 @@ }: Props = $props() const castVote = async (newVote: number) => { - if (!profile.data?.jwt) { + if (!profile.current?.jwt) { toast({ content: $t('toast.loginVoteGate'), type: 'warning' }) return } diff --git a/src/lib/components/lemmy/community/CommunityCard.svelte b/src/lib/components/lemmy/community/CommunityCard.svelte index ae055a4c..c81233f2 100644 --- a/src/lib/components/lemmy/community/CommunityCard.svelte +++ b/src/lib/components/lemmy/community/CommunityCard.svelte @@ -113,7 +113,7 @@ }) async function subscribe() { - if (!profile.data?.jwt) return + if (!profile.current?.jwt) return loading.subscribing = true const subscribed = community_view.subscribed == 'Subscribed' || @@ -227,7 +227,7 @@ {/if}
- {#if profile.data?.jwt} + {#if profile.current?.jwt} {/snippet} - {#if (profile.data?.user && amMod(profile.data.user, item.community)) || (profile.data?.user && isAdmin(profile.data.user))} + {#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))} - {#if !item.community.local && !amMod(profile.data.user, item.community)} + {#if !item.community.local && !amMod(profile.current.user, item.community)} {$t('moderation.labelInstanceOnly')} {:else} {$t('moderation.label')} @@ -52,7 +52,7 @@ : $t('moderation.remove')} {/if} - {#if profile.data?.user && profile.data.user?.local_user_view.person.id != item.creator.id} + {#if profile.current?.user && profile.current.user?.local_user_view.person.id != item.creator.id} { - if (!profile.data.jwt) return + if (!profile.current.jwt) return item.comment = ( await feature( !item.comment.distinguished, item.comment, - profile.data.jwt, + profile.current.jwt, ) ).comment_view.comment }} @@ -104,7 +104,7 @@ {/if} - {#if profile.data?.user && isAdmin(profile.data.user)} + {#if profile.current?.user && isAdmin(profile.current.user)} {$t('admin.label')} remove(item, true)}> {#snippet prefix()} diff --git a/src/lib/components/lemmy/moderation/ModerationMenu.svelte b/src/lib/components/lemmy/moderation/ModerationMenu.svelte index 5338e3dc..ee02024e 100644 --- a/src/lib/components/lemmy/moderation/ModerationMenu.svelte +++ b/src/lib/components/lemmy/moderation/ModerationMenu.svelte @@ -32,7 +32,7 @@ let acting = $derived(locking || pinning) async function lock(lock: boolean) { - if (!profile.data?.jwt || !isPostView(item)) return + if (!profile.current?.jwt || !isPostView(item)) return locking = true try { @@ -53,7 +53,7 @@ } async function pin(pinned: boolean, toInstance: boolean = false) { - if (!profile.data?.jwt || !isPostView(item)) return + if (!profile.current?.jwt || !isPostView(item)) return pinning = true @@ -88,9 +88,9 @@ {/snippet} - {#if (profile.data?.user && amMod(profile.data.user, item.community)) || (profile.data?.user && isAdmin(profile.data.user))} + {#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))} - {#if !item.community.local && !amMod(profile.data.user, item.community)} + {#if !item.community.local && !amMod(profile.current.user, item.community)} {$t('moderation.labelInstanceOnly')} {:else} {$t('moderation.label')} @@ -124,7 +124,7 @@ ? $t('moderation.unfeature') : $t('moderation.feature')} - {#if isAdmin(profile.data.user)} + {#if isAdmin(profile.current.user)} {$t('form.post.community')} {/if}
@@ -139,7 +139,7 @@ {item.post.removed ? $t('moderation.restore') : $t('moderation.remove')} {/if}
- {#if profile.data?.user && profile.data.user.local_user_view.person.id != item.creator.id} + {#if profile.current?.user && profile.current.user.local_user_view.person.id != item.creator.id} @@ -164,7 +164,7 @@ {$t('moderation.votes')} {/if} - {#if profile.data?.user && isAdmin(profile.data.user)} + {#if profile.current?.user && isAdmin(profile.current.user)} {$t('admin.label')} - {#if !removed && profile.data?.user && (amMod(profile.data.user, item.community) || (isAdmin(profile.data.user) && item.community.local))} + {#if !removed && profile.current?.user && (amMod(profile.current.user, item.community) || (isAdmin(profile.current.user) && item.community.local))} {$t('moderation.removeSubmission.withReason')} diff --git a/src/lib/components/lemmy/moderation/ReportModal.svelte b/src/lib/components/lemmy/moderation/ReportModal.svelte index 465b9d09..d3a7aa2d 100644 --- a/src/lib/components/lemmy/moderation/ReportModal.svelte +++ b/src/lib/components/lemmy/moderation/ReportModal.svelte @@ -39,7 +39,7 @@ let reason = $state('') async function report() { - if (!item || !profile.data?.jwt || reason == '') return + if (!item || !profile.current?.jwt || reason == '') return loading = true try { diff --git a/src/lib/components/lemmy/post/Post.svelte b/src/lib/components/lemmy/post/Post.svelte index d26c11a5..6976521f 100644 --- a/src/lib/components/lemmy/post/Post.svelte +++ b/src/lib/components/lemmy/post/Post.svelte @@ -117,7 +117,7 @@ user={post.creator} published={publishedToDate(post.post.published)} {badges} - subscribed={profile.data?.user?.follows + subscribed={profile.current?.user?.follows .map(c => c.community.id) .includes(post.community.id) ? 'Subscribed' diff --git a/src/lib/components/lemmy/post/PostActions.svelte b/src/lib/components/lemmy/post/PostActions.svelte index f201b9a9..e7a66ccc 100644 --- a/src/lib/components/lemmy/post/PostActions.svelte +++ b/src/lib/components/lemmy/post/PostActions.svelte @@ -117,8 +117,8 @@ score={post.counts.score} upvotes={post.counts.upvotes} downvotes={post.counts.downvotes} - showCounts={profile.data?.user?.local_user_view?.local_user?.show_scores ?? - true} + showCounts={profile.current?.user?.local_user_view?.local_user + ?.show_scores ?? true} /> {/snippet} {$t('nav.menu.label')} - {#if profile.data?.jwt} + {#if profile.current?.jwt} {#snippet prefix()} diff --git a/src/lib/components/ui/navbar/commands/Commands.svelte b/src/lib/components/ui/navbar/commands/Commands.svelte index f4417c33..af8bb11e 100644 --- a/src/lib/components/ui/navbar/commands/Commands.svelte +++ b/src/lib/components/ui/navbar/commands/Commands.svelte @@ -23,7 +23,7 @@ $effect(() => { groups = getGroups( $resumables, - profile.data, + profile.current, profileData.profiles, theme.data, page.data.contextual?.actions, diff --git a/src/lib/components/ui/sidebar/CommunityList.svelte b/src/lib/components/ui/sidebar/CommunityList.svelte index 6b70ecf7..8a433872 100644 --- a/src/lib/components/ui/sidebar/CommunityList.svelte +++ b/src/lib/components/ui/sidebar/CommunityList.svelte @@ -25,7 +25,7 @@ animate:flip={{ duration: 500, easing: expoOut }} >
- {#if profile && !hasFavorite(profile.data, follow.id)} + {#if profile && !hasFavorite(profile.current, follow.id)} - {:else if isFavorites && profile && hasFavorite(profile.data, follow.id)} + {:else if isFavorites && profile && hasFavorite(profile.current, follow.id)}