page.ts 856 B

123456789101112131415161718192021222324252627282930313233343536
  1. import type {Alert} from '~/types/interfaces'
  2. import {defineStore} from "pinia";
  3. import {TYPE_ALERT} from "~/types/enum/enums";
  4. import {ref} from "@vue/reactivity";
  5. import type {Ref} from "@vue/reactivity";
  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: type,
  22. messages: messages
  23. }
  24. alerts.value.push(alert)
  25. }
  26. return {
  27. alerts,
  28. loading,
  29. removeSlowlyAlert,
  30. addAlert
  31. }
  32. })