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 = 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} })