feat(pwa-offline): Pinia store + IndexedDB; contexto para cache/eliminación; toasts; compatibilidad PWA offline
- Agrega @pinia/nuxt, idb y store central (stores/music.ts) - Cacheo manual desde menú contextual y borrado (TrackContextMenu) - Ícono verde para canciones cacheadas, sin auto-cache al reproducir - Toasts de feedback (stores/toast.ts, ToastContainer) - Fallback offline de listado a IndexedDB; fix MUSIC_DIR absoluto en preview/prod - Ajustes PWA: navigateFallback '/', devOptions, workbox condicional - Estilos y animación del context menu (tema light/dark, blur fuerte) - Correcciones de sintaxis y posicionamiento exacto al cursor
This commit is contained in:
42
stores/toast.ts
Normal file
42
stores/toast.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
type ToastType = 'success' | 'error' | 'info'
|
||||
|
||||
export type Toast = {
|
||||
id: number
|
||||
type: ToastType
|
||||
message: string
|
||||
timeout?: number
|
||||
}
|
||||
|
||||
let counter = 1
|
||||
|
||||
export const useToastStore = defineStore('toast', {
|
||||
state: () => ({
|
||||
toasts: [] as Toast[]
|
||||
}),
|
||||
actions: {
|
||||
push(message: string, type: ToastType = 'info', timeout = 2500) {
|
||||
const id = counter++
|
||||
const toast: Toast = { id, type, message, timeout }
|
||||
this.toasts.push(toast)
|
||||
if (timeout && timeout > 0) {
|
||||
setTimeout(() => this.remove(id), timeout)
|
||||
}
|
||||
return id
|
||||
},
|
||||
success(message: string, timeout = 2500) {
|
||||
return this.push(message, 'success', timeout)
|
||||
},
|
||||
error(message: string, timeout = 3000) {
|
||||
return this.push(message, 'error', timeout)
|
||||
},
|
||||
info(message: string, timeout = 2500) {
|
||||
return this.push(message, 'info', timeout)
|
||||
},
|
||||
remove(id: number) {
|
||||
this.toasts = this.toasts.filter(t => t.id !== id)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user