feat: add modularity

This commit is contained in:
martabal 2023-10-07 16:51:53 +02:00
parent 02f1b828d3
commit 8c37a7cb60
No known key found for this signature in database
GPG key ID: C00196E3148A52BD
4 changed files with 190 additions and 182 deletions

View file

@ -16,6 +16,7 @@
import { AppRoute } from '$lib/constants';
import SwapHorizontal from 'svelte-material-icons/SwapHorizontal.svelte';
import CircleIconButton from '../elements/buttons/circle-icon-button.svelte';
import PeopleList from './people-list.svelte';
export let person: PersonResponseDto;
let people: PersonResponseDto[] = [];
@ -131,16 +132,8 @@
<FaceThumbnail {person} border circle selectable={false} thumbnailSize={180} />
</div>
</div>
<div
class="immich-scrollbar overflow-y-auto rounded-3xl bg-gray-200 p-10 dark:bg-immich-dark-gray"
style:max-height={screenHeight - 200 - 200 + 'px'}
>
<div class="grid-col-2 grid gap-8 md:grid-cols-3 lg:grid-cols-6 xl:grid-cols-8 2xl:grid-cols-10">
{#each unselectedPeople as person (person.id)}
<FaceThumbnail {person} on:click={() => onSelect(person)} circle border selectable />
{/each}
</div>
</div>
<PeopleList people={unselectedPeople} {screenHeight} on:select={({ detail }) => onSelect(detail)} />
</section>
{#if isShowConfirmation}

View file

@ -1,170 +1,26 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
import type { PersonResponseDto } from '@api';
import FaceThumbnail from './face-thumbnail.svelte';
import { quintOut } from 'svelte/easing';
import { fly } from 'svelte/transition';
import { api, AssetFaceUpdateItem, type PersonResponseDto } from '@api';
import ControlAppBar from '../shared-components/control-app-bar.svelte';
import Button from '../elements/buttons/button.svelte';
import Merge from 'svelte-material-icons/Merge.svelte';
import Plus from 'svelte-material-icons/Plus.svelte';
import LoadingSpinner from '../shared-components/loading-spinner.svelte';
import { handleError } from '$lib/utils/handle-error';
import { notificationController, NotificationType } from '../shared-components/notification/notification';
import { createEventDispatcher } from 'svelte';
export let screenHeight: number;
export let people: PersonResponseDto[] = [];
export let assetIds: string[];
export let personId: string;
const data: AssetFaceUpdateItem[] = [];
for (const assetId of assetIds) {
data.push({ assetId, personId });
}
let selectedPerson: PersonResponseDto | null = null;
let disableButtons = false;
let showLoadingSpinnerCreate = false;
let showLoadingSpinnerReassign = false;
let hasSelection = false;
let screenHeight: number;
let dispatch = createEventDispatcher();
const onClose = () => {
dispatch('close');
};
const handleSelectedPerson = (person: PersonResponseDto) => {
if (selectedPerson && selectedPerson.id === person.id) {
handleRemoveSelectedPerson();
return;
}
selectedPerson = person;
hasSelection = true;
};
const handleRemoveSelectedPerson = () => {
selectedPerson = null;
hasSelection = false;
};
const handleCreate = async () => {
try {
showLoadingSpinnerCreate = true;
disableButtons = true;
await api.personApi.createPerson({
assetFaceUpdateDto: { data },
});
notificationController.show({
message: `Re-assigned ${assetIds.length} asset${assetIds.length > 1 ? 's' : ''} to a new person`,
type: NotificationType.Info,
});
} catch (error) {
handleError(error, 'Unable to reassign assets to a new person');
}
dispatch('confirm');
};
const handleReassign = async () => {
try {
showLoadingSpinnerReassign = true;
disableButtons = true;
if (selectedPerson) {
await api.personApi.reassignFaces({
id: selectedPerson.id,
assetFaceUpdateDto: { data },
});
notificationController.show({
message: `Re-assigned ${assetIds.length} asset${assetIds.length > 1 ? 's' : ''} to ${
selectedPerson.name || 'an existing person'
}`,
type: NotificationType.Info,
});
}
} catch (error) {
handleError(error, `Unable to reassign assets to ${selectedPerson?.name || 'an existing person'}`);
}
dispatch('confirm');
};
let dispatch = createEventDispatcher<{
select: PersonResponseDto;
}>();
</script>
<svelte:window bind:innerHeight={screenHeight} />
<section
transition:fly={{ y: 500, duration: 100, easing: quintOut }}
class="absolute left-0 top-0 z-[9999] h-full w-full bg-immich-bg dark:bg-immich-dark-bg"
>
<ControlAppBar on:close-button-click={onClose}>
<svelte:fragment slot="leading">
<slot name="header" />
<div />
</svelte:fragment>
<svelte:fragment slot="trailing">
<div class="flex gap-4">
<!-- TODO: Implement actions -->
<Button
title={'Assign selected assets to a new person'}
size={'sm'}
disabled={disableButtons}
on:click={() => {
handleCreate();
}}
>
{#if !showLoadingSpinnerCreate}
<Plus size={18} />
{:else}
<LoadingSpinner />
{/if}
<span class="ml-2"> Create new Person</span></Button
>
<Button
size={'sm'}
title={'Assign selected assets to an existing person'}
disabled={disableButtons || !hasSelection}
on:click={() => {
handleReassign();
}}
>
{#if !showLoadingSpinnerReassign}
<Merge size={18} class="rotate-180" />
{:else}
<LoadingSpinner />
{/if}
<span class="ml-2"> Reassign</span></Button
>
</div>
</svelte:fragment>
</ControlAppBar>
<slot name="merge" />
<section class="bg-immich-bg px-[70px] pt-[100px] dark:bg-immich-dark-bg">
<section id="merge-face-selector relative">
{#if selectedPerson !== null}
<div class="mb-10 h-[200px] place-content-center place-items-center">
<p class="mb-4 text-center uppercase dark:text-white">Choose matching faces to re assign</p>
<div class="grid grid-flow-col-dense place-content-center place-items-center gap-4">
<FaceThumbnail
person={selectedPerson}
border
circle
selectable
thumbnailSize={180}
on:click={handleRemoveSelectedPerson}
/>
</div>
</div>
{/if}
<div
<div
class="immich-scrollbar overflow-y-auto rounded-3xl bg-gray-200 p-10 dark:bg-immich-dark-gray"
style:max-height={screenHeight - 200 - 200 + 'px'}
>
>
<div class="grid-col-2 grid gap-8 md:grid-cols-3 lg:grid-cols-6 xl:grid-cols-8 2xl:grid-cols-10">
{#each people as person (person.id)}
<FaceThumbnail
{person}
on:click={() => {
handleSelectedPerson(person);
dispatch('select', person);
}}
circle
border
@ -172,7 +28,4 @@
/>
{/each}
</div>
</div>
</section>
</section>
</section>
</div>

View file

@ -0,0 +1,162 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
import FaceThumbnail from './face-thumbnail.svelte';
import { quintOut } from 'svelte/easing';
import { fly } from 'svelte/transition';
import { api, AssetFaceUpdateItem, type PersonResponseDto } from '@api';
import ControlAppBar from '../shared-components/control-app-bar.svelte';
import Button from '../elements/buttons/button.svelte';
import Merge from 'svelte-material-icons/Merge.svelte';
import Plus from 'svelte-material-icons/Plus.svelte';
import LoadingSpinner from '../shared-components/loading-spinner.svelte';
import { handleError } from '$lib/utils/handle-error';
import { notificationController, NotificationType } from '../shared-components/notification/notification';
import PeopleList from './people-list.svelte';
export let people: PersonResponseDto[] = [];
export let assetIds: string[];
export let personId: string;
const data: AssetFaceUpdateItem[] = [];
for (const assetId of assetIds) {
data.push({ assetId, personId });
}
let selectedPerson: PersonResponseDto | null = null;
let disableButtons = false;
let showLoadingSpinnerCreate = false;
let showLoadingSpinnerReassign = false;
let hasSelection = false;
let screenHeight: number;
let dispatch = createEventDispatcher();
const onClose = () => {
dispatch('close');
};
const handleSelectedPerson = (person: PersonResponseDto) => {
if (selectedPerson && selectedPerson.id === person.id) {
handleRemoveSelectedPerson();
return;
}
selectedPerson = person;
hasSelection = true;
};
const handleRemoveSelectedPerson = () => {
selectedPerson = null;
hasSelection = false;
};
const handleCreate = async () => {
try {
showLoadingSpinnerCreate = true;
disableButtons = true;
await api.personApi.createPerson({
assetFaceUpdateDto: { data },
});
notificationController.show({
message: `Re-assigned ${assetIds.length} asset${assetIds.length > 1 ? 's' : ''} to a new person`,
type: NotificationType.Info,
});
} catch (error) {
handleError(error, 'Unable to reassign assets to a new person');
}
dispatch('confirm');
};
const handleReassign = async () => {
try {
showLoadingSpinnerReassign = true;
disableButtons = true;
if (selectedPerson) {
await api.personApi.reassignFaces({
id: selectedPerson.id,
assetFaceUpdateDto: { data },
});
notificationController.show({
message: `Re-assigned ${assetIds.length} asset${assetIds.length > 1 ? 's' : ''} to ${
selectedPerson.name || 'an existing person'
}`,
type: NotificationType.Info,
});
}
} catch (error) {
handleError(error, `Unable to reassign assets to ${selectedPerson?.name || 'an existing person'}`);
}
dispatch('confirm');
};
</script>
<svelte:window bind:innerHeight={screenHeight} />
<section
transition:fly={{ y: 500, duration: 100, easing: quintOut }}
class="absolute left-0 top-0 z-[9999] h-full w-full bg-immich-bg dark:bg-immich-dark-bg"
>
<ControlAppBar on:close-button-click={onClose}>
<svelte:fragment slot="leading">
<slot name="header" />
<div />
</svelte:fragment>
<svelte:fragment slot="trailing">
<div class="flex gap-4">
<!-- TODO: Implement actions -->
<Button
title={'Assign selected assets to a new person'}
size={'sm'}
disabled={disableButtons}
on:click={() => {
handleCreate();
}}
>
{#if !showLoadingSpinnerCreate}
<Plus size={18} />
{:else}
<LoadingSpinner />
{/if}
<span class="ml-2"> Create new Person</span></Button
>
<Button
size={'sm'}
title={'Assign selected assets to an existing person'}
disabled={disableButtons || !hasSelection}
on:click={() => {
handleReassign();
}}
>
{#if !showLoadingSpinnerReassign}
<Merge size={18} class="rotate-180" />
{:else}
<LoadingSpinner />
{/if}
<span class="ml-2"> Reassign</span></Button
>
</div>
</svelte:fragment>
</ControlAppBar>
<slot name="merge" />
<section class="bg-immich-bg px-[70px] pt-[100px] dark:bg-immich-dark-bg">
<section id="merge-face-selector relative">
{#if selectedPerson !== null}
<div class="mb-10 h-[200px] place-content-center place-items-center">
<p class="mb-4 text-center uppercase dark:text-white">Choose matching faces to re assign</p>
<div class="grid grid-flow-col-dense place-content-center place-items-center gap-4">
<FaceThumbnail
person={selectedPerson}
border
circle
selectable
thumbnailSize={180}
on:click={handleRemoveSelectedPerson}
/>
</div>
</div>
{/if}
<PeopleList {people} {screenHeight} on:select={({ detail }) => handleSelectedPerson(detail)} />
</section>
</section>
</section>

View file

@ -32,7 +32,7 @@
import DotsVertical from 'svelte-material-icons/DotsVertical.svelte';
import Plus from 'svelte-material-icons/Plus.svelte';
import type { PageData } from './$types';
import PeopleList from '$lib/components/faces-page/people-list.svelte';
import UnmergeFaceSelector from '$lib/components/faces-page/unmerge-face-selector.svelte';
import { clickOutside } from '$lib/utils/click-outside';
import { assetViewingStore } from '$lib/stores/asset-viewing.store';
@ -307,7 +307,7 @@
{/if}
{#if viewMode === ViewMode.UNASSIGN_ASSETS}
<PeopleList
<UnmergeFaceSelector
{people}
assetIds={Array.from($selectedAssets).map((a) => a.id)}
personId={data.person.id}