Skip to content

Commit

Permalink
fix: address pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
wescopeland committed Jul 29, 2023
1 parent 0ba4a16 commit 504938a
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 35 deletions.
35 changes: 23 additions & 12 deletions app/View/Components/Platform/Cards/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Game extends Component
{
private int $gameId;
private int $hubConsoleId = 100;
private int $eventConsoleId = 101;
private array $userGameProgressionAwards;
private ?string $usernameContext;

Expand Down Expand Up @@ -193,36 +194,41 @@ private function buildAllCardViewValues(array $rawGameData, array $userGameProgr
$consoleName = $rawGameData['ConsoleName'];
$achievementsCount = count($rawGameData['Achievements']);
$isHub = $rawGameData['ConsoleID'] === $this->hubConsoleId;
$isEvent = $rawGameData['ConsoleID'] === $this->eventConsoleId;
$altGamesCount = count($rawGameData['AltGames']);

[$pointsSum, $retroPointsSum, $retroRatio, $lastUpdated] = $this->buildCardAchievementsData(
$rawGameData['Achievements'],
$rawGameData['Updated'],
);

[$highestProgressionStatus, $highestProgressionAwardDate] = $this->buildCardUserProgressionData($userGameProgressionAwards);
[$highestProgressionStatus, $highestProgressionAwardDate] = $this->buildCardUserProgressionData(
$userGameProgressionAwards,
$isEvent,
);

$activeClaims = array_filter($rawGameData['Claims'], fn ($claim) => $claim['Status'] == ClaimStatus::Active);
$activeDeveloperUsernames = array_map(fn ($activeClaim) => $activeClaim['User'], array_values($activeClaims));
$activeDevelopersLabel = $this->buildActiveDevelopersLabel($activeDeveloperUsernames);

return compact(
'isHub',
'achievementsCount',
'activeDevelopersLabel',
'activeDeveloperUsernames',
'altGamesCount',
'rawTitle',
'renderedTitle',
'badgeUrl',
'gameSystemIconSrc',
'consoleName',
'achievementsCount',
'gameSystemIconSrc',
'highestProgressionAwardDate',
'highestProgressionStatus',
'isEvent',
'isHub',
'lastUpdated',
'pointsSum',
'rawTitle',
'renderedTitle',
'retroPointsSum',
'retroRatio',
'lastUpdated',
'highestProgressionStatus',
'highestProgressionAwardDate',
'activeDeveloperUsernames',
'activeDevelopersLabel',
);
}

Expand Down Expand Up @@ -270,10 +276,11 @@ private function buildCardAchievementsData(array $rawAchievements, string $gameL
* If neither "Mastered" nor "Completed" are present, both the status and award date are returned as null.
*
* @param array $userGameProgressionAwards an array of user's game progression awards
* @param bool $isEvent whether or not the game ID is associated with an event
*
* @return array an array containing the highest progression status and corresponding award date
*/
private function buildCardUserProgressionData(array $userGameProgressionAwards): array
private function buildCardUserProgressionData(array $userGameProgressionAwards, bool $isEvent): array
{
$highestProgressionStatus = null;
$highestProgressionAwardDate = null;
Expand All @@ -288,6 +295,10 @@ private function buildCardUserProgressionData(array $userGameProgressionAwards):
$highestProgressionAwardDate = Carbon::parse($userGameProgressionAwards['Mastered']['AwardDate']);
}

if ($isEvent && $highestProgressionStatus !== null) {
$highestProgressionStatus = 'Awarded';
}

return [$highestProgressionStatus, $highestProgressionAwardDate];
}
}
1 change: 1 addition & 0 deletions public/test/cards.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
</div>
<div class="flex w-full justify-between mb-2">
<?= Blade::render('<x-platform.cards.game gameId="586" />') ?>
<?= Blade::render('<x-platform.cards.game gameId="22561" />') ?>
</div>
</div>

Expand Down
51 changes: 28 additions & 23 deletions resources/views/platform/components/cards/game.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
<!-- Progression Status -->
@if ($highestProgressionStatus && $highestProgressionAwardDate)
<div class="my-1 flex items-center gap-x-1">
<div class="rounded-full w-2 h-2" style="background-color: {{ $highestProgressionColor }}"></div>
@if (!$isEvent)
<div class="rounded-full w-2 h-2" style="background-color: {{ $highestProgressionColor }}"></div>
@endif

<span>{{ $highestProgressionStatus }} {{ $highestProgressionAwardDate->format('j F Y') }}</span>
</div>
@else
Expand All @@ -35,31 +38,33 @@
@endif

@if ($achievementsCount > 0)
<!-- Achievement Count -->
<x-card.info-row label="Achievements">
{{ localized_number($achievementsCount) }}
</x-card.info-row>

@if ($pointsSum > 0)
<!-- Points Sum -->
<x-card.info-row label="Points">
{{ localized_number($pointsSum) }}
<span @if ($retroPointsSum === 0) class="text-text-muted" @endif>
({{ localized_number($retroPointsSum) }})
</span>
@if (!$isEvent)
<!-- Achievement Count -->
<x-card.info-row label="Achievements">
{{ localized_number($achievementsCount) }}
</x-card.info-row>

<!-- Retro Ratio -->
<x-card.info-row label="Retro Ratio">
{{ $retroRatio == 0 ? 'None yet' : $retroRatio }}
</x-card.info-row>
@endif
@if ($pointsSum > 0)
<!-- Points Sum -->
<x-card.info-row label="Points">
{{ localized_number($pointsSum) }}
<span @if ($retroPointsSum === 0) class="text-text-muted" @endif>
({{ localized_number($retroPointsSum) }})
</span>
</x-card.info-row>

<!-- Last Updated -->
@if (!$highestProgressionStatus && !$highestProgressionAwardDate)
<x-card.info-row label="Last Updated">
{{ $lastUpdated->format('j F Y') }}
</x-card.info-row>
<!-- Retro Ratio -->
<x-card.info-row label="Retro Ratio">
{{ $retroRatio == 0 ? 'None yet' : $retroRatio }}
</x-card.info-row>
@endif

<!-- Last Updated -->
@if (!$highestProgressionStatus && !$highestProgressionAwardDate)
<x-card.info-row label="Last Updated">
{{ $lastUpdated->format('j F Y') }}
</x-card.info-row>
@endif
@endif

<!-- Revision Notice -->
Expand Down
34 changes: 34 additions & 0 deletions tests/Feature/Platform/GameCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,38 @@ public function testItRendersMasteries(): void
// Assert
$view->assertSeeText('Mastered 2 July 2015');
}

public function testItRendersEvents(): void
{
// Arrange
/** @var User $user */
$user = User::factory()->create(['User' => 'AAA']);
/** @var System $system */
$system = System::factory()->create(['ID' => 101, 'Name' => 'Events']);
/** @var Game $game */
$game = Game::factory()->create(['ID' => 1, 'ConsoleID' => $system->ID]);
Achievement::factory()->published()->count(6)->create(['GameID' => $game->ID, 'Points' => 5]);

$awardDate = '2015-07-02 16:44:46';
PlayerBadge::factory()->create([
'User' => $user->User,
'AwardType' => AwardType::Mastery,
'AwardData' => $game->ID,
'AwardDataExtra' => 1,
'AwardDate' => $awardDate,
'DisplayOrder' => 0,
]);

// Act
$view = $this->blade('<x-platform.cards.game gameId="1" targetUsername="AAA" />');

// Assert
$view->assertDontSeeText('Achievements');
$view->assertDontSeeText('Points');
$view->assertDontSeeText('Last Updated');
$view->assertDontSeeText('Mastered');

$view->assertSeeText('Events');
$view->assertSeeText('Awarded 2 July 2015');
}
}

0 comments on commit 504938a

Please sign in to comment.