From 3a079b01f14b3d861a74256e33d622e837b0954f Mon Sep 17 00:00:00 2001 From: Xylight Date: Wed, 12 Jun 2024 18:49:35 -0700 Subject: [PATCH] fix: favorites bar --- src/lib/auth.ts | 6 +- .../ui/sidebar/CommunityList.svelte | 56 +++++++++++-------- src/lib/components/ui/sidebar/Sidebar.svelte | 12 +--- .../ui/sidebar/SidebarButton.svelte | 4 +- src/lib/i18n/en.json | 3 +- src/lib/lemmy/item.ts | 23 +++++--- src/routes/c/[name]/+page.svelte | 1 - .../post/[instance]/[id=integer]/+page.svelte | 1 - 8 files changed, 60 insertions(+), 46 deletions(-) diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 3287631d..6617c494 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -11,6 +11,7 @@ import { LemmyHttp, type GetSiteResponse, type MyUserInfo, + type Community, } from 'lemmy-js-client' import { get, writable } from 'svelte/store' import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js' @@ -43,7 +44,7 @@ export interface Profile { user?: PersonData username?: string avatar?: string - favorites?: ResumableItem[] + favorites?: Community[] color?: string } @@ -151,11 +152,10 @@ profile.subscribe(async (p) => { instance?.set(get(profileData).defaultInstance ?? DEFAULT_INSTANCE_URL) } if (!p) return - if (p.user) return instance.set(p.instance) // fetch the user because p.user is undefined - if (p?.jwt) { + if (p?.jwt && !p?.user) { const user = await userFromJwt(p.jwt, p.instance) .then((user) => { if (!user?.user) diff --git a/src/lib/components/ui/sidebar/CommunityList.svelte b/src/lib/components/ui/sidebar/CommunityList.svelte index c579a0fb..a8d243b8 100644 --- a/src/lib/components/ui/sidebar/CommunityList.svelte +++ b/src/lib/components/ui/sidebar/CommunityList.svelte @@ -1,52 +1,64 @@ {#each items.sort( (a, b) => a.title.localeCompare(b.title) ) as follow (follow.id)}
- + style="grid-column: 1; grid-row: 1;" + on:click={() => addFavorite(follow)} + > + + + {:else if isFavorites && $profile && hasFavorite($profile, follow.id)} + + {/if}
diff --git a/src/lib/components/ui/sidebar/Sidebar.svelte b/src/lib/components/ui/sidebar/Sidebar.svelte index bf722c84..1c3b05ea 100644 --- a/src/lib/components/ui/sidebar/Sidebar.svelte +++ b/src/lib/components/ui/sidebar/Sidebar.svelte @@ -28,6 +28,8 @@ import Application from '../../../../routes/admin/applications/Application.svelte' import { t } from '$lib/translations' import ItemList from '$lib/components/lemmy/generic/ItemList.svelte' + + $: if ($profile) console.log('profile changed')