All files / src/stores notifications.ts

100% Statements 7/7
100% Branches 0/0
100% Functions 5/5
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33                      3x 24x     15x               5x       8x     24x    
import { defineStore } from 'pinia'
import { ref } from 'vue'
 
export interface InAppNotification {
  id: string
  listId: string
  listName: string
  message: string
  ts: number
}
 
export const useNotificationsStore = defineStore('notifications', () => {
  const notifications = ref<InAppNotification[]>([])
 
  function add(n: Omit<InAppNotification, 'id' | 'ts'>) {
    notifications.value.push({
      ...n,
      id: crypto.randomUUID(),
      ts: Date.now(),
    })
  }
 
  function dismiss(id: string) {
    notifications.value = notifications.value.filter((n) => n.id !== id)
  }
 
  function dismissAll() {
    notifications.value = []
  }
 
  return { notifications, add, dismiss, dismissAll }
})