From ecf09b564112aca9e73c567eee35e73400d871cb Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 29 Dec 2021 17:04:55 -0500 Subject: [PATCH 01/22] Allow adding items to anime collection that are in the anime list --- app/views/collection/add.php | 2 +- frontEndSrc/js/anime.js | 23 +++++++++++++++++-- frontEndSrc/js/template-helpers.js | 16 +++++++++---- public/js/scripts.min.js | 2 +- public/js/scripts.min.js.map | 2 +- public/js/tables.min.js | 2 +- public/js/tables.min.js.map | 2 +- .../Controller/AnimeCollection.php | 2 +- src/AnimeClient/Model/MediaTrait.php | 12 ++++++++-- 9 files changed, 48 insertions(+), 15 deletions(-) diff --git a/app/views/collection/add.php b/app/views/collection/add.php index aa625fa5..c08d514a 100644 --- a/app/views/collection/add.php +++ b/app/views/collection/add.php @@ -9,7 +9,7 @@
- +
diff --git a/frontEndSrc/js/anime.js b/frontEndSrc/js/anime.js index f82a496a..9f531bc3 100644 --- a/frontEndSrc/js/anime.js +++ b/frontEndSrc/js/anime.js @@ -1,7 +1,7 @@ import _ from './anime-client.js' import { renderSearchResults } from './template-helpers.js' -const search = (query) => { +const search = (query, isCollection = false) => { // Show the loader _.show('.cssload-loader'); @@ -13,10 +13,11 @@ const search = (query) => { _.hide('.cssload-loader'); // Show the results - _.$('#series-list')[ 0 ].innerHTML = renderSearchResults('anime', searchResults); + _.$('#series-list')[ 0 ].innerHTML = renderSearchResults('anime', searchResults, isCollection); }); }; +// Anime list search if (_.hasElement('.anime #search')) { let prevRequest = null; @@ -34,6 +35,24 @@ if (_.hasElement('.anime #search')) { })); } +// Anime collection search +if (_.hasElement('#search-anime-collection')) { + let prevRequest = null; + + _.on('#search-anime-collection', 'input', _.throttle(250, (e) => { + const query = encodeURIComponent(e.target.value); + if (query === '') { + return; + } + + if (prevRequest !== null) { + prevRequest.abort(); + } + + prevRequest = search(query, true); + })); +} + // Action to increment episode count _.on('body.anime.list', 'click', '.plus-one', (e) => { let parentSel = _.closestParent(e.target, 'article'); diff --git a/frontEndSrc/js/template-helpers.js b/frontEndSrc/js/template-helpers.js index 55c33aa8..e492566f 100644 --- a/frontEndSrc/js/template-helpers.js +++ b/frontEndSrc/js/template-helpers.js @@ -13,10 +13,11 @@ _.on('main', 'change', '.big-check', (e) => { * * @param {'anime'|'manga'} type * @param {Object} item + * @param isCollection * @returns {String} */ -function renderEditLink (type, item) { - if (item.libraryEntry === null) { +function renderEditLink (type, item, isCollection = false) { + if (isCollection || item.libraryEntry === null) { return ''; } @@ -38,13 +39,18 @@ function renderEditLink (type, item) { * * @param {'anime'|'manga'} type * @param {Object} data + * @param {boolean} isCollection * @returns {String} */ -export function renderSearchResults (type, data) { +export function renderSearchResults (type, data, isCollection = false) { return data.map(item => { const titles = item.titles.join('
'); - const disabled = item.libraryEntry !== null ? 'disabled' : ''; - const editLink = renderEditLink(type, item); + let disabled = item.libraryEntry !== null ? 'disabled' : ''; + const editLink = renderEditLink(type, item, isCollection); + + if (isCollection) { + disabled = ''; + } return `