Skip to content

Instantly share code, notes, and snippets.

@BartoszBilejczyk
Last active August 3, 2020 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BartoszBilejczyk/7b24cb28b1830d036e26358c89159f30 to your computer and use it in GitHub Desktop.
Save BartoszBilejczyk/7b24cb28b1830d036e26358c89159f30 to your computer and use it in GitHub Desktop.
// 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