chore(Notification): improve types

This commit is contained in:
Benjamin Canac
2023-05-23 15:24:32 +02:00
parent 6d3309c42d
commit 45ba3b26da
7 changed files with 41 additions and 35 deletions

View File

@@ -1,8 +1,8 @@
import { useClipboard } from '@vueuse/core'
import type { ToastNotification } from '../types/toast'
import type { Notification } from '../types/notification'
import { useToast } from './useToast'
export function useCopyToClipboard (options: Partial<ToastNotification> = {}) {
export function useCopyToClipboard (options: Partial<Notification> = {}) {
const { copy: copyToClipboard, isSupported } = useClipboard()
const toast = useToast()

View File

@@ -1,25 +1,25 @@
import type { ToastNotification } from '../types'
import type { Notification } from '../types'
import { useState } from '#imports'
export function useToast () {
const notifications = useState<ToastNotification[]>('notifications', () => [])
const notifications = useState<Notification[]>('notifications', () => [])
function add (notification: Partial<ToastNotification>) {
function add (notification: Partial<Notification>) {
const body = {
id: new Date().getTime().toString(),
...notification
}
const index = notifications.value.findIndex((n: ToastNotification) => n.id === body.id)
const index = notifications.value.findIndex((n: Notification) => n.id === body.id)
if (index === -1) {
notifications.value.push(body as ToastNotification)
notifications.value.push(body as Notification)
}
return body
}
function remove (id: string) {
notifications.value = notifications.value.filter((n: ToastNotification) => n.id !== id)
notifications.value = notifications.value.filter((n: Notification) => n.id !== id)
}
return {