Skip to content

Commit

Permalink
feat(web): Lazy load thumbnails on the people page (immich-app#5356)
Browse files Browse the repository at this point in the history
* feat(web): Lazy load thumbnails on the people page

Instead of loading all people thumbnails at once, only the first few
should be loaded eagerly.
This reduces the load on client and server side.

* chore: change name

---------

Co-authored-by: Alex Tran <[email protected]>
  • Loading branch information
l0nax and alextran1502 authored Nov 28, 2023
1 parent 4d72770 commit 5781ae9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
export let circle = false;
export let hidden = false;
export let border = false;
export let preload = true;
let complete = false;
export let eyeColor: 'black' | 'white' = 'white';
</script>

<img
loading={preload ? 'eager' : 'lazy'}
style:width={widthStyle}
style:height={heightStyle}
style:filter={hidden ? 'grayscale(50%)' : 'none'}
Expand Down
2 changes: 2 additions & 0 deletions web/src/lib/components/faces-page/people-card.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import Icon from '$lib/components/elements/icon.svelte';
export let person: PersonResponseDto;
export let preload = false;
type MenuItemEvent = 'change-name' | 'set-birth-date' | 'merge-faces' | 'hide-face';
let dispatch = createEventDispatcher<{
Expand Down Expand Up @@ -48,6 +49,7 @@
<div class="h-48 w-48 rounded-xl brightness-95 filter">
<ImageThumbnail
shadow
{preload}
url={api.getPeopleThumbnailUrl(person.id)}
altText={person.name}
title={person.name}
Expand Down
6 changes: 4 additions & 2 deletions web/src/routes/(user)/people/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,11 @@
{#if countVisiblePeople > 0}
<div class="pl-4">
<div class="flex flex-row flex-wrap gap-1">
{#each people as person (person.id)}
{#each people as person, idx (person.id)}
{#if !person.isHidden}
<PeopleCard
{person}
preload={idx < 20}
on:change-name={() => handleChangeName(person)}
on:set-birth-date={() => handleSetBirthDate(person)}
on:merge-faces={() => handleMergeFaces(person)}
Expand Down Expand Up @@ -444,14 +445,15 @@
bind:showLoadingSpinner
bind:toggleVisibility
>
{#each people as person (person.id)}
{#each people as person, idx (person.id)}
<button
class="relative h-36 w-36 md:h-48 md:w-48"
on:click={() => (person.isHidden = !person.isHidden)}
on:mouseenter={() => (eyeColorMap[person.id] = 'black')}
on:mouseleave={() => (eyeColorMap[person.id] = 'white')}
>
<ImageThumbnail
preload={idx < 20}
bind:hidden={person.isHidden}
shadow
url={api.getPeopleThumbnailUrl(person.id)}
Expand Down

0 comments on commit 5781ae9

Please sign in to comment.