From 1de4580ee75f75ffc7c443faf4799a85a32ee41d Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 8 Oct 2021 12:06:08 -0400 Subject: [PATCH 1/8] Check user library when searching for new media --- src/AnimeClient/API/Kitsu/Model.php | 1 + src/AnimeClient/API/Kitsu/Queries/SearchAnime.graphql | 4 ++++ src/AnimeClient/API/Kitsu/Queries/SearchManga.graphql | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/src/AnimeClient/API/Kitsu/Model.php b/src/AnimeClient/API/Kitsu/Model.php index 60123ab5..ca7befa8 100644 --- a/src/AnimeClient/API/Kitsu/Model.php +++ b/src/AnimeClient/API/Kitsu/Model.php @@ -535,6 +535,7 @@ final class Model { 'slug' => $item['slug'], 'canonicalTitle' => $item['titles']['canonical'], 'titles' => array_values(K::getTitles($item['titles'])), + 'libraryEntry' => $item['myLibraryEntry'], ]; // Search for MAL mapping diff --git a/src/AnimeClient/API/Kitsu/Queries/SearchAnime.graphql b/src/AnimeClient/API/Kitsu/Queries/SearchAnime.graphql index fbe03936..b72aad30 100644 --- a/src/AnimeClient/API/Kitsu/Queries/SearchAnime.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/SearchAnime.graphql @@ -14,6 +14,10 @@ query ($query: String!) { localized alternatives } + myLibraryEntry { + id + status + } } } } \ No newline at end of file diff --git a/src/AnimeClient/API/Kitsu/Queries/SearchManga.graphql b/src/AnimeClient/API/Kitsu/Queries/SearchManga.graphql index 88b9430d..8ad9a6e8 100644 --- a/src/AnimeClient/API/Kitsu/Queries/SearchManga.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/SearchManga.graphql @@ -14,6 +14,10 @@ query ($query: String!) { localized alternatives } + myLibraryEntry { + id + status + } } } } \ No newline at end of file From 52d6cd797aed3756f3c77397d6b4bd819d2921be Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 8 Oct 2021 12:15:34 -0400 Subject: [PATCH 2/8] Refactor media search rendering to be less redundant --- frontEndSrc/css/src/general.css | 8 +++ frontEndSrc/js/anime.js | 4 +- frontEndSrc/js/manga.js | 4 +- frontEndSrc/js/template-helpers.js | 80 ++++++++++++++++-------------- 4 files changed, 54 insertions(+), 42 deletions(-) diff --git a/frontEndSrc/css/src/general.css b/frontEndSrc/css/src/general.css index 29efb1f5..9d00cff3 100644 --- a/frontEndSrc/css/src/general.css +++ b/frontEndSrc/css/src/general.css @@ -628,6 +628,14 @@ picture.cover { background-size: contain; background-repeat: no-repeat; } +/* There are two .name elements, just darken them both in this case! */ +.media.search.disabled .name { + background-color: #000; + background-color: rgba(0, 0, 0, 0.75); + background-size: cover; + background-size: contain; + background-repeat: no-repeat; +} .media.search > .row { z-index: 6; diff --git a/frontEndSrc/js/anime.js b/frontEndSrc/js/anime.js index 77ec194b..f82a496a 100644 --- a/frontEndSrc/js/anime.js +++ b/frontEndSrc/js/anime.js @@ -1,5 +1,5 @@ import _ from './anime-client.js' -import { renderAnimeSearchResults } from './template-helpers.js' +import { renderSearchResults } from './template-helpers.js' const search = (query) => { // Show the loader @@ -13,7 +13,7 @@ const search = (query) => { _.hide('.cssload-loader'); // Show the results - _.$('#series-list')[ 0 ].innerHTML = renderAnimeSearchResults(searchResults); + _.$('#series-list')[ 0 ].innerHTML = renderSearchResults('anime', searchResults); }); }; diff --git a/frontEndSrc/js/manga.js b/frontEndSrc/js/manga.js index 21992d26..d07907bb 100644 --- a/frontEndSrc/js/manga.js +++ b/frontEndSrc/js/manga.js @@ -1,12 +1,12 @@ import _ from './anime-client.js' -import { renderMangaSearchResults } from './template-helpers.js' +import { renderSearchResults } from './template-helpers.js' const search = (query) => { _.show('.cssload-loader'); return _.get(_.url('/manga/search'), { query }, (searchResults, status) => { searchResults = JSON.parse(searchResults); _.hide('.cssload-loader'); - _.$('#series-list')[ 0 ].innerHTML = renderMangaSearchResults(searchResults); + _.$('#series-list')[ 0 ].innerHTML = renderSearchResults('manga', searchResults); }); }; diff --git a/frontEndSrc/js/template-helpers.js b/frontEndSrc/js/template-helpers.js index 33bdeb5c..55c33aa8 100644 --- a/frontEndSrc/js/template-helpers.js +++ b/frontEndSrc/js/template-helpers.js @@ -7,52 +7,55 @@ _.on('main', 'change', '.big-check', (e) => { document.getElementById(`mal_${id}`).checked = true; }); -export function renderAnimeSearchResults (data) { - return data.map(item => { - const titles = item.titles.join('
'); +/** + * 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 ''; + } - return ` - - `; - }).join(''); + return ` +
+ [ Already in List ] +
+
+ + Edit + +
+
 
+ ` } -export function renderMangaSearchResults (data) { +/** + * Show the search results for a media item + * + * @param {'anime'|'manga'} type + * @param {Object} data + * @returns {String} + */ +export function renderSearchResults (type, data) { return data.map(item => { const titles = item.titles.join('
'); + const disabled = item.libraryEntry !== null ? 'disabled' : ''; + const editLink = renderEditLink(type, item); + return ` -