Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use proper transition with objects for avatars #157

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/lib/components/AvatarWithFallback.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
export let avatarUrl: string = '';
export let altText: string = '';
export let channelId: string = '';
export let listId: string = '';

let currentUrl = '';
let showFallback = false;
Expand All @@ -25,7 +26,31 @@

{#if !showFallback}
<img
use:transition={`avatar-${channelId}`}
use:transition={{
name: `avatar-${channelId}`,
shouldApply({ navigation }) {
// here we are navigating from main page to detail page
if (navigation.to?.params?.id != null) {
// we should apply if the id we are navigating to
// has the listId of this avatar
return navigation.to.params.id === listId;
}
// here we are navigating back from the detail to the home, we should apply
// only if we are coming from the page with the same id as listId
return navigation.from?.params?.id === listId;
},
applyImmediately({ navigation }) {
// here we are navigating from main page to detail page
if (navigation.to?.params?.id != null) {
// we should apply immediately if the id we are navigating to
// has the listId of this avatar
return navigation.to.params.id === listId;
}
// here we are navigating back from the detail to the home, we should apply
// immediately only if we are coming from the page with the same id as listId
return navigation.from?.params?.id === listId;
},
}}
class="mr-1 inline-block h-14 w-14 rounded-full"
referrerpolicy="no-referrer"
src={currentUrl}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/components/ChannelCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import AvatarWithFallback from '$/lib/components/AvatarWithFallback.svelte';
import type { YouTubeChannelMetaAPIResponse } from '$/lib/server/YouTubeAPI';
import { onMount } from 'svelte';
import { page } from '$app/stores';

export let channel: YouTubeChannelMetaAPIResponse;
export let locale: string;
Expand Down Expand Up @@ -42,7 +43,8 @@
<AvatarWithFallback
channelId={channel.originId}
avatarUrl={channel.avatarUrl}
altText={channel.name} />
altText={channel.name}
listId={$page.params?.id} />
<div>
<div class="font-bold">{channel.name}</div>
<div>{channel.customUrl}</div>
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/ListCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
<AvatarWithFallback
channelId={item?.meta?.youtubeMeta?.originId}
avatarUrl={item?.meta?.youtubeMeta?.avatarUrl}
altText={item?.meta?.youtubeMeta?.name} />
altText={item?.meta?.youtubeMeta?.name}
listId={list.id} />
{/each}
{#if hiddenItems > 0}
<span
Expand Down
Loading