Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions app/Devnull/Data/Badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public static function fromArray(array $data): self
);
}

/**
* The picture the web draws in place of the badge's icon: the pastel de nata for Sweet Tooth. Null for the rest.
*/
public function image(): ?string
{
return $this->icon === 'pastel-de-nata' ? Pasteis::Image : null;
}

/**
* The web only counts progress on a locked badge that takes more than one step: "(3/10)".
*/
Expand Down
10 changes: 7 additions & 3 deletions app/Icons/Lucide.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ enum Lucide
case GitMerge;
case Maximize;
case Key;
case Cookie;
case BotOff;
case Bomb;
/** Lucide has no dragon ball, so this is the web's own drawing, from its dragon-ball-icon.tsx. */
case DragonBall;
/** Lucide has no mushroom cloud either, so this is the web's mushroom-cloud-icon.tsx. */
case MushroomCloud;
case GitCommitHorizontal;
case PinOff;
case BellOff;
case LogOut;
Expand Down Expand Up @@ -150,10 +152,11 @@ public static function forBadge(string $icon): self
'git-merge' => self::GitMerge,
'maximize' => self::Maximize,
'key' => self::Key,
'cookie' => self::Cookie,
'bot-off' => self::BotOff,
'bomb' => self::Bomb,
'dragon-ball' => self::DragonBall,
'mushroom-cloud' => self::MushroomCloud,
'git-commit-horizontal' => self::GitCommitHorizontal,
default => self::Terminal,
};
}
Expand Down Expand Up @@ -232,10 +235,11 @@ public function custom(bool $filled = false): string
self::GitMerge => 'git-merge',
self::Maximize => 'maximize',
self::Key => 'key',
self::Cookie => 'cookie',
self::BotOff => 'bot-off',
self::Bomb => 'bomb',
self::DragonBall => 'dragon-ball',
self::MushroomCloud => 'mushroom-cloud',
self::GitCommitHorizontal => 'git-commit-horizontal',
self::Pin => $filled ? 'pin-filled' : 'pin',
self::PinOff => 'pin-off',
self::BellOff => 'bell-off',
Expand Down
1 change: 0 additions & 1 deletion resources/icons/cookie.svg

This file was deleted.

1 change: 1 addition & 0 deletions resources/icons/git-commit-horizontal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/icons/mushroom-cloud.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion resources/views/native/partials/achievements-sheet.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@
<native:column ref="sheet-badge-{{ $badge->id }}" class="w-full p-3 gap-[6] rounded-lg {{ $index === $markedIndex ? 'border-2 border-theme-'.\App\Devnull\Lane::token($lane) : 'border border-theme-hairline' }} {{ $badge->unlocked ? 'bg-theme-surface' : 'bg-theme-wash/20' }}" a11y-label="{{ $badge->name }}, {{ $badge->statusLabel() }}. {{ $badge->description }}">
<native:row class="w-full gap-2 items-center">
<native:column :width="24" :height="24" class="items-center justify-center rounded border bg-theme-wash {{ $badge->unlocked ? 'border-theme-hairline' : 'border-theme-hairline/60' }}">
<native:icon :ios="$icon->ios()" :android="$icon->android()" :size="14" class="{{ $badge->unlocked ? 'text-theme-ink' : 'text-theme-ink-muted/60' }}" />
@if ($badge->image() !== null)
<native:image :src="$badge->image()" :width="14" :height="14" :fit="1" />
@else
<native:icon :ios="$icon->ios()" :android="$icon->android()" :size="14" class="{{ $badge->unlocked ? 'text-theme-ink' : 'text-theme-ink-muted/60' }}" />
@endif
</native:column>
<native:text font="mono-medium" class="flex-1 text-xs text-theme-ink" :max-lines="1">{{ $badge->name }}</native:text>
@if ($badge->unlocked)
Expand Down
6 changes: 5 additions & 1 deletion resources/views/native/partials/achievements.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
@php($icon = \App\Icons\Lucide::forBadge($badge->icon))
<native:pressable ref="badge-{{ $badge->id }}" class="flex-shrink" @press="openAchievements('{{ $badge->id }}')" a11y-label="{{ $badge->name }}, {{ $badge->statusLabel() }}. {{ $badge->description }}">
<native:row class="px-[10] py-1 gap-[6] items-center rounded-full border border-theme-hairline bg-theme-surface">
<native:icon :ios="$icon->ios()" :android="$icon->android()" :size="14" class="text-theme-ink" />
@if ($badge->image() !== null)
<native:image :src="$badge->image()" :width="14" :height="14" :fit="1" />
@else
<native:icon :ios="$icon->ios()" :android="$icon->android()" :size="14" class="text-theme-ink" />
@endif
<native:text font="mono" class="text-xs text-theme-ink flex-shrink" :max-lines="1">{{ $badge->name }}</native:text>
</native:row>
</native:pressable>
Expand Down
20 changes: 19 additions & 1 deletion tests/Feature/Screens/AchievementsSheetTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Devnull\Data\Pasteis;
use Native\Mobile\Testing\Native;
use Native\Mobile\Testing\TestableComponent;

Expand Down Expand Up @@ -114,12 +115,29 @@ function markedBadges(TestableComponent $screen): array

expect(findNode(nodeByRef($screen, "sheet-badge-{$id}"), fn (array $node): bool => ($node['type'] ?? null) === 'icon')['props']['name'] ?? null)->toBe("custom:{$icon}");
})->with([
'sweet tooth' => ['sweet_tooth', 'cookie'],
'luddite' => ['luddite', 'bot-off'],
'shell shocked' => ['shell_shocked', 'bomb'],
'super-saiyan' => ['super_saiyan', 'dragon-ball'],
'whoopsie' => ['whoopsie', 'mushroom-cloud'],
'git blame' => ['git_blame', 'git-commit-horizontal'],
]);

it('draws sweet tooth with the pastel de nata on the profile and in the sheet, as the web does', function () {
$json = achievementsProfileJson();
$json['achievements']['badges'][] = ['id' => 'sweet_tooth', 'name' => 'Sweet Tooth', 'description' => '', 'icon' => 'pastel-de-nata', 'unlocked' => true, 'progress' => 1, 'target' => 1];

fakeApi(['GET /api/v1/users/ada' => [$json], 'GET /api/v1/users/ada/commits' => [pageJson([])]]);

$pastel = fn (array $node): bool => ($node['type'] ?? null) === 'image' && ($node['props']['src'] ?? null) === Pasteis::Image;
$screen = Native::visit('/log/users/ada', platform: 'ios');

expect(findNode(nodeByRef($screen, 'badge-sweet_tooth'), $pastel))->not->toBeNull();

$screen->tap('achievements-open');

expect(findNode(nodeByRef($screen, 'sheet-badge-sweet_tooth'), $pastel))->not->toBeNull();
});

it('marks the badge it was opened on in the owner\'s lane', function () {
$screen = adaWithAchievements();

Expand Down