page.ts 771 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { defineStore } from 'pinia'
  2. import { ref } from 'vue'
  3. import type { Ref } from 'vue'
  4. import type { TYPE_ALERT } from '~/types/enum/enums'
  5. import type { Alert } from '~/types/interfaces'
  6. export const usePageStore = defineStore('page', () => {
  7. const alerts: Ref<Array<Alert>> = ref([])
  8. const loading: Ref<boolean> = ref(false)
  9. const removeSlowlyAlert = () => {
  10. setTimeout(() => {
  11. alerts.value.shift()
  12. }, 300)
  13. }
  14. /**
  15. * Ajout des alerts dans le store
  16. * @param type
  17. * @param messages
  18. */
  19. const addAlert = (type: TYPE_ALERT, messages: Array<string>) => {
  20. const alert: Alert = {
  21. type,
  22. messages,
  23. }
  24. alerts.value.push(alert)
  25. }
  26. return {
  27. alerts,
  28. loading,
  29. removeSlowlyAlert,
  30. addAlert,
  31. }
  32. })