mirror of
https://github.com/immich-app/immich.git
synced 2025-01-21 00:52:43 -05:00
web(feat): Add support for actions when clicking notifications (#966)
* feat(web): Add button to close notification popups * feat(web): Add support for actions on notification click * feat(web): Open CLI docs when clicking asset upload count message * test(web): Add action field to notification-card tests * chore(web): Formatting * feat(web): Allow HTML in notification message * feat(web): Do not use link element in file upload count notification * feat(web): Prevent notification discard button from triggering action * feat(web): Add noop action support for notifications * chore(web): Remove unused function argument
This commit is contained in:
parent
70cd313082
commit
afae5fd972
4 changed files with 48 additions and 15 deletions
|
@ -15,7 +15,8 @@ describe('NotificationCard component', () => {
|
||||||
id: 1234,
|
id: 1234,
|
||||||
message: 'Notification message',
|
message: 'Notification message',
|
||||||
timeout: 1000,
|
timeout: 1000,
|
||||||
type: NotificationType.Info
|
type: NotificationType.Info,
|
||||||
|
action: { type: 'discard' }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -29,7 +30,8 @@ describe('NotificationCard component', () => {
|
||||||
id: 1234,
|
id: 1234,
|
||||||
message: 'Notification message',
|
message: 'Notification message',
|
||||||
timeout: 1000,
|
timeout: 1000,
|
||||||
type: NotificationType.Info
|
type: NotificationType.Info,
|
||||||
|
action: { type: 'discard' }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
import CloseCircleOutline from 'svelte-material-icons/CloseCircleOutline.svelte';
|
import CloseCircleOutline from 'svelte-material-icons/CloseCircleOutline.svelte';
|
||||||
import InformationOutline from 'svelte-material-icons/InformationOutline.svelte';
|
import InformationOutline from 'svelte-material-icons/InformationOutline.svelte';
|
||||||
|
import WindowClose from 'svelte-material-icons/WindowClose.svelte';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ImmichNotification,
|
ImmichNotification,
|
||||||
|
@ -51,26 +52,42 @@
|
||||||
let removeNotificationTimeout: NodeJS.Timeout | undefined = undefined;
|
let removeNotificationTimeout: NodeJS.Timeout | undefined = undefined;
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
removeNotificationTimeout = setTimeout(() => {
|
removeNotificationTimeout = setTimeout(discard, notificationInfo.timeout);
|
||||||
notificationController.removeNotificationById(notificationInfo.id);
|
|
||||||
}, notificationInfo.timeout);
|
|
||||||
|
|
||||||
return () => clearTimeout(removeNotificationTimeout);
|
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);
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
transition:fade={{ duration: 250 }}
|
transition:fade={{ duration: 250 }}
|
||||||
style:background-color={backgroundColor()}
|
style:background-color={backgroundColor()}
|
||||||
style:border={borderStyle()}
|
style:border={borderStyle()}
|
||||||
class="min-h-[80px] w-[300px] rounded-2xl z-[999999] shadow-md p-4 mb-4"
|
class="min-h-[80px] w-[300px] rounded-2xl z-[999999] shadow-md p-4 mb-4 hover:cursor-pointer"
|
||||||
|
on:click={handleClick}
|
||||||
>
|
>
|
||||||
<div class="flex gap-2 place-items-center">
|
<div class="flex justify-between">
|
||||||
<svelte:component this={icon} color={primaryColor()} size="20" />
|
<div class="flex gap-2 place-items-center">
|
||||||
<h2 style:color={primaryColor()} class="font-medium" data-testid="title">
|
<svelte:component this={icon} color={primaryColor()} size="20" />
|
||||||
{notificationInfo.type.toString()}
|
<h2 style:color={primaryColor()} class="font-medium" data-testid="title">
|
||||||
</h2>
|
{notificationInfo.type.toString()}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<button on:click|stopPropagation={discard}>
|
||||||
|
<svelte:component this={WindowClose} size="20" />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p class="text-sm pl-[28px] pr-[16px]" data-testid="message">{notificationInfo.message}</p>
|
<p class="text-sm pl-[28px] pr-[16px]" data-testid="message">{@html notificationInfo.message}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -9,9 +9,15 @@ export class ImmichNotification {
|
||||||
id = new Date().getTime();
|
id = new Date().getTime();
|
||||||
type!: NotificationType;
|
type!: NotificationType;
|
||||||
message!: string;
|
message!: string;
|
||||||
|
action!: NotificationAction;
|
||||||
timeout = 3000;
|
timeout = 3000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DiscardAction = { type: 'discard' };
|
||||||
|
type NoopAction = { type: 'noop' };
|
||||||
|
type LinkAction = { type: 'link'; target: string };
|
||||||
|
export type NotificationAction = DiscardAction | NoopAction | LinkAction;
|
||||||
|
|
||||||
export class ImmichNotificationDto {
|
export class ImmichNotificationDto {
|
||||||
/**
|
/**
|
||||||
* Notification type
|
* Notification type
|
||||||
|
@ -28,7 +34,13 @@ export class ImmichNotificationDto {
|
||||||
* Timeout in miliseconds
|
* Timeout in miliseconds
|
||||||
*/
|
*/
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The action to take when the notification is clicked
|
||||||
|
*/
|
||||||
|
action?: NotificationAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createNotificationList() {
|
function createNotificationList() {
|
||||||
const notificationList = writable<ImmichNotification[]>([]);
|
const notificationList = writable<ImmichNotification[]>([]);
|
||||||
|
|
||||||
|
@ -37,6 +49,7 @@ function createNotificationList() {
|
||||||
newNotification.message = notificationInfo.message;
|
newNotification.message = notificationInfo.message;
|
||||||
newNotification.type = notificationInfo.type;
|
newNotification.type = notificationInfo.type;
|
||||||
newNotification.timeout = notificationInfo.timeout || 3000;
|
newNotification.timeout = notificationInfo.timeout || 3000;
|
||||||
|
newNotification.action = notificationInfo.action || { type: 'discard' };
|
||||||
|
|
||||||
notificationList.update((currentList) => [...currentList, newNotification]);
|
notificationList.update((currentList) => [...currentList, newNotification]);
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,8 +44,9 @@ export const openFileUploadDialog = (uploadType: UploadType) => {
|
||||||
notificationController.show({
|
notificationController.show({
|
||||||
type: NotificationType.Error,
|
type: NotificationType.Error,
|
||||||
message: `Cannot upload more than 50 files at a time - you are uploading ${files.length} files.
|
message: `Cannot upload more than 50 files at a time - you are uploading ${files.length} files.
|
||||||
Please use the CLI tool if you need to upload more than 50 files.`,
|
Please check out <u>the bulk upload documentation</u> if you need to upload more than 50 files.`,
|
||||||
timeout: 5000
|
timeout: 10000,
|
||||||
|
action: { type: 'link', target: 'https://immich.app/docs/usage/bulk-upload' }
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue