modified: serv_nginx/bbvue/src/stores/user.js
add export useStore
This commit is contained in:
@@ -16,11 +16,11 @@ export const useUserStore = defineStore('user', () => {
|
||||
const error = ref('')
|
||||
|
||||
// Getters
|
||||
const completedAchievements = computed(() =>
|
||||
const completedAchievements = computed(() =>
|
||||
userAchievements.value.filter(achievement => achievement.verified || achievement.achieved)
|
||||
)
|
||||
|
||||
const pendingAchievements = computed(() =>
|
||||
|
||||
const pendingAchievements = computed(() =>
|
||||
userAchievements.value.filter(achievement => !(achievement.verified || achievement.achieved))
|
||||
)
|
||||
|
||||
@@ -29,19 +29,19 @@ export const useUserStore = defineStore('user', () => {
|
||||
return Math.round((completedAchievements.value.length / userAchievements.value.length) * 100)
|
||||
})
|
||||
|
||||
const verifiedPersonalBests = computed(() =>
|
||||
const verifiedPersonalBests = computed(() =>
|
||||
personalBests.value.filter(best => best.verified)
|
||||
)
|
||||
|
||||
const confirmedEvents = computed(() =>
|
||||
const confirmedEvents = computed(() =>
|
||||
upcomingEvents.value.filter(event => event.registrationStatus === 'confirmed')
|
||||
)
|
||||
|
||||
const totalWorkouts = computed(() =>
|
||||
const totalWorkouts = computed(() =>
|
||||
userStats.value?.workoutsCount || workoutHistory.value.length
|
||||
)
|
||||
|
||||
const totalCalories = computed(() =>
|
||||
const totalCalories = computed(() =>
|
||||
workoutHistory.value.reduce((sum, workout) => sum + (workout.calories || 0), 0)
|
||||
)
|
||||
|
||||
@@ -102,46 +102,46 @@ export const useUserStore = defineStore('user', () => {
|
||||
} catch (error) {
|
||||
console.warn('Achievements endpoint not available, using mock data', error)
|
||||
userAchievements.value = [
|
||||
{
|
||||
id: 1,
|
||||
{
|
||||
id: 1,
|
||||
type: 'distance',
|
||||
title: 'Первый забег',
|
||||
description: 'Пробежать первую 5км',
|
||||
verified: true,
|
||||
title: 'Первый забег',
|
||||
description: 'Пробежать первую 5км',
|
||||
verified: true,
|
||||
date: '2024-01-20',
|
||||
badgeImage: '/badges/first-run.png'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
{
|
||||
id: 2,
|
||||
type: 'consistency',
|
||||
title: 'Неделя тренировок',
|
||||
description: 'Тренироваться 7 дней подряд',
|
||||
verified: true,
|
||||
title: 'Неделя тренировок',
|
||||
description: 'Тренироваться 7 дней подряд',
|
||||
verified: true,
|
||||
date: '2024-02-15',
|
||||
badgeImage: '/badges/week-streak.png'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
{
|
||||
id: 3,
|
||||
type: 'distance',
|
||||
title: '100 км',
|
||||
description: 'Пробежать 100 км',
|
||||
verified: true,
|
||||
title: '100 км',
|
||||
description: 'Пробежать 100 км',
|
||||
verified: true,
|
||||
date: '2024-03-01',
|
||||
badgeImage: '/badges/100km.png'
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
{
|
||||
id: 4,
|
||||
type: 'distance',
|
||||
title: 'Полумарафон',
|
||||
description: 'Пробежать 21.1 км',
|
||||
title: 'Полумарафон',
|
||||
description: 'Пробежать 21.1 км',
|
||||
verified: false,
|
||||
badgeImage: '/badges/half-marathon.png'
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
{
|
||||
id: 5,
|
||||
type: 'speed',
|
||||
title: 'Скорость',
|
||||
description: 'Пробежать 5км быстрее 25 минут',
|
||||
title: 'Скорость',
|
||||
description: 'Пробежать 5км быстрее 25 минут',
|
||||
verified: false,
|
||||
badgeImage: '/badges/speedster.png'
|
||||
}
|
||||
@@ -152,7 +152,7 @@ export const useUserStore = defineStore('user', () => {
|
||||
}
|
||||
|
||||
// Новые actions для дополнительных данных
|
||||
const fetchPersonalBests = async () => {
|
||||
const fetchPersonalBests = async () => {
|
||||
return withStoreLoading(async () => {
|
||||
try {
|
||||
const response = await apiClient.get('/user/personal-bests')
|
||||
@@ -353,7 +353,7 @@ export const useUserStore = defineStore('user', () => {
|
||||
workoutHistory,
|
||||
loading,
|
||||
error,
|
||||
|
||||
|
||||
// Getters
|
||||
completedAchievements,
|
||||
pendingAchievements,
|
||||
@@ -362,7 +362,7 @@ export const useUserStore = defineStore('user', () => {
|
||||
confirmedEvents,
|
||||
totalWorkouts,
|
||||
totalCalories,
|
||||
|
||||
|
||||
// Actions
|
||||
fetchUserStats,
|
||||
fetchUserAchievements,
|
||||
@@ -376,4 +376,7 @@ export const useUserStore = defineStore('user', () => {
|
||||
completeWorkout,
|
||||
resetUserStore
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
export const userStore = useUserStore
|
||||
Reference in New Issue
Block a user