Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | 7x 2x 2x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 3x | <template>
<div class="entity-subscriptions-list">
<LoadingSpinner v-if="loading" :grid="false" :padding="3" />
<EmptyState v-else-if="entities.length === 0" variant="info" :grid="false">
{{ t('follows.noSubscriptions') }}
</EmptyState>
<VirtualCardGrid v-else :items="entities" :has-more="false" :offset-height="280">
<template #card="{ item: entity }">
<EntityCard
:entity="entity"
navigation-source="catalog"
@subscribe="handleSubscribe(entity)"
@unsubscribe="handleUnsubscribe(entity)"
/>
</template>
</VirtualCardGrid>
</div>
</template>
<script setup lang="ts">
// @implements UC-PROFILE-008.1
import { ref, onMounted } from 'vue'
import LoadingSpinner from '@/components/LoadingSpinner.vue'
import EmptyState from '@/components/EmptyState.vue'
import VirtualCardGrid from '@/components/VirtualCardGrid.vue'
import EntityCard from '@/components/EntityCard.vue'
import api from '@/services/api'
import { useUILanguage } from '@/composables/useUILanguage'
import { useToastStore } from '@/stores/toast'
import { useEntitiesStore, type Entity } from '@/stores/entities'
import { getErrorMessage } from '@/utils/errors'
const { t } = useUILanguage()
const toastStore = useToastStore()
const entitiesStore = useEntitiesStore()
const entities = ref<Entity[]>([])
const loading = ref(true)
async function load() {
loading.value = true
try {
const response = await api.get<{ items: Entity[] }>('/v1/users/me/subscriptions')
entities.value = response.data.items ?? []
} catch (error) {
console.error('Failed to load entity subscriptions:', error)
toastStore.error(t('follows.loadSubscriptionsError'))
} finally {
loading.value = false
}
}
async function handleSubscribe(entity: Entity) {
entity.subscribedByCurrentUser = true
entity.subscriberCount = (entity.subscriberCount ?? 0) + 1
try {
await entitiesStore.subscribeToEntity(entity.id)
} catch (error) {
entity.subscribedByCurrentUser = false
entity.subscriberCount = Math.max(0, (entity.subscriberCount ?? 0) - 1)
toastStore.error(getErrorMessage(error, t('catalog.subscribe-error')))
}
}
async function handleUnsubscribe(entity: Entity) {
entity.subscribedByCurrentUser = false
entity.subscriberCount = Math.max(0, (entity.subscriberCount ?? 0) - 1)
entities.value = entities.value.filter((e) => e.id !== entity.id)
try {
await entitiesStore.unsubscribeFromEntity(entity.id)
} catch (error) {
entities.value.push(entity)
entity.subscribedByCurrentUser = true
entity.subscriberCount = (entity.subscriberCount ?? 0) + 1
toastStore.error(getErrorMessage(error, t('catalog.unsubscribe-error')))
}
}
onMounted(load)
</script>
|