1
0
Fork 0
mirror of https://gitlab.com/Alamantus/Readlebee.git synced 2025-06-06 01:16:37 +02:00

Style search page results

This commit is contained in:
Robbie Antenesse 2019-09-10 17:16:01 -06:00
parent 24d416ec02
commit b4bb1fc392
6 changed files with 85 additions and 20 deletions

View file

@ -12,6 +12,9 @@
"login_button": "Log In!" "login_button": "Log In!"
}, },
"search": { "search": {
"header": "Search" "header": "Search",
"people_header": "People",
"series_header": "Series",
"books_header": "Books"
} }
} }

6
app/styles/_search.scss Normal file
View file

@ -0,0 +1,6 @@
.search-result {
.search-image {
width: 100%;
max-width: 300px;
}
}

View file

@ -40,3 +40,6 @@
// Custom global styling // Custom global styling
@import './picnic-customizations/custom'; @import './picnic-customizations/custom';
// View styling
@import './search';

View file

@ -7,7 +7,11 @@ export class SearchController extends ViewController {
super(state, 'search', { super(state, 'search', {
lastSearch: undefined, lastSearch: undefined,
done: false, done: false,
results: [], results: {
humans: [],
series: [],
works: [],
},
}); });
// If using controller methods in an input's onchange or onclick instance, // If using controller methods in an input's onchange or onclick instance,
@ -15,8 +19,12 @@ export class SearchController extends ViewController {
// or use `onclick=${() => controller.submit()}` to maintain the 'this' of the class instead. // or use `onclick=${() => controller.submit()}` to maintain the 'this' of the class instead.
} }
get doneSearching() {
return this.state.done;
}
get results() { get results() {
return []; return this.state.results;
} }
get hasQuery() { get hasQuery() {
@ -33,7 +41,6 @@ export class SearchController extends ViewController {
return fetch(`/api/search?for=${searchTerm}&lang=${this.appState.language}`) return fetch(`/api/search?for=${searchTerm}&lang=${this.appState.language}`)
.then(response => response.json()) .then(response => response.json())
.then(responseJSON => { .then(responseJSON => {
console.log(responseJSON);
this.state.results = responseJSON; this.state.results = responseJSON;
this.state.done = true; this.state.done = true;
}); });

View file

@ -19,24 +19,70 @@ export const searchView = (state, emit) => {
// This one doesn't have the problem right now, but it's good to remember. // This one doesn't have the problem right now, but it's good to remember.
return [ return [
html`<section> html`<section>
<h2 class="subtitle">${i18n.__('search.header')}</h2> <h1 class="title">${i18n.__('search.header')}</h1>
<article> <article>
${controller.state.done ? 'Done searching' : 'Loading...'} ${controller.doneSearching ? 'Done searching' : 'Loading...'}
${controller.results.map(result => { ${controller.results.works < 1
return html`<div class="card"> ? null
<header> : [
${result.covers.map(cover => { html`<h2>${i18n.__('search.books_header')}</h2>`,
return html`<img src=${cover} />`; controller.results.works.map(result => {
})} return html`<div class="flex search-result">
<h1 class="title">${result.title}</h1> <div class="sixth-500">
${result.authors.map(author => { ${result.image ? html`<img src=${result.image.url} class="search-image">` : null}
return html`<h2 class="subtitle">${author}</h2>`; </div>
})} <div class="half-500">
</header> <h3 class="title">${result.name}</h3>
</div>`; ${result.description ? html`<h4 class="subtitle">${result.description}</h4>` : null}
})} </div>
<div class="third-500">
<a href=${result.link} target="_blank">See details on Inventaire</a>
</div>
</div>`;
}),
]}
${controller.results.series.length < 1
? null
: [
html`<h2>${i18n.__('search.series_header')}</h2>`,
controller.results.series.map(result => {
return html`<div class="flex search-result">
<div class="sixth-500">
${result.image ? html`<img src=${result.image.url} class="search-image">` : null}
</div>
<div class="half-500">
<h3 class="title">${result.name}</h3>
${result.description ? html`<h4 class="subtitle">${result.description}</h4>` : null}
</div>
<div class="third-500">
<a href=${result.link} target="_blank">See details on Inventaire</a>
</div>
</div>`;
}),
]}
${controller.results.humans.length < 1
? null
: [
html`<h2>${i18n.__('search.people_header')}</h2>`,
controller.results.humans.map(result => {
return html`<div class="flex search-result">
<div class="sixth-500">
${result.image ? html`<img src=${result.image.url} class="search-image">` : null}
</div>
<div class="half-500">
<h3 class="title">${result.name}</h3>
${result.description ? html`<h4 class="subtitle">${result.description}</h4>` : null}
</div>
<div class="third-500">
<a href=${result.link} target="_blank">See details on Inventaire</a>
</div>
</div>`;
}),
]}
</article> </article>
</section>`, </section>`,
]; ];

View file

@ -124,7 +124,7 @@ class SearchController {
: null : null
), ),
image: ( image: (
hasImage && typeof human.image.url !== 'undefined' hasImage && typeof work.image.url !== 'undefined'
? human.image ? human.image
: null : null
), ),