bookfarm-frontend/src/services/stores/bookStore.ts

24 lines
596 B
TypeScript

import {defineStore} from 'pinia'
import type {Ref} from "vue";
import {ref} from "vue";
import type {Book} from "@/services/models/book";
import {getBookById} from "@/services/bookApi";
export const useBookStore = defineStore('book', () => {
const book: Ref<Book | undefined> = ref(undefined)
const isLoading = ref(false);
async function loadBook(id: string) {
isLoading.value = true;
return getBookById(id)
.then(result => {
book.value = result
})
.finally(() => {
isLoading.value = false;
})
}
return {book, isLoading, loadBook}
})