Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<script lang="ts">
import { fly } from 'svelte/transition';
import type { Readable } from 'svelte/store';
import type { I18Next } from '$lib/IONOS/i18next.d.ts';
import Heart from '$lib/IONOS/components/icons/Heart.svelte';
import XMark from '$lib/IONOS/components/icons/XMark.svelte';
import EmojiSad from '$lib/IONOS/components/icons/EmojiSad.svelte';
import Touch from '$lib/IONOS/components/icons/Touch.svelte';
import Link from '$lib/IONOS/components/common/Link.svelte';
import { NotificationType, type SubscribableNotification } from '$lib/IONOS/stores/notifications';
import { createEventDispatcher, getContext } from 'svelte';
import { createEventDispatcher } from 'svelte';

const dispatch = createEventDispatcher();
const i18n = getContext<Readable<I18Next>>('i18n');

export let notification: SubscribableNotification;
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
isIOSDevice,
isSafari
} from '$lib/IONOS/services/pwa';
import { deferredPrompt, isPWAInstallable, setupGlobalPWAListener, clearDeferredPrompt } from '$lib/IONOS/stores/pwa-prompt';
import { deferredPrompt, isPWAInstallable, clearDeferredPrompt } from '$lib/IONOS/stores/pwa-prompt';

const i18n = getContext<Readable<I18Next>>('i18n');
const DAYS = 24 * 60 * 60 * 1000;

let showPWADialog = false;
let cleanupPWAListeners: (() => void) | null = null;

const unsubscribeChats = chats.subscribe(async (chats: Chat[]|null) => {
const userSettings = await getUserSettings(localStorage.token);
Expand Down Expand Up @@ -67,13 +66,13 @@
};

const dismissHandler = (event: CustomEvent) => {
const notification = event.detail.notification;
const notification: SubscribableNotification = event.detail.notification as SubscribableNotification;

if (get(notification).type === NotificationType.PWA_INSTALL) {
dismissPWAPrompt();
}

removeNotification(notification);
removeNotification("pwa");
};

onDestroy(() => {
Expand All @@ -92,9 +91,7 @@

$: if (!$isPWAInstallable && !$deferredPrompt) {
showPWADialog = false;
notifications.update((currentNotifications: Notification[]) =>
currentNotifications.filter(n => n.type !== NotificationType.PWA_INSTALL)
);
removeNotification("pwa");
}

const addPWANotification = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Touch from '$lib/IONOS/components/icons/Touch.svelte';
import Share from '$lib/IONOS/components/icons/Share.svelte';
import Button from '$lib/IONOS/components/common/Button.svelte';
import { ButtonType } from '$lib/IONOS/components/common/buttons.ts';
import { ButtonType } from '$lib/IONOS/components/common/buttons';
import { getContext } from 'svelte';
import { createEventDispatcher } from 'svelte';
import { isIOSDevice, isSafari } from '$lib/IONOS/services/pwa';
Expand Down
26 changes: 15 additions & 11 deletions src/lib/IONOS/stores/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { type Writable, writable, type Readable } from 'svelte/store';
import { get, writable, type Writable, type Readable } from 'svelte/store';

export enum NotificationType {
INFO = 'bg-blue-100 text-blue-800',
INFO = 'bg-blue-100 text-blue-800 info',
SUCCESS = 'success',
ERROR = 'bg-red-100 text-blue-800',
ERROR = 'bg-red-100 text-blue-800 error',
WARNING = 'warning',
FEEDBACK = NotificationType.INFO,
PWA_INSTALL = NotificationType.INFO,
FEEDBACK = 'bg-blue-100 text-blue-800 feedback',
PWA_INSTALL = 'bg-blue-100 text-blue-800 pwa-install',
}

export type NotificationActionBase = {
Expand Down Expand Up @@ -42,14 +42,18 @@ export type SubscribableNotification = Readable<Notification>;

export const notifications: Writable<SubscribableNotification[]> = writable([]);

export const addNotification = (notification: SubscribableNotification): void => {
notifications.update((currentNotifications: SubscribableNotification[]) => {
return [...currentNotifications, notification];
});
export const addNotification = (newNotificationStore: SubscribableNotification): void => {
const newNotification: Notification = get(newNotificationStore);
const currentNotifications: SubscribableNotification[] = get(notifications);
const alreadyPresent = currentNotifications.some(n => get(n).id === newNotification.id);

if (!alreadyPresent) {
notifications.update((current: SubscribableNotification[]) => [...current, newNotificationStore]);
}
};

export const removeNotification = (id: string): void => {
notifications.update((currentNotifications: Notification[]) =>
currentNotifications.filter(n => n.id !== id)
notifications.update((currentNotifications: SubscribableNotification[]) =>
currentNotifications.filter(n => get(n).id !== id)
);
};
Loading