2023-07-18 12:36:20 -05:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { PersonResponseDto, api } from '@api';
|
2023-09-29 13:41:58 -04:00
|
|
|
import { getContextMenuPosition } from '$lib/utils/context-menu';
|
2023-07-18 12:36:20 -05:00
|
|
|
import ImageThumbnail from '../assets/thumbnail/image-thumbnail.svelte';
|
|
|
|
|
import IconButton from '../elements/buttons/icon-button.svelte';
|
|
|
|
|
import ContextMenu from '../shared-components/context-menu/context-menu.svelte';
|
|
|
|
|
import MenuOption from '../shared-components/context-menu/menu-option.svelte';
|
|
|
|
|
import Portal from '../shared-components/portal/portal.svelte';
|
|
|
|
|
import { createEventDispatcher } from 'svelte';
|
2023-10-12 17:31:34 +02:00
|
|
|
import { AppRoute } from '$lib/constants';
|
2023-10-25 09:48:25 -04:00
|
|
|
import { mdiDotsVertical } from '@mdi/js';
|
|
|
|
|
import Icon from '$lib/components/elements/icon.svelte';
|
2023-07-18 12:36:20 -05:00
|
|
|
|
|
|
|
|
export let person: PersonResponseDto;
|
|
|
|
|
|
2023-08-25 13:35:52 +02:00
|
|
|
type MenuItemEvent = 'change-name' | 'set-birth-date' | 'merge-faces' | 'hide-face';
|
2023-08-18 22:10:29 +02:00
|
|
|
let dispatch = createEventDispatcher<{
|
|
|
|
|
'change-name': void;
|
|
|
|
|
'set-birth-date': void;
|
|
|
|
|
'merge-faces': void;
|
|
|
|
|
'hide-face': void;
|
|
|
|
|
}>();
|
2023-08-25 13:35:52 +02:00
|
|
|
|
|
|
|
|
let showVerticalDots = false;
|
|
|
|
|
let showContextMenu = false;
|
|
|
|
|
let contextMenuPosition = { x: 0, y: 0 };
|
2023-09-29 13:41:58 -04:00
|
|
|
const showMenu = (event: MouseEvent) => {
|
|
|
|
|
contextMenuPosition = getContextMenuPosition(event);
|
2023-08-25 13:35:52 +02:00
|
|
|
showContextMenu = !showContextMenu;
|
|
|
|
|
};
|
|
|
|
|
const onMenuExit = () => {
|
|
|
|
|
showContextMenu = false;
|
|
|
|
|
};
|
|
|
|
|
const onMenuClick = (event: MenuItemEvent) => {
|
|
|
|
|
onMenuExit();
|
|
|
|
|
dispatch(event);
|
|
|
|
|
};
|
2023-07-18 12:36:20 -05:00
|
|
|
</script>
|
|
|
|
|
|
2023-08-25 13:35:52 +02:00
|
|
|
<div
|
|
|
|
|
id="people-card"
|
|
|
|
|
class="relative"
|
|
|
|
|
on:mouseenter={() => (showVerticalDots = true)}
|
|
|
|
|
on:mouseleave={() => (showVerticalDots = false)}
|
|
|
|
|
role="group"
|
|
|
|
|
>
|
2023-10-12 17:31:34 +02:00
|
|
|
<a href="/people/{person.id}?previousRoute={AppRoute.PEOPLE}" draggable="false">
|
2023-07-23 05:00:43 +02:00
|
|
|
<div class="h-48 w-48 rounded-xl brightness-95 filter">
|
2023-09-01 01:25:13 +02:00
|
|
|
<ImageThumbnail
|
|
|
|
|
shadow
|
|
|
|
|
url={api.getPeopleThumbnailUrl(person.id)}
|
|
|
|
|
altText={person.name}
|
|
|
|
|
title={person.name}
|
|
|
|
|
widthStyle="100%"
|
|
|
|
|
/>
|
2023-07-18 12:36:20 -05:00
|
|
|
</div>
|
|
|
|
|
{#if person.name}
|
2023-08-21 01:36:31 +02:00
|
|
|
<span
|
|
|
|
|
class="text-white-shadow absolute bottom-2 left-0 w-full select-text px-1 text-center font-medium text-white"
|
2023-09-01 01:25:13 +02:00
|
|
|
title={person.name}
|
2023-08-21 01:36:31 +02:00
|
|
|
>
|
2023-07-18 12:36:20 -05:00
|
|
|
{person.name}
|
|
|
|
|
</span>
|
|
|
|
|
{/if}
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
|
|
<button
|
2023-09-29 15:21:51 +02:00
|
|
|
class="absolute right-2 top-2"
|
2023-08-25 13:35:52 +02:00
|
|
|
on:click|stopPropagation|preventDefault={showMenu}
|
|
|
|
|
class:hidden={!showVerticalDots}
|
2023-07-18 12:36:20 -05:00
|
|
|
data-testid="context-button-parent"
|
|
|
|
|
id={`icon-${person.id}`}
|
|
|
|
|
>
|
|
|
|
|
<IconButton color="transparent-primary">
|
2023-10-25 09:48:25 -04:00
|
|
|
<Icon path={mdiDotsVertical} size="20" class="icon-white-drop-shadow text-white" />
|
2023-07-18 12:36:20 -05:00
|
|
|
</IconButton>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{#if showContextMenu}
|
|
|
|
|
<Portal target="body">
|
2023-08-25 13:35:52 +02:00
|
|
|
<ContextMenu {...contextMenuPosition} on:outclick={() => onMenuExit()}>
|
|
|
|
|
<MenuOption on:click={() => onMenuClick('hide-face')} text="Hide face" />
|
|
|
|
|
<MenuOption on:click={() => onMenuClick('change-name')} text="Change name" />
|
|
|
|
|
<MenuOption on:click={() => onMenuClick('set-birth-date')} text="Set date of birth" />
|
|
|
|
|
<MenuOption on:click={() => onMenuClick('merge-faces')} text="Merge faces" />
|
|
|
|
|
</ContextMenu>
|
2023-07-18 12:36:20 -05:00
|
|
|
</Portal>
|
|
|
|
|
{/if}
|