<!--
This component freezes during sync. Refactor it to improve UX and data reactivity.
-->
<template>
<div>
<h1>Editorial books</h1>
<ul>
<li v-for="book in books" :key="book.id">
{{ book.name }} - {{ book.status }}
<button @click="syncBook(book.id)">
Sync Now
</button>
</li>
</ul>
</div>
</template>
 
<script setup>
import { ref, onMounted } from 'vue';
 
const books = ref([]);
 
onMounted(async () => {
const res = await fetch('http://localhost:8000/books');
books.value = await res.json();
});
 
const syncBook = async (id) => {
await fetch(`http://localhost:8000/sync-books/${id}`);
 
const res = await fetch('http://localhost:8000/books');
books.value = await res.json();
};
</script>