NotificacoesAssociadoPage.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div class="notificacoes-page">
  3. <DefaultHeaderPage class="q-px-md"/>
  4. <div v-if="loading" class="flex flex-center q-pa-xl ">
  5. <q-spinner color="violet-normal" size="50px" />
  6. </div>
  7. <div v-else-if="pagedItems.length === 0" class="flex flex-center q-pa-xl text-grey-6 q-px-md">
  8. {{ $t('notification.empty') }}
  9. </div>
  10. <div v-else class="notifications-grid q-px-md">
  11. <NotificationCard
  12. v-for="item in pagedItems"
  13. :key="item.id"
  14. :notification="item.notification"
  15. :unread="!item.read"
  16. :date="item.created_at"
  17. @click="onRead(item)"
  18. />
  19. </div>
  20. <div v-if="totalPages > 1" class="flex flex-center q-mt-lg">
  21. <q-pagination
  22. v-model="currentPage"
  23. :max="totalPages"
  24. :max-pages="6"
  25. boundary-numbers
  26. color="violet-normal"
  27. active-color="violet-normal"
  28. direction-links
  29. />
  30. </div>
  31. </div>
  32. </template>
  33. <script setup>
  34. import { ref, computed, onMounted } from "vue";
  35. import { useQuasar } from "quasar";
  36. import { getMyNotificationsAssociado } from "src/api/notification";
  37. import DefaultHeaderPage from "src/components/layout/DefaultHeaderPage.vue";
  38. import NotificationDetailDialog from "src/components/NotificationDetailDialog.vue";
  39. import NotificationCard from "src/components/NotificationCard.vue";
  40. const $q = useQuasar();
  41. const loading = ref(true);
  42. const notifications = ref([]);
  43. const currentPage = ref(1);
  44. const PER_PAGE = 20;
  45. const totalPages = computed(() => Math.max(1, Math.ceil(notifications.value.length / PER_PAGE)));
  46. const pagedItems = computed(() => {
  47. const start = (currentPage.value - 1) * PER_PAGE;
  48. return notifications.value.slice(start, start + PER_PAGE);
  49. });
  50. const onRead = (item) => {
  51. $q.dialog({ component: NotificationDetailDialog, componentProps: { item } }).onOk((markedId) => {
  52. if (markedId) {
  53. const found = notifications.value.find((n) => n.id === markedId);
  54. if (found) found.read = true;
  55. }
  56. });
  57. };
  58. onMounted(async () => {
  59. try {
  60. notifications.value = await getMyNotificationsAssociado();
  61. } catch (e) {
  62. console.error(e);
  63. } finally {
  64. loading.value = false;
  65. }
  66. });
  67. </script>
  68. <style scoped lang="scss">
  69. @use "src/css/quasar.variables.scss" as vars;
  70. .notificacoes-page {
  71. background: vars.$violet-light;
  72. min-height: calc(100dvh - 68px);
  73. box-sizing: border-box;
  74. overflow-x: hidden;
  75. padding-bottom: 16px;
  76. }
  77. </style>