index.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div>
  3. <h1 class="text-center mb-6">
  4. Authors
  5. </h1>
  6. <v-card v-if="pending" class="text-center pa-4">
  7. <v-progress-circular
  8. :indeterminate="true"
  9. />
  10. <div class="mt-2">
  11. Loading authors...
  12. </div>
  13. </v-card>
  14. <v-card v-else-if="error" class="text-center pa-4 error--text">
  15. <v-icon color="error" large>
  16. mdi-alert-circle
  17. </v-icon>
  18. <div class="mt-2">
  19. Error loading authors: {{ error }}
  20. </div>
  21. </v-card>
  22. <v-card v-else-if="authors.length === 0" class="text-center pa-4">
  23. <div>No authors found</div>
  24. </v-card>
  25. <v-card v-else class="pa-4">
  26. <v-expansion-panels class="w-80 flex-column" multiple>
  27. <AuthorPanel
  28. v-for="author in authors"
  29. :key="author.id"
  30. :author="author"
  31. />
  32. </v-expansion-panels>
  33. </v-card>
  34. </div>
  35. </template>
  36. <script setup lang="ts">
  37. import { ref, onMounted } from 'vue'
  38. import AuthorPanel from '~/components/AuthorPanel.vue'
  39. import type Author from '~/types/interfaces'
  40. useHead({
  41. title: 'Authors'
  42. })
  43. const runtimeConfig = useRuntimeConfig()
  44. const apiBaseUrl = runtimeConfig.apiBaseUrl ?? runtimeConfig.public.apiBaseUrl
  45. const authors = ref<Author[]>([])
  46. const error = ref<string | null>(null)
  47. const pending = ref(true)
  48. onMounted(async () => {
  49. try {
  50. const response = await fetch(apiBaseUrl + '/api/authors')
  51. if (!response.ok) {
  52. throw new Error(`HTTP error. Status: ${response.status}`)
  53. }
  54. const data = await response.json()
  55. authors.value = data.member || []
  56. } catch (err) {
  57. error.value = err instanceof Error ? err.message : 'Unknown error'
  58. console.error('Error fetching authors:', err)
  59. } finally {
  60. pending.value = false
  61. }
  62. })
  63. </script>