41 lines
882 B
TypeScript
41 lines
882 B
TypeScript
import { defineStore } from 'pinia'
|
|
import { ref } from 'vue'
|
|
|
|
export interface Notification {
|
|
id: number
|
|
message: string
|
|
type: 'info' | 'success' | 'error' | 'warning'
|
|
timestamp: Date
|
|
visible: boolean
|
|
}
|
|
|
|
export interface AppUser {
|
|
id: number
|
|
username: string
|
|
full_name: string | null
|
|
is_superuser: boolean
|
|
[key: string]: any
|
|
}
|
|
|
|
export const useAppStore = defineStore('app', () => {
|
|
const user = ref<AppUser | null>(null)
|
|
const token = ref<string | null>(null)
|
|
const loading = ref(false)
|
|
const notifications = ref<Notification[]>([])
|
|
const initialized = ref(false)
|
|
|
|
function dismissNotification(id: number) {
|
|
const index = notifications.value.findIndex(n => n.id === id)
|
|
if (index > -1) notifications.value.splice(index, 1)
|
|
}
|
|
|
|
return {
|
|
user,
|
|
token,
|
|
loading,
|
|
notifications,
|
|
initialized,
|
|
dismissNotification,
|
|
}
|
|
})
|