Skip to content

Commit 2a127e4

Browse files
committed
fix: use proper transition with objects for avatars
1 parent 2489fb2 commit 2a127e4

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/lib/components/AvatarWithFallback.svelte

+26-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
export let avatarUrl: string = '';
66
export let altText: string = '';
77
export let channelId: string = '';
8+
export let listId: string = '';
89
910
let currentUrl = '';
1011
let showFallback = false;
@@ -25,7 +26,31 @@
2526

2627
{#if !showFallback}
2728
<img
28-
use:transition={`avatar-${channelId}`}
29+
use:transition={{
30+
name: `avatar-${channelId}`,
31+
shouldApply({ navigation }) {
32+
// here we are navigating from main page to detail page
33+
if (navigation.to?.params?.id != null) {
34+
// we should apply if the id we are navigating to
35+
// has the listId of this avatar
36+
return navigation.to.params.id === listId;
37+
}
38+
// here we are navigating back from the detail to the home, we should apply
39+
// only if we are coming from the page with the same id as listId
40+
return navigation.from?.params?.id === listId;
41+
},
42+
applyImmediately({ navigation }) {
43+
// here we are navigating from main page to detail page
44+
if (navigation.to?.params?.id != null) {
45+
// we should apply immediately if the id we are navigating to
46+
// has the listId of this avatar
47+
return navigation.to.params.id === listId;
48+
}
49+
// here we are navigating back from the detail to the home, we should apply
50+
// immediately only if we are coming from the page with the same id as listId
51+
return navigation.from?.params?.id === listId;
52+
},
53+
}}
2954
class="mr-1 inline-block h-14 w-14 rounded-full"
3055
referrerpolicy="no-referrer"
3156
src={currentUrl}

src/lib/components/ChannelCard.svelte

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import AvatarWithFallback from '$/lib/components/AvatarWithFallback.svelte';
33
import type { YouTubeChannelMetaAPIResponse } from '$/lib/server/YouTubeAPI';
44
import { onMount } from 'svelte';
5+
import { page } from '$app/stores';
56
67
export let channel: YouTubeChannelMetaAPIResponse;
78
export let locale: string;
@@ -42,7 +43,8 @@
4243
<AvatarWithFallback
4344
channelId={channel.originId}
4445
avatarUrl={channel.avatarUrl}
45-
altText={channel.name} />
46+
altText={channel.name}
47+
listId={$page.params?.id} />
4648
<div>
4749
<div class="font-bold">{channel.name}</div>
4850
<div>{channel.customUrl}</div>

src/lib/components/ListCard.svelte

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
<AvatarWithFallback
3434
channelId={item?.meta?.youtubeMeta?.originId}
3535
avatarUrl={item?.meta?.youtubeMeta?.avatarUrl}
36-
altText={item?.meta?.youtubeMeta?.name} />
36+
altText={item?.meta?.youtubeMeta?.name}
37+
listId={list.id} />
3738
{/each}
3839
{#if hiddenItems > 0}
3940
<span

0 commit comments

Comments
 (0)