Collections: open collection form on creation

This commit is contained in:
2026-04-08 14:18:34 +02:00
parent f2899b968c
commit 6e3899b25e
2 changed files with 8 additions and 2 deletions

View File

@@ -29,7 +29,7 @@ function createCollection() {
if (res.ok) { if (res.ok) {
addingCollection.value = false addingCollection.value = false
collection.value.name = '' collection.value.name = ''
emit('created') res.json().then((json) => emit('created', json.id))
} else { } else {
res.json().then((json) => (errors.value = json)) res.json().then((json) => (errors.value = json))
} }

View File

@@ -1,10 +1,12 @@
<script setup> <script setup>
import { ref, computed } from 'vue' import { ref, computed } from 'vue'
import { getCollections } from './api.js' import { getCollections } from './api.js'
import { useRouter } from 'vue-router'
import CollectionListElement from './CollectionListElement.vue' import CollectionListElement from './CollectionListElement.vue'
import Pagination from './Pagination.vue' import Pagination from './Pagination.vue'
import AddCollection from './AddCollection.vue' import AddCollection from './AddCollection.vue'
const router = useRouter()
const limit = 5 const limit = 5
const pageNumber = ref(1) const pageNumber = ref(1)
@@ -29,13 +31,17 @@ function pageChange(newPageNumber) {
data.value = null data.value = null
fetchData() fetchData()
} }
function goToCollection(id) {
router.push(`/collection/${id}`)
}
</script> </script>
<template> <template>
<div> <div>
<div v-if="error">{{ $t('collections.error', { error: error.message }) }}</div> <div v-if="error">{{ $t('collections.error', { error: error.message }) }}</div>
<div v-else-if="data"> <div v-else-if="data">
<AddCollection @created="fetchData" /> <AddCollection @created="goToCollection" />
<div class="collectionslist"> <div class="collectionslist">
<div class="my-2" v-for="collection in data.collections" :key="collection.id"> <div class="my-2" v-for="collection in data.collections" :key="collection.id">
<CollectionListElement v-bind="collection" /> <CollectionListElement v-bind="collection" />