Skip to content

Commit f1ba278

Browse files
committed
fix: make profile button reactive
fix: dont show following when not available
1 parent 092da89 commit f1ba278

8 files changed

Lines changed: 30 additions & 18 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ui",
3-
"version": "6.4.354",
3+
"version": "6.4.355",
44
"license": "BUSL-1.1",
55
"private": true,
66
"packageManager": "pnpm@10.28.0",

src/lib/components/EpisodesList.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1414
import Logo from '$lib/components/icons/Logo.svelte'
1515
import { episodes as _episodes, client, notes, type Media } from '$lib/modules/anilist'
16-
import { authAggregator, list, progress } from '$lib/modules/auth'
16+
import { list, progress } from '$lib/modules/auth'
1717
import { makeEpisodeList } from '$lib/modules/extensions'
1818
import { click, dragScroll } from '$lib/modules/navigate'
1919
import { settings, SUPPORTS } from '$lib/modules/settings'
@@ -44,7 +44,9 @@
4444
4545
export let following = client.following(media.id)
4646
47-
$: followerEntries = $following?.data?.following?.mediaList?.filter(e => e?.user?.id !== authAggregator.id()) ?? []
47+
const viewer = client.client.viewer
48+
49+
$: followerEntries = ($viewer?.viewer?.id && $following?.data?.following?.mediaList?.filter(e => e?.user?.id !== $viewer.viewer?.id)) || []
4850
4951
$: watchProgress = liveAnimeProgress(media.id)
5052
</script>

src/lib/components/ui/banner/full-banner.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import { goto } from '$app/navigation'
1111
import { client, desc, duration, format, getTextColorForRating, season, status, title, type Media } from '$lib/modules/anilist'
1212
import { episodesCached } from '$lib/modules/anizip'
13-
import { authAggregator, of } from '$lib/modules/auth'
13+
import { of } from '$lib/modules/auth'
1414
import { click } from '$lib/modules/navigate'
1515
import { colors } from '$lib/utils'
1616
export let mediaList: Array<Media | null>
@@ -66,7 +66,9 @@
6666
const ids = mediaList.map(m => m?.id).filter(e => e) as number[]
6767
const following = client.followingMany(ids, 'cache-first')
6868
69-
$: filtered = $following?.data?.Page?.mediaList?.filter(ml => ml?.user?.id !== authAggregator.id()) ?? []
69+
const viewer = client.client.viewer
70+
71+
$: filtered = ($viewer?.viewer?.id && $following?.data?.Page?.mediaList?.filter(ml => ml?.user?.id !== $viewer.viewer?.id)) || []
7072
7173
$: usersForCurrent = filtered.filter((f): f is NonNullable<typeof f> => f?.media?.id === current?.id && !!f?.user).map(({ user }) => user!)
7274
</script>

src/lib/components/ui/sidebar/sidebarlist.svelte

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
import { SUPPORTS } from '$lib/modules/settings'
2121
import { cn, highEntropyValues } from '$lib/utils'
2222
23-
const auth = client.hasAuth
24-
25-
$: hasAuth = $auth
26-
2723
let visibilityState: DocumentVisibilityState
2824
2925
$: active = ($lockedState === 'locked' || visibilityState === 'hidden' || ($idleState === 'active' && $activityState === 'active')) && $page.route.id !== '/app/player' && !SUPPORTS.isUnderPowered
@@ -44,6 +40,8 @@
4440
function manualUpdate () {
4541
native.openURL('https://hayase.watch/download/')
4642
}
43+
44+
const viewer = client.viewer
4745
</script>
4846

4947
<svelte:document bind:visibilityState />
@@ -133,11 +131,10 @@
133131
</SidebarButton>
134132
<SidebarButton href='/app/profile/'>
135133
<!-- <SidebarButton href='/app/profile/' class='hidden md:flex py-0 animated-icon'> -->
136-
{#if hasAuth}
137-
{@const viewer = client.profile()}
134+
{#if $viewer}
138135
<Avatar.Root class='size-6 rounded-md'>
139-
<Avatar.Image src={viewer?.avatar?.large ?? ''} alt={viewer?.name} />
140-
<Avatar.Fallback>{viewer?.name}</Avatar.Fallback>
136+
<Avatar.Image src={$viewer.avatar?.large ?? ''} alt={$viewer.name} />
137+
<Avatar.Fallback>{$viewer.name}</Avatar.Fallback>
141138
</Avatar.Root>
142139
{:else}
143140
<LogIn size={18} />

src/lib/modules/anilist/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,13 @@ class AnilistClient {
228228

229229
following (animeID: number) {
230230
debug('following: fetching following for anime with ID', animeID)
231+
if (!this.client.viewer.value?.viewer?.id) return
231232
return queryStore({ client: this.client, query: Following, variables: { id: animeID } })
232233
}
233234

234235
followingMany (animeIDs: number[], requestPolicy: RequestPolicy = 'cache-and-network') {
235236
debug('followingMany: fetching following for anime with IDs', animeIDs)
237+
if (!this.client.viewer.value?.viewer?.id) return
236238
return queryStore({ client: this.client, query: FollowingMany, variables: { ids: animeIDs }, context: { requestPolicy } })
237239
}
238240

src/lib/modules/anilist/queries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ export const AnimePage = gql(`
590590
}
591591
}
592592
},
593-
threads: Page(page: 1, perPage: 16) {
593+
threads: Page(perPage: 16) {
594594
pageInfo {
595595
hasNextPage,
596596
total

src/lib/modules/auth/client.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { readable } from 'simple-store-svelte'
2-
import { get } from 'svelte/store'
2+
import { derived, get } from 'svelte/store'
33
import { persisted } from 'svelte-persisted-store'
44

55
import { client, episodes, type Media } from '../anilist'
@@ -25,6 +25,13 @@ export default new class AuthAggregator {
2525
return () => unsub.forEach(fn => fn())
2626
})
2727

28+
viewer = derived([client.client.viewer, kitsu.viewer, mal.viewer], ([$anilistViewer, $kitsuViewer, $malViewer]) => {
29+
if ($anilistViewer?.viewer?.id) return $anilistViewer.viewer
30+
if ($kitsuViewer?.id) return $kitsuViewer
31+
if ($malViewer?.id) return $malViewer
32+
return null
33+
})
34+
2835
syncSettings = persisted('syncSettings', { al: true, local: true, kitsu: true, mal: true })
2936
// AUTH
3037

src/routes/app/anime/[id]/+layout.svelte

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import * as Dialog from '$lib/components/ui/dialog'
1818
import { Load } from '$lib/components/ui/img'
1919
import { Profile } from '$lib/components/ui/profile'
20-
import { cover, desc, duration, format, season, status, title, getBGColorForRating } from '$lib/modules/anilist'
21-
import { authAggregator, list, of } from '$lib/modules/auth'
20+
import { cover, desc, duration, format, season, status, title, getBGColorForRating, client } from '$lib/modules/anilist'
21+
import { list, of } from '$lib/modules/auth'
2222
import native from '$lib/modules/native'
2323
import { dragScroll } from '$lib/modules/navigate'
2424
import { settings, SUPPORTS } from '$lib/modules/settings'
@@ -46,8 +46,10 @@
4646
hideBanner.value = target.scrollTop > 100
4747
}
4848
49+
const viewer = client.client.viewer
50+
4951
$: info = data.info
50-
$: followerEntries = $info?.data?.following?.mediaList?.filter(e => e?.user?.id !== authAggregator.id()) ?? []
52+
$: followerEntries = ($viewer?.viewer?.id && $info.data?.following?.mediaList?.filter(e => e?.user?.id !== $viewer.viewer?.id)) || []
5153
5254
$: nativeTitle = media.title?.native ?? media.title?.romaji ?? ''
5355
$: romajiTitle = media.title?.romaji ?? media.title?.native ?? ''

0 commit comments

Comments
 (0)