Skip to content
Draft
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
42 changes: 42 additions & 0 deletions app/NativeComponents/Concerns/SlotsInNewCommits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\NativeComponents\Concerns;

/**
* New commits on a screen with no new commits pill, a profile or an
* organization, used with HoldsNewCommits. While you're at the top of the
* list they go straight in on top. Otherwise they wait out of sight, in
* $newCommits, which nothing draws, for the next time you're at the top.
*
* EDGE never says where a list is scrolled, so this goes by what the screen
* knows. The list is at its top when the screen opens, after a pull to
* refresh, and when a tab tap or a swipe starts it again. Once you've been
* somewhere else and come back, or the list has asked for its next page, you
* may be anywhere in it, and rows put above the ones you're reading would
* push them down. So the commits wait until you pull to refresh or tap the
* tab you're on.
*/
trait SlotsInNewCommits
{
/**
* You may have scrolled the list away from its top since it was last known to be there.
*/
public bool $mayBeScrolled = false;

/**
* Whether newer commits in a fresh first page go in now. $showNewer says you asked for them.
*/
protected function newCommitsGoIn(bool $showNewer): bool
{
return $showNewer || ! $this->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();
}
}
11 changes: 9 additions & 2 deletions app/NativeComponents/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,6 +50,7 @@ class Organization extends NativeComponent
use OpensLiveStream;
use RefreshesInBackground;
use ShowsCommits;
use SlotsInNewCommits;
use TalksToDevnull;

/**
Expand Down Expand Up @@ -113,6 +115,7 @@ public function mount(): void
*/
public function onResume(): void
{
$this->mayBeScrolled = true;
$this->forgetRefreshes();
$this->showKept();
$this->revalidate();
Expand All @@ -128,6 +131,7 @@ public function navTitle(): string
*/
public function load(): void
{
$this->mayBeScrolled = false;
$this->refreshOrganization(showNewer: true);
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 11 additions & 3 deletions app/NativeComponents/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -78,6 +80,7 @@ class Profile extends NativeComponent
use OpensLiveStream;
use RefreshesInBackground;
use ShowsCommits;
use SlotsInNewCommits;
use TalksToDevnull;
use WatchesForCalls;

Expand Down Expand Up @@ -167,6 +170,7 @@ public function mount(): void
*/
public function onResume(): void
{
$this->mayBeScrolled = true;
$this->forgetRefreshes();
$this->showKept();
$this->revalidate();
Expand Down Expand Up @@ -261,6 +265,7 @@ private function safetyActions(): array
*/
public function load(): void
{
$this->mayBeScrolled = false;
$this->refreshProfile(showNewer: true);
}

Expand All @@ -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++;
}
}
Expand All @@ -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);
Expand All @@ -314,6 +321,8 @@ private function switchTo(string $tab): void

public function loadMore(): void
{
$this->mayBeScrolled = true;

if ($this->nextCursor === null) {
return;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions resources/views/native/organization.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ class="w-full flex-1 bg-theme-surface"
@foreach ($pages as $page)
@include('native.partials.organization-page', ['page' => $page])
@endforeach

<native:pager-overlay>
@include('native.partials.new-commits-pill', ['label' => $newCommitsLabel, 'press' => 'showNewCommits', 'shown' => $newCommits !== []])
</native:pager-overlay>
</native:pager>
@else
{{--
Expand Down
4 changes: 2 additions & 2 deletions resources/views/native/partials/new-commits-pill.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions resources/views/native/profile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
--}}
<native:pager
native:key="profile-pager"
Expand All @@ -47,10 +48,6 @@ class="w-full flex-1 bg-theme-surface"
@foreach ($pages as $page)
@include('native.partials.profile-page', ['page' => $page])
@endforeach

<native:pager-overlay>
@include('native.partials.new-commits-pill', ['label' => $newCommitsLabel, 'press' => 'showNewCommits', 'shown' => $newCommits !== []])
</native:pager-overlay>
</native:pager>
@else
<native:list native:key="profile-{{ $listKey }}" class="w-full flex-1 bg-theme-surface" on-refresh="load">
Expand Down
16 changes: 16 additions & 0 deletions tests/Feature/Screens/LogCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
26 changes: 26 additions & 0 deletions tests/Feature/Screens/OrganizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
Loading
Loading