Fix some bugs with history view
timw4mail/HummingBirdAnimeClient/pipeline/head This commit looks good Details

This commit is contained in:
Timothy Warren 2020-04-24 14:14:52 -04:00
parent ae276a536f
commit badf941265
6 changed files with 72 additions and 18 deletions

View File

@ -151,6 +151,11 @@ final class ListItem extends AbstractListItem {
]
];
if (((int) $data->progress) === 0)
{
$data->progress = 0;
}
$request = $this->requestBuilder->newRequest('PATCH', "library-entries/{$id}")
->setJsonBody($requestData);

View File

@ -186,7 +186,6 @@ final class Model {
{
$raw = $this->getRawHistoryList('anime');
$organized = JsonAPI::organizeData($raw);
$organized = array_filter($organized, fn ($item) => array_key_exists('relationships', $item));
return (new AnimeHistoryTransformer())->transform($organized);
@ -203,7 +202,6 @@ final class Model {
{
$raw = $this->getRawHistoryList('manga');
$organized = JsonAPI::organizeData($raw);
$organized = array_filter($organized, fn ($item) => array_key_exists('relationships', $item));
return (new MangaHistoryTransformer())->transform($organized);
@ -1034,11 +1032,13 @@ final class Model {
'offset' => $offset,
'limit' => $limit,
],
'fields' => ($type === 'anime')
? ['anime' => 'canonicalTitle,titles,slug,posterImage']
: ['manga' => 'canonicalTitle,titles,slug,posterImage'],
'fields' => [
'anime' => 'canonicalTitle,titles,slug,posterImage',
'manga' => 'canonicalTitle,titles,slug,posterImage',
'libraryEntry' => 'reconsuming,reconsumeCount',
],
'sort' => '-updated_at',
'include' => $type,
'include' => 'anime,manga,libraryEntry',
],
]);
}

View File

@ -23,9 +23,11 @@ class AnimeHistoryTransformer extends HistoryTransformer {
protected string $progressAction = 'Watched episode';
protected string $smallAggregateAction = 'Watched episodes';
protected string $reconsumeAction = 'Rewatched episode';
protected string $largeAggregateAction = 'Marathoned episodes';
protected string $reconsumingStatus = 'Rewatching';
protected array $statusMap = AnimeWatchingStatus::KITSU_TO_TITLE;
}

View File

@ -33,15 +33,20 @@ abstract class HistoryTransformer {
protected string $progressAction;
/**
* @var string The message for going though a small number of media in a series
* @var string The message for rewatching/rereading episode(s)/chapter(s)
*/
protected string $smallAggregateAction;
protected string $reconsumeAction;
/**
* @var string The message for going through a large number of media in a series
*/
protected string $largeAggregateAction;
/**
* @var string The status for items you are rewatching/rereading
*/
protected string $reconsumingStatus;
/**
* @var array The mapping of api status to display status
*/
@ -121,7 +126,8 @@ abstract class HistoryTransformer {
foreach ($entries as $e)
{
$items[] = max($e['original']['attributes']['changedData']['progress']);
$progressItem = $e['original']['attributes']['changedData']['progress'];
$items[] = array_pop($progressItem);
$updated[] = $e['updated'];
}
$firstItem = min($items);
@ -131,15 +137,23 @@ abstract class HistoryTransformer {
$title = $entries[0]['title'];
$action = (count($entries) > 3)
? "{$this->largeAggregateAction} {$firstItem}-{$lastItem}"
: "{$this->smallAggregateAction} {$firstItem}-{$lastItem}";
if ($this->isReconsuming($entries[0]['original']))
{
$action = "{$this->reconsumeAction}s {$firstItem}-{$lastItem}";
}
else
{
$action = (count($entries) > 3)
? "{$this->largeAggregateAction} {$firstItem}-{$lastItem}"
: "{$this->progressAction}s {$firstItem}-{$lastItem}";
}
$output[] = HistoryItem::from([
'action' => $action,
'coverImg' => $entries[0]['coverImg'],
'dateRange' => [$firstUpdate, $lastUpdate],
'isAggregate' => true,
'original' => $entries,
'title' => $title,
'updated' => $entries[0]['updated'],
'url' => $entries[0]['url'],
@ -162,10 +176,14 @@ abstract class HistoryTransformer {
$data = $entry['relationships'][$this->type][$id]['attributes'];
$title = $this->linkTitle($data);
$imgUrl = "images/{$this->type}/{$id}.webp";
$item = array_pop($entry['attributes']['changedData']['progress']);
$item = end($entry['attributes']['changedData']['progress']);
$action = ($this->isReconsuming($entry))
? "{$this->reconsumeAction} {$item}"
: "{$this->progressAction} {$item}";
return HistoryItem::from([
'action' => "{$this->progressAction} {$item}",
'action' => $action,
'coverImg' => $imgUrl,
'kind' => 'progressed',
'original' => $entry,
@ -189,6 +207,13 @@ abstract class HistoryTransformer {
$status = array_pop($entry['attributes']['changedData']['status']);
$statusName = $this->statusMap[$status];
if ($this->isReconsuming($entry))
{
$statusName = ($statusName === 'Completed')
? "Finished {$this->reconsumingStatus}"
: $this->reconsumingStatus;
}
return HistoryItem::from([
'action' => $statusName,
'coverImg' => $imgUrl,
@ -222,4 +247,23 @@ abstract class HistoryTransformer {
{
return "/{$this->type}/details/{$data['slug']}";
}
protected function isReconsuming ($entry): bool
{
$le = $this->getLibraryEntry($entry);
return $le['reconsuming'];
}
private function getLibraryEntry ($entry): ?array
{
if ( ! isset($entry['relationships']['libraryEntry']['libraryEntries']))
{
return NULL;
}
$libraryEntries = $entry['relationships']['libraryEntry']['libraryEntries'];
$id = array_keys($libraryEntries)[0];
return $libraryEntries[$id]['attributes'];
}
}

View File

@ -23,9 +23,11 @@ class MangaHistoryTransformer extends HistoryTransformer {
protected string $progressAction = 'Read chapter';
protected string $smallAggregateAction = 'Read chapters';
protected string $reconsumeAction = 'Reread chapter';
protected string $largeAggregateAction = 'Blew through chapters';
protected string $reconsumingStatus = 'Rereading';
protected array $statusMap = MangaReadingStatus::KITSU_TO_TITLE;
}

View File

@ -20,6 +20,7 @@ use Aura\Html\HelperLocator;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
use const EXTR_OVERWRITE;
/**
* View class for outputting HTML
@ -67,13 +68,13 @@ class HtmlView extends HttpView {
$data['container'] = $this->container;
ob_start();
extract($data, \EXTR_OVERWRITE);
extract($data, EXTR_OVERWRITE);
include_once $path;
$buffer = ob_get_clean();
// Very basic html minify, that won't affect content between html tags
// $buffer = preg_replace('/>\s+</', '> <', $buffer);
$buffer = preg_replace('/>\s+</', '> <', $buffer);
return $buffer;
}