better selection

This commit is contained in:
Alex Tran 2023-08-13 16:53:57 -05:00
parent 1eb3cdca42
commit e682de67fa
3 changed files with 39 additions and 31 deletions

View file

@ -6,7 +6,7 @@
import Button from '$lib/components/elements/buttons/button.svelte'; import Button from '$lib/components/elements/buttons/button.svelte';
import FaceThumbnail from '$lib/components/assets/thumbnail/face-thumbnail.svelte'; import FaceThumbnail from '$lib/components/assets/thumbnail/face-thumbnail.svelte';
export let selectedPeopleIds: string[] = []; export let selectedPeopleIds: Set<string> = new Set();
let people: PersonResponseDto[] = []; let people: PersonResponseDto[] = [];
let selectedPeople: PersonResponseDto[] = []; let selectedPeople: PersonResponseDto[] = [];
@ -15,9 +15,7 @@
onMount(async () => { onMount(async () => {
const { data } = await api.personApi.getAllPeople({ withHidden: false }); const { data } = await api.personApi.getAllPeople({ withHidden: false });
people = data.people; people = data.people.filter((p) => !selectedPeopleIds.has(p.id));
selectedPeople = people.filter((p) => selectedPeopleIds.includes(p.id));
}); });
const handleSelection = (e: CustomEvent<{ person: PersonResponseDto }>) => { const handleSelection = (e: CustomEvent<{ person: PersonResponseDto }>) => {

View file

@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import BaseModal from '$lib/components/shared-components/base-modal.svelte'; import BaseModal from '$lib/components/shared-components/base-modal.svelte';
import { createEventDispatcher } from 'svelte'; import { createEventDispatcher, onMount } from 'svelte';
import { RuleKey, type AlbumResponseDto, type PersonResponseDto, api } from '@api'; import { RuleKey, type AlbumResponseDto, type PersonResponseDto, api } from '@api';
import Plus from 'svelte-material-icons/Plus.svelte'; import Plus from 'svelte-material-icons/Plus.svelte';
import Button from '../../elements/buttons/button.svelte'; import Button from '../../elements/buttons/button.svelte';
@ -12,11 +12,7 @@
let peopleSelection = false; let peopleSelection = false;
let locationSelection = false; let locationSelection = false;
$: selectedFaces = album.rules.map((r) => { let selectedPeopleIds = new Set<string>();
if (r.key === RuleKey.Person) {
return String(r.value);
}
}) as string[];
const dispatch = createEventDispatcher<{ close: void }>(); const dispatch = createEventDispatcher<{ close: void }>();
@ -24,7 +20,7 @@
peopleSelection = false; peopleSelection = false;
const people = e.detail.people; const people = e.detail.people;
selectedFaces = people.map((p) => p.id); selectedPeopleIds = new Set([...selectedPeopleIds, ...people.map((p) => p.id)]);
}; };
const updateRule = async () => { const updateRule = async () => {
@ -39,6 +35,16 @@
// album.rules = [...album.rules, data]; // album.rules = [...album.rules, data];
// } // }
}; };
onMount(() => {
const addedFaceIds = album.rules.map((r) => {
if (r.key === RuleKey.Person) {
return String(r.value);
}
}) as string[];
selectedPeopleIds = new Set([...selectedPeopleIds, ...addedFaceIds]);
});
</script> </script>
<BaseModal <BaseModal
@ -57,7 +63,14 @@
<!-- People Selection --> <!-- People Selection -->
<div id="people-selection"> <div id="people-selection">
<p class="text-sm font-medium">PEOPLE</p> <p class="text-sm font-medium">PEOPLE</p>
<div class="mt-4">
<div class="mt-4 flex flex-wrap gap-2">
{#each selectedPeopleIds as personId (personId)}
<button>
<img src={api.getPeopleThumbnailUrl(personId)} alt={personId} class="h-20 w-20 rounded-lg" />
</button>
{/each}
<button <button
class="immich-text-primary border-1 flex h-20 w-20 place-content-center place-items-center rounded-lg border border-gray-300 hover:bg-gray-500/20 dark:border-gray-500" class="immich-text-primary border-1 flex h-20 w-20 place-content-center place-items-center rounded-lg border border-gray-300 hover:bg-gray-500/20 dark:border-gray-500"
on:click={() => (peopleSelection = true)} on:click={() => (peopleSelection = true)}
@ -65,10 +78,6 @@
<Plus size="24" /> <Plus size="24" />
</button> </button>
</div> </div>
{#each selectedFaces as person (person)}
<div>id: {person}</div>
{/each}
</div> </div>
<!-- Location Selection --> <!-- Location Selection -->
@ -98,15 +107,14 @@
</div> </div>
</div> </div>
</div> </div>
</section>
<!-- Buttons rows --> <!-- Buttons rows -->
<div> <svelte:fragment slot="sticky-bottom">
<div class="mt-5 flex justify-end gap-2"> <div class="flex justify-end gap-2">
<Button size="sm" color="secondary" on:click={() => dispatch('close')}>Cancel</Button> <Button size="sm" color="secondary" on:click={() => dispatch('close')}>Cancel</Button>
<Button size="sm" color="primary">Confirm</Button> <Button size="sm" color="primary">Confirm</Button>
</div> </div>
</div> </svelte:fragment>
</section>
</BaseModal> </BaseModal>
<Portal target="body"> <Portal target="body">
@ -115,11 +123,7 @@
transition:fly={{ y: 500 }} transition:fly={{ y: 500 }}
class="dark:bg-immich-dark-bg absolute left-0 top-0 z-[10000] h-full min-h-max w-full overflow-y-auto bg-gray-200" class="dark:bg-immich-dark-bg absolute left-0 top-0 z-[10000] h-full min-h-max w-full overflow-y-auto bg-gray-200"
> >
<FaceSelection <FaceSelection on:close={() => (peopleSelection = false)} on:confirm={handleFaceSelected} {selectedPeopleIds} />
on:close={() => (peopleSelection = false)}
on:confirm={handleFaceSelected}
selectedPeopleIds={selectedFaces}
/>
</section> </section>
{/if} {/if}
</Portal> </Portal>

View file

@ -37,7 +37,7 @@
<div <div
use:clickOutside use:clickOutside
on:outclick={() => !ignoreClickOutside && dispatch('close')} on:outclick={() => !ignoreClickOutside && dispatch('close')}
class="bg-immich-bg dark:bg-immich-dark-gray dark:text-immich-dark-fg min-h-[200px] w-[450px] overflow-y-auto rounded-lg shadow-md" class="bg-immich-bg dark:bg-immich-dark-gray dark:text-immich-dark-fg max-h-[700px] min-h-[200px] w-[450px] overflow-y-auto rounded-lg shadow-md"
> >
<div class="dark:bg-immich-dark-gray bg-immich-bg sticky top-0 flex place-items-center justify-between px-5 py-3"> <div class="dark:bg-immich-dark-gray bg-immich-bg sticky top-0 flex place-items-center justify-between px-5 py-3">
<div> <div>
@ -49,8 +49,14 @@
<CircleIconButton on:click={() => dispatch('close')} logo={Close} size={'20'} /> <CircleIconButton on:click={() => dispatch('close')} logo={Close} size={'20'} />
</div> </div>
<div class="max-h-[600px]"> <div class="">
<slot /> <slot />
</div> </div>
{#if $$slots['sticky-bottom']}
<div class="dark:bg-immich-dark-gray bg-immich-bg sticky bottom-0 px-5 pb-5 pt-3">
<slot name="sticky-bottom" />
</div>
{/if}
</div> </div>
</div> </div>