2024-11-02 18:41:13 +00:00
|
|
|
<template>
|
2024-11-03 21:57:12 +00:00
|
|
|
<Loading class="container" :loading="loading" :message="error" type="danger">
|
|
|
|
<div class="block">
|
|
|
|
<router-link class="button" to="/new">
|
|
|
|
<Icon name="plus">New container</Icon>
|
|
|
|
</router-link>
|
|
|
|
</div>
|
|
|
|
<div class="block">
|
|
|
|
<ul>
|
|
|
|
<li v-for="container in containers" :key="container.id">
|
|
|
|
<router-link :to="`/container/${container.name}`">
|
|
|
|
{{ container.name }}
|
|
|
|
</router-link>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2024-11-03 17:54:42 +00:00
|
|
|
</Loading>
|
2024-11-02 18:41:13 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2024-11-03 18:14:47 +00:00
|
|
|
import axios, { AxiosError } from 'axios'
|
2024-11-03 22:10:21 +00:00
|
|
|
import type { Container } from '../types'
|
|
|
|
import Icon from '../components/Icon.vue'
|
|
|
|
import Loading from '../components/Loading.vue'
|
2024-11-03 17:54:42 +00:00
|
|
|
|
2024-11-02 18:41:13 +00:00
|
|
|
export default {
|
2024-11-03 19:42:55 +00:00
|
|
|
name: 'Home',
|
2024-11-03 17:54:42 +00:00
|
|
|
components: {
|
2024-11-03 21:57:12 +00:00
|
|
|
Icon,
|
2024-11-03 17:54:42 +00:00
|
|
|
Loading,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2024-11-03 22:10:21 +00:00
|
|
|
containers: [] as Container[],
|
2024-11-03 18:14:47 +00:00
|
|
|
error: '',
|
2024-11-03 17:54:42 +00:00
|
|
|
loading: true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async mounted() {
|
|
|
|
try {
|
2024-11-03 22:10:21 +00:00
|
|
|
const response = await axios.get<Container[]>('/api/containers')
|
2024-11-03 18:14:47 +00:00
|
|
|
this.containers = response.data
|
2024-11-03 17:54:42 +00:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error)
|
2024-11-03 18:14:47 +00:00
|
|
|
this.error =
|
|
|
|
error instanceof AxiosError ? error.message : 'Error loading containers'
|
2024-11-03 17:54:42 +00:00
|
|
|
} finally {
|
|
|
|
this.loading = false
|
|
|
|
}
|
|
|
|
},
|
2024-11-02 18:41:13 +00:00
|
|
|
}
|
|
|
|
</script>
|