feat: добавил личные уведомления для пользователей
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 9s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 26s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 19s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 8s
🚀 Create and publish a Docker image / Detect changes in backend and frontend (push) Successful in 9s
🚀 Create and publish a Docker image / Build & publish backend image (push) Successful in 26s
🚀 Create and publish a Docker image / Build & publish frontend image (push) Successful in 19s
🚀 Create and publish a Docker image / Update stack on Portainer (push) Successful in 8s
Реализовал хранение, получение и отметку прочитанными пользовательских уведомлений. Обновил фронтенд для отображения и управления уведомлениями в профиле студента.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { achievementsApi, usersApi } from '@/api'
|
||||
import { mapApiAchievement, mapApiCoinTransaction } from '@/api/mappers'
|
||||
import { achievementsApi, notificationsApi, usersApi } from '@/api'
|
||||
import { mapApiAchievement, mapApiCoinTransaction, mapApiNotification } from '@/api/mappers'
|
||||
import type { Achievement, CoinTransaction, Notification } from '@/types'
|
||||
import { useAuthStore } from './auth'
|
||||
|
||||
@@ -25,7 +25,10 @@ export const useUserStore = defineStore('user', () => {
|
||||
usersApi.achievements(id),
|
||||
usersApi.transactions(id),
|
||||
])
|
||||
const achievementCatalog = await achievementsApi.list()
|
||||
const [achievementCatalog, notificationPayload] = await Promise.all([
|
||||
achievementsApi.list(),
|
||||
notificationsApi.list(),
|
||||
])
|
||||
|
||||
if (auth.user) {
|
||||
auth.setUser({
|
||||
@@ -55,6 +58,7 @@ export const useUserStore = defineStore('user', () => {
|
||||
(a, b) => Number(a.id) - Number(b.id),
|
||||
)
|
||||
coinHistory.value = transactions.map(mapApiCoinTransaction)
|
||||
notifications.value = notificationPayload.map(mapApiNotification)
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : 'Не удалось загрузить данные профиля.'
|
||||
} finally {
|
||||
@@ -62,7 +66,13 @@ export const useUserStore = defineStore('user', () => {
|
||||
}
|
||||
}
|
||||
|
||||
function markAllRead() {
|
||||
async function fetchNotifications() {
|
||||
const payload = await notificationsApi.list()
|
||||
notifications.value = payload.map(mapApiNotification)
|
||||
}
|
||||
|
||||
async function markAllRead() {
|
||||
await notificationsApi.markAllRead()
|
||||
notifications.value.forEach(n => (n.read = true))
|
||||
}
|
||||
|
||||
@@ -75,6 +85,7 @@ export const useUserStore = defineStore('user', () => {
|
||||
loading,
|
||||
error,
|
||||
fetchStudentData,
|
||||
fetchNotifications,
|
||||
markAllRead,
|
||||
unreadCount,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user