Add a button to choose to query inventaire from search
This commit is contained in:
@@ -43,7 +43,7 @@ function openBook() {
|
||||
<p>{{error}}</p>
|
||||
</div>
|
||||
<div class="columns no-padding box container has-background-dark">
|
||||
<div class="media column no-margin" @click="openBook">
|
||||
<div class="media column no-margin clickable" @click="openBook">
|
||||
<div class="media-left">
|
||||
<figure class="image mb-3">
|
||||
<img v-bind:src="imagePathOrDefault" v-bind:alt="title">
|
||||
@@ -55,7 +55,7 @@ function openBook() {
|
||||
<div class="has-text-text-65 is-size-6" v-if="props.description">{{description}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-narrow">
|
||||
<div v-if="!inventaireid" class="column is-narrow">
|
||||
<button @click="" class="button is-large verticalbutton">
|
||||
<span class="icon" :title="$t('booklistelement.wantread')">
|
||||
<b-icon-eye-fill v-if="props.wantread" />
|
||||
@@ -85,6 +85,10 @@ img {
|
||||
width:auto;
|
||||
}
|
||||
|
||||
.clickable {
|
||||
cursor:pointer
|
||||
}
|
||||
|
||||
.box {
|
||||
transition:ease-in-out 0.04s;
|
||||
margin-bottom: 15px;
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<p>{{error}}</p>
|
||||
</div>
|
||||
<div class="columns no-padding box container has-background-dark">
|
||||
<div class="media column no-margin" @click="openBook">
|
||||
<div class="media column no-margin clickable" @click="openBook">
|
||||
<div class="media-left">
|
||||
<figure class="image mb-3">
|
||||
<img v-bind:src="imagePathOrDefault" v-bind:alt="title">
|
||||
@@ -55,6 +55,11 @@ img {
|
||||
width:auto;
|
||||
}
|
||||
|
||||
|
||||
.clickable {
|
||||
cursor:pointer
|
||||
}
|
||||
|
||||
.box {
|
||||
transition:ease-in-out 0.04s;
|
||||
margin-bottom: 15px;
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
authorId: Number
|
||||
});
|
||||
|
||||
const forceSearchInventaire = ref(false);
|
||||
|
||||
const searchInventaire = computed(() => {
|
||||
return forceSearchInventaire.value || (data.value !== null && data.value['inventaire'])
|
||||
});
|
||||
|
||||
let data = ref(null);
|
||||
let error = ref(null);
|
||||
|
||||
@@ -27,9 +33,11 @@
|
||||
|
||||
|
||||
function fetchData(searchTerm, authorId) {
|
||||
data.value = null;
|
||||
error.value = null;
|
||||
if (searchTerm != null) {
|
||||
const lang = navigator.language.substring(0,2);
|
||||
getSearchBooks(data, error, searchTerm, lang, limit, offset.value);
|
||||
getSearchBooks(data, error, searchTerm, lang, forceSearchInventaire.value, limit, offset.value);
|
||||
} else if (authorId != null) {
|
||||
getAuthorBooks(data, error, authorId, limit, offset.value);
|
||||
}
|
||||
@@ -46,15 +54,26 @@
|
||||
fetchData(props.searchterm, props.authorId);
|
||||
}
|
||||
|
||||
function toggleSearchInventaire() {
|
||||
pageNumber.value = 1;
|
||||
forceSearchInventaire.value = !forceSearchInventaire.value;
|
||||
fetchData(props.searchterm, props.authorId)
|
||||
window.scrollTo(0,0);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="booksearch my-2">
|
||||
<h1 class="title" v-if="data && data.inventaire">{{$t('searchbook.importinventaire')}}</h1>
|
||||
<div v-if="error">{{$t('searchbook.error', {error: error.message})}}</div>
|
||||
<div v-else-if="data && data.books && data.books.length > 0">
|
||||
<div class="booksearchlist" v-for="book in data.books" :key="book.id">
|
||||
<BookListElement v-bind="book" />
|
||||
</div>
|
||||
<div v-if="!searchInventaire || forceSearchInventaire" class="box container clickable has-background-dark" @click="toggleSearchInventaire">
|
||||
<div class="is-size-4">{{searchInventaire ? $t('searchbook.backtosearch') : $t('searchbook.searchinventaire')}}</div>
|
||||
</div>
|
||||
<Pagination
|
||||
:pageNumber="pageNumber"
|
||||
:pageTotal="pageTotal"
|
||||
@@ -66,5 +85,10 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
<style scoped>
|
||||
|
||||
.clickable {
|
||||
cursor:pointer
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ export function getMyBooks(data, error, arg, limit, offset) {
|
||||
return useFetch(data, error, baseUrl + '/mybooks/' + arg + "?" + queryParams.toString());
|
||||
}
|
||||
|
||||
export function getSearchBooks(data, error, searchterm, lang, limit, offset) {
|
||||
const queryParams = new URLSearchParams({lang: lang, limit: limit, offset: offset});
|
||||
export function getSearchBooks(data, error, searchterm, lang, searchInventaire, limit, offset) {
|
||||
const queryParams = new URLSearchParams({lang: lang, inventaire: searchInventaire, limit: limit, offset: offset});
|
||||
return useFetch(data, error, baseUrl + '/search/' + encodeURIComponent(searchterm) + "?" + queryParams.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,10 @@
|
||||
"searchbook": {
|
||||
"error": "Error when loading books: {error}",
|
||||
"loading": "Loading...",
|
||||
"noresult": "No results found."
|
||||
"noresult": "No results found.",
|
||||
"importinventaire": "Import from inventaire.io",
|
||||
"searchinventaire": "Load more results from inventaire.io",
|
||||
"backtosearch": "Go back to regular search"
|
||||
},
|
||||
"booklistelement": {
|
||||
"read": "Read",
|
||||
|
||||
@@ -36,7 +36,10 @@
|
||||
"searchbook": {
|
||||
"error": "Erreur pendant le chargement des livres: {error}",
|
||||
"loading": "Chargement...",
|
||||
"noresult": "Aucun résultat trouvé."
|
||||
"noresult": "Aucun résultat trouvé.",
|
||||
"importinventaire": "Importer depuis inventaire.io",
|
||||
"searchinventaire": "Charger plus de résultats depuis inventaire.io",
|
||||
"backtosearch": "Retourner à la recherche"
|
||||
},
|
||||
"booklistelement": {
|
||||
"read": "Lu",
|
||||
|
||||
@@ -7,6 +7,7 @@ type AuthorGet struct {
|
||||
|
||||
type BookSearchGetParam struct {
|
||||
Lang string `form:"lang" binding:"max=5"`
|
||||
Inventaire bool `form:"inventaire"`
|
||||
}
|
||||
|
||||
type BookPostCreate struct {
|
||||
|
||||
@@ -32,6 +32,7 @@ type BookUserGetBook struct {
|
||||
|
||||
type BookSearchGet struct {
|
||||
Count int64 `json:"count"`
|
||||
Inventaire bool `json:"inventaire"`
|
||||
Books []BookSearchGetBook `json:"books"`
|
||||
}
|
||||
|
||||
|
||||
@@ -36,20 +36,21 @@ func GetSearchBooksHandler(ac appcontext.AppContext) {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
var returnedBooks dto.BookSearchGet
|
||||
if !params.Inventaire {
|
||||
books, err := query.FetchBookSearchGet(ac.Db, user.ID, searchterm, limit, offset)
|
||||
if err != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
var returnedBooks dto.BookSearchGet
|
||||
if len(books) > 0 {
|
||||
count, err := query.FetchBookSearchGetCount(ac.Db, user.ID, searchterm)
|
||||
if err != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
returnedBooks = dto.BookSearchGet{Count: count, Books: books}
|
||||
} else {
|
||||
returnedBooks = dto.BookSearchGet{Count: count, Inventaire: false, Books: books}
|
||||
}
|
||||
if params.Inventaire || len(returnedBooks.Books) == 0 {
|
||||
queryResult, err := inventaire.CallInventaireSearch(searchterm, params.Lang, limit, offset)
|
||||
if err != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
@@ -80,5 +81,5 @@ func InventaireBooksToBookSearchGet(results inventaire.InventaireSearchResult) d
|
||||
}
|
||||
books = append(books, bookSearchGetBook)
|
||||
}
|
||||
return dto.BookSearchGet{Count: results.Total, Books: books}
|
||||
return dto.BookSearchGet{Count: results.Total, Inventaire: true, Books: books}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user