Add author books list
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
import BookListElement from './BookListElement.vue';
|
||||
import { getSearchBooks, getCountSearchBooks } from './api.js'
|
||||
import { getSearchBooks, getCountSearchBooks, getAuthorBooks, getCountAuthorBooks } from './api.js'
|
||||
import { onBeforeRouteUpdate } from 'vue-router'
|
||||
import Pagination from './Pagination.vue'
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
const offset = computed(() => (pageNumber.value - 1) * limit);
|
||||
|
||||
const props = defineProps({
|
||||
searchterm: String
|
||||
searchterm: String,
|
||||
authorId: Number
|
||||
});
|
||||
|
||||
let data = ref(null);
|
||||
@@ -24,29 +25,34 @@
|
||||
return Math.ceil(countValue / limit);
|
||||
});
|
||||
|
||||
fetchData(props.searchterm);
|
||||
fetchData(props.searchterm, props.authorId);
|
||||
|
||||
|
||||
function fetchData(searchTerm) {
|
||||
getSearchBooks(data, error, searchTerm, limit, offset.value);
|
||||
getCountSearchBooks(totalBooksData, errorFetchTotal, searchTerm);
|
||||
function fetchData(searchTerm, authorId) {
|
||||
if (searchTerm != null) {
|
||||
getSearchBooks(data, error, searchTerm, limit, offset.value);
|
||||
getCountSearchBooks(totalBooksData, errorFetchTotal, searchTerm);
|
||||
} else if (authorId != null) {
|
||||
getAuthorBooks(data, error, authorId, limit, offset.value);
|
||||
getCountAuthorBooks(totalBooksData, errorFetchTotal, searchTerm);
|
||||
}
|
||||
}
|
||||
|
||||
onBeforeRouteUpdate(async (to, from) => {
|
||||
pageNumber.value = 1;
|
||||
fetchData(to.params.searchterm);
|
||||
fetchData(to.params.searchterm, props.authorId);
|
||||
})
|
||||
|
||||
function pageChange(newPageNumber) {
|
||||
pageNumber.value = newPageNumber;
|
||||
data.value = null;
|
||||
fetchData(props.searchterm);
|
||||
fetchData(props.searchterm, props.authorId);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="booksearch">
|
||||
<div class="booksearch my-2">
|
||||
<div v-if="error">{{$t('searchbook.error', {error: error.message})}}</div>
|
||||
<div v-else-if="data && data.length > 0">
|
||||
<div class="booksearchlist" v-for="book in data" :key="book.id">
|
||||
|
||||
Reference in New Issue
Block a user