All files / src/components FollowingList.vue

88.88% Statements 32/36
72% Branches 18/25
75% Functions 6/8
87.87% Lines 29/33

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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109  8x     4x     2x 1x         1x 2x                                                           3x   3x 3x 3x   3x 3x 3x 3x     3x 3x 3x     3x 2x 2x 2x     2x 3x 3x 3x         2x               3x 3x     3x                                          
<template>
  <div class="following-list">
    <LoadingSpinner v-if="loading && users.length === 0" :grid="false" :padding="3" />
    <EmptyState v-else-if="users.length === 0" variant="info" :grid="false">
      {{ t('follows.noFollowing') }}
    </EmptyState>
    <template v-else>
      <ul class="list-unstyled mb-3">
        <li v-for="user in users" :key="user.id" class="follow-row">
          <router-link
            class="follow-row-link"
            :to="{ name: 'user-profile', params: { userId: user.id } }"
          >
            <UserAvatar :picture-key="user.profilePicture" class="follow-row-avatar" />
            <span class="follow-row-name">{{ user.name }}</span>
            <span v-if="user.nickname" class="follow-row-nickname text-muted">
              @{{ user.nickname }}
            </span>
          </router-link>
        </li>
      </ul>
      <button
        v-if="hasMore"
        class="btn btn-outline-secondary btn-sm"
        :disabled="loading"
        @click="loadMore"
      >
        {{ t('common.loadMore') }}
      </button>
    </template>
  </div>
</template>
 
<script setup lang="ts">
// @implements UC-PROFILE-007.1
import { ref, onMounted, watch } from 'vue'
import LoadingSpinner from '@/components/LoadingSpinner.vue'
import EmptyState from '@/components/EmptyState.vue'
import UserAvatar from '@/components/UserAvatar.vue'
import { useUILanguage } from '@/composables/useUILanguage'
import { useFollowsStore } from '@/stores/follows'
import { useToastStore } from '@/stores/toast'
import type { User } from '@/stores/users'
 
const props = defineProps<{ userId: string }>()
 
const { t } = useUILanguage()
const followsStore = useFollowsStore()
const toastStore = useToastStore()
 
const users = ref<User[]>([])
const loading = ref(false)
const hasMore = ref(false)
const nextToken = ref<string | null>(null)
 
async function load(reset = true) {
  Eif (reset) {
    users.value = []
    nextToken.value = null
  }
  // Empty while the signed-in user is being signed out (account deletion)
  if (!props.userId) return
  loading.value = true
  try {
    const page = await followsStore.fetchFollowing(props.userId, {
      ...(nextToken.value ? { nextToken: nextToken.value } : {})
    })
    const items = page.items ?? []
    users.value = reset ? items : [...users.value, ...items]
    hasMore.value = page.hasMore ?? false
    nextToken.value = page.nextToken ?? null
  } catch (error) {
    console.error('Failed to load following:', error)
    toastStore.error(t('follows.loadFollowingError'))
  } finally {
    loading.value = false
  }
}
 
function loadMore() {
  load(false)
}
 
watch(
  () => props.userId,
  () => load(true)
)
onMounted(() => load(true))
</script>
 
<style scoped>
.follow-row {
  border-bottom: 1px solid var(--bw-border);
}
 
.follow-row-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  color: inherit;
  text-decoration: none;
}
 
.follow-row-nickname {
  font-size: 0.875rem;
}
</style>