add userbook from searched book

This commit is contained in:
2025-10-20 17:56:12 +02:00
parent 6d15374c87
commit e5347e3583
5 changed files with 43 additions and 6 deletions

View File

@@ -1,4 +1,9 @@
<script setup>
import { ref } from 'vue'
import { postUserBook } from './api.js'
import { useRouter } from 'vue-router'
const router = useRouter();
const props = defineProps({
title: String,
@@ -6,15 +11,27 @@
id: BigInt,
imagePath: String,
});
const imagePathOrDefault = (props.imagePath == "" || typeof props.imagePath === 'undefined') ? "../defaultbook.png" : props.imagePath;
const imagePathOrDefault = (props.imagePath == "" || typeof props.imagePath === 'undefined') ? "../defaultbook.png" : props.imagePath;
const error = ref(null)
async function onUserBookAdd() {
const res = await postUserBook({bookId: props.id});
if (res.ok) {
router.push('/books')
} else {
res.json().then((json) => (error.value = json));
}
}
</script>
<template>
<div v-if="error" class="notification is-danger">
<p>{{error}}</p>
</div>
<div class="columns box container has-background-dark">
<div class="column is-narrow">
<button class="button">
<button @click="onUserBookAdd" class="button">
<span class="icon" title="Add">
<b-icon-plus />
</span>

View File

@@ -36,6 +36,10 @@ export function postBook(book) {
return genericPostCall('/book', book.value)
}
export async function postUserBook(userbook) {
return genericPostCall('/userbook', userbook)
}
export function postLogin(user) {
return genericPostCallNoAuth('/auth/login', user.value)
}