2019-09-12 01:34:11 +02:00
|
|
|
import html from 'choo/html';
|
|
|
|
|
2019-09-12 06:42:01 +02:00
|
|
|
import { starRating } from '../partials/starRating';
|
2019-09-12 01:34:11 +02:00
|
|
|
import { modal } from '../partials/modal';
|
|
|
|
|
2019-09-13 01:04:50 +02:00
|
|
|
export const resultDetails = (searchController, result, emit = () => {}) => {
|
2019-09-12 05:51:59 +02:00
|
|
|
const { i18n } = searchController;
|
2019-09-12 06:42:01 +02:00
|
|
|
const modalId = `result_${result.uri}`;
|
|
|
|
|
|
|
|
const buttonHTML = html`<label for=${modalId} class="pseudo button">
|
2019-09-12 20:41:10 +02:00
|
|
|
<span data-tooltip="${i18n.__('interaction.average_rating')}: ${result.averageRating}">
|
|
|
|
${starRating(result.averageRating)}
|
2019-09-12 06:42:01 +02:00
|
|
|
</span>
|
|
|
|
<span style="margin-left:10px;" data-tooltip=${i18n.__('interaction.reviews_written')}>
|
|
|
|
<span style="margin-right:8px;"><i class="icon-chat"></i></span>
|
2019-09-12 20:41:10 +02:00
|
|
|
<span>${result.numberOfReviews}</span>
|
2019-09-12 06:42:01 +02:00
|
|
|
</span>
|
|
|
|
</label>`;
|
|
|
|
|
2019-09-13 01:04:50 +02:00
|
|
|
const tabNames = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty'];
|
|
|
|
|
2019-09-12 07:41:18 +02:00
|
|
|
const modalContent = html`<article class="flex">
|
|
|
|
<div class="sixth-700" style="text-align:center;">
|
|
|
|
<h4>Covers</h4>
|
2019-09-13 01:04:50 +02:00
|
|
|
${typeof result.covers === 'undefined'
|
|
|
|
? html`<span style="font-size:3em;"><i class="icon-loading animate-spin"></i></span>`
|
|
|
|
: html`<div class="tabs ${typeof tabNames[result.covers.length - 1] !== 'undefined' ? tabNames[result.covers.length - 1] : null}">
|
|
|
|
${result.covers.map((cover, index) => {
|
|
|
|
return [
|
|
|
|
html`<input id="cover_${cover.uri}" type="radio" name="${modalId}_covers" ${index === 0 ? 'checked' : null} />`,
|
|
|
|
// html`<label class="small pseudo button toggle" for="cover_${cover.uri}">•</label>`,
|
|
|
|
];
|
|
|
|
})}
|
|
|
|
<div class="row">
|
|
|
|
${result.covers.map((cover, index, allCovers) => {
|
|
|
|
return html`<div>
|
|
|
|
<img src=${cover.url} alt="${cover.uri.replace(':', ' ').toUpperCase()}, Published: ${cover.publishDate}">
|
|
|
|
${typeof allCovers[index - 1] === 'undefined'
|
|
|
|
? null
|
|
|
|
: html`<label class="button" for="cover_${allCovers[index - 1].uri}" style="margin-right:8px;">
|
|
|
|
${'<'}
|
|
|
|
</label>`
|
|
|
|
}
|
|
|
|
${typeof allCovers[index + 1] === 'undefined'
|
|
|
|
? null
|
|
|
|
: html`<label class="button" for="cover_${allCovers[index + 1].uri}">
|
|
|
|
${'>'}
|
|
|
|
</label>`
|
|
|
|
}
|
|
|
|
</div>`;
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</div>`
|
|
|
|
}
|
2019-09-12 07:41:18 +02:00
|
|
|
</div>
|
|
|
|
<div class="two-third-700">
|
|
|
|
<h4>${i18n.__('interaction.average_rating')}</h4>
|
2019-09-12 20:41:10 +02:00
|
|
|
<span data-tooltip="${result.averageRating}">${starRating(result.averageRating)}</span>
|
2019-09-12 07:41:18 +02:00
|
|
|
|
|
|
|
<div class="flex">
|
|
|
|
<div>
|
|
|
|
<h4>Top Reviews</h4>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<a href="/book/${result.uri}" class="small button">
|
|
|
|
<span style="margin-right:8px;"><i class="icon-chat"></i></span>
|
2019-09-12 20:41:10 +02:00
|
|
|
<span>${result.numberOfReviews}</span>
|
2019-09-12 07:41:18 +02:00
|
|
|
<span>${i18n.__('search.see_interaction_details')}</span>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-09-12 20:41:10 +02:00
|
|
|
${result.reviews.map(review => {
|
|
|
|
return html`<article class="card">
|
|
|
|
<header style="font-weight:normal;">
|
|
|
|
<strong>${review.reviewer.name}</strong> <em>${review.reviewer.handle}</em><br>
|
|
|
|
${review.date} ${starRating(Math.ceil(review.rating))}
|
|
|
|
</header>
|
|
|
|
<footer>
|
|
|
|
<div class="content">
|
|
|
|
<p>
|
|
|
|
${review.review}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<span class="tooltip-top" data-tooltip=${i18n.__('interaction.heart')}>
|
|
|
|
<button class="pseudo">
|
|
|
|
<i class="icon-heart-outline"></i>
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
<span>
|
|
|
|
${review.hearts}
|
|
|
|
</span>
|
|
|
|
</footer>
|
|
|
|
</article>`;
|
|
|
|
})}
|
2019-09-12 07:41:18 +02:00
|
|
|
</div>
|
|
|
|
<div class="sixth-700">
|
|
|
|
<p>
|
|
|
|
<span data-tooltip=${i18n.__('interaction.add')}>
|
|
|
|
<button class="success">
|
|
|
|
<i class="icon-plus"></i>
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<span data-tooltip=${i18n.__('search.see_details_tooltip')}>
|
|
|
|
<a class="small pseudo button" href=${result.link} target="_blank">
|
|
|
|
${i18n.__('search.see_book_details')}
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
</div>
|
2019-09-12 01:34:11 +02:00
|
|
|
</article>`;
|
|
|
|
|
|
|
|
return modal(modalId, searchController, modalContent, {
|
2019-09-12 07:41:18 +02:00
|
|
|
styles: "width:90%;",
|
2019-09-12 06:42:01 +02:00
|
|
|
buttonHTML, // This should be replaced with buttonHTML containing the ratings and number of reviews etc.
|
2019-09-12 01:34:11 +02:00
|
|
|
headerText: result.name,
|
2019-09-13 01:04:50 +02:00
|
|
|
onShow: () => {
|
|
|
|
if (typeof result.covers === 'undefined') {
|
|
|
|
searchController.getCovers(result.uri).then(() => emit('render'));
|
|
|
|
}
|
|
|
|
},
|
2019-09-12 01:34:11 +02:00
|
|
|
});
|
|
|
|
}
|