2020-04-10 15:07:08 -04:00
|
|
|
import _ from './anime-client.js';
|
2018-09-20 16:08:46 -04:00
|
|
|
|
2018-09-27 16:45:12 -04:00
|
|
|
// Click on hidden MAL checkbox so
|
|
|
|
// that MAL id is passed
|
2018-09-20 16:08:46 -04:00
|
|
|
_.on('main', 'change', '.big-check', (e) => {
|
|
|
|
const id = e.target.id;
|
|
|
|
document.getElementById(`mal_${id}`).checked = true;
|
|
|
|
});
|
|
|
|
|
2021-10-08 12:15:34 -04:00
|
|
|
/**
|
|
|
|
* On search results with an existing library entry, this shows that fact, with an edit link for the existing
|
|
|
|
* library entry
|
|
|
|
*
|
|
|
|
* @param {'anime'|'manga'} type
|
|
|
|
* @param {Object} item
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
|
|
|
function renderEditLink (type, item) {
|
|
|
|
if (item.libraryEntry === null) {
|
|
|
|
return '';
|
|
|
|
}
|
2018-08-22 12:54:06 -04:00
|
|
|
|
2021-10-08 12:15:34 -04:00
|
|
|
return `
|
|
|
|
<div class="row">
|
|
|
|
<span class="edit"><big>[ Already in List ]</big></span>
|
|
|
|
</div>
|
|
|
|
<div class="row">
|
|
|
|
<span class="edit">
|
|
|
|
<a class="bracketed" href="/${type}/edit/${item.libraryEntry.id}/${item.libraryEntry.status}">Edit</a>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div class="row"><span class="edit"> </span></div>
|
|
|
|
`
|
2018-08-22 12:54:06 -04:00
|
|
|
}
|
|
|
|
|
2021-10-08 12:15:34 -04:00
|
|
|
/**
|
|
|
|
* Show the search results for a media item
|
|
|
|
*
|
|
|
|
* @param {'anime'|'manga'} type
|
|
|
|
* @param {Object} data
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
|
|
|
export function renderSearchResults (type, data) {
|
2021-02-18 07:14:07 -05:00
|
|
|
return data.map(item => {
|
2020-04-23 18:51:12 -04:00
|
|
|
const titles = item.titles.join('<br />');
|
2021-10-08 12:15:34 -04:00
|
|
|
const disabled = item.libraryEntry !== null ? 'disabled' : '';
|
|
|
|
const editLink = renderEditLink(type, item);
|
|
|
|
|
2021-02-18 07:14:07 -05:00
|
|
|
return `
|
2021-10-08 12:15:34 -04:00
|
|
|
<article class="media search ${disabled}">
|
2018-08-22 12:54:06 -04:00
|
|
|
<div class="name">
|
2021-10-08 12:15:34 -04:00
|
|
|
<input type="radio" class="mal-check" id="mal_${item.slug}" name="mal_id" value="${item.mal_id}" ${disabled} />
|
|
|
|
<input type="radio" class="big-check" id="${item.slug}" name="id" value="${item.id}" ${disabled} />
|
2018-08-22 12:54:06 -04:00
|
|
|
<label for="${item.slug}">
|
2018-10-05 22:36:54 -04:00
|
|
|
<picture width="220">
|
2021-10-08 12:15:34 -04:00
|
|
|
<source srcset="/public/images/${type}/${item.id}.webp" type="image/webp" />
|
|
|
|
<source srcset="/public/images/${type}/${item.id}.jpg" type="image/jpeg" />
|
|
|
|
<img src="/public/images/${type}/${item.id}.jpg" alt="" width="220" />
|
2018-10-05 22:36:54 -04:00
|
|
|
</picture>
|
2018-08-22 12:54:06 -04:00
|
|
|
<span class="name">
|
|
|
|
${item.canonicalTitle}<br />
|
|
|
|
<small>${titles}</small>
|
|
|
|
</span>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div class="table">
|
2021-10-08 12:15:34 -04:00
|
|
|
${editLink}
|
2018-08-22 12:54:06 -04:00
|
|
|
<div class="row">
|
|
|
|
<span class="edit">
|
2021-10-08 12:15:34 -04:00
|
|
|
<a class="bracketed" href="/${type}/details/${item.slug}">Info Page</a>
|
2018-08-22 12:54:06 -04:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</article>
|
2021-02-18 07:14:07 -05:00
|
|
|
`;
|
|
|
|
}).join('');
|
2018-08-22 12:54:06 -04:00
|
|
|
}
|