Skip to content

Commit bc942af

Browse files
authored
Draw follow backs as the web's icon, and open a group of followers in place (#45)
1 parent e3683ef commit bc942af

8 files changed

Lines changed: 81 additions & 26 deletions

File tree

‎app/Icons/Lucide.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ enum Lucide
4646
case Check;
4747
case X;
4848
case UserPlus;
49+
case UserCheck;
4950
case AtSign;
5051
case FoldVertical;
5152
case Award;
@@ -137,6 +138,7 @@ public function custom(bool $filled = false): ?string
137138
self::Check => 'check',
138139
self::X => 'x',
139140
self::UserPlus => 'user-plus',
141+
self::UserCheck => 'user-check',
140142
self::AtSign => 'at-sign',
141143
self::FoldVertical => 'fold-vertical',
142144
self::Award => 'award',

‎app/NativeComponents/Notifications.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ public function loadMore(): void
238238
}
239239
}
240240

241+
/**
242+
* A tap on a notification opens its commit, or the profile of whoever
243+
* followed you. A tap on a group of followers lists them in place instead,
244+
* as its toggle does, rather than opening only the latest of them.
245+
*/
241246
public function open(string $id): void
242247
{
243248
$notification = $this->find($id);
@@ -246,6 +251,12 @@ public function open(string $id): void
246251
return;
247252
}
248253

254+
if ($notification->isFollow() && $notification->isGrouped()) {
255+
$this->toggleGroup($id);
256+
257+
return;
258+
}
259+
249260
$commitId = $notification->commitToOpen();
250261

251262
$this->openInTab($commitId !== null

‎resources/icons/user-check.svg‎

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
{{-- The web's Follow button on a follow: Follow in your colour, or Following once you do. A tap flips it. --}}
2-
<native:button ref="follow-back-{{ $actor->username }}" size="sm" :variant="$isFollowing ? 'secondary' : $myColour" @press="toggleFollowBack('{{ $actor->username }}')" a11y-hint="{{ $isFollowing ? 'Unfollows' : 'Follows' }} {{ $actor->handle() }}">{{ $isFollowing ? 'Following' : 'Follow' }}</native:button>
1+
{{--
2+
The web's follow back on a follow: an icon rather than a full button, since an expanded group of followers repeats it
3+
on every row, so each is the same size. A muted user-plus, or a user-check in Commit Blue once you follow them. A tap
4+
flips it.
5+
--}}
6+
@php($followIcon = $isFollowing ? \App\Icons\Lucide::UserCheck : \App\Icons\Lucide::UserPlus)
7+
<native:pressable ref="follow-back-{{ $actor->username }}" @press="toggleFollowBack('{{ $actor->username }}')" class="flex-shrink-0" a11y-label="{{ $isFollowing ? 'Unfollow' : 'Follow' }} {{ $actor->handle() }}">
8+
<native:stack ref="follow-back-icon-{{ $actor->username }}" :width="32" :height="32" center class="rounded-md">
9+
<native:icon :ios="$followIcon->ios()" :android="$followIcon->android()" :size="16" class="{{ $isFollowing ? 'text-theme-primary' : 'text-theme-ink-muted' }}" />
10+
</native:stack>
11+
</native:pressable>

‎resources/views/native/partials/notification-group.blade.php‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{--
22
A group opened in place, as the web expands it: each of its notifications on a compact line behind a 1pt Rail Gray
3-
guide line, with a 28pt avatar, the name, the icon and time, and the words someone wrote. Each opens its own
4-
commit, or profile for a follow. Older ones come with "Show older stars"; one that wouldn't load says so in git's
3+
guide line, with a 28pt avatar, the name, the icon and time, and the words someone wrote. A follower has no icon,
4+
as on the web, only the time and their follow back. Each opens its own commit, or profile for a follow. Older ones come with "Show older stars"; one that wouldn't load says so in git's
55
voice, with Try again.
66
--}}
77
@php($noun = $group->groupNoun())
@@ -16,8 +16,10 @@
1616
<native:row class="w-full min-h-[28] gap-2 items-center">
1717
<native:text font="semibold" class="flex-shrink text-[15px] text-theme-ink" :max-lines="1" @press="openActor('{{ $item->actor->username }}')" a11y-label="{{ $item->actor->handle() }}'s profile">{{ $item->actor->name }}</native:text>
1818
<native:spacer />
19-
@php($itemIcon = \App\Icons\Lucide::forNotification($item->type))
20-
<native:icon :ios="$itemIcon->ios($item->isStar())" :android="$itemIcon->android($item->isStar())" :size="16" class="{{ $item->isModeration() ? 'text-theme-ink-muted' : 'text-theme-'.\App\Devnull\Lane::token($item->actor->lane()) }}" />
19+
@unless ($item->isFollow())
20+
@php($itemIcon = \App\Icons\Lucide::forNotification($item->type))
21+
<native:icon :ios="$itemIcon->ios($item->isStar())" :android="$itemIcon->android($item->isStar())" :size="16" class="{{ $item->isModeration() ? 'text-theme-ink-muted' : 'text-theme-'.\App\Devnull\Lane::token($item->actor->lane()) }}" />
22+
@endunless
2123
<native:text font="mono" class="text-[13px] text-theme-ink-muted flex-shrink-0">{{ \App\Devnull\Display::relativeTime($item->createdAt) }}</native:text>
2224
@if ($item->isFollow() && $item->actorIsFollowed !== null)
2325
@include('native.partials.follow-back', ['actor' => $item->actor, 'isFollowing' => $item->actorIsFollowed])

‎resources/views/native/partials/notification.blade.php‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
commit sits under a star or a verdict in a muted hairline box. A rejection gives the moderator's reason.
77
88
A group of more than one opens in place from a Commit Blue toggle ("5 stars"), listing each event behind a Rail
9-
Gray guide line, each follower with their own Follow button.
9+
Gray guide line, each follower with their own follow back. A group of followers has none of its own, as the web
10+
leaves it out, since it could only follow one of them back, and a tap on it opens the list rather than the latest
11+
follower's profile.
1012
1113
No press-* feedback: on iOS it holds any drag that starts on the row, and these rows cover the whole list.
1214
The name's run carries font-semibold as well as the font: inside a sentence, NativeUITextRenderer sets each run's
@@ -32,7 +34,7 @@
3234
@endif
3335
<native:spacer />
3436
<native:text font="mono" class="text-[13px] text-theme-ink-muted flex-shrink-0">{{ \App\Devnull\Display::relativeTime($notification->createdAt) }}</native:text>
35-
@if ($notification->isFollow() && $notification->actorIsFollowed !== null)
37+
@if ($notification->isFollow() && $notification->actorsCount === 1 && $notification->actorIsFollowed !== null)
3638
@include('native.partials.follow-back', ['actor' => $notification->actor, 'isFollowing' => $notification->actorIsFollowed])
3739
@endif
3840
</native:row>

‎tests/Feature/Screens/LaneButtonsTest.php‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,6 @@ function laneLog(): TestableComponent
6161

6262
return Native::visit('/log');
6363
}, 'follow-ada'],
64-
'Follow, back from a follow' => [function (): TestableComponent {
65-
$follow = notificationJson('followed', ['actor' => userJson(['id' => 'u-linus', 'username' => 'linus', 'name' => 'Linus', 'is_followed' => false])]);
66-
serveApi(['GET /api/v1/notifications' => [[
67-
...pageJson([$follow], path: 'http://devnull.test/api/v1/notifications'),
68-
'filters' => ['type' => 'all'],
69-
'read_at' => now()->toIso8601ZuluString(),
70-
]]]);
71-
72-
return Native::visit('/notifications');
73-
}, 'follow-back-linus'],
7464
'Follow, on a profile' => [function (): TestableComponent {
7565
serveApi([
7666
'GET /api/v1/users/ada' => [['data' => userWithCountsJson(['id' => 'u2', 'username' => 'ada', 'name' => 'Ada']), 'is_following' => false]],

‎tests/Feature/Screens/NotificationsTest.php‎

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -449,16 +449,23 @@ function ringColour(TestableComponent $screen, string $id): ?string
449449
'DELETE /api/v1/users/linus/follow' => [['message' => 'Too Many Attempts.', 'code' => 'rate_limited'], 429],
450450
]);
451451

452-
$label = fn (string $label): Closure => fn (array $node): bool => ($node['ref'] ?? null) === 'follow-back-linus' && $node['props']['label'] === $label;
452+
// The web's icon: a muted user-plus to follow back, a user-check in Commit Blue once you do.
453+
$followBack = fn (TestableComponent $screen): array => [
454+
nodeByRef($screen, 'follow-back-linus')['props']['a11y_label'],
455+
findNode(nodeByRef($screen, 'follow-back-linus'), fn (array $node): bool => ($node['type'] ?? null) === 'icon')['props']['name'],
456+
];
453457

454-
$screen = Native::visit('/notifications')
455-
->assertElement('button', $label('Follow'))
456-
->tap('follow-back-linus')
457-
->assertElement('button', $label('Following'));
458+
$screen = Native::visit('/notifications', platform: 'ios');
459+
460+
expect($followBack($screen))->toBe(['Follow @linus', 'custom:user-plus']);
461+
462+
$screen->tap('follow-back-linus');
458463

459-
$screen->tap('follow-back-linus')
460-
->assertElement('button', $label('Following'))
461-
->assertSee('Too Many Attempts.');
464+
expect($followBack($screen))->toBe(['Unfollow @linus', 'custom:user-check']);
465+
466+
$screen->tap('follow-back-linus')->assertSee('Too Many Attempts.');
467+
468+
expect($followBack($screen))->toBe(['Unfollow @linus', 'custom:user-check']);
462469

463470
Http::assertSent(fn (Request $request): bool => $request->method() === 'POST' && $request->url() === 'http://devnull.test/api/v1/users/linus/follow');
464471
});
@@ -496,3 +503,34 @@ function ringColour(TestableComponent $screen, string $id): ?string
496503

497504
finishRefreshes($screen)->assertSet('skeletonFrame', false)->assertSee('followed you');
498505
});
506+
507+
it('lists a group of followers when it is tapped, each with the same small follow back, and none for the group', function () {
508+
serveApi(function (Request $request) {
509+
return str_contains($request->url(), '/group')
510+
? Http::response(pageJson([
511+
notificationJson('followed', ['id' => 'n-follow-1', 'actor' => personJson('linus', 'Linus', overrides: ['is_followed' => false])]),
512+
notificationJson('followed', ['id' => 'n-follow-2', 'actor' => personJson('grace', 'Grace Brewster Murray Hopper', overrides: ['is_followed' => true])]),
513+
]))
514+
: Http::response(inboxJson([notificationJson('followed', ['event_count' => 2, 'actors_count' => 2, 'actor' => personJson('linus', 'Linus', overrides: ['is_followed' => false])])]));
515+
});
516+
517+
$screen = Native::visit('/notifications', platform: 'ios');
518+
519+
// The group could only follow one of them back, so it leaves it to the list, as the web does.
520+
$screen->assertMissingElement('pressable', fn (array $node): bool => ($node['ref'] ?? null) === 'follow-back-linus');
521+
522+
// A tap on the group lists them rather than opening the latest follower.
523+
$screen->tap('notification-n-followed')->assertNoNavigation()->assertSee('Grace Brewster Murray Hopper');
524+
525+
foreach (['linus' => 'custom:user-plus', 'grace' => 'custom:user-check'] as $username => $icon) {
526+
$row = nodeByRef($screen, 'group-item-n-follow-'.($username === 'linus' ? 1 : 2));
527+
$box = nodeByRef($screen, 'follow-back-icon-'.$username);
528+
529+
expect([(float) $box['layout']['width'], (float) $box['layout']['height']])->toBe([32.0, 32.0])
530+
// The follow back is the row's only icon: a follower's row has no type icon, as on the web.
531+
->and(array_map(fn (array $node): string => $node['props']['name'], findNodes($row, fn (array $node): bool => ($node['type'] ?? null) === 'icon')))->toBe([$icon]);
532+
}
533+
534+
// A second tap folds it away.
535+
$screen->tap('notification-n-followed')->assertDontSee('Grace Brewster Murray Hopper');
536+
});

0 commit comments

Comments
 (0)