2022-08-25 23:04:23 -07:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import { fade } from 'svelte/transition';
|
2023-10-25 09:48:25 -04:00
|
|
|
import Icon from '$lib/components/elements/icon.svelte';
|
2023-07-01 00:50:47 -04:00
|
|
|
import {
|
|
|
|
|
ImmichNotification,
|
|
|
|
|
notificationController,
|
|
|
|
|
NotificationType,
|
|
|
|
|
} from '$lib/components/shared-components/notification/notification';
|
|
|
|
|
import { onMount } from 'svelte';
|
2023-10-25 09:48:25 -04:00
|
|
|
import { mdiCloseCircleOutline, mdiInformationOutline, mdiWindowClose } from '@mdi/js';
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
|
export let notificationInfo: ImmichNotification;
|
|
|
|
|
|
|
|
|
|
let infoPrimaryColor = '#4250AF';
|
|
|
|
|
let errorPrimaryColor = '#E64132';
|
2023-08-09 18:11:26 -07:00
|
|
|
let warningPrimaryColor = '#D08613';
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2023-10-25 09:48:25 -04:00
|
|
|
$: icon = notificationInfo.type === NotificationType.Error ? mdiCloseCircleOutline : mdiInformationOutline;
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
|
$: backgroundColor = () => {
|
|
|
|
|
if (notificationInfo.type === NotificationType.Info) {
|
|
|
|
|
return '#E0E2F0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (notificationInfo.type === NotificationType.Error) {
|
|
|
|
|
return '#FBE8E6';
|
|
|
|
|
}
|
2023-08-09 18:11:26 -07:00
|
|
|
|
|
|
|
|
if (notificationInfo.type === NotificationType.Warning) {
|
|
|
|
|
return '#FFF6DC';
|
|
|
|
|
}
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$: borderStyle = () => {
|
|
|
|
|
if (notificationInfo.type === NotificationType.Info) {
|
|
|
|
|
return '1px solid #D8DDFF';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (notificationInfo.type === NotificationType.Error) {
|
|
|
|
|
return '1px solid #F0E8E7';
|
|
|
|
|
}
|
2023-08-09 18:11:26 -07:00
|
|
|
|
|
|
|
|
if (notificationInfo.type === NotificationType.Warning) {
|
|
|
|
|
return '1px solid #FFE6A5';
|
|
|
|
|
}
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$: primaryColor = () => {
|
|
|
|
|
if (notificationInfo.type === NotificationType.Info) {
|
|
|
|
|
return infoPrimaryColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (notificationInfo.type === NotificationType.Error) {
|
|
|
|
|
return errorPrimaryColor;
|
|
|
|
|
}
|
2023-08-09 18:11:26 -07:00
|
|
|
|
|
|
|
|
if (notificationInfo.type === NotificationType.Warning) {
|
|
|
|
|
return warningPrimaryColor;
|
|
|
|
|
}
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let removeNotificationTimeout: NodeJS.Timeout | undefined = undefined;
|
|
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
removeNotificationTimeout = setTimeout(discard, notificationInfo.timeout);
|
|
|
|
|
return () => clearTimeout(removeNotificationTimeout);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const discard = () => {
|
|
|
|
|
notificationController.removeNotificationById(notificationInfo.id);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleClick = () => {
|
|
|
|
|
const action = notificationInfo.action;
|
|
|
|
|
if (action.type == 'discard') {
|
|
|
|
|
discard();
|
|
|
|
|
} else if (action.type == 'link') {
|
|
|
|
|
window.open(action.target);
|
|
|
|
|
}
|
|
|
|
|
};
|
2022-08-25 23:04:23 -07:00
|
|
|
</script>
|
|
|
|
|
|
2023-07-15 20:13:04 -05:00
|
|
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
2022-08-25 23:04:23 -07:00
|
|
|
<div
|
2023-07-01 00:50:47 -04:00
|
|
|
transition:fade={{ duration: 250 }}
|
|
|
|
|
style:background-color={backgroundColor()}
|
|
|
|
|
style:border={borderStyle()}
|
2023-07-18 13:19:39 -05:00
|
|
|
class="z-[999999] mb-4 min-h-[80px] w-[300px] rounded-2xl p-4 shadow-md hover:cursor-pointer"
|
2023-07-01 00:50:47 -04:00
|
|
|
on:click={handleClick}
|
|
|
|
|
on:keydown={handleClick}
|
2022-08-25 23:04:23 -07:00
|
|
|
>
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="flex justify-between">
|
2023-07-18 13:19:39 -05:00
|
|
|
<div class="flex place-items-center gap-2">
|
2023-10-25 09:48:25 -04:00
|
|
|
<Icon path={icon} color={primaryColor()} size="20" />
|
2023-07-01 00:50:47 -04:00
|
|
|
<h2 style:color={primaryColor()} class="font-medium" data-testid="title">
|
|
|
|
|
{notificationInfo.type.toString()}
|
|
|
|
|
</h2>
|
|
|
|
|
</div>
|
|
|
|
|
<button on:click|stopPropagation={discard}>
|
2023-10-25 09:48:25 -04:00
|
|
|
<Icon path={mdiWindowClose} size="20" />
|
2023-07-01 00:50:47 -04:00
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
2023-07-18 13:19:39 -05:00
|
|
|
<p class="whitespace-pre-wrap pl-[28px] pr-[16px] text-sm" data-testid="message">
|
2023-07-01 00:50:47 -04:00
|
|
|
{notificationInfo.message}
|
|
|
|
|
</p>
|
2022-08-25 23:04:23 -07:00
|
|
|
</div>
|