Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(card)!: modernize game and hub tooltips #1700

Merged
merged 25 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7bbb3d1
feat: modernize game and hub tooltips
wescopeland Jul 29, 2023
9bde1d8
chore: fix test
wescopeland Jul 29, 2023
64c01de
docs: write a lot of words
wescopeland Jul 29, 2023
06e7c56
chore: lint
wescopeland Jul 29, 2023
4f9d29c
chore: more fixes
wescopeland Jul 29, 2023
0ed1f60
chore: update test
wescopeland Jul 29, 2023
fb09c51
chore: attempt to fix ci
wescopeland Jul 29, 2023
0ba4a16
Merge branch 'master' into game-hub-tooltips-02
wescopeland Jul 29, 2023
504938a
fix: address pr feedback
wescopeland Jul 29, 2023
51da9a9
chore: lint
wescopeland Jul 29, 2023
a2da137
fix: address pr feedback
wescopeland Jul 30, 2023
fc8ac91
Merge branch 'master' into game-hub-tooltips-02
wescopeland Jul 30, 2023
59f3825
fix: address pr feedback
wescopeland Jul 30, 2023
503bff6
fix: address pr feedback
wescopeland Jul 31, 2023
17be3ac
fix: address pr feedback
wescopeland Jul 31, 2023
386b027
fix: address pr feedback
wescopeland Jul 31, 2023
d115632
chore: lint
wescopeland Jul 31, 2023
ef4980e
Merge branch 'master' into game-hub-tooltips-02
wescopeland Jul 31, 2023
1d529d2
chore: commit excluded change
wescopeland Jul 31, 2023
30dfa60
Merge branch 'game-hub-tooltips-02' of https://github.com/wescopeland…
wescopeland Jul 31, 2023
f907dd2
Merge branch 'master' into game-hub-tooltips-02
wescopeland Jul 31, 2023
468f7e3
Merge branch 'master' into game-hub-tooltips-02
wescopeland Aug 8, 2023
7db0c44
chore: lint
wescopeland Aug 8, 2023
da6b5b3
Merge branch 'master' into game-hub-tooltips-02
wescopeland Aug 10, 2023
449e556
chore: fix merge conflicts
wescopeland Aug 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/Community/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Community\Commands\SyncTickets;
use App\Community\Commands\SyncUserRelations;
use App\Community\Commands\SyncVotes;
use App\Community\Components\UserCard;
use App\Community\Models\AchievementComment;
use App\Community\Models\AchievementSetClaim;
use App\Community\Models\Comment;
Expand All @@ -36,6 +37,7 @@
use App\Community\Models\UserRelation;
use App\Community\Models\Vote;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
Expand Down Expand Up @@ -98,6 +100,8 @@ public function boot(): void
TriggerTicketComment::disableSearchSyncing();
UserComment::disableSearchSyncing();

Blade::component('user-card', UserCard::class);

// Livewire::component('forum-topics', ForumTopics::class);
//
// Livewire::component('achievement.comments', AchievementComments::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace App\View\Components\Community;
namespace App\Community\Components;

use App\Community\Enums\Rank;
use App\Community\Enums\RankType;
use App\Site\Enums\Permissions;
use App\Site\Models\User as UserModel;
use App\Site\Models\User;
use App\Support\Cache\CacheKey;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Carbon;
Expand Down Expand Up @@ -55,11 +55,10 @@ private function getUsername(string|array $user): ?string

private function getUserData(string $username): ?array
{
return Cache::store('array')->remember(
return Cache::store('array')->rememberForever(
CacheKey::buildUserCardDataCacheKey($username),
Carbon::now()->addMonths(3),
function () use ($username): ?array {
$foundUser = UserModel::firstWhere('User', $username);
$foundUser = User::firstWhere('User', $username);

return $foundUser ? $foundUser->toArray() : null;
}
Expand Down
52 changes: 9 additions & 43 deletions app/Helpers/render/game.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

use App\Site\Enums\Permissions;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Cache;

function gameAvatar(
int|string|array $game,
?bool $label = null,
bool|string|null $icon = null,
int $iconSize = 32,
string $iconClass = 'badgeimg',
bool|string|array $tooltip = true,
bool $tooltip = true,
?string $context = null,
?string $title = null,
): string {
Expand All @@ -36,19 +35,14 @@ function gameAvatar(
if ($icon === null) {
$icon = media_asset($game['GameIcon'] ?? $game['ImageIcon']);
}

// pre-render tooltip
if (!is_string($tooltip)) {
$tooltip = $tooltip !== false ? $game : false;
}
}

return avatar(
resource: 'game',
id: $id,
label: $label !== false && ($label || !$icon) ? $label : null,
link: route('game.show', $id),
tooltip: is_array($tooltip) ? renderGameCard($tooltip) : $tooltip,
tooltip: $tooltip,
iconUrl: $icon !== false && ($icon || !$label) ? $icon : null,
iconSize: $iconSize,
iconClass: $iconClass,
Expand Down Expand Up @@ -163,46 +157,18 @@ function renderGameBreadcrumb(array|int $data, bool $addLinkToLastCrumb = true):
return $html;
}

function renderGameCard(int|array $game): string
function renderGameCard(int|array $game, ?string $targetUsername): string
{
$id = is_int($game) ? $game : ($game['GameID'] ?? $game['ID'] ?? null);
$gameId = is_int($game) ? $game : ($game['GameID'] ?? $game['ID'] ?? null);

if (empty($id)) {
if (empty($gameId)) {
return __('legacy.error.error');
}

$data = [];
if (is_array($game)) {
$data = $game;
}

if (empty($data)) {
$data = Cache::store('array')->rememberForever('game:' . $id . ':card-data', fn () => getGameData($id));
}

if (empty($data)) {
return '';
}

$gameName = renderGameTitle($data['GameTitle'] ?? $data['Title'] ?? '');
$consoleName = $data['Console'] ?? $data['ConsoleName'] ?? '';
$icon = $data['GameIcon'] ?? $data['ImageIcon'] ?? null;

$tooltip = "<div class='tooltip-body flex items-start' style='max-width: 400px'>";
$tooltip .= "<img style='margin-right:5px' src='" . media_asset($icon) . "' width='64' height='64' />";
$tooltip .= "<div>";
$tooltip .= "<b>$gameName</b><br>";
$tooltip .= $consoleName;

$mastery = $game['Mastery'] ?? null;
if (!empty($mastery)) {
$tooltip .= "<div>$mastery</div>";
}

$tooltip .= "</div>";
$tooltip .= "</div>";

return $tooltip;
return Blade::render('<x-game-card :gameId="$gameId" :targetUsername="$targetUsername" />', [
'gameId' => $gameId,
'targetUsername' => $targetUsername,
]);
}

function RenderGameSort(bool $isFullyFeaturedGame, ?int $flag, int $officialFlag, int $gameID, ?int $sortBy): void
Expand Down
12 changes: 6 additions & 6 deletions app/Helpers/render/site-award.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function SeparateAwards(array $userAwards): array
return [$gameAwards, $eventAwards, $siteAwards];
}

function RenderSiteAwards(array $userAwards): void
function RenderSiteAwards(array $userAwards, string $awardsOwnerUsername): void
{
[$gameAwards, $eventAwards, $siteAwards] = SeparateAwards($userAwards);

Expand Down Expand Up @@ -75,11 +75,11 @@ function RenderSiteAwards(array $userAwards): void
usort($groups, fn ($a, $b) => $a[0] - $b[0]);

foreach ($groups as $group) {
RenderAwardGroup($group[1], $group[2]);
RenderAwardGroup($group[1], $group[2], $awardsOwnerUsername);
}
}

function RenderAwardGroup(array $awards, string $title): void
function RenderAwardGroup(array $awards, string $title, string $awardsOwnerUsername): void
{
$numItems = count($awards);
$numHidden = 0;
Expand Down Expand Up @@ -139,7 +139,7 @@ function RenderAwardGroup(array $awards, string $title): void
$imageSize = 48;
foreach ($awards as $award) {
if ($award['DisplayOrder'] >= 0) {
RenderAward($award, $imageSize);
RenderAward($award, $imageSize, $awardsOwnerUsername);
}
}
echo "</div>";
Expand All @@ -160,7 +160,7 @@ function RenderCounter(string $icon, string $text, int $numItems, int $numHidden
return $counter;
}

function RenderAward(array $award, int $imageSize, bool $clickable = true): void
function RenderAward(array $award, int $imageSize, string $ownerUsername, bool $clickable = true): void
{
$awardType = $award['AwardType'];
$awardType = (int) $awardType;
Expand All @@ -186,7 +186,7 @@ function RenderAward(array $award, int $imageSize, bool $clickable = true): void
$award['GameID'] = $award['AwardData'];
$award['Mastery'] = "<br clear=all>$awarded";

echo "<div>" . gameAvatar($award, label: false, iconSize: $imageSize, context: 'mastery', iconClass: $imgclass) . "</div>";
echo "<div>" . gameAvatar($award, label: false, iconSize: $imageSize, context: $ownerUsername, iconClass: $imgclass) . "</div>";

return;
}
Expand Down
13 changes: 8 additions & 5 deletions app/Helpers/render/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class: 'inline whitespace-nowrap',

function renderUserCard(string|array $user): string
{
return Blade::render('<x-community.user-card :user="$user" />', [
return Blade::render('<x-user-card :user="$user" />', [
'user' => $user,
]);
}
Expand All @@ -90,8 +90,11 @@ function getCompletedAndIncompletedSetsCounts(array $userCompletedGamesList): ar
return ['completedSetsCount' => $completedSetsCount, 'incompletedSetsCount' => $incompletedSetsCount];
}

function RenderCompletedGamesList(array $userCompletedGamesList, bool $isInitiallyHidingCompletedSets = false): void
{
function RenderCompletedGamesList(
array $userCompletedGamesList,
string $username,
bool $isInitiallyHidingCompletedSets = false,
): void {
echo "<div id='completedgames' class='component' >";

echo "<h3>Completion Progress</h3>";
Expand Down Expand Up @@ -143,10 +146,10 @@ function RenderCompletedGamesList(array $userCompletedGamesList, bool $isInitial
echo "<tr class='$isCompletedClassName'>";

echo "<td>";
echo gameAvatar($userCompletedGamesList[$i], label: false);
echo gameAvatar($userCompletedGamesList[$i], label: false, context: $username);
echo "</td>";
echo "<td class='smaller'>";
echo gameAvatar($userCompletedGamesList[$i], icon: false);
echo gameAvatar($userCompletedGamesList[$i], icon: false, context: $username);
echo "</td>";
echo "<td>";

Expand Down
4 changes: 4 additions & 0 deletions app/Platform/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use App\Platform\Commands\UpdatePlayerMetrics;
use App\Platform\Commands\UpdatePlayerPoints;
use App\Platform\Commands\UpdatePlayerRanks;
use App\Platform\Components\GameCard;
use App\Platform\Models\Achievement;
use App\Platform\Models\Badge;
use App\Platform\Models\BadgeStage;
Expand All @@ -53,6 +54,7 @@
use App\Platform\Models\System;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
Expand Down Expand Up @@ -153,6 +155,8 @@ public function boot(): void
Leaderboard::disableSearchSyncing();
System::disableSearchSyncing();

Blade::component('game-card', GameCard::class);

// Livewire::component('achievement-grid', AchievementGrid::class);
// Livewire::component('achievement-player-grid', AchievementPlayerGrid::class);
// Livewire::component('badge-grid', BadgeGrid::class);
Expand Down
Loading
Loading