From be16ceecb29e02977f671b7a8919b8cb2f672863 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 12 Dec 2018 15:31:59 -0500 Subject: [PATCH] Make syncing slightly more robust --- app/views/collection/list-item.php | 2 +- public/css/dark-override.css | 18 ++++++++++++++++++ public/css/dark.min.css | 2 +- .../Transformer/AnimeListTransformer.php | 11 ++++++++--- src/Command/SyncLists.php | 16 +++++++++++++--- src/Controller/AnimeCollection.php | 2 +- 6 files changed, 42 insertions(+), 9 deletions(-) diff --git a/app/views/collection/list-item.php b/app/views/collection/list-item.php index 94473545..1c758dca 100644 --- a/app/views/collection/list-item.php +++ b/app/views/collection/list-item.php @@ -9,7 +9,7 @@ - " . $item['alternate_title'] . "" : "" ?> + ' . $item['alternate_title'] . '' : '' ?> diff --git a/public/css/dark-override.css b/public/css/dark-override.css index 5c4e6355..744fc3e3 100644 --- a/public/css/dark-override.css +++ b/public/css/dark-override.css @@ -1,5 +1,6 @@ a { color: rgb(25, 120, 226); + text-shadow: var(--link-shadow); } a:hover { @@ -55,6 +56,23 @@ input, select, textarea { color: #111; } +.message, .static-message { + text-shadow: var(--white-link-shadow); +} + +.message.success, .static-message.success { + background: #1f8454; + border-color: #70dda9; +} +.message.error, .static-message.error { + border-color:#f3e6e6; + background: #924949; +} +.message.info, .static-message.info { + border-color: #FFFFCC; + background: #bfbe3a; +} + .invisible tr, .invisible td, .invisible th, diff --git a/public/css/dark.min.css b/public/css/dark.min.css index dafafb74..acfd102f 100644 --- a/public/css/dark.min.css +++ b/public/css/dark.min.css @@ -1 +1 @@ -a{color:#1978e2}a:hover{color:#9e34fd}body,legend,nav ul li a{background:#333;color:#eee}nav a:hover,nav li.selected a{border-color:#fff}header button{background:transparent}table{-webkit-box-shadow:none;box-shadow:none}td,th{border-color:#111}thead td,thead th{background:#333;color:#eee}tbody>tr:nth-child(2n){background:#555;color:#eee}tbody>tr:nth-child(odd){background:#333}footer,hr,legend{border-color:#ddd}small{color:#fff}input,select,textarea{color:#111}.invisible tbody>tr:nth-child(2n),.invisible tbody>tr:nth-child(odd),.invisible td,.invisible th,.invisible tr{background:transparent}#main-nav{border-bottom:.1rem solid #ddd}.tabs,.vertical-tabs{background:#333}.tabs>label,.vertical-tabs .tab label{background:#222;border:0;color:#eee}.vertical-tabs .tab label{width:100%}.tabs>label:hover,.vertical-tabs .tab>label:hover{background:#888}.tabs>label:active,.vertical-tabs .tab>label:active{background:#999}.tabs>[type=radio]:checked+label,.tabs>[type=radio]:checked+label+.content,.vertical-tabs [type=radio]:checked+label,.vertical-tabs [type=radio]:checked~.content{border:0;background:#666;color:#eee}.vertical-tabs{background:#222;border:1px solid #444}.vertical-tabs .tab{background:#666;border-bottom:1px solid #444} \ No newline at end of file +a{color:#1978e2;text-shadow:var(--link-shadow)}a:hover{color:#9e34fd}body,legend,nav ul li a{background:#333;color:#eee}nav a:hover,nav li.selected a{border-color:#fff}header button{background:transparent}table{-webkit-box-shadow:none;box-shadow:none}td,th{border-color:#111}thead td,thead th{background:#333;color:#eee}tbody>tr:nth-child(2n){background:#555;color:#eee}tbody>tr:nth-child(odd){background:#333}footer,hr,legend{border-color:#ddd}small{color:#fff}input,select,textarea{color:#111}.message,.static-message{text-shadow:var(--white-link-shadow)}.message.success,.static-message.success{background:#1f8454;border-color:#70dda9}.message.error,.static-message.error{border-color:#f3e6e6;background:#924949}.message.info,.static-message.info{border-color:#ffc;background:#bfbe3a}.invisible tbody>tr:nth-child(2n),.invisible tbody>tr:nth-child(odd),.invisible td,.invisible th,.invisible tr{background:transparent}#main-nav{border-bottom:.1rem solid #ddd}.tabs,.vertical-tabs{background:#333}.tabs>label,.vertical-tabs .tab label{background:#222;border:0;color:#eee}.vertical-tabs .tab label{width:100%}.tabs>label:hover,.vertical-tabs .tab>label:hover{background:#888}.tabs>label:active,.vertical-tabs .tab>label:active{background:#999}.tabs>[type=radio]:checked+label,.tabs>[type=radio]:checked+label+.content,.vertical-tabs [type=radio]:checked+label,.vertical-tabs [type=radio]:checked~.content{border:0;background:#666;color:#eee}.vertical-tabs{background:#222;border:1px solid #444}.vertical-tabs .tab{background:#666;border-bottom:1px solid #444} \ No newline at end of file diff --git a/src/API/Anilist/Transformer/AnimeListTransformer.php b/src/API/Anilist/Transformer/AnimeListTransformer.php index fe98bcd1..4059a47e 100644 --- a/src/API/Anilist/Transformer/AnimeListTransformer.php +++ b/src/API/Anilist/Transformer/AnimeListTransformer.php @@ -17,6 +17,7 @@ namespace Aviat\AnimeClient\API\Anilist\Transformer; use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\Anilist as AnilistStatus; +use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\Kitsu as KitsuStatus; use Aviat\AnimeClient\API\Mapping\AnimeWatchingStatus; use Aviat\AnimeClient\Types\{AnimeListItem, FormItem}; @@ -39,6 +40,8 @@ class AnimeListTransformer extends AbstractTransformer { */ public function untransform(array $item): FormItem { + $reconsuming = $item['status'] === AnilistStatus::REPEATING; + return new FormItem([ 'id' => $item['id'], 'mal_id' => $item['media']['idMal'], @@ -46,10 +49,12 @@ class AnimeListTransformer extends AbstractTransformer { 'notes' => $item['notes'] ?? '', 'private' => $item['private'], 'progress' => $item['progress'], - 'rating' => $item['score'], + 'rating' => $item['score'] ?? NULL, 'reconsumeCount' => $item['repeat'], - 'reconsuming' => $item['status'] === AnilistStatus::REPEATING, - 'status' => AnimeWatchingStatus::ANILIST_TO_KITSU[$item['status']], + 'reconsuming' => $reconsuming, + 'status' => $reconsuming + ? KitsuStatus::WATCHING + :AnimeWatchingStatus::ANILIST_TO_KITSU[$item['status']], 'updatedAt' => (new DateTime()) ->setTimestamp($item['updatedAt']) ->format(DateTime::W3C) diff --git a/src/Command/SyncLists.php b/src/Command/SyncLists.php index 7da84115..c1917cd1 100644 --- a/src/Command/SyncLists.php +++ b/src/Command/SyncLists.php @@ -268,7 +268,7 @@ final class SyncLists extends BaseCommand { { continue; } - + if (array_key_exists($mappingId, $includes['mappings'])) { $malId = $includes['mappings'][$mappingId]['externalId']; @@ -510,12 +510,16 @@ final class SyncLists extends BaseCommand { // Use the first set rating, otherwise use the newer rating if ( ! $sameRating) { - if ($kitsuItem['data']['rating'] !== 0 && $dateDiff === 1) + if ( + $dateDiff === 1 && + $kitsuItem['data']['rating'] !== 0 && + $kitsuItem['data']['ratingTwenty'] !== 0 + ) { $update['data']['ratingTwenty'] = $kitsuItem['data']['ratingTwenty']; $return['updateType'][] = 'anilist'; } - else if($dateDiff === -1) + else if($dateDiff === -1 && $anilistItem['data']['rating'] !== 0) { $update['data']['ratingTwenty'] = $anilistItem['data']['rating'] * 2; $return['updateType'][] = 'kitsu'; @@ -552,6 +556,12 @@ final class SyncLists extends BaseCommand { } } + // No changes? Let's bail! + if (empty($return['updateType'])) + { + return $return; + } + $return['meta'] = [ 'kitsu' => $kitsuItem['data'], 'anilist' => $anilistItem['data'], diff --git a/src/Controller/AnimeCollection.php b/src/Controller/AnimeCollection.php index f637c16f..cdb3e487 100644 --- a/src/Controller/AnimeCollection.php +++ b/src/Controller/AnimeCollection.php @@ -137,7 +137,7 @@ final class AnimeCollection extends BaseController { * @throws \InvalidArgumentException * @return void */ - public function edit() + public function edit(): void { $data = $this->request->getParsedBody(); if (array_key_exists('hummingbird_id', $data))