From 2b53679323c2e21b6b7d4f7bf49465692987d419 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 23:05:27 +0000 Subject: [PATCH] Never show the new commits pill on profiles or organizations On someone's profile the "2 new commits" pill floated over the header and the Remote button. Profiles and organization pages now have no pill. New commits go straight in on top when the list is known to be at its top: when the page opens, after a pull to refresh, and when you tap the tab you're on or swipe to the other one. After you've left the page and come back, or the list has loaded its next page, you may be scrolled down, so they wait out of sight until the next pull to refresh or tab tap rather than pushing the rows you're reading down. The list keeps its key when they go in, so nothing is re-keyed. The Log keeps its pill as it was. Co-Authored-By: Claude Opus 5.5 --- .../Concerns/SlotsInNewCommits.php | 42 +++++++++ app/NativeComponents/Organization.php | 11 ++- app/NativeComponents/Profile.php | 14 ++- resources/views/native/organization.blade.php | 4 - .../partials/new-commits-pill.blade.php | 4 +- resources/views/native/profile.blade.php | 9 +- tests/Feature/Screens/LogCacheTest.php | 16 ++++ tests/Feature/Screens/OrganizationTest.php | 26 ++++++ tests/Feature/Screens/ProfileCacheTest.php | 92 +++++++++++++++---- tests/Feature/Screens/ProfilePagerTest.php | 8 +- 10 files changed, 186 insertions(+), 40 deletions(-) create mode 100644 app/NativeComponents/Concerns/SlotsInNewCommits.php diff --git a/app/NativeComponents/Concerns/SlotsInNewCommits.php b/app/NativeComponents/Concerns/SlotsInNewCommits.php new file mode 100644 index 00000000..86a7ed5e --- /dev/null +++ b/app/NativeComponents/Concerns/SlotsInNewCommits.php @@ -0,0 +1,42 @@ +mayBeScrolled; + } + + /** + * The list is at its top, with any commits that were waiting on top of it. + */ + protected function backAtTheTop(): void + { + $this->mayBeScrolled = false; + $this->putNewCommitsOnTop(); + } +} diff --git a/app/NativeComponents/Organization.php b/app/NativeComponents/Organization.php index 2eb04846..a879f38a 100644 --- a/app/NativeComponents/Organization.php +++ b/app/NativeComponents/Organization.php @@ -20,6 +20,7 @@ use App\NativeComponents\Concerns\OpensLiveStream; use App\NativeComponents\Concerns\RefreshesInBackground; use App\NativeComponents\Concerns\ShowsCommits; +use App\NativeComponents\Concerns\SlotsInNewCommits; use App\NativeComponents\Concerns\TalksToDevnull; use Closure; use Illuminate\View\View; @@ -49,6 +50,7 @@ class Organization extends NativeComponent use OpensLiveStream; use RefreshesInBackground; use ShowsCommits; + use SlotsInNewCommits; use TalksToDevnull; /** @@ -113,6 +115,7 @@ public function mount(): void */ public function onResume(): void { + $this->mayBeScrolled = true; $this->forgetRefreshes(); $this->showKept(); $this->revalidate(); @@ -128,6 +131,7 @@ public function navTitle(): string */ public function load(): void { + $this->mayBeScrolled = false; $this->refreshOrganization(showNewer: true); } @@ -149,12 +153,15 @@ public function showPage(int $index): void public function backToTop(int $index): void { if ((self::Tabs[$index] ?? null) === $this->tab) { + $this->backAtTheTop(); $this->listKey++; } } public function loadMore(): void { + $this->mayBeScrolled = true; + if ($this->nextCursor === null) { return; } @@ -260,7 +267,6 @@ public function render(): View return view('native.organization', [ 'handle' => $this->handle(), 'myColour' => $this->myColour(), - 'newCommitsLabel' => $this->newCommitsLabel(), 'viewer' => $this->me(), 'stashed' => app(Stash::class)->names($this->me()?->id), 'pages' => $pages, @@ -326,6 +332,7 @@ private function switchTo(string $tab): void $this->commitsLoaded = false; $this->commitsFailed = false; $this->forgetNewCommits(); + $this->mayBeScrolled = false; if (($kept = $this->cached($this->commitsPath())) !== null) { $this->takeCommits($tab, $kept); @@ -397,7 +404,7 @@ private function takeCommits(string $tab, array $json, bool $showNewer = false): return; } - $this->layFreshCommits($json, $showNewer || ! $this->commitsLoaded); + $this->layFreshCommits($json, $this->newCommitsGoIn($showNewer) || ! $this->commitsLoaded); $this->commitsLoaded = true; $this->commitsFailed = false; } diff --git a/app/NativeComponents/Profile.php b/app/NativeComponents/Profile.php index d4c1e690..8c5f5f03 100644 --- a/app/NativeComponents/Profile.php +++ b/app/NativeComponents/Profile.php @@ -24,6 +24,7 @@ use App\NativeComponents\Concerns\OpensLiveStream; use App\NativeComponents\Concerns\RefreshesInBackground; use App\NativeComponents\Concerns\ShowsCommits; +use App\NativeComponents\Concerns\SlotsInNewCommits; use App\NativeComponents\Concerns\TalksToDevnull; use App\NativeComponents\Concerns\WatchesForCalls; use Closure; @@ -58,7 +59,8 @@ * * It opens on the profile as it was last time, or opened from a commit, on * what the commit knew of its author, then asks devnull again behind it. The - * header changes in place; newer commits wait in the pill (see HoldsNewCommits). + * header changes in place. There's no new commits pill: newer commits go in + * on top while you're at the top, and otherwise wait (see SlotsInNewCommits). * * Commits and Replies are pages you swipe between, as on the Log (see Log), * under a header that scrolls up with the page you're on until the tabs pin @@ -78,6 +80,7 @@ class Profile extends NativeComponent use OpensLiveStream; use RefreshesInBackground; use ShowsCommits; + use SlotsInNewCommits; use TalksToDevnull; use WatchesForCalls; @@ -167,6 +170,7 @@ public function mount(): void */ public function onResume(): void { + $this->mayBeScrolled = true; $this->forgetRefreshes(); $this->showKept(); $this->revalidate(); @@ -261,6 +265,7 @@ private function safetyActions(): array */ public function load(): void { + $this->mayBeScrolled = false; $this->refreshProfile(showNewer: true); } @@ -282,6 +287,7 @@ public function showPage(int $index): void public function backToTop(int $index): void { if ((self::Tabs[$index] ?? null) === $this->tab) { + $this->backAtTheTop(); $this->listKey++; } } @@ -304,6 +310,7 @@ private function switchTo(string $tab): void $this->nextCursor = null; $this->commitsLoaded = false; $this->forgetNewCommits(); + $this->mayBeScrolled = false; if (($kept = $this->cached($this->commitsPath(), $this->commitsQuery())) !== null) { $this->takeCommits($tab, $kept); @@ -314,6 +321,8 @@ private function switchTo(string $tab): void public function loadMore(): void { + $this->mayBeScrolled = true; + if ($this->nextCursor === null) { return; } @@ -865,7 +874,7 @@ private function takeCommits(string $tab, array $json, bool $showNewer = false): return; } - $this->layFreshCommits($json, $showNewer || ! $this->commitsLoaded); + $this->layFreshCommits($json, $this->newCommitsGoIn($showNewer) || ! $this->commitsLoaded); $this->commitsLoaded = true; } @@ -897,7 +906,6 @@ public function render(): View 'isBlocked' => $this->isBlocking(), 'isMe' => $this->isMe(), 'canRemote' => $this->canRemote(), - 'newCommitsLabel' => $this->newCommitsLabel(), 'viewer' => $this->me(), 'stashed' => app(Stash::class)->names($this->me()?->id), 'pages' => $pages, diff --git a/resources/views/native/organization.blade.php b/resources/views/native/organization.blade.php index c0db5efb..67bd69bf 100644 --- a/resources/views/native/organization.blade.php +++ b/resources/views/native/organization.blade.php @@ -37,10 +37,6 @@ class="w-full flex-1 bg-theme-surface" @foreach ($pages as $page) @include('native.partials.organization-page', ['page' => $page]) @endforeach - - - @include('native.partials.new-commits-pill', ['label' => $newCommitsLabel, 'press' => 'showNewCommits', 'shown' => $newCommits !== []]) - @else {{-- diff --git a/resources/views/native/partials/new-commits-pill.blade.php b/resources/views/native/partials/new-commits-pill.blade.php index 21b5187e..b5bcb216 100644 --- a/resources/views/native/partials/new-commits-pill.blade.php +++ b/resources/views/native/partials/new-commits-pill.blade.php @@ -3,8 +3,8 @@ top with nothing to wait for. It floats over the commits, hung just under the pager's tabs, in the pager's overlay. There it stays put while the - list scrolls under it, and under a profile's header it follows the tabs wherever the header has scrolled them. The - overlay lets taps on either side of it through to the commits beneath. + list scrolls under it. The overlay lets taps on either side of it through to the commits beneath. Only the Log has + it: profiles and organizations put new commits in without one (see SlotsInNewCommits). Its slot is always in the overlay, hidden until there's something to show ($shown), so the pager keeps its shape when new commits come in. A node added beside a scrolled list sometimes left the list blank on iOS: its rows still in diff --git a/resources/views/native/profile.blade.php b/resources/views/native/profile.blade.php index efd5934b..3d198f76 100644 --- a/resources/views/native/profile.blade.php +++ b/resources/views/native/profile.blade.php @@ -19,8 +19,9 @@ so it scrolls up with it until the tabs pin under the nav bar. It stays where it is while you swipe, and the pages keep level with it. - The pill hangs under the tabs wherever they are. Keyed so the banners above coming and going don't make it - a new pager, with new lists. + There's no new commits pill here: new commits go in on top while you're at the top, and otherwise wait for + a pull to refresh (see SlotsInNewCommits). Keyed so the banners above coming and going don't make it a new + pager, with new lists. --}} $page]) @endforeach - - - @include('native.partials.new-commits-pill', ['label' => $newCommitsLabel, 'press' => 'showNewCommits', 'shown' => $newCommits !== []]) - @else diff --git a/tests/Feature/Screens/LogCacheTest.php b/tests/Feature/Screens/LogCacheTest.php index 1839334b..c1d39578 100644 --- a/tests/Feature/Screens/LogCacheTest.php +++ b/tests/Feature/Screens/LogCacheTest.php @@ -396,3 +396,19 @@ function shownCommitIds(TestableComponent $screen): array ->and(findNode($overlay(), fn (array $node): bool => ($node['ref'] ?? null) === 'new-commits'))->not->toBeNull() ->and($firstInTheList())->toBe('commit-c1'); }); + +it('still holds new commits in the pill when you come back to it, unlike a profile', function () { + holdRefreshes(); + fakeFreshLog([commitJson(['id' => 'c1', 'body' => 'Seen before'])]); + + $screen = finishRefreshes(Native::visit('/log')); + + fakeFreshLog([commitJson(['id' => 'c2', 'body' => 'Just in', 'author' => userJson(['id' => 'u2', 'handle' => 'ada'])]), commitJson(['id' => 'c1', 'body' => 'Seen before'])]); + + finishRefreshes($screen->call('onResume')) + ->assertSee('1 new commit') + ->assertDontSee('Just in') + ->assertElement('pressable', fn (array $node): bool => ($node['ref'] ?? null) === 'new-commits'); + + expect(shownCommitIds($screen))->toBe(['c1']); +}); diff --git a/tests/Feature/Screens/OrganizationTest.php b/tests/Feature/Screens/OrganizationTest.php index 55ad2060..9d7c84fd 100644 --- a/tests/Feature/Screens/OrganizationTest.php +++ b/tests/Feature/Screens/OrganizationTest.php @@ -235,3 +235,29 @@ function tapOrganizationTab(TestableComponent $screen, string $tab): TestableCom $screen->call('openGitHubMention', 'taylorotwell') ->assertNativeCalled('Browser.OpenInApp', fn (array $params): bool => $params['url'] === 'https://github.com/taylorotwell'); }); + +it('never shows a new commits pill: new commits go on top when it opens, and wait when you come back to it', function () { + holdRefreshes(); + keep('organizations/laravel', organizationJson()); + keep('organizations/laravel/commits', pageJson([organizationCommitJson(['id' => 'c1', 'body' => 'Older'])])); + $serve = fn (array $commits) => serveApi([ + 'GET /api/v1/organizations/laravel' => [organizationJson()], + 'GET /api/v1/organizations/laravel/commits' => [pageJson($commits)], + ]); + $pill = fn (TestableComponent $screen): bool => findNode($screen->tree(), fn (array $node): bool => in_array($node['ref'] ?? null, ['new-commits', 'new-commits-slot'], true)) !== null; + $ids = fn (TestableComponent $screen): array => array_map(fn ($commit): string => $commit->id, $screen->instance()->commits); + + $serve([organizationCommitJson(['id' => 'c2', 'body' => 'Laravel 13 is out']), organizationCommitJson(['id' => 'c1', 'body' => 'Older'])]); + $screen = finishRefreshes(Native::visit('/log/organizations/laravel'))->assertSee('Laravel 13 is out')->assertDontSee('1 new commit'); + + expect($ids($screen))->toBe(['c2', 'c1'])->and($pill($screen))->toBeFalse(); + + $serve([organizationCommitJson(['id' => 'c3', 'body' => 'Cloud is live']), organizationCommitJson(['id' => 'c2', 'body' => 'Laravel 13 is out']), organizationCommitJson(['id' => 'c1', 'body' => 'Older'])]); + finishRefreshes($screen->call('onResume'))->assertDontSee('Cloud is live')->assertDontSee('1 new commit'); + + expect($ids($screen))->toBe(['c2', 'c1'])->and($pill($screen))->toBeFalse(); + + finishRefreshes($screen->call('load'))->assertSee('Cloud is live'); + + expect($ids($screen))->toBe(['c3', 'c2', 'c1']); +}); diff --git a/tests/Feature/Screens/ProfileCacheTest.php b/tests/Feature/Screens/ProfileCacheTest.php index 9820272e..d78937a6 100644 --- a/tests/Feature/Screens/ProfileCacheTest.php +++ b/tests/Feature/Screens/ProfileCacheTest.php @@ -1,8 +1,10 @@ 'http://devnull.test']); @@ -100,42 +102,94 @@ function serveAda(array $commits, int $followers = 5): void finishRefreshes($screen)->assertSee('Ada Lovelace')->assertSee("@ada hasn't committed anything yet."); }); -it('holds their new commits in the pill and puts them on top without a request', function () { +/** + * The ids of the commits on the profile's tab, top first. + * + * @return list + */ +function profileCommitIds(TestableComponent $screen): array +{ + return array_map(fn (Commit $commit): string => $commit->id, $screen->instance()->commits); +} + +function showsNewCommitsPill(TestableComponent $screen): bool +{ + return findNode($screen->tree(), fn (array $node): bool => in_array($node['ref'] ?? null, ['new-commits', 'new-commits-slot'], true)) !== null; +} + +it('never shows a new commits pill, and puts new commits on top when it opens', function () { holdRefreshes(); keep('users/ada', adaProfile()); keep('users/ada/commits', pageJson([adaCommit(['id' => 'a1', 'body' => 'Older'])])); serveAda([adaCommit(['id' => 'a2', 'body' => 'Brand new']), adaCommit(['id' => 'a1', 'body' => 'Older'])]); - $screen = finishRefreshes(Native::visit('/log/users/ada')) - ->assertSee('1 new commit') - ->assertDontSee('Brand new'); + $screen = Native::visit('/log/users/ada'); - $requests = count(Http::recorded()); + expect(showsNewCommitsPill($screen))->toBeFalse(); + + $listKey = $screen->get('listKey'); - $screen->tap('new-commits')->assertSee('Brand new')->assertDontSee('1 new commit'); + finishRefreshes($screen)->assertSee('Brand new')->assertDontSee('1 new commit'); - expect(count(Http::recorded()))->toBe($requests); + expect(profileCommitIds($screen))->toBe(['a2', 'a1']) + ->and(showsNewCommitsPill($screen))->toBeFalse() + // The same list, so rows already showing keep their place. + ->and($screen->get('listKey'))->toBe($listKey); }); -it('hangs the pill under the tabs in the pager, there before it shows', function () { +it('holds new commits out of sight when you come back to it, until you pull to refresh', function () { holdRefreshes(); keep('users/ada', adaProfile()); - keep('users/ada/commits', pageJson([adaCommit(['id' => 'a1', 'body' => 'Older'])])); + serveAda([adaCommit(['id' => 'a1', 'body' => 'Older'])]); + + $screen = finishRefreshes(Native::visit('/log/users/ada')); + + // Back from a commit you may be anywhere in the list, and rows put above the ones you're reading would push them down. serveAda([adaCommit(['id' => 'a2', 'body' => 'Brand new']), adaCommit(['id' => 'a1', 'body' => 'Older'])]); + finishRefreshes($screen->call('onResume'))->assertDontSee('Brand new')->assertDontSee('1 new commit'); - $screen = Native::visit('/log/users/ada'); - $overlay = fn (): array => findNode(nodeByRef($screen, 'profile-pager'), fn (array $node): bool => ($node['type'] ?? null) === 'pager_overlay'); + expect(profileCommitIds($screen))->toBe(['a1']) + ->and(showsNewCommitsPill($screen))->toBeFalse(); + + $listKey = $screen->get('listKey'); + + finishRefreshes($screen->call('load'))->assertSee('Brand new'); - // Hidden and empty until there are new commits, but already in its place, outside the lists. - expect(findNode($overlay(), fn (array $node): bool => ($node['ref'] ?? null) === 'new-commits-slot'))->not->toBeNull() - ->and(nodeByRef($screen, 'new-commits-slot')['layout']['display'] ?? null)->toBe(1) - ->and(nodeByRef($screen, 'new-commits-slot')['children'] ?? [])->toBe([]) - ->and(findNode(showingProfile($screen), fn (array $node): bool => ($node['ref'] ?? null) === 'new-commits-slot'))->toBeNull(); + expect(profileCommitIds($screen))->toBe(['a2', 'a1']) + ->and($screen->get('listKey'))->toBe($listKey); +}); + +it('holds new commits once the list has asked for its next page', function () { + holdRefreshes(); + keep('users/ada', adaProfile()); + serveAda([adaCommit(['id' => 'a1', 'body' => 'Older'])]); + + $screen = finishRefreshes(Native::visit('/log/users/ada'))->call('loadMore'); + + serveAda([adaCommit(['id' => 'a2', 'body' => 'Brand new']), adaCommit(['id' => 'a1', 'body' => 'Older'])]); + finishRefreshes($screen->call('retry'))->assertDontSee('Brand new'); + + expect(profileCommitIds($screen))->toBe(['a1']); +}); + +it('puts held commits on top when you tap the tab you are on, which goes back to the top', function () { + holdRefreshes(); + keep('users/ada', adaProfile()); + serveAda([adaCommit(['id' => 'a1', 'body' => 'Older'])]); + + $screen = finishRefreshes(Native::visit('/log/users/ada')); + + serveAda([adaCommit(['id' => 'a2', 'body' => 'Brand new']), adaCommit(['id' => 'a1', 'body' => 'Older'])]); + finishRefreshes($screen->call('onResume'))->assertDontSee('Brand new'); + + $listKey = $screen->get('listKey'); + $requests = count(Http::recorded()); - finishRefreshes($screen)->assertSee('1 new commit'); + tapProfileTab($screen, 'commits')->assertSee('Brand new'); - expect(nodeByRef($screen, 'new-commits-slot')['layout']['display'] ?? null)->toBeNull() - ->and(findNode($overlay(), fn (array $node): bool => ($node['ref'] ?? null) === 'new-commits'))->not->toBeNull(); + expect(profileCommitIds($screen))->toBe(['a2', 'a1']) + ->and($screen->get('listKey'))->toBe($listKey + 1) + ->and(count(Http::recorded()))->toBe($requests); }); it('keeps a follow, so their profile opens followed next time', function () { diff --git a/tests/Feature/Screens/ProfilePagerTest.php b/tests/Feature/Screens/ProfilePagerTest.php index 38d67ec0..dcd8e49d 100644 --- a/tests/Feature/Screens/ProfilePagerTest.php +++ b/tests/Feature/Screens/ProfilePagerTest.php @@ -82,7 +82,7 @@ function profileList(TestableComponent $screen, string $tab): array $screen->changeTab('showPage', -1)->assertSet('tab', 'commits'); }); -it('draws the header once, for the pager to put above its tabs, and hangs the pill under them', function () { +it('draws the header once, for the pager to put above its tabs, with no new commits pill', function () { holdRefreshes(); keepProfile('ada', [commitJson(['id' => 'c1'])], [commitJson(['id' => 'r1'])]); @@ -90,11 +90,11 @@ function profileList(TestableComponent $screen, string $tab): array $pager = nodeByRef($screen, 'profile-pager'); $hasRef = fn (string $ref): Closure => fn (array $node): bool => ($node['ref'] ?? null) === $ref; - expect(array_column($pager['children'], 'type'))->toBe(['pager_header', 'column', 'column', 'pager_overlay']) + expect(array_column($pager['children'], 'type'))->toBe(['pager_header', 'column', 'column']) ->and(findNode($pager['children'][0], $hasRef('profile-header')))->not->toBeNull() ->and(findNode(showingProfile($screen), $hasRef('profile-header')))->toBeNull() ->and(findNode(profileList($screen, 'replies'), $hasRef('profile-header')))->toBeNull() - ->and(findNode($pager['children'][3], $hasRef('new-commits-slot')))->not->toBeNull(); + ->and(findNode($pager, $hasRef('new-commits-slot')))->toBeNull(); }); it('keeps the list a tab was drawn in when you swipe to it, and starts the tab you leave again in a fresh one', function () { @@ -183,5 +183,5 @@ function profileList(TestableComponent $screen, string $tab): array $props = fn (array $pager): array => array_intersect_key($pager['props'], array_flip(['horizontal', 'count', 'tabs', 'report_on_settle', 'tab_font', 'tab_active_color'])); expect($props($pager('/log/users/ada')))->toBe($props($pager('/profile'))) - ->and(array_column($pager('/profile')['children'], 'type'))->toBe(['pager_header', 'column', 'column', 'pager_overlay']); + ->and(array_column($pager('/profile')['children'], 'type'))->toBe(['pager_header', 'column', 'column']); });