mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 15:11:58 +00:00
fix(web): single row of items (#11729)
* fix(web): single row of items * remove filterBoxWidth * slight size adjustment * rewrite action as component
This commit is contained in:
parent
e384692025
commit
5acdc958b6
4 changed files with 68 additions and 49 deletions
|
@ -77,8 +77,6 @@
|
||||||
: MediaType.All,
|
: MediaType.All,
|
||||||
};
|
};
|
||||||
|
|
||||||
let filterBoxWidth = 0;
|
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
filter = {
|
filter = {
|
||||||
personIds: new Set(),
|
personIds: new Set(),
|
||||||
|
@ -120,7 +118,6 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
bind:clientWidth={filterBoxWidth}
|
|
||||||
transition:fly={{ y: 25, duration: 250 }}
|
transition:fly={{ y: 25, duration: 250 }}
|
||||||
class="absolute w-full rounded-b-3xl border-2 border-t-0 border-gray-200 bg-white shadow-2xl dark:border-gray-700 dark:bg-immich-dark-gray dark:text-gray-300"
|
class="absolute w-full rounded-b-3xl border-2 border-t-0 border-gray-200 bg-white shadow-2xl dark:border-gray-700 dark:bg-immich-dark-gray dark:text-gray-300"
|
||||||
>
|
>
|
||||||
|
@ -132,7 +129,7 @@
|
||||||
>
|
>
|
||||||
<div class="px-4 sm:px-6 py-4 space-y-10 max-h-[calc(100dvh-12rem)] overflow-y-auto immich-scrollbar" tabindex="-1">
|
<div class="px-4 sm:px-6 py-4 space-y-10 max-h-[calc(100dvh-12rem)] overflow-y-auto immich-scrollbar" tabindex="-1">
|
||||||
<!-- PEOPLE -->
|
<!-- PEOPLE -->
|
||||||
<SearchPeopleSection width={filterBoxWidth} bind:selectedPeople={filter.personIds} />
|
<SearchPeopleSection bind:selectedPeople={filter.personIds} />
|
||||||
|
|
||||||
<!-- TEXT -->
|
<!-- TEXT -->
|
||||||
<SearchTextSection bind:filename={filter.filename} bind:context={filter.context} />
|
<SearchTextSection bind:filename={filter.filename} bind:context={filter.context} />
|
||||||
|
|
|
@ -8,14 +8,14 @@
|
||||||
import { mdiClose, mdiArrowRight } from '@mdi/js';
|
import { mdiClose, mdiArrowRight } from '@mdi/js';
|
||||||
import { handleError } from '$lib/utils/handle-error';
|
import { handleError } from '$lib/utils/handle-error';
|
||||||
import { t } from 'svelte-i18n';
|
import { t } from 'svelte-i18n';
|
||||||
|
import SingleGridRow from '$lib/components/shared-components/single-grid-row.svelte';
|
||||||
|
|
||||||
export let width: number;
|
|
||||||
export let selectedPeople: Set<string>;
|
export let selectedPeople: Set<string>;
|
||||||
|
|
||||||
let peoplePromise = getPeople();
|
let peoplePromise = getPeople();
|
||||||
let showAllPeople = false;
|
let showAllPeople = false;
|
||||||
let name = '';
|
let name = '';
|
||||||
$: numberOfPeople = (width - 80) / 85;
|
let numberOfPeople = 1;
|
||||||
|
|
||||||
function orderBySelectedPeopleFirst(people: PersonResponseDto[]) {
|
function orderBySelectedPeopleFirst(people: PersonResponseDto[]) {
|
||||||
return [
|
return [
|
||||||
|
@ -60,11 +60,14 @@
|
||||||
<SearchBar bind:name placeholder={$t('filter_people')} showLoadingSpinner={false} />
|
<SearchBar bind:name placeholder={$t('filter_people')} showLoadingSpinner={false} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex -mx-1 max-h-64 gap-1 mt-2 flex-wrap overflow-y-auto immich-scrollbar">
|
<SingleGridRow
|
||||||
|
class="grid grid-cols-[repeat(auto-fill,minmax(5rem,1fr))] -mx-1 gap-1 mt-2 overflow-y-auto immich-scrollbar"
|
||||||
|
bind:itemCount={numberOfPeople}
|
||||||
|
>
|
||||||
{#each peopleList as person (person.id)}
|
{#each peopleList as person (person.id)}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="flex flex-col items-center w-20 rounded-3xl border-2 hover:bg-immich-gray dark:hover:bg-immich-dark-primary/20 p-2 transition-all {selectedPeople.has(
|
class="flex flex-col items-center rounded-3xl border-2 hover:bg-immich-gray dark:hover:bg-immich-dark-primary/20 p-2 transition-all {selectedPeople.has(
|
||||||
person.id,
|
person.id,
|
||||||
)
|
)
|
||||||
? 'dark:border-slate-500 border-slate-400 bg-slate-200 dark:bg-slate-800 dark:text-white'
|
? 'dark:border-slate-500 border-slate-400 bg-slate-200 dark:bg-slate-800 dark:text-white'
|
||||||
|
@ -75,7 +78,7 @@
|
||||||
<p class="mt-2 line-clamp-2 text-sm font-medium dark:text-white">{person.name}</p>
|
<p class="mt-2 line-clamp-2 text-sm font-medium dark:text-white">{person.name}</p>
|
||||||
</button>
|
</button>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</SingleGridRow>
|
||||||
|
|
||||||
{#if showAllPeople || people.length > peopleList.length}
|
{#if showAllPeople || people.length > peopleList.length}
|
||||||
<div class="flex justify-center mt-2">
|
<div class="flex justify-center mt-2">
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
<script lang="ts">
|
||||||
|
let className = '';
|
||||||
|
export { className as class };
|
||||||
|
export let itemCount = 1;
|
||||||
|
|
||||||
|
let container: HTMLElement | undefined;
|
||||||
|
let contentRect: DOMRectReadOnly | undefined;
|
||||||
|
|
||||||
|
const getGridGap = (element: Element) => {
|
||||||
|
const style = getComputedStyle(element);
|
||||||
|
|
||||||
|
return {
|
||||||
|
columnGap: parsePixels(style.columnGap),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const parsePixels = (style: string) => Number.parseInt(style, 10) || 0;
|
||||||
|
|
||||||
|
const getItemCount = (container: HTMLElement, containerWidth: number) => {
|
||||||
|
if (!container.firstElementChild) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const childContentRect = container.firstElementChild.getBoundingClientRect();
|
||||||
|
const childWidth = Math.floor(childContentRect.width || Infinity);
|
||||||
|
const { columnGap } = getGridGap(container);
|
||||||
|
|
||||||
|
return Math.floor((containerWidth + columnGap) / (childWidth + columnGap)) || 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
$: if (container && contentRect) {
|
||||||
|
itemCount = getItemCount(container, contentRect.width);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class={className} bind:this={container} bind:contentRect>
|
||||||
|
<slot {itemCount} />
|
||||||
|
</div>
|
|
@ -10,6 +10,7 @@
|
||||||
import EmptyPlaceholder from '$lib/components/shared-components/empty-placeholder.svelte';
|
import EmptyPlaceholder from '$lib/components/shared-components/empty-placeholder.svelte';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { websocketEvents } from '$lib/stores/websocket';
|
import { websocketEvents } from '$lib/stores/websocket';
|
||||||
|
import SingleGridRow from '$lib/components/shared-components/single-grid-row.svelte';
|
||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
|
|
||||||
|
@ -19,25 +20,14 @@
|
||||||
OBJECTS = 'smartInfo.objects',
|
OBJECTS = 'smartInfo.objects',
|
||||||
}
|
}
|
||||||
|
|
||||||
let MAX_PEOPLE_ITEMS: number;
|
|
||||||
let MAX_PLACE_ITEMS: number;
|
|
||||||
let innerWidth: number;
|
|
||||||
let screenSize: number;
|
|
||||||
const getFieldItems = (items: SearchExploreResponseDto[], field: Field) => {
|
const getFieldItems = (items: SearchExploreResponseDto[], field: Field) => {
|
||||||
const targetField = items.find((item) => item.fieldName === field);
|
const targetField = items.find((item) => item.fieldName === field);
|
||||||
return targetField?.items || [];
|
return targetField?.items || [];
|
||||||
};
|
};
|
||||||
|
|
||||||
$: places = getFieldItems(data.items, Field.CITY).slice(0, MAX_PLACE_ITEMS);
|
$: places = getFieldItems(data.items, Field.CITY);
|
||||||
$: people = data.response.people.slice(0, MAX_PEOPLE_ITEMS);
|
$: people = data.response.people;
|
||||||
$: hasPeople = data.response.total > 0;
|
$: hasPeople = data.response.total > 0;
|
||||||
$: {
|
|
||||||
if (innerWidth && screenSize) {
|
|
||||||
// Set the number of faces according to the screen size and the div size
|
|
||||||
MAX_PEOPLE_ITEMS = screenSize < 768 ? Math.floor(innerWidth / 96) : Math.floor(innerWidth / 120);
|
|
||||||
MAX_PLACE_ITEMS = screenSize < 768 ? Math.floor(innerWidth / 150) : Math.floor(innerWidth / 172);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
return websocketEvents.on('on_person_thumbnail', (personId: string) => {
|
return websocketEvents.on('on_person_thumbnail', (personId: string) => {
|
||||||
|
@ -52,8 +42,6 @@
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window bind:innerWidth={screenSize} />
|
|
||||||
|
|
||||||
<UserPageLayout title={data.meta.title}>
|
<UserPageLayout title={data.meta.title}>
|
||||||
{#if hasPeople}
|
{#if hasPeople}
|
||||||
<div class="mb-6 mt-2">
|
<div class="mb-6 mt-2">
|
||||||
|
@ -65,25 +53,17 @@
|
||||||
draggable="false">{$t('view_all')}</a
|
draggable="false">{$t('view_all')}</a
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<SingleGridRow
|
||||||
class="flex flex-row {MAX_PEOPLE_ITEMS < 5 ? 'justify-center' : ''} flex-wrap gap-4"
|
class="grid md:grid-cols-[repeat(auto-fill,minmax(7rem,1fr))] grid-cols-[repeat(auto-fill,minmax(5rem,1fr))] gap-x-4"
|
||||||
bind:offsetWidth={innerWidth}
|
let:itemCount
|
||||||
>
|
>
|
||||||
{#if MAX_PEOPLE_ITEMS}
|
{#each people.slice(0, itemCount) as person (person.id)}
|
||||||
{#each people as person (person.id)}
|
<a href="{AppRoute.PEOPLE}/{person.id}" class="text-center">
|
||||||
<a href="{AppRoute.PEOPLE}/{person.id}" class="w-20 md:w-24 text-center">
|
<ImageThumbnail circle shadow url={getPeopleThumbnailUrl(person)} altText={person.name} widthStyle="100%" />
|
||||||
<ImageThumbnail
|
<p class="mt-2 text-ellipsis text-sm font-medium dark:text-white">{person.name}</p>
|
||||||
circle
|
</a>
|
||||||
shadow
|
{/each}
|
||||||
url={getPeopleThumbnailUrl(person)}
|
</SingleGridRow>
|
||||||
altText={person.name}
|
|
||||||
widthStyle="100%"
|
|
||||||
/>
|
|
||||||
<p class="mt-2 text-ellipsis text-sm font-medium dark:text-white">{person.name}</p>
|
|
||||||
</a>
|
|
||||||
{/each}
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
@ -97,16 +77,17 @@
|
||||||
draggable="false">{$t('view_all')}</a
|
draggable="false">{$t('view_all')}</a
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-row flex-wrap gap-4">
|
<SingleGridRow
|
||||||
{#each places as item (item.data.id)}
|
class="grid md:grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] grid-cols-[repeat(auto-fill,minmax(7rem,1fr))] gap-x-4"
|
||||||
|
let:itemCount
|
||||||
|
>
|
||||||
|
{#each places.slice(0, itemCount) as item (item.data.id)}
|
||||||
<a class="relative" href="{AppRoute.SEARCH}?{getMetadataSearchQuery({ city: item.value })}" draggable="false">
|
<a class="relative" href="{AppRoute.SEARCH}?{getMetadataSearchQuery({ city: item.value })}" draggable="false">
|
||||||
<div
|
<div class="flex justify-center overflow-hidden rounded-xl brightness-75 filter">
|
||||||
class="flex w-[calc((100vw-(72px+5rem))/2)] max-w-[156px] justify-center overflow-hidden rounded-xl brightness-75 filter"
|
|
||||||
>
|
|
||||||
<img
|
<img
|
||||||
src={getAssetThumbnailUrl({ id: item.data.id, size: AssetMediaSize.Thumbnail })}
|
src={getAssetThumbnailUrl({ id: item.data.id, size: AssetMediaSize.Thumbnail })}
|
||||||
alt={item.value}
|
alt={item.value}
|
||||||
class="object-cover w-[156px] h-[156px]"
|
class="object-cover aspect-square w-full"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<span
|
<span
|
||||||
|
@ -116,7 +97,7 @@
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</SingleGridRow>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue