Last active
August 3, 2020 12:53
-
-
Save BartoszBilejczyk/7b24cb28b1830d036e26358c89159f30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// part of dashboard.interfaces.ts | |
export interface Notification { | |
id: number, | |
type: string, | |
message: string, | |
date: string | |
} | |
export interface NotificationsReturnData { | |
list: Ref<Notification[]>, | |
handleNotificationsDismissal: any, | |
addNotification: any | |
} | |
// dashboard-notifications.setup.ts | |
import { ref } from 'vue'; | |
import { notificationsMock } from '@/mocks/mocks'; | |
import { Notification, NotificationsReturnData } from "@/views/dashboard.interfaces"; | |
export function useNotifications(): NotificationsReturnData { | |
const list = ref<Notification[]>(notificationsMock); | |
function handleNotificationsDismissal(id: number) { | |
list.value = list.value.filter(notif => notif.id !== id) | |
} | |
function addNotification(type: string, message: string) { | |
const newNotification: Notification = { | |
id: Number(list.value.length + 1), | |
type, | |
message, | |
date: '01/08/2020' | |
}; | |
list.value = [ | |
{...newNotification}, | |
...list.value | |
] | |
} | |
return { | |
list, | |
handleNotificationsDismissal, | |
addNotification | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment