From 3436948ee850e4c991a682379bd1575b1adc427c Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Mon, 16 Nov 2026 00:23:34 +0000 Subject: [PATCH 01/18] Hide replies on the Log until asked, and line the rail's end dot up with the actions Replies no longer show under a commit in a feed. The replies button moves to its own line under the action row and opens the thread in place, ten replies at a time, with Show more for the next ten. A reply has the same button under its own actions, which opens its replies inline one step in. Deeper than that, the button opens the reply's page. devnull's API sends 50 replies a page whatever `limit` asks for, so the app keeps what it was sent and shows ten at a time, asking for the next page only once they all show. The end dot of a commit's rail is now drawn inside its action row, so it sits level with the actions whatever is above or below them. It used to be placed a fixed distance from the row's bottom, which assumed the action row's -my-[6] pulled it in. iOS does that, Android keeps the space and only moves the drawing, and a row with a thread under it had no bottom padding, so the dot sat above the actions in some rows and below in others. The action row now has no vertical negative margins, and the rail's lines are worked out from the fixed heights under it to meet the dot. Opening and closing a thread fades its rows in and out, and the chevron turns. Starring a commit pops the star as the web's star-pop does, and giving a pastel bumps it as the web's pastel button does. EDGE only animates from one frame to the next, so each step is a frame drawn when a short background Beat comes back. Quote now has its label beside its icon, as Reply always does. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/Beat.php | 34 ++ app/Devnull/Client.php | 6 +- app/Devnull/Pop.php | 39 ++ app/Devnull/RowInputs.php | 4 +- app/Devnull/ThreadRows.php | 119 +++++ app/NativeComponents/CommitDetail.php | 4 +- .../Concerns/ExpandsThreads.php | 263 +++++++++-- .../Concerns/HoldsNewCommits.php | 2 +- .../Concerns/PopsReactions.php | 59 +++ .../Concerns/ShowsCommits.php | 7 + app/NativeComponents/Log.php | 4 +- app/NativeComponents/Organization.php | 2 +- app/NativeComponents/Profile.php | 4 +- .../views/native/commit-detail.blade.php | 4 +- .../native/partials/commit-actions.blade.php | 73 ++-- .../partials/commit-row-content.blade.php | 20 +- .../views/native/partials/feed.blade.php | 42 +- .../views/native/partials/rail.blade.php | 17 +- .../native/partials/thread-more-row.blade.php | 33 ++ .../native/partials/thread-reply.blade.php | 14 +- tests/Feature/Screens/CommitCardTest.php | 9 +- .../Feature/Screens/CommitDetailCacheTest.php | 2 +- tests/Feature/Screens/CommitDetailTest.php | 24 +- tests/Feature/Screens/DraftStashTest.php | 2 +- tests/Feature/Screens/LogTest.php | 46 +- tests/Feature/Screens/LogThreadTest.php | 412 ++++++++++++++++++ tests/Feature/Screens/LogWindowTest.php | 23 +- tests/Feature/Screens/PasteisTest.php | 9 +- tests/Feature/Screens/ProfileTest.php | 7 +- tests/Feature/Screens/ReplyPreviewTest.php | 252 ----------- 30 files changed, 1097 insertions(+), 439 deletions(-) create mode 100644 app/Devnull/Beat.php create mode 100644 app/Devnull/Pop.php create mode 100644 app/Devnull/ThreadRows.php create mode 100644 app/NativeComponents/Concerns/PopsReactions.php create mode 100644 resources/views/native/partials/thread-more-row.blade.php create mode 100644 tests/Feature/Screens/LogThreadTest.php delete mode 100644 tests/Feature/Screens/ReplyPreviewTest.php diff --git a/app/Devnull/Beat.php b/app/Devnull/Beat.php new file mode 100644 index 00000000..c6598cfe --- /dev/null +++ b/app/Devnull/Beat.php @@ -0,0 +1,34 @@ +runningUnitTests()) { + usleep(max(0, $milliseconds) * 1000); + } + + return true; + } +} diff --git a/app/Devnull/Client.php b/app/Devnull/Client.php index b6538ae5..fc9990f1 100644 --- a/app/Devnull/Client.php +++ b/app/Devnull/Client.php @@ -110,10 +110,10 @@ public const string IssuesPath = 'issues'; /** - * How many replies the app asks for at a time. devnull sends 50 a page - * unless it's asked for fewer, and the app never asks for more than this. + * How many replies the app asks for at a time, in a feed's thread and on + * a commit's page. devnull sends 50 a page unless it's asked for fewer. */ - public const int RepliesPerPage = 5; + public const int RepliesPerPage = 10; /** * Where the signed-in account's timezone is saved, or unset, with whether their profile shows their local time. diff --git a/app/Devnull/Pop.php b/app/Devnull/Pop.php new file mode 100644 index 00000000..dc9e86f3 --- /dev/null +++ b/app/Devnull/Pop.php @@ -0,0 +1,39 @@ + ['scale' => 1.0, 'rotate' => 0.0, 'duration' => 150, 'easing' => 'ease-out'], + self::Up => ['scale' => $star ? 1.35 : 1.25, 'rotate' => $star ? -12.0 : 0.0, 'duration' => 150, 'easing' => 'ease-out'], + self::Down => ['scale' => 1.0, 'rotate' => 0.0, 'duration' => $star ? 320 : 180, 'easing' => $star ? 'spring' : 'ease-out'], + default => ['scale' => null, 'rotate' => null, 'duration' => null, 'easing' => null], + }; + } +} diff --git a/app/Devnull/RowInputs.php b/app/Devnull/RowInputs.php index 0659a309..c0409343 100644 --- a/app/Devnull/RowInputs.php +++ b/app/Devnull/RowInputs.php @@ -32,7 +32,9 @@ public static function for(Commit $commit, array $scope): array 'stashed' => $scope['stashed'] ?? [], 'unfolded' => $scope['unfolded'] ?? [], 'expandable' => isset($scope['threads']), - 'opened' => array_key_exists($commit->id, $scope['threads'] ?? []), + 'opened' => array_key_exists($commit->id, $scope['threads'] ?? []) && ! in_array($commit->id, $scope['closingThreads'] ?? [], true), + 'faded' => in_array($commit->id, $scope['fadedRows'] ?? [], true), + 'popping' => [$scope['popping']['star-'.$commit->id] ?? null, $scope['popping']['pastel-'.$commit->id] ?? null], 'tombstones' => $scope['tombstones'] ?? false, 'tombstoneReplies' => array_key_exists($commit->id, $scope['tombstoneReplies'] ?? []), 'shown' => [self::changing($commit), $commit->quotedCommit === null ? null : self::changing($commit->quotedCommit)], diff --git a/app/Devnull/ThreadRows.php b/app/Devnull/ThreadRows.php new file mode 100644 index 00000000..3affe2a7 --- /dev/null +++ b/app/Devnull/ThreadRows.php @@ -0,0 +1,119 @@ +> $threads Open threads, by the id of the commit or reply they answer. + * @param array $cursors Where each open thread with more carries on. + * @param array $shown How many of each open thread's replies show. + * @param int|string|null $railLane The commit's rail running on past its thread, when its author's run carries on below. + * @return list, reply: Commit|null}> + */ + public static function under(Commit $commit, array $threads, array $cursors, array $shown, int|string|null $railLane = null): array + { + $thread = fn (string $id): array => array_slice($threads[$id] ?? [], 0, $shown[$id] ?? null); + $hasMore = fn (string $id): bool => isset($cursors[$id]) || count($thread($id)) < count($threads[$id] ?? []); + $replies = $thread($commit->id); + + if ($replies === []) { + return []; + } + + $rows = []; + $more = $hasMore($commit->id); + + foreach ($replies as $index => $reply) { + $nested = $reply->isDeleted() ? [] : $thread($reply->id); + $nestedMore = $nested !== [] && $hasMore($reply->id); + $followed = $index < count($replies) - 1 || $more; + + $rows[] = self::reply($reply, [ + 'lane' => $commit->lane(), + 'previousLane' => $index === 0 ? null : $replies[$index - 1]->lane(), + 'hasNext' => $followed || $nested !== [], + 'railLane' => $railLane, + 'thread' => $commit, + 'repliesInPlace' => true, + ]); + + foreach ($nested as $nestedIndex => $nestedReply) { + $rows[] = self::reply($nestedReply, [ + 'lane' => $reply->lane(), + 'previousLane' => $nestedIndex === 0 ? null : $nested[$nestedIndex - 1]->lane(), + 'hasNext' => $nestedIndex < count($nested) - 1 || $nestedMore, + 'railLane' => $railLane, + 'indent' => 32, + 'spine' => $followed ? $reply->lane() : null, + 'thread' => $reply, + 'repliesInPlace' => false, + ]); + } + + if ($nestedMore) { + $rows[] = self::more($reply->id, $nested[array_key_last($nested)]->lane(), $railLane, 32, $followed ? $reply->lane() : null); + } + } + + if ($more) { + $rows[] = self::more($commit->id, $replies[array_key_last($replies)]->lane(), $railLane); + } + + $last = array_key_last($rows); + $rows[$last]['data']['last'] = true; + + return $rows; + } + + /** + * @param array $data + * @return array{key: string, partial: string, data: array, reply: Commit} + */ + private static function reply(Commit $reply, array $data): array + { + return [ + 'key' => 'thread-reply-'.$reply->id, + 'partial' => 'native.partials.thread-reply', + 'data' => ['reply' => $reply, 'indent' => 0, 'spine' => null, 'last' => false, 'fades' => true, ...$data], + 'reply' => $reply, + ]; + } + + /** + * "Show more" at the foot of a thread, on a line down in the lane of the reply above it. + * + * @return array{key: string, partial: string, data: array, reply: null} + */ + private static function more(string $threadId, int|string $lane, int|string|null $railLane, int $indent = 0, int|string|null $spine = null): array + { + return [ + 'key' => 'thread-more-'.$threadId, + 'partial' => 'native.partials.thread-more-row', + 'data' => ['threadId' => $threadId, 'lane' => $lane, 'railLane' => $railLane, 'indent' => $indent, 'spine' => $spine, 'last' => false], + 'reply' => null, + ]; + } +} diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index f20c88a3..9fb0b843 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -39,9 +39,9 @@ * The commit opens near the top, under the commit it replies to, with the * ones before that behind "↑ N earlier commits" and its replies behind * "› N replies", each opened in place. Opened from a "› N replies" button - * ($data['replies']), its replies already show. They come five at a time + * ($data['replies']), its replies already show. They come ten at a time * (see Client::RepliesPerPage), and "Show more" under the last asks for the - * next five, as it does under a deleted reply's replies opened in place. + * next ten, as it does under a deleted reply's replies opened in place. * * It opens on the commit as it was last time, or opened from a row, on what * the row knew of it, then asks devnull for the rest behind it and fills it in. diff --git a/app/NativeComponents/Concerns/ExpandsThreads.php b/app/NativeComponents/Concerns/ExpandsThreads.php index 2a5763ce..bee2b638 100644 --- a/app/NativeComponents/Concerns/ExpandsThreads.php +++ b/app/NativeComponents/Concerns/ExpandsThreads.php @@ -2,52 +2,83 @@ namespace App\NativeComponents\Concerns; +use App\Devnull\Beat; +use App\Devnull\Client; use App\Devnull\Data\Commit; use App\Devnull\Data\Page; +use App\Devnull\ThreadRows; /** - * "› N replies" under a commit in a feed opens its replies in place, the way - * the web's thread toggle does, and "Hide replies" closes them again. One - * level deep: a reply's own replies open its page. + * Replies in a feed stay hidden until you ask for them. "N replies", on its + * own line under a commit's actions, opens its replies in place, oldest first, + * ten at a time (Client::RepliesPerPage), with "Show more" under the last for + * the next ten. Tapped again ("Hide replies") it closes them. devnull's API + * sends 50 replies a page whatever `limit` asks for, so the replies it sent + * are kept and shown ten at a time ($threadShown), and the next page is only + * asked for once they're all showing. * - * The app asks for replies oldest first, five at a time (see - * Client::RepliesPerPage). A thread opened in place shows its first five, - * and "Show more" under them opens the rest on the commit's page, with its - * replies showing. + * A reply opened in place has the same button under its own actions, which + * opens its replies in place too, one step in. A reply that deep opens its + * replies on its page. Every thread is kept by the id of the commit or reply + * it answers, so a reply's replies sit in $threads beside its commit's. * - * Under a commit devnull sends with its newest reply, "Show more" opens the - * rest in place, newest first as on the web, so they're turned round here, - * and a thread longer than a page opens the commit's page instead. + * EDGE can't animate a row coming into a list or going out of it, so replies + * fade: a page that opens is drawn see-through ($fadedRows) and drawn again + * as it should be once a Beat comes back, which every row in a thread + * animates to. Closing fades its rows out the same way, then takes them out. * * A thread opened before opens at once from the cache, and refreshes behind. */ trait ExpandsThreads { /** - * The replies of each commit opened in place, by the commit's id. + * The replies opened in place, by the id of the commit or reply they answer. * * @var array> */ public array $threads = []; /** - * Threads opened from a preview with "Show more", which read newest first. + * Where the next page of each open thread starts, by the same id, for those with more. + * + * @var array + */ + public array $threadCursors = []; + + /** + * How many of each open thread's replies show, by the same id. + * + * @var array + */ + public array $threadShown = []; + + /** + * Open threads that have had a page after their first. + * + * @var list + */ + public array $pagedThreads = []; + + /** + * Rows drawn see-through: a page about to fade in, or a thread fading out. + * A reply's row goes by its id, a thread's "Show more" by "more-" and the + * thread's id. * * @var list */ - public array $newestFirst = []; + public array $fadedRows = []; /** - * Threads opened in place with more replies than they show. + * Threads fading out, still drawn until they've faded. * * @var list */ - public array $threadsWithMore = []; + public array $closingThreads = []; public function toggleReplies(string $id): void { if (array_key_exists($id, $this->threads)) { - $this->closeThread($id); + $this->fadeOut($id); return; } @@ -56,37 +87,96 @@ public function toggleReplies(string $id): void if ($kept === null) { $this->loadThread($id); - - return; + } else { + $this->takeThread($id, $kept); + $this->refreshThread($id); } - $this->takeThread($id, $kept); - $this->refreshThread($id); + if (array_key_exists($id, $this->threads)) { + $this->threadShown[$id] = min(Client::RepliesPerPage, count($this->threads[$id])); + $this->fadeIn($this->rowsOf($id, $this->shownReplies($id))); + } } /** - * "Show more" under the newest reply: the rest of the thread, in place. + * "Show more" under an open thread: its next page, under what's showing. */ public function showMoreReplies(string $id): void { - if (array_key_exists($id, $this->threads)) { + if (! $this->isOpenThread($id)) { return; } - if (! in_array($id, $this->newestFirst, true)) { - $this->newestFirst[] = $id; + $shown = $this->threadShown[$id] ?? count($this->threads[$id]); + + if ($shown >= count($this->threads[$id]) && ! $this->loadNextPage($id)) { + return; } - $kept = $this->cached('commits/'.$id.'/replies'); + $this->threadShown[$id] = min($shown + Client::RepliesPerPage, count($this->threads[$id])); + $this->fadeIn($this->rowsOf($id, array_slice($this->threads[$id], $shown, $this->threadShown[$id] - $shown))); + } - if ($kept === null) { - $this->loadThread($id); + /** + * The replies of an open thread that show. + * + * @return list + */ + public function shownReplies(string $id): array + { + return array_slice($this->threads[$id] ?? [], 0, $this->threadShown[$id] ?? null); + } - return; + /** + * Whether an open thread has replies past those that show, kept or still to ask for. + */ + public function hasMoreReplies(string $id): bool + { + return isset($this->threadCursors[$id]) || count($this->shownReplies($id)) < count($this->threads[$id] ?? []); + } + + /** + * Asks for the page after an open thread's replies, under them. False when there's none or it didn't come. + */ + private function loadNextPage(string $id): bool + { + $cursor = $this->threadCursors[$id] ?? null; + + if ($cursor === null) { + return false; } - $this->takeThread($id, $kept); - $this->refreshThread($id); + $page = $this->attempt(fn ($devnull) => $devnull->replies($id, $cursor)); + + if ($page === null || ! $this->isOpenThread($id)) { + return false; + } + + $loaded = array_flip(array_map(fn (Commit $reply): string => $reply->id, $this->threads[$id])); + $added = array_values(array_filter($page->items, fn (Commit $reply): bool => ! isset($loaded[$reply->id]))); + + $this->threads[$id] = [...$this->threads[$id], ...$added]; + $this->keepCursor($id, $page->nextCursor); + $this->pagedThreads = array_values(array_unique([...$this->pagedThreads, $id])); + + return $added !== []; + } + + /** + * Whether a thread shows, and isn't on its way out. + */ + public function isOpenThread(string $id): bool + { + return array_key_exists($id, $this->threads) && ! in_array($id, $this->closingThreads, true); + } + + /** + * Closes every thread at once, for a list that starts again. + */ + protected function forgetThreads(): void + { + $this->threads = $this->threadCursors = $this->threadShown = $this->pagedThreads = []; + $this->fadedRows = $this->closingThreads = []; } /** @@ -103,7 +193,7 @@ private function refreshThread(string $id): void { $this->refresh('commits/'.$id.'/replies', [], function (array $json) use ($id): void { // Closed while it was on its way. - if (array_key_exists($id, $this->threads)) { + if ($this->isOpenThread($id)) { $this->takeThread($id, $json); } }); @@ -118,6 +208,9 @@ private function takeThread(string $id, array $json): void } /** + * A thread's first page, over what it showed. Pages loaded after the first + * stay, past what it holds, with their own cursor. + * * @param Page $page */ private function openThread(string $id, Page $page): void @@ -129,33 +222,111 @@ private function openThread(string $id, Page $page): void return; } - if (! in_array($id, $this->newestFirst, true)) { - $this->threads[$id] = $page->items; - $this->threadsWithMore = array_values(array_diff($this->threadsWithMore, [$id])); + // With only the first page loaded, the fresh one is the whole thread: a reply that's gone goes. + if (in_array($id, $this->pagedThreads, true)) { + $fresh = array_flip(array_map(fn (Commit $reply): string => $reply->id, $page->items)); + $later = array_values(array_filter(array_slice($this->threads[$id], count($page->items)), fn (Commit $reply): bool => ! isset($fresh[$reply->id]))); + $this->threads[$id] = [...$page->items, ...$later]; - if ($page->hasMore()) { - $this->threadsWithMore[] = $id; - } + return; + } + + $this->threads[$id] = $page->items; + $this->keepCursor($id, $page->nextCursor); + } + + private function keepCursor(string $id, ?string $cursor): void + { + unset($this->threadCursors[$id]); + + if ($cursor !== null) { + $this->threadCursors[$id] = $cursor; + } + } + /** + * Takes a thread out, and the replies opened in it. + */ + private function closeThread(string $id): void + { + foreach ($this->threads[$id] ?? [] as $reply) { + $this->closeThread($reply->id); + } + + unset($this->threads[$id], $this->threadCursors[$id], $this->threadShown[$id]); + $this->pagedThreads = array_values(array_diff($this->pagedThreads, [$id])); + $this->closingThreads = array_values(array_diff($this->closingThreads, [$id])); + } + + /** + * Draws rows see-through for a frame, then as they are, which they fade to. + * + * @param list $rows + */ + private function fadeIn(array $rows): void + { + if ($rows === []) { return; } - // More than a page: the newest replies aren't on it, so the commit's page shows them. - if ($page->hasMore()) { - $this->closeThread($id); - $this->newestFirst = array_values(array_diff($this->newestFirst, [$id])); - $this->openReplies($id); + $this->fadedRows = array_values(array_unique([...$this->fadedRows, ...$rows])); + $shown = fn () => $this->fadedRows = array_values(array_diff($this->fadedRows, $rows)); + + Beat::dispatch(Beat::Step)->finished($shown)->failed($shown); + } + + /** + * Fades a thread's rows out, and the replies opened in it, then takes them out. + */ + private function fadeOut(string $id): void + { + if (in_array($id, $this->closingThreads, true)) { return; } - $this->threads[$id] = array_reverse($page->items); + $rows = $this->rowsInside($id); + $this->closingThreads[] = $id; + $this->fadedRows = array_values(array_unique([...$this->fadedRows, ...$rows])); + + $closed = function () use ($id, $rows): void { + $this->closeThread($id); + $this->fadedRows = array_values(array_diff($this->fadedRows, $rows)); + }; + + Beat::dispatch(ThreadRows::Fade)->finished($closed)->failed($closed); } - private function closeThread(string $id): void + /** + * The rows of $replies in a thread, and its "Show more" when it has more. + * + * @param list $replies + * @return list + */ + private function rowsOf(string $id, array $replies): array + { + return [ + ...array_map(fn (Commit $reply): string => $reply->id, $replies), + ...($this->hasMoreReplies($id) ? ['more-'.$id] : []), + ]; + } + + /** + * Every row a thread draws, the replies opened inside it included. + * + * @return list + */ + private function rowsInside(string $id): array { - unset($this->threads[$id]); - $this->threadsWithMore = array_values(array_diff($this->threadsWithMore, [$id])); + $rows = $this->rowsOf($id, $this->shownReplies($id)); + + foreach ($this->shownReplies($id) as $reply) { + if (array_key_exists($reply->id, $this->threads)) { + $rows = [...$rows, ...$this->rowsInside($reply->id)]; + } + } + + return $rows; } /** diff --git a/app/NativeComponents/Concerns/HoldsNewCommits.php b/app/NativeComponents/Concerns/HoldsNewCommits.php index 25e2ef68..dd5e42fb 100644 --- a/app/NativeComponents/Concerns/HoldsNewCommits.php +++ b/app/NativeComponents/Concerns/HoldsNewCommits.php @@ -111,7 +111,7 @@ protected function putNewCommitsOnTop(): void $shown = (new FreshPage($this->commits, $this->nextCursor, $this->newCommits, $this->newCommitsReplaceList, $this->newCommitsCursor))->withNewer(); if ($this->newCommitsReplaceList) { - $this->threads = []; + $this->forgetThreads(); $this->replacedList(); } diff --git a/app/NativeComponents/Concerns/PopsReactions.php b/app/NativeComponents/Concerns/PopsReactions.php new file mode 100644 index 00000000..3683ebd5 --- /dev/null +++ b/app/NativeComponents/Concerns/PopsReactions.php @@ -0,0 +1,59 @@ + + */ + public array $popping = []; + + protected function pop(string $button): void + { + $this->popping[$button] = Pop::Ready; + + $this->popStep($button, Pop::Ready, Pop::Up, Beat::Step, fn () => $this->popStep($button, Pop::Up, Pop::Down, 150, fn () => $this->popStep($button, Pop::Down, null, 400))); + } + + /** + * Moves $button from $from to $to after $wait milliseconds, unless a tap since started it again. + */ + private function popStep(string $button, string $from, ?string $to, int $wait, ?\Closure $then = null): void + { + $step = function () use ($button, $from, $to, $then): void { + if (($this->popping[$button] ?? null) !== $from) { + return; + } + + if ($to === null) { + unset($this->popping[$button]); + + return; + } + + $this->popping[$button] = $to; + + if ($then !== null) { + $then(); + } + }; + + Beat::dispatch($wait)->finished($step)->failed($step); + } +} diff --git a/app/NativeComponents/Concerns/ShowsCommits.php b/app/NativeComponents/Concerns/ShowsCommits.php index 05407927..19ce6212 100644 --- a/app/NativeComponents/Concerns/ShowsCommits.php +++ b/app/NativeComponents/Concerns/ShowsCommits.php @@ -45,6 +45,7 @@ trait ShowsCommits use OpensCommitSheet; use OpensHashtags; use OpensStargazers; + use PopsReactions; use VotesOnPolls; use WritesInBackground; @@ -223,6 +224,11 @@ public function toggleStar(string $id): void $this->showStar($id, ! $commit->starred); $this->queueStar($id, ! $commit->starred); + + // The web only pops a star going on. + if (! $commit->starred) { + $this->pop('star-'.$id); + } } /** @@ -250,6 +256,7 @@ public function givePastel(string $id): void app(Account::class)->rememberPasteis($pasteis->afterGiving()); $this->changeShownCommit($id, fn (Commit $shown): Commit => $shown->withMorePasteis(1)); + $this->pop('pastel-'.$id); $this->writeInBackground('POST', Client::pastelPath($id), null, fn (array $json) => $this->pastelGiven($id, $json), function (string $message, ?ApiException $exception = null) use ($id): void { $this->pastelTurnedDown($id, $exception); diff --git a/app/NativeComponents/Log.php b/app/NativeComponents/Log.php index 050e79e2..e99f8fe4 100644 --- a/app/NativeComponents/Log.php +++ b/app/NativeComponents/Log.php @@ -412,7 +412,7 @@ private function switchTo(string $log): void private function openAfresh(): void { $this->commits = []; - $this->threads = []; + $this->forgetThreads(); $this->latestCommits = []; $this->suggestions = []; $this->rankedSince = null; @@ -959,7 +959,7 @@ private function takeRanking(string $log, array $json, bool $prefetch = true): v $this->commits = $page->items; $this->nextCursor = $page->nextCursor; $this->latestCommits = []; - $this->threads = []; + $this->forgetThreads(); $this->rankedSince = is_string($json['newest_commit_id'] ?? null) ? $json['newest_commit_id'] : null; $this->forgetNewCommits(); $this->keepStagedOnTop(); diff --git a/app/NativeComponents/Organization.php b/app/NativeComponents/Organization.php index c2f3718c..4531c108 100644 --- a/app/NativeComponents/Organization.php +++ b/app/NativeComponents/Organization.php @@ -296,7 +296,7 @@ private function switchTo(string $tab): void $this->tab = $tab; $this->listKey = $this->listKeys[$tab] ?? 0; $this->commits = []; - $this->threads = []; + $this->forgetThreads(); $this->nextCursor = null; $this->commitsLoaded = false; $this->commitsFailed = false; diff --git a/app/NativeComponents/Profile.php b/app/NativeComponents/Profile.php index d4c1e690..4f19fc52 100644 --- a/app/NativeComponents/Profile.php +++ b/app/NativeComponents/Profile.php @@ -300,7 +300,7 @@ private function switchTo(string $tab): void $this->tab = $tab; $this->listKey = $this->listKeys[$tab] ?? 0; $this->commits = []; - $this->threads = []; + $this->forgetThreads(); $this->nextCursor = null; $this->commitsLoaded = false; $this->forgetNewCommits(); @@ -732,7 +732,7 @@ private function showBlocked(): void private function forgetShownCommits(): void { $this->commits = []; - $this->threads = []; + $this->forgetThreads(); $this->nextCursor = null; $this->forgetNewCommits(); } diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index c633a3d0..4eda3db3 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -19,10 +19,10 @@ behind "↑ N earlier commits", since EDGE can't open the page scrolled down to the commit. Opened, the ancestors, the commit and the rest of its series share one rail, so someone replying to themselves shows their avatar once. The replies hang under it on the thread's dashed lines, with the rail ending in a dot - above them, five at a time with "Show more" under the last. A part of a series with more parts after it + above them, ten at a time with "Show more" under the last. A part of a series with more parts after it has its replies right under it, beside the rail running on, and the later parts follow. Everything around the commit is muted, and still opens its own page. A deleted reply's own replies open in place, - one level in, five at a time too, since a deleted commit has no page. + one level in, ten at a time too, since a deleted commit has no page. --}} @if ($earlierCount > 0) @include('native.partials.earlier-commits', ['count' => $earlierCount, 'lane' => $earlierLane]) diff --git a/resources/views/native/partials/commit-actions.blade.php b/resources/views/native/partials/commit-actions.blade.php index 5c86cf74..9f0e361d 100644 --- a/resources/views/native/partials/commit-actions.blade.php +++ b/resources/views/native/partials/commit-actions.blade.php @@ -1,29 +1,31 @@ {{-- The action row under a commit, in the web's order. On the left: the star and its count, in pastéis mode the pastel - and its count, Quote, Reply, and in Commit Blue "› N replies" when the row has no thread under it already. On the - right: More. + and its count, Quote and Reply, each with its label. On the right: More. Under the row, on a line of its own, the + replies button: "› N replies" in Commit Blue, or "Hide replies" with the chevron turned down while they show. Share link, Report and Delete live in More, which opens the platform's own menu (a UIMenu on iOS, a dropdown on Android, see CommitMenu for what's in it). Tapping More only opens the menu. - Reply opens the commit with its reply composer focused. In a feed ($expandable) the replies link opens the thread in - place, as on the web; elsewhere it opens the commit with its replies showing. Like the web, someone else's commit - that isn't approved gets no star or Quote. devnull doesn't let you star your own commits, so on those the star is - the count, which opens who starred it (see OpensStargazers), or a faint star until there are any, as on the web. + Reply opens the commit with its reply composer focused. In a feed ($expandable) the replies button opens the replies + in place, as on the web (see Concerns\ExpandsThreads); elsewhere it opens the commit with its replies showing. Like + the web, someone else's commit that isn't approved gets no star or Quote. devnull doesn't let you star your own + commits, so on those the star is the count, which opens who starred it (see OpensStargazers), or a faint star until + there are any, as on the web. Quote opens a sheet to write the quote in, over the commit being quoted (see commit-sheet). The pastel is the web's: the pastel de nata and how many the commit was given, always, even 0. On someone else's published commit it gives one more per tap; on your own, or one that isn't published, it's just the count. It - only shows in pastéis mode ($pasteis). + only shows in pastéis mode ($pasteis). A star you give and a pastel pop as they do on the web (see PopsReactions). A commit with a quote or a reply you started and didn't send marks that button, as the web does with stash@{0} - beside its label. That doesn't fit the row, so here it's a dot after the icon or label, inside the button's 44pt. + beside its label. That doesn't fit the row, so here it's a dot after the label, inside the button. The screen passes the names of the drafts it has kept ($stashed, see App\Devnull\Stash). - Each action is at least 44pt wide and 36pt tall to tap, as Apple asks, with the row pulled in by the extra height so - the commit keeps its rhythm. EDGE makes a pressable's whole box tappable, so the box is the target. Off the log, - "› N replies" sits beside Reply, and both won't fit on a phone with their labels, so Reply is just its icon there. + Each action is at least 44pt wide and 36pt tall to tap, as Apple asks. The row has no negative vertical margins: + Android draws a negative margin as an offset and keeps the space, so the row sat 6pt lower there than on iOS, and + with it everything placed against it. $endDot draws the end of the commit's rail, a lane dot, inside the row at the + rail's x, so it's level with the actions whatever is above or below them (see commit-row-content). A button is the pressable itself, laid out as a row, with no row inside it, since a list builds and measures every node of a row as it scrolls in. More keeps its column: a pressable with a menu draws its content as the menu's @@ -38,7 +40,7 @@ @php($withQuote ??= true) @php($compact ??= false) @php($expandable ??= isset($threads)) -@php($isOpen = $repliesOpen ?? ($expandable && array_key_exists($commit->id, $threads))) +@php($isOpen = $repliesOpen ?? ($expandable && array_key_exists($commit->id, $threads) && ! in_array($commit->id, $closingThreads ?? [], true))) @php($repliesPress = $repliesToggle ?? ($expandable ? "toggleReplies('{$commit->id}')" : "openReplies('{$commit->id}')")) @php($repliesCount ??= $commit->repliesCount) @php($iconSize = $compact ? 14 : 16) @@ -49,17 +51,19 @@ @php($hasReplyStash = in_array('reply-'.$commit->id, $stashed, true)) @php($isOwn = $commit->author->id === $viewer?->id) @php($canQuote = $commit->isApproved() || $isOwn) -@php($hasThread = $expandable && $commit->replyPreview !== null) -@php($showsReplies = $withReplies && ! $hasThread && $repliesCount > 0) +@php($showsReplies = $withReplies && ! $commit->isDeleted() && $repliesCount > 0) +@php($endDot ??= null) +@php($starPop = \App\Devnull\Pop::transform($popping['star-'.$commit->id] ?? null, 'star')) +@php($pastelPop = \App\Devnull\Pop::transform($popping['pastel-'.$commit->id] ?? null, 'pastel')) @php($pasteis ??= app(\App\Devnull\Account::class)->pasteis()) @php($canGivePastel = $pasteis !== null && $viewer !== null && ! $isOwn && $commit->isApproved()) @php($pastelLabel = \App\Devnull\Display::count($commit->pasteisCount, 'pastel', 'pastéis')) @php($pastelSize = $compact ? 18 : 20) @php($starLabel = ($commit->starred ? 'Unstar commit' : 'Star commit').($commit->starsCount > 0 ? ', '.\App\Devnull\Display::count($commit->starsCount, 'star', 'stars') : '')) - + @if ($commit->isApproved() && ! $isOwn && $viewer !== null && ! $commit->isDeleted()) - + @if ($commit->starsCount > 0) {{ \App\Devnull\Display::compactCount($commit->starsCount) }} @endif @@ -77,7 +81,7 @@ @if ($canGivePastel) - + {{ \App\Devnull\Display::compactCount($commit->pasteisCount) }} @elseif ($pasteis !== null) @@ -88,38 +92,25 @@ @endif @if ($withQuote && $canQuote) - + + Quote @if ($hasQuoteStash) - + @endif @endif @if ($withReply) - + - @unless ($showsReplies) - Reply - @endunless + Reply @if ($hasReplyStash) @endif @endif - @if ($showsReplies) - - @if ($isOpen) - - Hide replies - @else - - {{ \App\Devnull\Display::count($repliesCount, 'reply', 'replies') }} - @endif - - @endif - @@ -127,4 +118,16 @@ + + @if ($endDot !== null) + {{-- The end of the rail, at its x: the row starts 8pt into the 64pt gutter's edge, and the dot is 18pt round. --}} + @include('native.partials.rail-node', ['lane' => $endDot, 'nodeRef' => 'end-dot', 'position' => 'absolute top-[9] -left-[33]']) + @endif + +@if ($showsReplies) + + + {{ $isOpen ? 'Hide replies' : \App\Devnull\Display::count($repliesCount, 'reply', 'replies') }} + +@endif diff --git a/resources/views/native/partials/commit-row-content.blade.php b/resources/views/native/partials/commit-row-content.blade.php index 553ac21e..8e3c8ea5 100644 --- a/resources/views/native/partials/commit-row-content.blade.php +++ b/resources/views/native/partials/commit-row-content.blade.php @@ -4,8 +4,11 @@ after it links to them, as the web's "2 more commits in this series" does. $withTail runs the rail on below. In a feed, $continuesNext says whether the author's run goes on in the next row. The rail then runs on, or for a - commit alone in its run ends in a dot of its own, and with replies under the row ($threadBelow) a dashed line in - the lane carries on down to them, as the web draws it. + commit alone in its run ends in a dot of its own, level with the action row, and with replies open under the row + ($threadBelow) a dashed line in the lane carries on down from the dot to them, as the web draws it. The dot is drawn + inside the action row (see commit-actions), so it's level with it whatever the body, images or replies line above + and below. Only the rail's lines are placed from the row's bottom, to meet it, and every height under the action + row is fixed here, so they meet it on both platforms. On a commit page the commit it's about ($focused) is the main thing: a larger name and body in full ink, its time, which tapped says when in your timezone, its hash, and its replies behind a toggle in its action row. The commits around it ($muted) step back: @@ -30,7 +33,11 @@ @php($laterParts = $seriesExpanded ? 0 : $commit->laterSeriesParts()) @php($hasHairline = $hairline && ! $threadBelow) @php($inset = $focused ? 16 : 12) -@php($padding = 'pt-['.$inset.']'.($threadBelow ? '' : ' pb-['.($hasHairline ? $inset + 1 : $inset).']')) +{{-- The action row's 36pt reaches 6pt into the inset below it, as its buttons are taller than their icons. --}} +@php($bottom = $threadBelow ? 0 : $inset - 6 + ($hasHairline ? 1 : 0)) +@php($padding = 'pt-['.$inset.']'.($bottom > 0 ? ' pb-['.$bottom.']' : '')) +@php($repliesLine = ! $commit->isStaged() && ! $commit->isDeleted() && ($focused ? ($replyCount ?? $commit->repliesCount) : $commit->repliesCount) > 0 ? 40 : 0) +@php($dotInActions = $endsWithDot && ! $commit->isStaged()) @php($metaSize = $muted ? 'text-xs' : 'text-[13px]') @@ -86,9 +93,10 @@ 'repliesToggle' => 'toggleReplies', 'repliesOpen' => $repliesShown ?? false, 'repliesCount' => $replyCount ?? $commit->repliesCount, + 'endDot' => $dotInActions ? $commit->lane() : null, ]) @else - @include('native.partials.commit-actions', ['compact' => $muted]) + @include('native.partials.commit-actions', ['compact' => $muted, 'endDot' => $dotInActions ? $commit->lane() : null]) @endif @@ -97,6 +105,10 @@ 'lane' => $commit->lane(), 'tail' => ($inFeed ? $continuesNext || ! $continuesRun : $withTail) ? $commit->lane() : null, 'endsWithDot' => $endsWithDot, + // The middle of the action row, where the rail's end dot is, above the row's bottom: its padding, the replies + // line under the actions (4pt gap and 36pt) and half the row. + 'endDotAt' => $bottom + $repliesLine + 18, + 'dotInActions' => $dotInActions, 'replyTail' => $threadBelow && ! ($inFeed && $continuesNext), 'node' => $continuesRun ? 'dot' : 'avatar', 'avatarSize' => $muted ? 36 : 48, diff --git a/resources/views/native/partials/feed.blade.php b/resources/views/native/partials/feed.blade.php index c85258e0..74d9e1da 100644 --- a/resources/views/native/partials/feed.blade.php +++ b/resources/views/native/partials/feed.blade.php @@ -1,9 +1,9 @@ {{-- A feed's rows from App\Devnull\Timeline: day markers, the last-visit marker, who to follow ($whoToFollow, see - partials/who-to-follow) and commits on the rail. Under a commit hangs its thread, inside its row's hairline, as on - the web: the newest reply devnull previews, with "Show more" when there are others, or the replies opened in place, - with "Show more" to the commit's page when there are more than they show. The commit's rail runs on past them when - its author's run goes on below. + partials/who-to-follow) and commits on the rail. A commit's replies stay hidden until its replies button opens them + in place (see Concerns\ExpandsThreads). Then its thread hangs under it, inside its row's hairline, a page at a time + with "Show more" under the last, and a reply's own replies opened under it one step in (see App\Devnull\ThreadRows). + The commit's rail runs on past them when its author's run goes on below. Given a $rowCache (see App\Devnull\RowCache), commits and replies that haven't changed since the last frame are drawn from it rather than built again. Given a $rowWindow (see App\Devnull\RowWindow), rows far from the screen @@ -42,20 +42,14 @@ @else @php $feedCommit = $row->commit; - $opened = $threads[$feedCommit->id] ?? null; - $threadReplies = $opened ?? ($feedCommit->isDeleted() ? [] : $feedCommit->replyPreview?->replies ?? []); - $feedDraws = $rowWindow?->place($feedIndex, 1 + count($threadReplies)) ?? true; - $hasMoreReplies = $opened === null - ? ! $feedCommit->isDeleted() && ($feedCommit->replyPreview?->hasMore ?? false) - : in_array($feedCommit->id, $threadsWithMore ?? [], true); - $morePress = $opened === null ? "showMoreReplies('{$feedCommit->id}')" : "openReplies('{$feedCommit->id}')"; - $railLane = $row->continuesNext ? $feedCommit->lane() : null; + $threadRows = $feedCommit->isDeleted() ? [] : \App\Devnull\ThreadRows::under($feedCommit, $threads ?? [], $threadCursors ?? [], $threadShown ?? [], $row->continuesNext ? $feedCommit->lane() : null); + $feedDraws = $rowWindow?->place($feedIndex, 1 + count($threadRows)) ?? true; $commitRow = [ 'commit' => $feedCommit, 'previousLane' => $row->previousLane, 'continuesRun' => $row->continuesRun, 'continuesNext' => $row->continuesNext, - 'threadBelow' => $threadReplies !== [], + 'threadBelow' => $threadRows !== [], ]; @endphp @if (! $feedDraws) @@ -70,29 +64,17 @@ $rowCache->include('commit-'.$feedCommit->id, \App\Devnull\RowInputs::for($feedCommit, $rowScope), 'native.partials.commit-row', $commitRow, $rowScope); @endphp @endif - @foreach ($threadReplies as $index => $threadReply) - @php - $replyRow = [ - 'reply' => $threadReply, - 'lane' => $feedCommit->lane(), - 'previousLane' => $index === 0 ? null : $threadReplies[$index - 1]->lane(), - 'hasNext' => ! $loop->last || $hasMoreReplies, - 'railLane' => $railLane, - 'thread' => $feedCommit, - 'more' => $loop->last && $hasMoreReplies ? $morePress : null, - 'last' => $loop->last, - ]; - @endphp + @foreach ($threadRows as $threadRow) @if (! $feedDraws) @php - $rowWindow->placeholder('thread-reply-'.$threadReply->id); + $rowWindow->placeholder($threadRow['key']); @endphp - @elseif ($rowCache === null) - @include('native.partials.thread-reply', $replyRow) + @elseif ($rowCache === null || $threadRow['reply'] === null) + @include($threadRow['partial'], $threadRow['data']) @else @php $rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]); - $rowCache->include('reply-'.$threadReply->id, \App\Devnull\RowInputs::for($threadReply, $rowScope), 'native.partials.thread-reply', $replyRow, $rowScope); + $rowCache->include('reply-'.$threadRow['reply']->id, \App\Devnull\RowInputs::for($threadRow['reply'], $rowScope), $threadRow['partial'], $threadRow['data'], $rowScope); @endphp @endif @endforeach diff --git a/resources/views/native/partials/rail.blade.php b/resources/views/native/partials/rail.blade.php index f64abf05..3af56dbd 100644 --- a/resources/views/native/partials/rail.blade.php +++ b/resources/views/native/partials/rail.blade.php @@ -10,7 +10,8 @@ 'tombstone' a dashed Rail Gray ring where a deleted commit's avatar was 'skeleton' a wash disc, for a row still loading null no node; a $previous segment then runs the full height of the row - $endsWithDot stops the $tail 20pt above the bottom at a lane dot, as the web ends a commit that's alone in its run. + $endsWithDot stops the $tail at a lane dot $endDotAt above the bottom (its middle), as the web ends a commit that's + alone in its run. A commit row draws that dot in its action row ($dotInActions), so the rail only runs to it. $replyTail runs a dashed line in the lane on down from the node, or from that dot, to the replies under the row. $avatarSize draws the avatar's ring smaller than its 48pt, centred in the same place. --}} @@ -23,7 +24,8 @@ @php($replyTail ??= false) @php($avatarSize ??= 48) @php($center = 32) -@php($endDot = 20) +@php($endDotAt ??= 20) +@php($dotInActions ??= false) @php($segment = fn (int|string $lane): string => 'bg-theme-'.\App\Devnull\Lane::token($lane)) @if ($node === null) @@ -41,18 +43,19 @@ @endforeach @elseif ($tail !== null) - {{-- `bottom-0`, never `bottom-[0]`: EDGE reads an arbitrary zero inset as no inset, which leaves the tail no height. --}} - + {{-- `bottom-0`, never `bottom-[0]`: EDGE reads an arbitrary zero inset as no inset, which leaves the tail no height. + Ending at a dot, it stops 2pt into the dot's ring, which is in the same lane, so no gap shows. --}} + @endif @if ($replyTail && $endsWithDot) - @include('native.partials.dashed-line', ['position' => 'bottom-0 h-['.$endDot.']', 'left' => 31.5, 'lane' => $lane]) + @include('native.partials.dashed-line', ['position' => 'bottom-0 h-['.($endDotAt - 9).']', 'left' => 31.5, 'lane' => $lane]) @elseif ($replyTail) @include('native.partials.dashed-line', ['position' => 'top-['.($node === 'dot' ? $center - 9 : $center).'] bottom-0', 'left' => 31.5, 'lane' => $lane]) @endif - @if ($endsWithDot && $tail !== null) - @include('native.partials.rail-node', ['lane' => $tail, 'nodeRef' => 'end-dot', 'position' => 'absolute bottom-['.($endDot - 9).'] left-[23]']) + @if ($endsWithDot && $tail !== null && ! $dotInActions) + @include('native.partials.rail-node', ['lane' => $tail, 'nodeRef' => 'end-dot', 'position' => 'absolute bottom-['.($endDotAt - 9).'] left-[23]']) @endif {{-- The node itself takes its place on the rail, or the pressable around it does: no wrapper just to position it. --}} diff --git a/resources/views/native/partials/thread-more-row.blade.php b/resources/views/native/partials/thread-more-row.blade.php new file mode 100644 index 00000000..d35dc8f2 --- /dev/null +++ b/resources/views/native/partials/thread-more-row.blade.php @@ -0,0 +1,33 @@ +{{-- + "Show more" at the foot of a thread opened in a feed (see App\Devnull\ThreadRows), as a list row of its own: a muted + rail dot where the next avatar would be, on the dashed line down from the reply above ($lane), and the words. + Tapped, the thread's next page opens under what's showing. $indent puts it one step in, under a reply's own replies. + + It's 44pt tall, as tall as the list's shortest row, so the list never pads it out under its hairline. The dot sits + in its middle, so the line from above stops at the top of the dot, 13pt down. +--}} +@php($indent ??= 0) +@php($spine ??= null) +@php($railLane ??= null) +@php($faded = in_array('more-'.$threadId, $fadedRows ?? [], true)) + + + + + + + + + + + Show more + + + @if ($railLane !== null) + @include('native.partials.rail', ['previous' => $railLane]) + @endif + @if ($spine !== null) + @include('native.partials.dashed-line', ['position' => 'top-0 bottom-0', 'left' => 75.5, 'lane' => $spine]) + @endif + @include('native.partials.dashed-line', ['position' => 'top-0 h-[13]', 'left' => 75.5 + $indent, 'lane' => $lane]) + diff --git a/resources/views/native/partials/thread-reply.blade.php b/resources/views/native/partials/thread-reply.blade.php index 6a1d0a7c..b93ec9b0 100644 --- a/resources/views/native/partials/thread-reply.blade.php +++ b/resources/views/native/partials/thread-reply.blade.php @@ -17,6 +17,11 @@ A commit page draws its replies $muted, smaller and in muted ink, so the commit they answer stays the main thing. A reply you just sent that devnull doesn't have yet is staged: dimmed, with the staged chip and no actions. + + In a feed a reply's replies button opens them under it ($repliesInPlace, see App\Devnull\ThreadRows); deeper in, + or on a commit page, it opens the reply's page. A feed's thread rows fade in as they open and out as they close + ($fades): drawn see-through and nudged up while they're in $fadedRows (see Concerns\ExpandsThreads), and eased + to where they belong. Only what's beside the rail fades, so the commit's rail running past never blinks. --}} @php($previousLane ??= null) @php($muted ??= false) @@ -26,11 +31,14 @@ @php($tombstones ??= false) @php($more ??= null) @php($avatarLine = 76 + $indent) +@php($repliesInPlace ??= false) +@php($fades ??= false) +@php($faded = $fades && in_array($reply->id, $fadedRows ?? [], true)) @if ($reply->isDeleted()) @php($opened = $tombstones && array_key_exists($reply->id, $tombstoneReplies ?? [])) - + @include('native.partials.dashed-ring', ['size' => 24, 'lane' => \App\Devnull\Lane::Rail]) @@ -67,7 +75,7 @@ - + @include('native.partials.rail-avatar', ['user' => $reply->author, 'lane' => $reply->lane(), 'size' => 24, 'staged' => false]) @@ -84,7 +92,7 @@ @include('native.partials.commit-body', ['size' => $muted ? 'text-sm' : 'text-[15px]']) @include('native.partials.commit-media', ['withEmbeds' => false]) @unless ($reply->isStaged()) - @include('native.partials.commit-actions', ['expandable' => false, 'withQuote' => false, 'compact' => $muted]) + @include('native.partials.commit-actions', ['expandable' => $repliesInPlace, 'withQuote' => false, 'compact' => $muted]) @endunless diff --git a/tests/Feature/Screens/CommitCardTest.php b/tests/Feature/Screens/CommitCardTest.php index 067cf306..966269ce 100644 --- a/tests/Feature/Screens/CommitCardTest.php +++ b/tests/Feature/Screens/CommitCardTest.php @@ -105,10 +105,12 @@ function logOf(array $commits): TestableComponent expect($target($ref))->toMatchArray(['min_width' => 44.0, 'height' => 36.0]); } + // The row takes its full 36pt, with no negative margins above or below, which Android draws as an offset and keeps + // the space of. The padding under it takes back the 6pt its buttons reach past their icons. expect($target('reply-to-c1')['height'])->toBe(36.0) ->and($target('replies-c1')['height'])->toBe(36.0) - // 6pt more above and below than the 24pt the row used to be, so it's pulled in by that much. - ->and(array_slice(nodeByRef($screen, 'actions-c1')['layout']['margin'], 0, 3))->toBe([-6.0, 0.0, -6.0]); + ->and(nodeByRef($screen, 'actions-c1')['layout']['height'])->toBe(36.0) + ->and(array_slice(nodeByRef($screen, 'actions-c1')['layout']['margin'] ?? [0.0, 0.0, 0.0], 0, 3))->toBe([0.0, 0.0, 0.0]); }); it('builds a row from as few views as it can, as a list builds and measures each of them while it scrolls', function () { @@ -122,7 +124,8 @@ function logOf(array $commits): TestableComponent ->and($content['layout']['margin'])->toBe([0.0, 0.0, 0.0, 64.0]) ->and($content['props']['border_b'])->toBe(1.0) ->and(array_column(nodeByRef($screen, 'star-c1')['children'], 'type'))->toBe(['icon', 'text']) - ->and(count(findNodes($row, fn (): bool => true)))->toBeLessThanOrEqual(35); + // Quote's label, and the end of the rail drawn in the action row, came to two more. + ->and(count(findNodes($row, fn (): bool => true)))->toBeLessThanOrEqual(37); }); it("draws a poll you haven't voted on as plain options, with nothing to tap, since the app can't vote yet", function () { diff --git a/tests/Feature/Screens/CommitDetailCacheTest.php b/tests/Feature/Screens/CommitDetailCacheTest.php index b864b63e..145eaedf 100644 --- a/tests/Feature/Screens/CommitDetailCacheTest.php +++ b/tests/Feature/Screens/CommitDetailCacheTest.php @@ -144,6 +144,6 @@ function serveThread(): void $screen->call('load'); - Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/d1/replies?limit=5'); + Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/d1/replies?limit=10'); $screen->assertSee('Under a deleted reply'); }); diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index fc0da284..d1e271be 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -431,36 +431,36 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->assertSee('Hide replies'); }); -it('asks for the replies five at a time, and the next five from Show more', function () { +it('asks for the replies a page at a time, and the next page from Show more', function () { $replies = fn (int ...$numbers): array => array_map(fn (int $n): array => replyJson(['id' => "r{$n}", 'parent_id' => 'c2', 'body' => "Reply {$n}"]), $numbers); Http::fake(fn (Request $request) => match (parse_url($request->url(), PHP_URL_PATH)) { '/api/v1/commits/c2/replies' => Http::response(str_contains($request->url(), 'cursor=page2') - ? pageJson($replies(6)) - : pageJson($replies(1, 2, 3, 4, 5), 'page2', 'http://devnull.test/api/v1/commits/c2/replies')), + ? pageJson($replies(11)) + : pageJson($replies(...range(1, 10)), 'page2', 'http://devnull.test/api/v1/commits/c2/replies')), '/api/v1/commits/c2/related' => Http::response(['data' => []]), - default => Http::response(commitPageJson(commitJson(['id' => 'c2', 'body' => 'The focused commit', 'replies_count' => 6]))), + default => Http::response(commitPageJson(commitJson(['id' => 'c2', 'body' => 'The focused commit', 'replies_count' => 11]))), }); $screen = Native::visit('/log/commits/c2', ['replies' => true]) - ->assertSee('Reply 5') - ->assertDontSee('Reply 6') + ->assertSee('Reply 10') + ->assertDontSee('Reply 11') ->tap('more-replies-c2') - ->assertSee('Reply 6') + ->assertSee('Reply 11') ->assertDontSee('Show more'); $asked = collect(Http::recorded())->map(fn (array $sent): string => $sent[0]->url())->filter(fn (string $url): bool => str_contains($url, '/replies')); expect($asked)->toHaveCount(2) - ->and($asked->every(fn (string $url): bool => str_contains($url, 'limit=5')))->toBeTrue(); + ->and($asked->every(fn (string $url): bool => str_contains($url, 'limit=10')))->toBeTrue(); - // Asking again for the first five keeps the one loaded after them. + // Asking again for the first page keeps the one loaded after it. $screen->call('load') - ->assertSee('Reply 6') + ->assertSee('Reply 11') ->assertDontSee('Show more'); }); -it('opens the replies of a deleted reply five at a time too', function () { +it('opens the replies of a deleted reply a page at a time too', function () { $nested = fn (int ...$numbers): array => array_map(fn (int $n): array => replyJson(['id' => "n{$n}", 'parent_id' => 'r1', 'body' => "Nested {$n}"]), $numbers); Http::fake(fn (Request $request) => match (parse_url($request->url(), PHP_URL_PATH)) { @@ -486,7 +486,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->assertSee('Nested 6') ->assertMissingElement('pressable', $more); - Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/r1/replies?cursor=page2&limit=5'); + Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/r1/replies?cursor=page2&limit=10'); }); it('keeps deleted ancestors on the rail as tombstones', function () { diff --git a/tests/Feature/Screens/DraftStashTest.php b/tests/Feature/Screens/DraftStashTest.php index 46baedf4..9a608c78 100644 --- a/tests/Feature/Screens/DraftStashTest.php +++ b/tests/Feature/Screens/DraftStashTest.php @@ -272,7 +272,7 @@ function stashLabel(TestableComponent $screen, string $ref): array $screen = Native::visit('/log', platform: 'ios'); // The dots sit inside the buttons, so the row has the same actions as without them. - expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'pastel-c2', 'quote-c2', 'reply-to-c2', 'replies-c2', 'more-c2']) + expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'pastel-c2', 'quote-c2', 'reply-to-c2', 'more-c2']) ->and(array_values(array_filter(childRefs($screen, 'actions-c1'))))->toBe(['star-c1', 'pastel-c1', 'quote-c1', 'reply-to-c1', 'more-c1']) ->and(showsRef($screen, 'quote-stash-c2'))->toBeTrue() ->and(showsRef($screen, 'reply-stash-c2'))->toBeTrue() diff --git a/tests/Feature/Screens/LogTest.php b/tests/Feature/Screens/LogTest.php index c0222442..ffc354b0 100644 --- a/tests/Feature/Screens/LogTest.php +++ b/tests/Feature/Screens/LogTest.php @@ -437,7 +437,7 @@ ], ]); -it('puts the web action row under each commit: the star, Quote, Reply and replies, then More', function () { +it('puts the web action row under each commit: the star, Quote, Reply, then More, with the replies on a line below', function () { $ada = userJson(['id' => 'u2', 'handle' => 'ada']); Http::fake(['devnull.test/*' => Http::response(pageJson([ @@ -458,8 +458,9 @@ // Someone else's pending commit can't be starred or quoted, so the web leaves them off. ->assertMissingElement('pressable', fn (array $node): bool => in_array($node['ref'] ?? null, ['star-c0', 'quote-c0'], true)); - // The web's order: star, Quote, Reply and replies on the left, then More for Share link and Report. - expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'quote-c2', 'reply-to-c2', 'replies-c2', 'more-c2']) + // The web's order: star, Quote and Reply on the left, then More for Share link and Report. The replies are under them. + expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'quote-c2', 'reply-to-c2', 'more-c2']) + ->and(findNode(nodeByRef($screen, 'actions-c2'), fn (array $node): bool => ($node['ref'] ?? null) === 'replies-c2'))->toBeNull() // Nor can it be reported, so all its menu has is the link. ->and(menuItems($screen, 'more-c0'))->toBe([['share-c0', 'Share link', 'custom:link']]); @@ -475,6 +476,8 @@ ->and($icon('reply-to-c1')['props']['name'] ?? null)->toBe('custom:message-square-reply') ->and($icon('replies-c2')['props']['name'] ?? null)->toBe('custom:chevron-right') ->and($text('replies-c2', '1 reply')['props']['color'] ?? null)->toBe($primary) + ->and($text('quote-c1', 'Quote'))->not->toBeNull() + ->and($text('reply-to-c1', 'Reply'))->not->toBeNull() ->and($icon('more-c1')['props']['name'] ?? null)->toBe('custom:ellipsis') ->and($icon('more-c1')['props']['color'] ?? null)->toBe($muted); @@ -607,7 +610,11 @@ ->assertSee('This commit was deleted.') ->assertSee('Hide replies'); - expect(findNode(nodeByRef($screen, 'replies-c2'), fn (array $node): bool => ($node['type'] ?? null) === 'icon')['props']['name'] ?? null)->toBe('custom:chevron-down'); + // The chevron turns down, which the phone animates. + $chevron = findNode(nodeByRef($screen, 'replies-c2'), fn (array $node): bool => ($node['type'] ?? null) === 'icon'); + expect($chevron['props']['name'] ?? null)->toBe('custom:chevron-right') + ->and($chevron['props']['rotate'] ?? null)->toBe(90.0) + ->and($chevron['props']['animate-duration'] ?? null)->toBeGreaterThan(0.0); // Its replies get the same actions, and open their own page. $screen->tap('star-r1'); @@ -618,24 +625,29 @@ Native::visit('/log')->tap('replies-c2')->tap('thread-reply-r1')->assertNavigatedTo('/log/commits/r1'); }); -it('opens five replies of a thread in place, and the rest on its commit page from Show more', function () { - fakeApi([ - 'GET /api/v1/log/following' => [pageJson([commitJson(['id' => 'c2', 'replies_count' => 7])])], - 'GET /api/v1/commits/c2/replies' => [pageJson(array_map(fn (int $n): array => replyJson(['id' => "r{$n}", 'parent_id' => 'c2', 'body' => "Reply {$n}"]), range(1, 5)), 'page2', 'http://devnull.test/api/v1/commits/c2/replies')], - 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2', 'replies_count' => 7]))], - ]); +it('opens ten replies of a thread in place, and the next ten under them from Show more', function () { + $replies = fn (int $from, int $to): array => array_map(fn (int $n): array => replyJson(['id' => "r{$n}", 'parent_id' => 'c2', 'body' => "Reply {$n}"]), range($from, $to)); + + Http::fake(fn (Request $request) => Http::response(match (true) { + str_contains($request->url(), '/log/following') => pageJson([commitJson(['id' => 'c2', 'replies_count' => 13])]), + str_contains($request->url(), 'cursor=page2') => pageJson($replies(11, 13), path: 'http://devnull.test/api/v1/commits/c2/replies'), + default => pageJson($replies(1, 10), 'page2', 'http://devnull.test/api/v1/commits/c2/replies'), + })); - Native::visit('/log', platform: 'ios') + $screen = Native::visit('/log', platform: 'ios') ->tap('replies-c2') ->assertNoNavigation() - ->assertSee('Reply 5') + ->assertSee('Reply 10') + ->assertDontSee('Reply 11') ->tap('more-replies-c2') - ->assertNavigatedTo('/log/commits/c2') - ->follow() - ->assertSet('repliesShown', true) - ->assertSee('Reply 5'); + ->assertNoNavigation() + ->assertSee('Reply 13') + ->assertDontSee('Show more'); + + expect(array_map(fn ($reply): string => $reply->id, $screen->instance()->threads['c2']))->toBe(array_map(fn (int $n): string => "r{$n}", range(1, 13))); - Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/c2/replies?limit=5'); + Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/c2/replies?limit=10'); + Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/c2/replies?cursor=page2&limit=10'); }); it('closes a thread whose replies have all gone', function () { diff --git a/tests/Feature/Screens/LogThreadTest.php b/tests/Feature/Screens/LogThreadTest.php new file mode 100644 index 00000000..2e6fa5ba --- /dev/null +++ b/tests/Feature/Screens/LogThreadTest.php @@ -0,0 +1,412 @@ + 'http://devnull.test']); + signIn(); +}); + +function grace(): array +{ + return userJson(['id' => 'u3', 'handle' => 'grace', 'name' => 'Grace', 'lane' => 4]); +} + +function threadAda(): array +{ + return userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada', 'lane' => 1]); +} + +/** + * A commit by Ada in a list, with $replies replies, and the newest one devnull previews under it. + * + * @param array $overrides + * @return array + */ +function threadedJson(int $replies = 1, array $overrides = []): array +{ + return commitJson([ + 'id' => 'c1', + 'body' => 'Ship it?', + 'replies_count' => $replies, + 'author' => threadAda(), + 'reply_preview' => ['data' => [replyJson(['id' => 'r9', 'parent_id' => 'c1', 'body' => 'The newest reply', 'author' => grace()])], 'next_cursor' => null], + ...$overrides, + ]); +} + +/** + * $count replies to $parentId, r1 to rN unless $prefix says otherwise. + * + * @return list> + */ +function repliesJson(string $parentId, int $count, string $prefix = 'r', int $from = 1, array $overrides = []): array +{ + return array_map(fn (int $n): array => replyJson(['id' => "{$prefix}{$n}", 'parent_id' => $parentId, 'body' => "Reply {$prefix}{$n}", 'author' => grace(), ...$overrides]), range($from, $from + $count - 1)); +} + +/** + * The colours of the dashed lines in a node, in order. + * + * @return list + */ +function dashColours(array $node): array +{ + return array_values(array_unique(array_map( + fn (array $line): string => $line['style']['border_color'] ?? '', + findNodes($node, fn (array $child): bool => ($child['props']['border_style'] ?? null) === 1), + ))); +} + +function refNode(array $node, string $ref): ?array +{ + return findNode($node, fn (array $child): bool => ($child['ref'] ?? null) === $ref); +} + +it('keeps replies hidden under a commit, with the replies button on its own line under the actions', function () { + Http::fake(['devnull.test/*' => Http::response(pageJson([threadedJson(3)]))]); + + $screen = Native::visit('/log', platform: 'ios') + ->assertSee('Ship it?') + ->assertDontSee('The newest reply') + ->assertSee('3 replies'); + + expect(refNode(nodeByRef($screen, 'actions-c1'), 'replies-c1'))->toBeNull() + ->and(refNode(nodeByRef($screen, 'commit-c1'), 'replies-c1'))->not->toBeNull() + ->and(findNode($screen->tree(), fn (array $node): bool => str_starts_with($node['ref'] ?? '', 'thread-reply-')))->toBeNull(); +}); + +it('opens the replies under a commit from its replies button, on a dashed elbow in its lane', function () { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([threadedJson(2)])], + 'GET /api/v1/commits/c1/replies' => [pageJson(repliesJson('c1', 2))], + ]); + + $screen = Native::visit('/log', platform: 'ios') + ->tap('replies-c1') + ->assertNoNavigation() + ->assertSee('Reply r1') + ->assertSee('Reply r2') + ->assertSee('Hide replies'); + + $reply = nodeByRef($screen, 'thread-reply-r1'); + $elbow = refNode($reply, 'thread-elbow'); + + expect($elbow)->not->toBeNull() + ->and(dashColours($elbow))->toBe([config('native-ui.theme.light.lane-1')]) + ->and($elbow['props'])->toMatchArray(['border_l' => 1.0, 'border_b' => 1.0, 'border_t' => 0.0, 'border_r' => 0.0, 'radius_bl' => 12.0]) + ->and($elbow['layout'])->toMatchArray(['width' => 31.5, 'height' => 22.5, 'position' => [0.0, 0.0, 0.0, 31.5]]) + // A reply's own actions: the star and Reply, but no Quote. + ->and(refNode($reply, 'reply-to-r1'))->not->toBeNull() + ->and(refNode($reply, 'quote-r1'))->toBeNull() + // The second hangs on a short link in the lane of the reply above it. + ->and(dashColours(nodeByRef($screen, 'thread-reply-r2')))->toContain(config('native-ui.theme.light.lane-4')) + ->and(refNode(nodeByRef($screen, 'thread-reply-r2'), 'thread-elbow'))->toBeNull() + // The last closes the commit's row with its hairline. + ->and(refNode($screen->tree(), 'thread-end-r2'))->not->toBeNull(); + + $screen->tap('thread-reply-r1')->assertNavigatedTo('/log/commits/r1'); +}); + +it('frames a reply avatar in its own lane without shifting the thread', function (string $platform) { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([threadedJson()])], + 'GET /api/v1/commits/c1/replies' => [pageJson(repliesJson('c1', 1))], + ]); + + $screen = Native::visit('/log', platform: $platform)->tap('replies-c1'); + $ring = findNode(nodeByRef($screen, 'thread-reply-r1'), fn (array $node): bool => ($node['style']['border_color'] ?? null) === config('native-ui.theme.light.lane-4') + && ($node['layout']['width'] ?? null) === 24.0 + && ($node['layout']['height'] ?? null) === 24.0); + + expect($ring)->not->toBeNull() + ->and($ring['style']['border_radius'])->toBeGreaterThanOrEqual(12.0) + ->and($ring['style'])->toMatchArray(['border_width' => 1.0, 'bg_color' => config('native-ui.theme.light.surface')]) + ->and($ring['children'])->toHaveCount(1) + ->and($ring['children'][0]['layout'])->toMatchArray(['width' => 20.0, 'height' => 20.0]); +})->with(['ios', 'android']); + +it('shows ten replies at a time when devnull sends more, and asks for the next page once they all show', function () { + Http::fake(fn (Request $request) => Http::response(match (true) { + str_contains($request->url(), '/log/following') => pageJson([threadedJson(25)]), + // devnull sends 50 a page whatever limit asks for. + str_contains($request->url(), 'cursor=page2') => pageJson(repliesJson('c1', 12, from: 14), path: 'http://devnull.test/api/v1/commits/c1/replies'), + default => pageJson(repliesJson('c1', 13), 'page2', 'http://devnull.test/api/v1/commits/c1/replies'), + })); + + $screen = Native::visit('/log', platform: 'ios') + ->tap('replies-c1') + ->assertSee('Reply r10') + ->assertDontSee('Reply r11') + ->assertSee('Show more'); + + $screen->tap('more-replies-c1')->assertSee('Reply r13')->assertDontSee('Reply r14')->assertNoNavigation(); + expect(sentTo('GET', 'commits/c1/replies'))->toHaveCount(1); + + $screen->tap('more-replies-c1')->assertSee('Reply r23')->assertDontSee('Reply r24'); + $screen->tap('more-replies-c1')->assertSee('Reply r25')->assertDontSee('Show more'); + + Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/c1/replies?limit=10'); + Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/c1/replies?cursor=page2&limit=10'); +}); + +it("opens a reply's own replies in place, one step in, hanging off the line from its avatar", function () { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([threadedJson(2)])], + 'GET /api/v1/commits/c1/replies' => [pageJson([ + replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'First', 'replies_count' => 12, 'author' => grace()]), + replyJson(['id' => 'r2', 'parent_id' => 'c1', 'body' => 'Second', 'author' => threadAda()]), + ])], + 'GET /api/v1/commits/r1/replies' => [pageJson(repliesJson('r1', 12, 'n', overrides: ['author' => threadAda(), 'replies_count' => 2]))], + ]); + + $screen = Native::visit('/log', platform: 'ios')->tap('replies-c1'); + + // Its replies button is under its actions too. + expect(refNode(nodeByRef($screen, 'actions-r1'), 'replies-r1'))->toBeNull() + ->and(refNode(nodeByRef($screen, 'thread-reply-r1'), 'replies-r1'))->not->toBeNull(); + + $screen->tap('replies-r1') + ->assertNoNavigation() + ->assertSee('Reply n10') + ->assertDontSee('Reply n11'); + + // In order: r1, its replies, its Show more, then r2. + $refs = array_values(array_filter(array_map(fn (array $node): ?string => $node['ref'] ?? null, findNodes($screen->tree(), fn (array $node): bool => preg_match('/^(thread-reply-|more-replies-)/', $node['ref'] ?? '') === 1)))); + expect($refs)->toBe(['thread-reply-r1', ...array_map(fn (int $n): string => "thread-reply-n{$n}", range(1, 10)), 'more-replies-r1', 'thread-reply-r2']); + + $nested = nodeByRef($screen, 'thread-reply-n1'); + $elbow = refNode($nested, 'thread-elbow'); + $spine = fn (array $node): ?array => findNode($node, fn (array $line): bool => ($line['props']['border_style'] ?? null) === 1 && ($line['layout']['position'][3] ?? null) === 75.5 && ! isset($line['layout']['height'])); + + // Its elbow leaves the line down from r1's avatar, in r1's lane, and that line runs on past it to r2. + expect($elbow['layout']['position'][3] ?? null)->toBe(75.5) + ->and(dashColours($elbow))->toBe([config('native-ui.theme.light.lane-4')]) + ->and($spine($nested))->not->toBeNull(); + + // One step in, a reply's replies open its page instead. + $screen->tap('replies-n1')->assertNavigatedTo('/log/commits/n1'); + expect($screen->navigationIntent()->data['replies'])->toBeTrue(); +}); + +it("closes a commit's thread, and the replies opened inside it, from Hide replies", function () { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([threadedJson(1)])], + 'GET /api/v1/commits/c1/replies' => [pageJson([replyJson(['id' => 'r1', 'parent_id' => 'c1', 'replies_count' => 1, 'author' => grace()])])], + 'GET /api/v1/commits/r1/replies' => [pageJson(repliesJson('r1', 1, 'n'))], + ]); + + $screen = Native::visit('/log', platform: 'ios')->tap('replies-c1')->tap('replies-r1')->assertSee('Reply n1'); + + $screen->tap('replies-c1')->assertDontSee('Reply n1')->assertSee('1 reply'); + + expect($screen->instance()->threads)->toBe([]) + ->and($screen->instance()->fadedRows)->toBe([]); +}); + +it('fades a thread in as it opens and out as it closes', function () { + holdRefreshes(); + keep('log/following', pageJson([threadedJson(1)])); + keep('commits/c1/replies', pageJson(repliesJson('c1', 1))); + serveApi(fn () => Http::response(pageJson([]))); + + $screen = Native::visit('/log', platform: 'ios'); + $content = fn (): array => nodeByRef($screen, 'thread-reply-r1')['children'][0]['children'][1]; + + // Drawn see-through and nudged up first, with the animation it eases in by. + $screen->tap('replies-c1'); + expect($content()['style']['opacity'] ?? null)->toBe(0.0) + ->and($content()['props']['translate-y'] ?? null)->toBe(-8.0) + ->and($content()['props']['animate-duration'] ?? null)->toBe(220.0); + + finishBeats($screen); + expect($content()['style']['opacity'] ?? 1.0)->toBe(1.0) + ->and($content()['props']['translate-y'] ?? null)->toBe(0.0); + + // Closing fades it out, and it goes once that's done. + $screen->tap('replies-c1')->assertSee('1 reply'); + expect($content()['style']['opacity'] ?? null)->toBe(0.0); + + finishBeats($screen); + expect(refNode($screen->tree(), 'thread-reply-r1'))->toBeNull(); +}); + +it('keeps a thread under a commit you star, and stars a reply in it in place', function () { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([threadedJson(1)])], + 'GET /api/v1/commits/c1/replies' => [pageJson(repliesJson('c1', 1))], + 'POST /api/v1/commits/c1/star' => [['data' => commitJson(['id' => 'c1', 'stars_count' => 1, 'starred' => true])]], + 'POST /api/v1/commits/r1/star' => [['data' => commitJson(['id' => 'r1', 'stars_count' => 1, 'starred' => true, 'author' => grace()])]], + ]); + + $screen = Native::visit('/log', platform: 'ios')->tap('replies-c1')->tap('star-c1')->tap('star-r1'); + + $screen->assertSee('Reply r1'); + expect($screen->instance()->commits[0]->starred)->toBeTrue() + ->and($screen->instance()->threads['c1'][0]->starred)->toBeTrue(); +}); + +it('pops a star you give, as the web does, and leaves it as it was', function () { + holdRefreshes(); + keep('log/following', pageJson([commitJson(['id' => 'c1', 'author' => threadAda(), 'starred' => false])])); + serveApi(fn () => Http::response(['data' => commitJson(['id' => 'c1', 'starred' => true, 'stars_count' => 1, 'author' => threadAda()])])); + + $screen = Native::visit('/log', platform: 'ios'); + $star = fn (): array => findNode(nodeByRef($screen, 'star-c1'), fn (array $node): bool => ($node['type'] ?? null) === 'icon'); + + expect($star()['props'])->not->toHaveKey('scale'); + + $screen->tap('star-c1'); + expect($screen->instance()->popping)->toBe(['star-c1' => Pop::Ready]) + ->and($star()['props'])->toMatchArray(['scale' => 1.0, 'animate-duration' => 150.0]); + + finishBeats($screen, 1); + expect($star()['props'])->toMatchArray(['scale' => 1.35, 'rotate' => -12.0]); + + finishBeats($screen, 1); + expect($star()['props'])->toMatchArray(['scale' => 1.0, 'rotate' => 0.0, 'animate-easing' => 'spring']); + + finishBeats($screen); + expect($screen->instance()->popping)->toBe([]) + ->and($star()['props'])->not->toHaveKey('scale'); +}); + +it("doesn't pop a star you take back, as the web doesn't", function () { + holdRefreshes(); + keep('log/following', pageJson([commitJson(['id' => 'c1', 'author' => threadAda(), 'starred' => true, 'stars_count' => 1])])); + serveApi(fn () => Http::response(['data' => commitJson(['id' => 'c1', 'starred' => false, 'stars_count' => 0, 'author' => threadAda()])])); + + $screen = Native::visit('/log', platform: 'ios')->tap('star-c1'); + + expect($screen->instance()->popping)->toBe([]); +}); + +it("runs the commit's rail on past its thread when the author's run carries on below", function () { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([threadedJson(1, ['id' => 'c2']), commitJson(['id' => 'c1', 'author' => threadAda()])])], + 'GET /api/v1/commits/c2/replies' => [pageJson(repliesJson('c2', 1))], + ]); + + $screen = Native::visit('/log', platform: 'ios')->tap('replies-c2'); + $lane = config('native-ui.theme.light.lane-1'); + $solidRail = fn (array $node): bool => ($node['layout']['width'] ?? null) === 2.0 && ($node['style']['bg_color'] ?? null) === $lane; + + expect(findNode(nodeByRef($screen, 'thread-reply-r1'), $solidRail))->not->toBeNull() + ->and(refNode(nodeByRef($screen, 'commit-c2'), 'end-dot'))->toBeNull() + ->and(railNode($screen, 'commit-c1'))->toBe('dot'); +}); + +it('ends a commit alone in its run with a dot inside its action row, level with the actions', function (string $platform) { + Http::fake(['devnull.test/*' => Http::response(pageJson([ + commitJson(['id' => 'c3', 'author' => threadAda()]), + commitJson(['id' => 'c2', 'author' => threadAda()]), + commitJson(['id' => 'c1', 'author' => grace(), 'replies_count' => 4]), + commitJson(['id' => 'c0', 'author' => threadAda(), 'body' => str_repeat('A long body that wraps. ', 20)]), + ]))]); + + $screen = Native::visit('/log', platform: $platform); + + expect(railNode($screen, 'commit-c3'))->toBe('avatar') + ->and(railNode($screen, 'commit-c2'))->toBe('dot') + ->and(refNode(nodeByRef($screen, 'commit-c3'), 'end-dot'))->toBeNull() + ->and(refNode(nodeByRef($screen, 'commit-c2'), 'end-dot'))->toBeNull(); + + foreach (['c1', 'c0'] as $id) { + $dot = refNode(nodeByRef($screen, "actions-{$id}"), 'end-dot'); + + // Centred in the 36pt row, at the rail's x: the row starts 56pt in, the dot's middle is at 32. + expect($dot)->not->toBeNull() + ->and($dot['layout'])->toMatchArray(['width' => 18.0, 'height' => 18.0]) + ->and($dot['layout']['position'][0])->toBe(9.0) + ->and($dot['layout']['position'][3])->toBe(-33.0) + ->and(nodeByRef($screen, "actions-{$id}")['layout']['height'])->toBe(36.0); + } +})->with(['ios', 'android']); + +it('stops the rail at the end dot, past the replies line, and carries it on in dashes once the replies open', function () { + fakeApi([ + 'GET /api/v1/log/following' => [pageJson([commitJson(['id' => 'c1', 'author' => grace(), 'replies_count' => 1])])], + 'GET /api/v1/commits/c1/replies' => [pageJson(repliesJson('c1', 1))], + ]); + + $screen = Native::visit('/log', platform: 'ios'); + $lane = config('native-ui.theme.light.lane-4'); + $tail = fn (): ?array => findNode(nodeByRef($screen, 'commit-c1'), fn (array $node): bool => ($node['layout']['width'] ?? null) === 2.0 && ($node['style']['bg_color'] ?? null) === $lane); + + // Closed: 7pt padding with the hairline, the replies line (4pt gap and 36pt) and half the action row (18pt) put + // the dot's middle 65pt up, and the rail stops 2pt into its ring, 9pt above that. + expect($tail()['layout']['position'][2])->toBe(72.0); + + $screen->tap('replies-c1'); + + // Open: no padding under the replies line, and the dashes run on from the dot's foot to the row's. + $dashes = findNode(nodeByRef($screen, 'commit-c1'), fn (array $node): bool => ($node['props']['border_style'] ?? null) === 1 && ($node['layout']['position'][2] ?? null) === 0.0); + + expect($tail()['layout']['position'][2])->toBe(65.0) + ->and($dashes['layout']['height'] ?? null)->toBe(49.0); +}); + +it('drops a reply that went from an open thread when the log refreshes, and keeps the pages loaded after the first', function () { + $gone = false; + + Http::fake(function (Request $request) use (&$gone) { + return Http::response(match (true) { + str_contains($request->url(), '/log/following') => pageJson([threadedJson(12)]), + str_contains($request->url(), 'cursor=page2') => pageJson(repliesJson('c1', 2, from: 11), path: 'http://devnull.test/api/v1/commits/c1/replies'), + default => pageJson(array_values(array_filter(repliesJson('c1', 10), fn (array $reply): bool => ! ($gone && $reply['id'] === 'r3'))), 'page2', 'http://devnull.test/api/v1/commits/c1/replies'), + }); + }); + + $screen = Native::visit('/log', platform: 'ios')->tap('replies-c1')->tap('more-replies-c1')->assertSee('Reply r12'); + + $gone = true; + $screen->call('load'); + + expect(array_map(fn ($reply): string => $reply->id, $screen->instance()->threads['c1']))->toBe(['r1', 'r2', ...array_map(fn (int $n): string => "r{$n}", range(4, 12))]); +}); + +it('opens a thread at once from the replies kept last time, and refreshes it behind', function () { + holdRefreshes(); + keep('log/following', pageJson([threadedJson(2)])); + keep('commits/c1/replies', pageJson([replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'First kept']), replyJson(['id' => 'r2', 'parent_id' => 'c1'])])); + serveApi(fn () => Http::response(pageJson([]))); + + $screen = Native::visit('/log', platform: 'ios'); + $requests = count(Http::recorded()); + + $screen->tap('replies-c1')->assertSee('First kept'); + + expect(count(Http::recorded()))->toBe($requests) + ->and(refreshesSent($screen))->toBeGreaterThan(1); +}); + +/** + * Runs the Beats a screen is waiting on, $times rounds of them or until none are left. + */ +function finishBeats(TestableComponent $screen, int $times = PHP_INT_MAX): TestableComponent +{ + $done = []; + + for ($round = 0; $round < $times; $round++) { + $beats = array_filter($screen->bridge()->callsTo('AsyncTask.Dispatch'), function (array $call) use (&$done): bool { + $payload = \Native\Mobile\Support\AsyncTaskTransport::readPayload($call['params']['id']); + + return ! isset($done[$call['params']['id']]) && $payload !== null && str_contains($payload, 'App\\Devnull\\Beat'); + }); + + if ($beats === []) { + break; + } + + foreach ($beats as $call) { + $done[$call['params']['id']] = true; + $screen->emitNative(\Native\Mobile\Events\Async\AsyncTaskFinished::class, ['id' => $call['params']['id'], 'result' => true]); + } + } + + return $screen; +} diff --git a/tests/Feature/Screens/LogWindowTest.php b/tests/Feature/Screens/LogWindowTest.php index 539f02ba..98546ae2 100644 --- a/tests/Feature/Screens/LogWindowTest.php +++ b/tests/Feature/Screens/LogWindowTest.php @@ -7,16 +7,25 @@ config(['devnull.url' => 'http://devnull.test']); signIn(); - // A day marker and 300 commits, with a reply under c220, then the row loading the next page. + // A day marker and 300 commits, with a reply under c220 (opened by visit()), then the row loading the next page. fakeApi([ + 'GET /api/v1/commits/c220/replies' => [pageJson([replyJson(['id' => 'r220', 'parent_id' => 'c220'])])], 'GET /api/v1/log/following' => [pageJson(array_map(fn (int $n): array => commitJson([ 'id' => "c{$n}", 'body' => "Commit {$n}", - ...($n === 220 ? ['replies_count' => 1, 'reply_preview' => ['data' => [replyJson(['id' => 'r220', 'parent_id' => 'c220'])], 'next_cursor' => null]] : []), + ...($n === 220 ? ['replies_count' => 1] : []), ]), range(0, 299)), nextCursor: 'more')], ]); }); +/** + * The log, with c220's reply opened under it. + */ +function visitWithThread(): TestableComponent +{ + return Native::visit('/log')->call('toggleReplies', 'c220'); +} + /** * Each row of the log's list as its ref, or "placeholder". * @@ -41,7 +50,7 @@ function windowRowIds(TestableComponent $screen): array } it('draws the first rows and those near the top, and puts placeholders in the rest', function () { - $rows = windowRows(Native::visit('/log')); + $rows = windowRows(visitWithThread()); // The first 151 rows of the timeline: the day marker and c0 to c149. expect($rows)->toHaveCount(303) @@ -53,7 +62,7 @@ function windowRowIds(TestableComponent $screen): array }); it('draws the rows around the ones on screen as you scroll, each keeping its place in the list', function () { - $screen = Native::visit('/log'); + $screen = visitWithThread(); $ids = windowRowIds($screen); // On screen: c229 to c234, which come after c220 and its reply. Drawn: the first ten rows of the timeline, and @@ -71,21 +80,21 @@ function windowRowIds(TestableComponent $screen): array it('draws more rows above the screen once you scroll back up and stop', function () { // Down to c229, then back up to c199: drawn from 150 above c199 (c49). - $rows = windowRows(Native::visit('/log')->call('showRows', 231, 236)->call('showRows', 200, 205)->call('scrollEnded', 200, 205)); + $rows = windowRows(visitWithThread()->call('showRows', 231, 236)->call('showRows', 200, 205)->call('scrollEnded', 200, 205)); expect($rows[49])->toBe('placeholder') ->and($rows[50])->toBe('commit-c49'); }); it('only asks the log you are on where it is scrolled to, and when it stops', function () { - $screen = Native::visit('/log'); + $screen = visitWithThread(); expect(showingLog($screen)['props'])->toHaveKeys(['on_visible_range', 'on_scroll_end']) ->and(nodeByRef($screen, 'log-latest')['props'] ?? [])->not->toHaveKey('on_visible_range')->not->toHaveKey('on_scroll_end'); }); it('draws the top again when the log goes back to the top of a new list', function () { - $screen = Native::visit('/log')->call('showRows', 231, 236)->call('show', 'following'); + $screen = visitWithThread()->call('showRows', 231, 236)->call('show', 'following'); $rows = windowRows($screen); expect($rows[21])->toBe('commit-c20') diff --git a/tests/Feature/Screens/PasteisTest.php b/tests/Feature/Screens/PasteisTest.php index 6f580305..1e7192fa 100644 --- a/tests/Feature/Screens/PasteisTest.php +++ b/tests/Feature/Screens/PasteisTest.php @@ -85,7 +85,7 @@ function textInside(TestableComponent $screen, string $ref): ?string $screen = Native::visit('/log', platform: 'ios')->assertSee('3 replies'); - expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'quote-c2', 'reply-to-c2', 'replies-c2', 'more-c2']) + expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'quote-c2', 'reply-to-c2', 'more-c2', 'end-dot']) ->and(findNode($screen->tree(), fn (array $node): bool => str_starts_with((string) ($node['ref'] ?? ''), 'pastel')))->toBeNull() ->and(findNode($screen->tree(), fn (array $node): bool => ($node['props']['src'] ?? null) === Pasteis::Image))->toBeNull(); @@ -103,7 +103,7 @@ function textInside(TestableComponent $screen, string $ref): ?string $screen = Native::visit('/log', platform: 'ios'); - expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'pastel-c2', 'quote-c2', 'reply-to-c2', 'replies-c2', 'more-c2']) + expect(array_values(array_filter(childRefs($screen, 'actions-c2'))))->toBe(['star-c2', 'pastel-c2', 'quote-c2', 'reply-to-c2', 'more-c2']) ->and(nodeByRef($screen, 'pastel-c2')['props']['a11y_label'])->toBe('Give a pastel, 3 pastéis, 7 left today') ->and(nodeByRef($screen, 'pastel-c1')['props']['a11y_label'])->toBe('Give a pastel, 0 pastéis, 7 left today') // The web shows the count even when it's 0. @@ -280,11 +280,12 @@ function textInside(TestableComponent $screen, string $ref): ?string pasteisOn(); $reply = commitJson(['id' => 'r1', 'parent_id' => 'c1', 'pasteis_count' => 1, 'author' => pastelAuthor()]); fakeApi([ - 'GET /api/v1/log/following' => [pageJson([commitJson(['id' => 'c1', 'replies_count' => 1, 'author' => pastelAuthor(), 'reply_preview' => ['data' => [$reply], 'next_cursor' => null]])])], + 'GET /api/v1/log/following' => [pageJson([commitJson(['id' => 'c1', 'replies_count' => 1, 'author' => pastelAuthor()])])], + 'GET /api/v1/commits/c1/replies' => [pageJson([$reply])], 'POST /api/v1/commits/r1/pasteis' => [pastelAnswer([...$reply, 'pasteis_count' => 2], remaining: 9)], ]); - $screen = Native::visit('/log', platform: 'ios')->tap('pastel-r1'); + $screen = Native::visit('/log', platform: 'ios')->tap('replies-c1')->tap('pastel-r1'); expect(pasteisSent())->toBe(['r1']) ->and(textInside($screen, 'pastel-r1'))->toBe('2'); diff --git a/tests/Feature/Screens/ProfileTest.php b/tests/Feature/Screens/ProfileTest.php index eea451e5..02e88cbb 100644 --- a/tests/Feature/Screens/ProfileTest.php +++ b/tests/Feature/Screens/ProfileTest.php @@ -58,7 +58,7 @@ function adaCommitJson(array $overrides = []): array ->assertSee("That's @ada's root commit."); }); -it("shows Reply as just its icon beside a commit's replies, so the row still fits a phone", function () { +it("labels Reply, with a commit's replies on their own line under the actions", function () { fakeApi([ 'GET /api/v1/users/ada' => [profileJson()], 'GET /api/v1/users/ada/commits' => [pageJson([ @@ -71,8 +71,9 @@ function adaCommitJson(array $overrides = []): array $labels = fn (string $ref): array => findNodes(nodeByRef($screen, $ref), fn (array $node): bool => ($node['type'] ?? null) === 'text'); expect(nodeByRef($screen, 'reply-to-c1')['props']['a11y_label'])->toBe('Reply') - ->and($labels('reply-to-c1'))->toBe([]) - ->and($labels('reply-to-c2'))->toHaveCount(1); + ->and($labels('reply-to-c1'))->toHaveCount(1) + ->and($labels('reply-to-c2'))->toHaveCount(1) + ->and(findNode(nodeByRef($screen, 'actions-c1'), fn (array $node): bool => ($node['ref'] ?? null) === 'replies-c1'))->toBeNull(); }); it('lists what GitHub says about them under the bio, as the web does', function () { diff --git a/tests/Feature/Screens/ReplyPreviewTest.php b/tests/Feature/Screens/ReplyPreviewTest.php deleted file mode 100644 index ca38f205..00000000 --- a/tests/Feature/Screens/ReplyPreviewTest.php +++ /dev/null @@ -1,252 +0,0 @@ - 'http://devnull.test']); - signIn(); -}); - -function grace(): array -{ - return userJson(['id' => 'u3', 'handle' => 'grace', 'name' => 'Grace', 'lane' => 4]); -} - -/** - * A commit by Ada in a list, with the newest reply devnull previews under it. - * - * @param list> $replies - * @param array $overrides - * @return array - */ -function previewedJson(array $replies, bool $more = false, array $overrides = []): array -{ - return commitJson([ - 'id' => 'c1', - 'body' => 'Ship it?', - 'replies_count' => count($replies) + ($more ? 2 : 0), - 'author' => userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada', 'lane' => 1]), - 'reply_preview' => ['data' => $replies, 'next_cursor' => $more ? 'eyJjcmVhdGVkX2F0IjoiMjAyNiJ9' : null], - ...$overrides, - ]); -} - -/** - * The colours of the dashed lines in a node, in order. - * - * @return list - */ -function dashColours(array $node): array -{ - return array_values(array_unique(array_map( - fn (array $line): string => $line['style']['border_color'] ?? '', - findNodes($node, fn (array $child): bool => ($child['props']['border_style'] ?? null) === 1), - ))); -} - -it('hangs the newest reply under a commit, on a dashed elbow in its lane, instead of a replies toggle', function () { - Http::fake(['devnull.test/*' => Http::response(pageJson([previewedJson([ - replyJson(['id' => 'r9', 'parent_id' => 'c1', 'body' => 'The newest reply', 'author' => grace()]), - ])]))]); - - $screen = Native::visit('/log', platform: 'ios') - ->assertSee('Ship it?') - ->assertSee('The newest reply') - ->assertDontSee('1 reply') - ->assertDontSee('Show more'); - - $reply = nodeByRef($screen, 'thread-reply-r9'); - $elbow = findNode($reply, fn (array $node): bool => ($node['ref'] ?? null) === 'thread-elbow'); - - expect($elbow)->not->toBeNull() - ->and(dashColours($elbow))->toBe([config('native-ui.theme.light.lane-1')]) - // One dashed border down from the rail, round a 12pt corner and across to 1pt short of the avatar. - ->and($elbow['props'])->toMatchArray(['border_l' => 1.0, 'border_b' => 1.0, 'border_t' => 0.0, 'border_r' => 0.0, 'radius_bl' => 12.0]) - ->and($elbow['layout'])->toMatchArray(['width' => 31.5, 'height' => 22.5, 'position' => [0.0, 0.0, 0.0, 31.5]]) - // A reply's own actions: the star and Reply, but no Quote. - ->and(findNode($reply, fn (array $node): bool => ($node['ref'] ?? null) === 'reply-to-r9'))->not->toBeNull() - ->and(findNode($reply, fn (array $node): bool => ($node['ref'] ?? null) === 'quote-r9'))->toBeNull(); - - // The commit ends its rail in a dot, and the dashes carry on from it to the reply. - expect(findNode(nodeByRef($screen, 'commit-c1'), fn (array $node): bool => ($node['ref'] ?? null) === 'end-dot'))->not->toBeNull(); - - $screen->tap('thread-reply-r9')->assertNavigatedTo('/log/commits/r9'); -}); - -it('frames a reply avatar in its own lane without shifting the thread', function (string $platform) { - Http::fake(['devnull.test/*' => Http::response(pageJson([previewedJson([ - replyJson(['id' => 'r9', 'parent_id' => 'c1', 'author' => grace()]), - ])]))]); - - $screen = Native::visit('/log', platform: $platform); - $reply = nodeByRef($screen, 'thread-reply-r9'); - $ring = findNode($reply, fn (array $node): bool => ($node['style']['border_color'] ?? null) === config('native-ui.theme.light.lane-4') - && ($node['layout']['width'] ?? null) === 24.0 - && ($node['layout']['height'] ?? null) === 24.0); - - expect($ring)->not->toBeNull() - ->and($ring['style']['border_radius'])->toBeGreaterThanOrEqual(12.0) - ->and($ring['style'])->toMatchArray(['border_width' => 1.0, 'bg_color' => config('native-ui.theme.light.surface')]) - ->and($ring['children'])->toHaveCount(1) - ->and($ring['children'][0]['layout'])->toMatchArray(['width' => 20.0, 'height' => 20.0]); -})->with(['ios', 'android']); - -it('opens the rest of the thread in place, newest first, from Show more', function () { - fakeApi([ - 'GET /api/v1/log/following' => [pageJson([previewedJson([replyJson(['id' => 'r3', 'parent_id' => 'c1', 'body' => 'Third', 'author' => grace()])], more: true)])], - 'GET /api/v1/commits/c1/replies' => [pageJson([ - replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'First']), - replyJson(['id' => 'r2', 'parent_id' => 'c1', 'body' => 'Second', 'author' => grace()]), - replyJson(['id' => 'r3', 'parent_id' => 'c1', 'body' => 'Third', 'author' => grace()]), - ])], - ]); - - $screen = Native::visit('/log', platform: 'ios') - ->assertSee('Third') - ->assertDontSee('Second') - ->assertSee('Show more'); - - $screen->tap('more-replies-c1') - ->assertNoNavigation() - ->assertSee('First') - ->assertSee('Second') - ->assertDontSee('Show more'); - - expect(array_map(fn ($reply): string => $reply->id, $screen->instance()->threads['c1']))->toBe(['r3', 'r2', 'r1']); - - // Each reply after the first hangs on a short link in the lane of the reply above it. - expect(dashColours(nodeByRef($screen, 'thread-reply-r2')))->toContain(config('native-ui.theme.light.lane-4')) - ->and(findNode(nodeByRef($screen, 'thread-reply-r2'), fn (array $node): bool => ($node['ref'] ?? null) === 'thread-elbow'))->toBeNull(); - - Http::assertSent(fn (Request $request): bool => $request->url() === 'http://devnull.test/api/v1/commits/c1/replies?limit=5'); -}); - -it('opens Show more at once from the thread kept last time, and refreshes it behind', function () { - holdRefreshes(); - keep('log/following', pageJson([previewedJson([replyJson(['id' => 'r2', 'parent_id' => 'c1', 'body' => 'Second'])], more: true)])); - keep('commits/c1/replies', pageJson([replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'First kept']), replyJson(['id' => 'r2', 'parent_id' => 'c1', 'body' => 'Second'])])); - serveApi(fn () => Http::response(pageJson([]))); - - $screen = Native::visit('/log', platform: 'ios'); - $requests = count(Http::recorded()); - - $screen->tap('more-replies-c1')->assertSee('First kept'); - - expect(count(Http::recorded()))->toBe($requests) - ->and(refreshesSent($screen))->toBeGreaterThan(1); -}); - -it('opens the commit with its replies showing instead when its thread is longer than a page', function () { - fakeApi([ - 'GET /api/v1/log/following' => [pageJson([previewedJson([replyJson(['id' => 'r60', 'parent_id' => 'c1'])], more: true)])], - 'GET /api/v1/commits/c1/replies' => [pageJson(array_map(fn (int $n): array => replyJson(['id' => "r{$n}", 'parent_id' => 'c1']), range(1, 5)), 'page2')], - 'GET /api/v1/commits/c1' => [commitPageJson(previewedJson([], more: true))], - ]); - - Native::visit('/log', platform: 'ios') - ->tap('more-replies-c1') - ->assertNavigatedTo('/log/commits/c1') - ->follow() - ->assertSet('repliesShown', true); -}); - -it('stars a reply in the thread in place', function () { - fakeApi([ - 'GET /api/v1/log/following' => [pageJson([previewedJson([replyJson(['id' => 'r1', 'parent_id' => 'c1', 'author' => grace(), 'stars_count' => 0])])])], - 'POST /api/v1/commits/r1/star' => [['data' => commitJson(['id' => 'r1', 'stars_count' => 1, 'starred' => true, 'author' => grace()])]], - ]); - - $screen = Native::visit('/log')->tap('star-r1'); - - expect($screen->instance()->commits[0]->replyPreview->replies[0]->starred)->toBeTrue() - ->and($screen->instance()->commits[0]->replyPreview->replies[0]->starsCount)->toBe(1); -}); - -it('keeps the thread under a commit you star below a quote of it, and unstars it on the next tap', function () { - $quoted = previewedJson([]); - unset($quoted['reply_preview']); - - fakeApi([ - 'GET /api/v1/log/following' => [pageJson([ - commitJson(['id' => 'q1', 'body' => 'Look at this', 'quoted_commit_id' => 'c1', 'quoted_commit' => $quoted]), - previewedJson([replyJson(['id' => 'r9', 'parent_id' => 'c1', 'body' => 'The newest reply', 'author' => grace()])]), - ])], - 'POST /api/v1/commits/c1/star' => [['data' => commitJson(['id' => 'c1', 'stars_count' => 1, 'starred' => true])]], - 'DELETE /api/v1/commits/c1/star' => [['data' => commitJson(['id' => 'c1', 'stars_count' => 0, 'starred' => false])]], - ]); - $screen = Native::visit('/log', platform: 'ios'); - - $screen->tap('star-c1')->assertSee('The newest reply'); - $starred = $screen->instance()->commits[1]->starred; - $screen->tap('star-c1'); - - expect($starred)->toBeTrue() - ->and($screen->instance()->commits[1]->starred)->toBeFalse() - ->and(sentTo('DELETE', 'commits/c1/star'))->toHaveCount(1); -}); - -it('keeps the thread under a commit you star that is also the reply previewed under its parent', function () { - fakeApi([ - 'GET /api/v1/log/following' => [pageJson([])], - 'GET /api/v1/log/latest' => [pageJson([ - previewedJson([replyJson(['id' => 'c1', 'parent_id' => 'p1', 'body' => 'Ship it?', 'replies_count' => 1, 'author' => userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada', 'lane' => 1])])], overrides: ['id' => 'p1', 'body' => 'Should we ship?']), - previewedJson([replyJson(['id' => 'r9', 'parent_id' => 'c1', 'body' => 'The newest reply', 'author' => grace()])], overrides: ['parent_id' => 'p1']), - ], path: 'http://devnull.test/api/v1/log/latest')], - 'POST /api/v1/commits/c1/star' => [['data' => commitJson(['id' => 'c1', 'stars_count' => 1, 'starred' => true])]], - ]); - $screen = tapLogTab(Native::visit('/log', platform: 'ios'), 'latest'); - - $screen->call('toggleStar', 'c1'); - - $screen->assertSee('The newest reply'); - expect($screen->instance()->commits[0]->replyPreview->replies[0]->starred)->toBeTrue() - ->and($screen->instance()->commits[1]->starred)->toBeTrue(); -}); - -it("runs the commit's rail on past its thread when the author's run carries on below", function () { - $ada = userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada', 'lane' => 1]); - - Http::fake(['devnull.test/*' => Http::response(pageJson([ - previewedJson([replyJson(['id' => 'r1', 'parent_id' => 'c1', 'author' => grace()])], overrides: ['id' => 'c2', 'author' => $ada]), - commitJson(['id' => 'c1', 'author' => $ada]), - ]))]); - - $screen = Native::visit('/log', platform: 'ios'); - $lane = config('native-ui.theme.light.lane-1'); - $solidRail = fn (array $node): bool => ($node['layout']['width'] ?? null) === 2.0 && ($node['style']['bg_color'] ?? null) === $lane; - - expect(findNode(nodeByRef($screen, 'thread-reply-r1'), $solidRail))->not->toBeNull() - ->and(findNode(nodeByRef($screen, 'commit-c2'), fn (array $node): bool => ($node['ref'] ?? null) === 'end-dot'))->toBeNull() - ->and(railNode($screen, 'commit-c1'))->toBe('dot'); -}); - -it('ends a commit alone in its run with a dot, and joins a run of one author', function () { - $ada = userJson(['id' => 'u2', 'handle' => 'ada', 'lane' => 1]); - - Http::fake(['devnull.test/*' => Http::response(pageJson([ - commitJson(['id' => 'c3', 'author' => $ada]), - commitJson(['id' => 'c2', 'author' => $ada]), - commitJson(['id' => 'c1', 'author' => grace()]), - ]))]); - - $screen = Native::visit('/log', platform: 'ios'); - $endDot = fn (string $ref): bool => findNode(nodeByRef($screen, $ref), fn (array $node): bool => ($node['ref'] ?? null) === 'end-dot') !== null; - - expect(railNode($screen, 'commit-c3'))->toBe('avatar') - ->and(railNode($screen, 'commit-c2'))->toBe('dot') - ->and($endDot('commit-c3'))->toBeFalse() - ->and($endDot('commit-c2'))->toBeFalse() - ->and($endDot('commit-c1'))->toBeTrue(); -}); - -it("closes a commit's row in the log with a hairline after its last previewed reply", function () { - Http::fake(['devnull.test/*' => Http::response(pageJson([previewedJson([ - replyJson(['id' => 'r9', 'parent_id' => 'c1', 'body' => 'The newest reply', 'author' => grace()]), - ])]))]); - - $screen = Native::visit('/log', platform: 'ios'); - - expect(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'thread-end-r9'))->not->toBeNull(); -}); From 22079e3a918bbcc7d3a616cb992a57738a2acfe8 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Mon, 16 Nov 2026 13:13:39 +0000 Subject: [PATCH 02/18] Keep a commit's row the same height with its replies open or shut On the Log, opening or closing a commit's replies dropped or added the 7pt under its replies line, where the hairline sits. When the commit's top was off screen, the iPhone's list held the row below still instead, so the commit's photo jumped by 7pt. The row now keeps that padding, the hairline's 1pt included, with its replies open, and only the hairline goes. The first reply takes the 7pt off its own top, so the thread looks the same, and the elbow and the lines beside a reply are placed from its avatar. The commit page is left as it was: it's a scroll view, which holds its top. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/Display.php | 6 -- app/Devnull/ThreadRows.php | 10 +++ .../partials/commit-row-content.blade.php | 9 ++- .../native/partials/thread-elbow.blade.php | 7 ++- .../native/partials/thread-links.blade.php | 9 +-- .../native/partials/thread-reply.blade.php | 10 ++- tests/Feature/Screens/LogThreadTest.php | 63 ++++++++++++++++--- 7 files changed, 88 insertions(+), 26 deletions(-) diff --git a/app/Devnull/Display.php b/app/Devnull/Display.php index 09d43f94..6cb0ecdf 100644 --- a/app/Devnull/Display.php +++ b/app/Devnull/Display.php @@ -35,12 +35,6 @@ final class Display */ public const int HomeIndicatorHeight = 34; - /** - * How far below the top of a reply's row its elbow comes level with the - * middle of the reply's avatar. - */ - public const int ElbowLevel = 22; - /** * How long ago a commit was made, as the web prints it beside the commit: * "now", "5m", "3h", "2d", then the date, in the same time zone as dayLabel(). diff --git a/app/Devnull/ThreadRows.php b/app/Devnull/ThreadRows.php index 3affe2a7..337766d9 100644 --- a/app/Devnull/ThreadRows.php +++ b/app/Devnull/ThreadRows.php @@ -26,6 +26,15 @@ final class ThreadRows */ public const int Fade = 220; + /** + * The space above the first reply's avatar, 7pt less than a reply's usual + * 10pt. The commit's row keeps the 7pt of padding under its replies line, + * where its hairline was, so it's as tall with its thread open as shut, + * and a list never moves the commit when the thread opens or closes (see + * partials/commit-row-content). + */ + public const int FirstReplyTop = 3; + /** * @param array> $threads Open threads, by the id of the commit or reply they answer. * @param array $cursors Where each open thread with more carries on. @@ -58,6 +67,7 @@ public static function under(Commit $commit, array $threads, array $cursors, arr 'railLane' => $railLane, 'thread' => $commit, 'repliesInPlace' => true, + ...($index === 0 ? ['top' => self::FirstReplyTop] : []), ]); foreach ($nested as $nestedIndex => $nestedReply) { diff --git a/resources/views/native/partials/commit-row-content.blade.php b/resources/views/native/partials/commit-row-content.blade.php index 8e3c8ea5..c42584dc 100644 --- a/resources/views/native/partials/commit-row-content.blade.php +++ b/resources/views/native/partials/commit-row-content.blade.php @@ -20,6 +20,13 @@ A list builds and measures every node of a row as it scrolls in, so the content is one column: the rail's 64pt gutter is its left margin, and the hairline under it is its bottom border. A border draws inside the box, so the bottom padding takes the hairline's 1pt to keep the row as tall as it was. + + In a feed the row is as tall with its replies open as shut. The replies are rows of their own, and when a row + whose top is off screen changes height, an iOS list can hold the row below it still and move this one instead, + so its photo jumped by the difference. With the replies open the row keeps its bottom padding, the hairline's 1pt + included, and only the hairline goes. The first reply takes that padding off its own top (see ThreadRows), so the + thread looks the same. A commit page's scroll view holds its top, so there the commit it's about ($focused) lets + its replies come straight up under it. --}} @php($author = $commit->author) @php($muted ??= false) @@ -34,7 +41,7 @@ @php($hasHairline = $hairline && ! $threadBelow) @php($inset = $focused ? 16 : 12) {{-- The action row's 36pt reaches 6pt into the inset below it, as its buttons are taller than their icons. --}} -@php($bottom = $threadBelow ? 0 : $inset - 6 + ($hasHairline ? 1 : 0)) +@php($bottom = $threadBelow && $focused ? 0 : $inset - 6 + ($hairline ? 1 : 0)) @php($padding = 'pt-['.$inset.']'.($bottom > 0 ? ' pb-['.$bottom.']' : '')) @php($repliesLine = ! $commit->isStaged() && ! $commit->isDeleted() && ($focused ? ($replyCount ?? $commit->repliesCount) : $commit->repliesCount) > 0 ? 40 : 0) @php($dotInActions = $endsWithDot && ! $commit->isStaged()) diff --git a/resources/views/native/partials/thread-elbow.blade.php b/resources/views/native/partials/thread-elbow.blade.php index 063ab961..f53f9afe 100644 --- a/resources/views/native/partials/thread-elbow.blade.php +++ b/resources/views/native/partials/thread-elbow.blade.php @@ -1,8 +1,9 @@ {{-- Where a thread leaves the rail, as the web's thread elbow from #121: a dashed line in the commit's lane down from - the rail ($from), round a 12pt corner, and across to the first reply's avatar ($to), level with its middle. A - nested reply's elbow leaves the spine of the reply above it the same way. It stops 1pt short of the avatar. + the rail ($from), round a 12pt corner, and across to the first reply's avatar ($to), level with its middle ($level + below the top of the reply's row). A nested reply's elbow leaves the spine of the reply above it the same way. It + stops 1pt short of the avatar. --}} @php($from ??= 31.5) @php($to ??= 64) - + diff --git a/resources/views/native/partials/thread-links.blade.php b/resources/views/native/partials/thread-links.blade.php index 858869c5..8f2c9084 100644 --- a/resources/views/native/partials/thread-links.blade.php +++ b/resources/views/native/partials/thread-links.blade.php @@ -11,12 +11,13 @@ @endif @if ($previousLane === null) - @include('native.partials.thread-elbow', ['lane' => $lane, 'from' => $indent > 0 ? 75.5 : 31.5, 'to' => 64 + $indent]) + @include('native.partials.thread-elbow', ['lane' => $lane, 'from' => $indent > 0 ? 75.5 : 31.5, 'to' => 64 + $indent, 'level' => $top + 12]) @else - @include('native.partials.dashed-line', ['position' => 'top-0 h-[6]', 'left' => $avatarLine - 0.5, 'lane' => $previousLane]) + @include('native.partials.dashed-line', ['position' => 'top-0 h-['.($top - 4).']', 'left' => $avatarLine - 0.5, 'lane' => $previousLane]) @endif @if ($hasNext) - {{-- Down to the next reply, or to the top of Show more's dot: 12pt under it, its padding and the hairline below. --}} - @include('native.partials.dashed-line', ['position' => 'top-[38] '.($more !== null ? 'bottom-[34]' : 'bottom-0'), 'left' => $avatarLine - 0.5, 'lane' => $reply->lane()]) + {{-- From 4pt under the avatar down to the next reply, or to the top of Show more's dot: 12pt under it, its padding + and the hairline below. --}} + @include('native.partials.dashed-line', ['position' => 'top-['.($top + 28).'] '.($more !== null ? 'bottom-[34]' : 'bottom-0'), 'left' => $avatarLine - 0.5, 'lane' => $reply->lane()]) @endif diff --git a/resources/views/native/partials/thread-reply.blade.php b/resources/views/native/partials/thread-reply.blade.php index b93ec9b0..18fb7eef 100644 --- a/resources/views/native/partials/thread-reply.blade.php +++ b/resources/views/native/partials/thread-reply.blade.php @@ -14,6 +14,9 @@ The last reply carries the thread's "Show more" when there's more ($more, what it presses), with the line from its avatar running down to it. + $top is the space above the avatar, 10pt, less for the first reply in a feed, which sits under the commit row's + bottom padding (see ThreadRows::FirstReplyTop). The lines beside it are placed from the avatar, so they move with it. + A commit page draws its replies $muted, smaller and in muted ink, so the commit they answer stays the main thing. A reply you just sent that devnull doesn't have yet is staged: dimmed, with the staged chip and no actions. @@ -33,13 +36,14 @@ @php($avatarLine = 76 + $indent) @php($repliesInPlace ??= false) @php($fades ??= false) +@php($top ??= 10) @php($faded = $fades && in_array($reply->id, $fadedRows ?? [], true)) @if ($reply->isDeleted()) @php($opened = $tombstones && array_key_exists($reply->id, $tombstoneReplies ?? [])) - + @include('native.partials.dashed-ring', ['size' => 24, 'lane' => \App\Devnull\Lane::Rail]) @@ -67,7 +71,7 @@ @include('native.partials.thread-links') @if ($opened && ($tombstoneReplies[$reply->id] ?? []) !== []) {{-- The spine its own replies hang off, down from its ring. --}} - @include('native.partials.dashed-line', ['position' => 'top-[38] bottom-0', 'left' => $avatarLine - 0.5, 'lane' => \App\Devnull\Lane::Rail]) + @include('native.partials.dashed-line', ['position' => 'top-['.($top + 28).'] bottom-0', 'left' => $avatarLine - 0.5, 'lane' => \App\Devnull\Lane::Rail]) @endif @else @@ -76,7 +80,7 @@ - + @include('native.partials.rail-avatar', ['user' => $reply->author, 'lane' => $reply->lane(), 'size' => 24, 'staged' => false]) diff --git a/tests/Feature/Screens/LogThreadTest.php b/tests/Feature/Screens/LogThreadTest.php index 2e6fa5ba..e17e2da9 100644 --- a/tests/Feature/Screens/LogThreadTest.php +++ b/tests/Feature/Screens/LogThreadTest.php @@ -3,6 +3,8 @@ use App\Devnull\Pop; use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; +use Native\Mobile\Events\Async\AsyncTaskFinished; +use Native\Mobile\Support\AsyncTaskTransport; use Native\Mobile\Testing\Native; use Native\Mobile\Testing\TestableComponent; @@ -99,7 +101,8 @@ function refNode(array $node, string $ref): ?array expect($elbow)->not->toBeNull() ->and(dashColours($elbow))->toBe([config('native-ui.theme.light.lane-1')]) ->and($elbow['props'])->toMatchArray(['border_l' => 1.0, 'border_b' => 1.0, 'border_t' => 0.0, 'border_r' => 0.0, 'radius_bl' => 12.0]) - ->and($elbow['layout'])->toMatchArray(['width' => 31.5, 'height' => 22.5, 'position' => [0.0, 0.0, 0.0, 31.5]]) + // Level with the middle of the avatar, which sits 3pt down, under the commit row's 7pt of bottom padding. + ->and($elbow['layout'])->toMatchArray(['width' => 31.5, 'height' => 15.5, 'position' => [0.0, 0.0, 0.0, 31.5]]) // A reply's own actions: the star and Reply, but no Quote. ->and(refNode($reply, 'reply-to-r1'))->not->toBeNull() ->and(refNode($reply, 'quote-r1'))->toBeNull() @@ -343,21 +346,63 @@ function refNode(array $node, string $ref): ?array $screen->tap('replies-c1'); - // Open: no padding under the replies line, and the dashes run on from the dot's foot to the row's. + // Open: the same 7pt padding without the hairline, so the dot stays put, and the dashes run on from the dot's foot + // to the row's, where the first reply's elbow takes over. $dashes = findNode(nodeByRef($screen, 'commit-c1'), fn (array $node): bool => ($node['props']['border_style'] ?? null) === 1 && ($node['layout']['position'][2] ?? null) === 0.0); - expect($tail()['layout']['position'][2])->toBe(65.0) - ->and($dashes['layout']['height'] ?? null)->toBe(49.0); + expect($tail()['layout']['position'][2])->toBe(72.0) + ->and($dashes['layout']['height'] ?? null)->toBe(56.0) + ->and(refNode(nodeByRef($screen, 'thread-reply-r1'), 'thread-elbow')['layout']['position'][0])->toBe(0.0); }); +it("keeps a commit's row the same height with its replies shut, opening, open and closing, so the list never moves it", function (string $platform) { + holdRefreshes(); + keep('log/following', pageJson([commitJson(['id' => 'c1', 'author' => grace(), 'replies_count' => 2])])); + keep('commits/c1/replies', pageJson(repliesJson('c1', 2))); + serveApi(fn () => Http::response(pageJson([]))); + + $screen = Native::visit('/log', platform: $platform); + $content = fn (): array => nodeByRef($screen, 'commit-c1')['children'][0]; + $heights = fn (): array => [ + $content()['layout'], + nodeByRef($screen, 'actions-c1')['layout'], + nodeByRef($screen, 'replies-c1')['layout'], + ]; + $hairline = fn (): ?float => $content()['props']['border_b'] ?? null; + + $shut = $heights(); + + // 12pt above, and under the replies line the 6pt the action row leaves and the hairline's 1pt. + expect($shut[0]['padding'])->toEqual([12, 16, 7, 0]) + ->and($hairline())->toBe(1.0); + + $screen->tap('replies-c1'); + expect($heights())->toBe($shut); + + finishBeats($screen); + expect($heights())->toBe($shut) + ->and($hairline())->toBeNull() + // The first reply takes the 7pt off its 10pt top, so the thread sits where it did; the next keeps its 10pt. + ->and(nodeByRef($screen, 'thread-reply-r1')['children'][0]['children'][1]['children'][0]['layout']['padding'][0])->toEqual(3) + ->and(nodeByRef($screen, 'thread-reply-r2')['children'][0]['children'][1]['children'][0]['layout']['padding'][0])->toEqual(10); + + $screen->tap('replies-c1')->assertSee('2 replies'); + expect($heights())->toBe($shut); + + finishBeats($screen); + expect(refNode($screen->tree(), 'thread-reply-r1'))->toBeNull() + ->and($heights())->toBe($shut) + ->and($hairline())->toBe(1.0); +})->with(['ios', 'android']); + it('drops a reply that went from an open thread when the log refreshes, and keeps the pages loaded after the first', function () { $gone = false; Http::fake(function (Request $request) use (&$gone) { return Http::response(match (true) { - str_contains($request->url(), '/log/following') => pageJson([threadedJson(12)]), - str_contains($request->url(), 'cursor=page2') => pageJson(repliesJson('c1', 2, from: 11), path: 'http://devnull.test/api/v1/commits/c1/replies'), - default => pageJson(array_values(array_filter(repliesJson('c1', 10), fn (array $reply): bool => ! ($gone && $reply['id'] === 'r3'))), 'page2', 'http://devnull.test/api/v1/commits/c1/replies'), + str_contains($request->url(), '/log/following') => pageJson([threadedJson(12)]), + str_contains($request->url(), 'cursor=page2') => pageJson(repliesJson('c1', 2, from: 11), path: 'http://devnull.test/api/v1/commits/c1/replies'), + default => pageJson(array_values(array_filter(repliesJson('c1', 10), fn (array $reply): bool => ! ($gone && $reply['id'] === 'r3'))), 'page2', 'http://devnull.test/api/v1/commits/c1/replies'), }); }); @@ -393,7 +438,7 @@ function finishBeats(TestableComponent $screen, int $times = PHP_INT_MAX): Testa for ($round = 0; $round < $times; $round++) { $beats = array_filter($screen->bridge()->callsTo('AsyncTask.Dispatch'), function (array $call) use (&$done): bool { - $payload = \Native\Mobile\Support\AsyncTaskTransport::readPayload($call['params']['id']); + $payload = AsyncTaskTransport::readPayload($call['params']['id']); return ! isset($done[$call['params']['id']]) && $payload !== null && str_contains($payload, 'App\\Devnull\\Beat'); }); @@ -404,7 +449,7 @@ function finishBeats(TestableComponent $screen, int $times = PHP_INT_MAX): Testa foreach ($beats as $call) { $done[$call['params']['id']] = true; - $screen->emitNative(\Native\Mobile\Events\Async\AsyncTaskFinished::class, ['id' => $call['params']['id'], 'result' => true]); + $screen->emitNative(AsyncTaskFinished::class, ['id' => $call['params']['id'], 'result' => true]); } } From 01cb5784a43f43a1aabbdb2021df80b7068f24d4 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 16:30:19 +0000 Subject: [PATCH 03/18] Turn the commit page's replies chevron down while they show, as on the Log The replies button's chevron only turned in feeds, where the replies open in place. A commit page opens its commit's replies in place too, but there the chevron kept pointing right with "Hide replies" beside it. It now turns down there as well, over the same 220ms, and carries the animation while shut so iOS animates the first turn. A reply's button on a commit page still opens its page, so its chevron stays put. Co-Authored-By: Claude Opus 5.5 --- .../native/partials/commit-actions.blade.php | 7 ++++++- tests/Feature/Screens/CommitDetailTest.php | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/resources/views/native/partials/commit-actions.blade.php b/resources/views/native/partials/commit-actions.blade.php index 9f0e361d..a73854dc 100644 --- a/resources/views/native/partials/commit-actions.blade.php +++ b/resources/views/native/partials/commit-actions.blade.php @@ -34,6 +34,10 @@ A commit page opens its replies under its commit in place: it passes what the toggle presses ($repliesToggle), whether they're open ($repliesOpen) and how many there are ($repliesCount). $compact draws the row smaller, for the commits around the one a page is about. + + Wherever the button opens the replies in place, in a feed or on a commit page, its chevron turns down while they + show and back as they close, over the time a feed's thread takes to fade (ThreadRows::Fade). The chevron carries + the animation shut as well as open: iOS only animates a change on a node that already had it. --}} @php($withReply ??= true) @php($withReplies ??= true) @@ -42,6 +46,7 @@ @php($expandable ??= isset($threads)) @php($isOpen = $repliesOpen ?? ($expandable && array_key_exists($commit->id, $threads) && ! in_array($commit->id, $closingThreads ?? [], true))) @php($repliesPress = $repliesToggle ?? ($expandable ? "toggleReplies('{$commit->id}')" : "openReplies('{$commit->id}')")) +@php($opensInPlace = $expandable || isset($repliesToggle)) @php($repliesCount ??= $commit->repliesCount) @php($iconSize = $compact ? 14 : 16) @php($labelSize = $compact ? 'text-xs' : 'text-[13px]') @@ -127,7 +132,7 @@ @if ($showsReplies) - + {{ $isOpen ? 'Hide replies' : \App\Devnull\Display::count($repliesCount, 'reply', 'replies') }} @endif diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index d1e271be..ff73f4ba 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -411,6 +411,26 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): Native::visit('/log/commits/c2')->call('openProfile', 'ada')->assertNavigatedTo('/log/users/ada'); }); +it("turns the replies button's chevron down while the replies show, as the Log does, and back as they close", function (string $platform) { + fakeThread(['replies_count' => 1], replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'First reply', 'replies_count' => 1])]); + + $screen = Native::visit('/log/commits/c2', platform: $platform); + $chevron = fn (string $ref): array => findNode(nodeByRef($screen, $ref), fn (array $node): bool => ($node['type'] ?? null) === 'icon'); + + // Shut, it points right, and already carries the animation, so the turn animates on iOS. + expect($chevron('replies-c2')['props'])->toMatchArray(['name' => 'custom:chevron-right', 'rotate' => 0.0, 'animate-duration' => 220.0]); + + $screen->tap('replies-c2')->assertSee('First reply')->assertSee('Hide replies'); + expect($chevron('replies-c2')['props'])->toMatchArray(['name' => 'custom:chevron-right', 'rotate' => 90.0, 'animate-duration' => 220.0]); + + $screen->tap('replies-c2')->assertDontSee('First reply')->assertSee('1 reply'); + expect($chevron('replies-c2')['props'])->toMatchArray(['name' => 'custom:chevron-right', 'rotate' => 0.0, 'animate-duration' => 220.0]); + + // A reply's button opens its page rather than its replies in place, so its chevron stays put. + $screen->tap('replies-c2'); + expect($chevron('replies-r1')['props'])->not->toHaveKey('rotate'); +})->with(['ios', 'android']); + it('opens with its replies showing from a replies button', function () { fakeThread(['replies_count' => 1], replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'First reply', 'replies_count' => 1])], extra: [ 'GET /api/v1/commits/r1' => [commitPageJson(replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'First reply', 'replies_count' => 1]))], From 2f4d5f4ff9d0d1189e7effdc95197e50d9f6c752 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 01:22:25 +0000 Subject: [PATCH 04/18] Read an author's replies to themselves as one thread, as the web does When someone replies to their own commit, the web treats their earliest reply as the next part of a thread rather than as a reply. The commit page now does the same: the parts follow the commit on its rail, each marked with its place (2/5), ten at a time with "Show more of this thread", and the last part's replies show under it. The next part is left out of each commit's replies, and the earlier parts above a commit get their places too. devnull's API doesn't send the web's continuation_id yet, so the app works the parts out from each commit's replies (SelfThread), fetching them one after another. When the API starts sending it, the app takes its word. On the Log, profiles, search, starred and organizations, a thread opened in place leaves out the author's next part and shows "Show thread", which opens the commit's page. Without continuation_id from the API, that link can only show once the replies have been opened. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/Data/Commit.php | 5 + app/Devnull/SelfThread.php | 176 +++++++++++++++++ app/Icons/Lucide.php | 2 + app/NativeComponents/CommitDetail.php | 162 +++++++++++++++- .../Concerns/ExpandsThreads.php | 37 ++++ resources/icons/list-tree.svg | 1 + .../views/native/commit-detail.blade.php | 38 +++- .../partials/commit-row-content.blade.php | 16 +- .../views/native/partials/feed.blade.php | 3 +- .../native/partials/show-thread.blade.php | 8 + .../partials/thread-continues.blade.php | 24 +++ .../native/partials/thread-position.blade.php | 4 + .../native/partials/thread-reply.blade.php | 5 + tests/Feature/Screens/CommitDetailTest.php | 2 +- tests/Feature/Screens/CommitMenuTest.php | 2 +- tests/Feature/Screens/SelfThreadTest.php | 179 ++++++++++++++++++ tests/Pest.php | 20 +- tests/Unit/Devnull/SelfThreadTest.php | 105 ++++++++++ 18 files changed, 775 insertions(+), 14 deletions(-) create mode 100644 app/Devnull/SelfThread.php create mode 100644 resources/icons/list-tree.svg create mode 100644 resources/views/native/partials/show-thread.blade.php create mode 100644 resources/views/native/partials/thread-continues.blade.php create mode 100644 resources/views/native/partials/thread-position.blade.php create mode 100644 tests/Feature/Screens/SelfThreadTest.php create mode 100644 tests/Unit/Devnull/SelfThreadTest.php diff --git a/app/Devnull/Data/Commit.php b/app/Devnull/Data/Commit.php index 1175a11e..28b52bbf 100644 --- a/app/Devnull/Data/Commit.php +++ b/app/Devnull/Data/Commit.php @@ -21,6 +21,9 @@ * * A Nata Nu//ers high score carries its signed run in a fenced block, which * shows as a card ($scoreCard) instead of as code. + * + * $continuationId is the reply that carries on a thread its author writes as + * replies to themselves, when devnull says which (see SelfThread). */ final readonly class Commit { @@ -76,6 +79,7 @@ public function __construct( public ?ReplyPreview $replyPreview = null, public int $pasteisCount = 0, public ?ScoreCard $scoreCard = null, + public ?string $continuationId = null, ) {} /** @@ -143,6 +147,7 @@ public static function fromArray(array $data): self replyPreview: is_array($data['reply_preview'] ?? null) ? ReplyPreview::fromArray($data['reply_preview']) : null, pasteisCount: max(0, (int) ($data['pasteis_count'] ?? 0)), scoreCard: $scoreCard, + continuationId: is_string($data['continuation_id'] ?? null) && $data['continuation_id'] !== '' ? $data['continuation_id'] : null, ); } diff --git a/app/Devnull/SelfThread.php b/app/Devnull/SelfThread.php new file mode 100644 index 00000000..56278e10 --- /dev/null +++ b/app/Devnull/SelfThread.php @@ -0,0 +1,176 @@ + $parts The commits carrying the thread on below the commit, in order, at most the limit. + * @param bool $hasMore Whether another part follows the last of $parts. + * @param bool $hasEnded Whether it's known that no part follows the last of $parts. + * @param string|null $waiting The commit whose replies the walk needs to go on. + */ + public function __construct( + public array $parts = [], + public bool $hasMore = false, + public bool $hasEnded = false, + public ?string $waiting = null, + ) {} + + /** + * The reply among $replies that carries $commit's thread on, if it's one of them. + * + * @param iterable $replies + */ + public static function next(Commit $commit, iterable $replies): ?Commit + { + if ($commit->isDeleted() || $commit->isStaged() || $commit->author->id === '') { + return null; + } + + $earliest = null; + + foreach ($replies as $reply) { + if ($commit->continuationId !== null) { + if ($reply->id === $commit->continuationId) { + return $reply; + } + + continue; + } + + if ($reply->parentId !== $commit->id || $reply->isDeleted() || $reply->isStaged() || $reply->author->id !== $commit->author->id) { + continue; + } + + if ($earliest === null || self::isEarlier($reply, $earliest)) { + $earliest = $reply; + } + } + + return $earliest; + } + + /** + * $replies without the one that carries $commit's thread on, which shows as the next part of it instead. + * + * @param list $replies + * @return list + */ + public static function others(Commit $commit, array $replies): array + { + $next = self::next($commit, $replies); + + return $next === null ? $replies : array_values(array_filter($replies, fn (Commit $reply): bool => $reply->id !== $next->id)); + } + + /** + * Walks down from $commit through the parts that carry its thread on, as far as $limit and the replies that + * have come allow. + * + * @param Closure(Commit): (list|null) $repliesOf A commit's first page of replies, or null until it comes. + */ + public static function below(Commit $commit, Closure $repliesOf, int $limit = self::PerPage): self + { + $parts = []; + $above = $commit; + + while (true) { + $replies = $repliesOf($above); + + if ($replies === null) { + return new self($parts, waiting: $above->id); + } + + $next = self::next($above, $replies); + + if ($next === null || in_array($next, $parts, true) || $next->id === $commit->id) { + return new self($parts, hasEnded: true); + } + + if (count($parts) >= $limit) { + return new self($parts, hasMore: true); + } + + $parts[] = $next; + $above = $next; + } + } + + /** + * How many of the commits just above $commit, of $ancestors (oldest first), are earlier parts of its thread, + * and whose replies are needed to look further up. Only the author's own commits can be; each one is a part + * when its earliest reply from them is the one below it. + * + * @param list $ancestors + * @param Closure(Commit): (list|null) $repliesOf + * @return array{0: int, 1: string|null} + */ + public static function above(array $ancestors, Commit $commit, Closure $repliesOf): array + { + $count = 0; + $below = $commit; + + foreach (array_reverse($ancestors) as $ancestor) { + if ($below->isDeleted() || $ancestor->isDeleted() || $ancestor->author->id !== $below->author->id || $below->parentId !== $ancestor->id) { + break; + } + + $replies = $repliesOf($ancestor); + + if ($replies === null) { + return [$count, $ancestor->id]; + } + + if (self::next($ancestor, $replies)?->id !== $below->id) { + break; + } + + $count++; + $below = $ancestor; + } + + return [$count, null]; + } + + /** + * The place in its thread of the commit at $position, as the web's ThreadPositionBadge writes it: "3/7", with + * a "+" when more of the thread follows than has been read. Null for a commit that isn't part of one. + */ + public static function position(int $position, int $size, bool $isOpenEnded): ?string + { + return $size > 1 && $position >= 1 ? $position.'/'.$size.($isOpenEnded ? '+' : '') : null; + } + + private static function isEarlier(Commit $reply, Commit $than): bool + { + if ($reply->createdAt === null || $than->createdAt === null || $reply->createdAt->equalTo($than->createdAt)) { + return strcmp($reply->id, $than->id) < 0; + } + + return $reply->createdAt->lessThan($than->createdAt); + } +} diff --git a/app/Icons/Lucide.php b/app/Icons/Lucide.php index 3df5fa55..24bcab8f 100644 --- a/app/Icons/Lucide.php +++ b/app/Icons/Lucide.php @@ -36,6 +36,7 @@ enum Lucide case ArrowUp; case Pin; case ListOrdered; + case ListTree; /** lucide-react 1.57 draws Building2 as building-complex, so that is the drawing in building-2.svg. */ case Building2; case MapPin; @@ -177,6 +178,7 @@ public function custom(bool $filled = false): string self::ArrowUp => 'arrow-up', self::ChevronsUp => 'chevrons-up', self::ListOrdered => 'list-ordered', + self::ListTree => 'list-tree', self::Building2 => 'building-2', self::MapPin => 'map-pin', self::CalendarDays => 'calendar-days', diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index dbc088eb..ea255221 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -17,6 +17,7 @@ use App\Devnull\PostAs; use App\Devnull\ResponseCache; use App\Devnull\RowCache; +use App\Devnull\SelfThread; use App\Devnull\Stash; use App\Devnull\Timeline; use App\Devnull\Toasts; @@ -75,6 +76,14 @@ * * A member of a GitHub organization can reply as it, from the avatar at the * start of the bar's row, as the web's reply composer does (see PostAs). + * + * A thread its author wrote as replies to themselves reads in order, as on + * the web (see SelfThread): the parts after the commit follow it on its rail, + * each with its place in the thread, ten at a time with "Show more of this + * thread", and the next part isn't among the commit's replies. The replies of + * the last part show under it. The earlier parts are the ancestors above it, + * and wear their places too. Each step needs the replies of the commit above + * it, which are asked for one after another ($partReplies). */ class CommitDetail extends NativeComponent { @@ -110,6 +119,26 @@ class CommitDetail extends NativeComponent /** @var list */ public array $replies = []; + /** + * The first page of replies of the commits around this one in its author's thread, by id, which say which + * reply carries it on (see SelfThread). + * + * @var array> + */ + public array $partReplies = []; + + /** + * The commits in $partReplies with more replies than their first page. + * + * @var list + */ + public array $partsWithMore = []; + + /** + * How many parts of the author's thread show after the commit. + */ + public int $threadLimit = SelfThread::PerPage; + public ?string $repliesCursor = null; /** @@ -291,6 +320,10 @@ protected function revalidate(): void app(ResponseCache::class)->forget($this->threadPath().'/related'); }); + foreach (array_keys($this->partReplies) as $id) { + $this->refreshPartReplies((string) $id); + } + foreach (array_keys($this->tombstoneReplies) as $id) { $id = (string) $id; @@ -338,6 +371,15 @@ public function toggleReplies(): void $this->repliesShown = ! $this->repliesShown; } + /** + * "Show more of this thread": the next ten parts of the author's thread, as on the web. + */ + public function showMoreThread(): void + { + $this->threadLimit += SelfThread::PerPage; + $this->followThread(); + } + /** * The web's preview toggle, in the reply bar: the reply shows as it will * look in the field's place, at once, and devnull is asked for its body, @@ -451,6 +493,7 @@ public function loadMoreReplies(): void $this->replies = [...array_values(array_filter($this->replies, fn (Commit $reply): bool => ! isset($loaded[$reply->id]))), ...$page->items]; $this->repliesCursor = $page->nextCursor; $this->keepStagedReplies(); + $this->followThread(); } } @@ -564,6 +607,7 @@ protected function showCommitWent(PendingWrite $write, Commit $commit): void $staged = PendingWrite::stagedId($write->client_id); $this->replies = array_map(fn (Commit $reply): Commit => $reply->id === $staged ? $commit : $reply, $this->replies); + $this->followThread(); } /** @@ -694,6 +738,7 @@ protected function updateShownCommits(Closure $update): void $this->ancestors = array_map($update, $this->ancestors); $this->series = array_map($update, $this->series); $this->replies = array_map($update, $this->replies); + $this->partReplies = array_map(fn (array $replies): array => array_map($update, $replies), $this->partReplies); $this->related = array_map($update, $this->related); $this->tombstoneReplies = array_map(fn (array $replies): array => array_map($update, $replies), $this->tombstoneReplies); } @@ -703,7 +748,7 @@ protected function updateShownCommits(Closure $update): void */ protected function shownCommits(): iterable { - return [...($this->commit === null ? [] : [$this->commit]), ...$this->ancestors, ...$this->series, ...$this->replies, ...$this->related, ...array_merge([], ...array_values($this->tombstoneReplies))]; + return [...($this->commit === null ? [] : [$this->commit]), ...$this->ancestors, ...$this->series, ...$this->replies, ...array_merge([], ...array_values($this->partReplies)), ...$this->related, ...array_merge([], ...array_values($this->tombstoneReplies))]; } /** @@ -766,6 +811,7 @@ private function showKept(): void $this->takeRelated($this->cached($this->threadPath().'/related') ?? []); $this->keepStagedReplies(); + $this->followThread(); } /** @@ -786,6 +832,7 @@ private function takeThread(array $json): void $this->commit = $thread->commit; $this->ancestors = $thread->ancestors; $this->series = $thread->series; + $this->followThread(); } /** @@ -798,6 +845,74 @@ private function takeReplies(array $json): void [$this->replies, $this->repliesCursor] = self::withFirstPage($this->replies, $this->repliesCursor, Page::fromArray($json, Commit::fromArray(...))); $this->repliesLoaded = true; $this->keepStagedReplies(); + $this->followThread(); + } + + /** + * Asks for the replies the author's thread needs next, above the commit and below it, each when the one + * before has come (see SelfThread). A page kept from before shows at once and refreshes behind. + */ + private function followThread(): void + { + if ($this->commit === null) { + return; + } + + $waiting = [ + $this->selfThread()->waiting, + SelfThread::above($this->ancestors, $this->commit, $this->repliesOf())[1], + ]; + + foreach (array_unique(array_filter($waiting, fn (?string $id): bool => $id !== null && $id !== $this->id)) as $id) { + $kept = $this->cached('commits/'.rawurlencode($id).'/replies'); + $this->refreshPartReplies($id); + + if ($kept !== null) { + $this->takePartReplies($id, $kept); + } + } + } + + private function refreshPartReplies(string $id): void + { + $this->refresh('commits/'.rawurlencode($id).'/replies', [], fn (array $json) => $this->takePartReplies($id, $json)); + } + + /** + * @param array $json + */ + private function takePartReplies(string $id, array $json): void + { + $page = Page::fromArray($json, Commit::fromArray(...)); + $this->partReplies[$id] = $page->items; + $this->partsWithMore = array_values(array_diff($this->partsWithMore, [$id])); + + if ($page->hasMore()) { + $this->partsWithMore[] = $id; + } + + $this->followThread(); + } + + /** + * The first page of a commit's replies as far as the page has them, or null until they come. The commit's + * own are the ones showing, less any still on their way. + * + * @return Closure(Commit): (list|null) + */ + private function repliesOf(): Closure + { + return fn (Commit $commit): ?array => $commit->id === $this->id + ? ($this->repliesLoaded ? array_values(array_filter($this->replies, fn (Commit $reply): bool => ! $reply->isStaged())) : null) + : ($this->partReplies[$commit->id] ?? null); + } + + /** + * The parts of the author's thread after the commit, as far as they've been read. + */ + private function selfThread(): SelfThread + { + return $this->commit === null ? new SelfThread : SelfThread::below($this->commit, $this->repliesOf(), $this->threadLimit); } /** @@ -859,6 +974,11 @@ public function render(): View $viewer = $this->me(); $this->replyRows ??= new RowCache; $this->replyRows->startFrame(); + $thread = $this->selfThread(); + $parts = $thread->parts; + $partsAbove = $this->commit === null ? 0 : SelfThread::above($this->ancestors, $this->commit, $this->repliesOf())[0]; + $lastPart = $thread->hasEnded && $parts !== [] ? end($parts) : null; + $replies = $this->commit === null ? $this->replies : SelfThread::others($this->commit, $this->replies); return view('native.commit-detail', [ 'replyRows' => $this->replyRows, @@ -868,13 +988,49 @@ public function render(): View 'stashed' => app(Stash::class)->names($viewer?->id), 'pasteis' => app(Account::class)->pasteis(), 'rows' => $this->commit === null ? [] : Timeline::thread( - [...$above, $this->commit, ...$this->series], + [...$above, $this->commit, ...$this->series, ...$parts], laneAbove: $earlier === [] ? null : end($earlier)->lane(), ), 'relatedRows' => Timeline::thread($this->related), 'earlierCount' => $this->commit === null ? 0 : count($earlier), 'earlierLane' => $earlier === [] ? null : end($earlier)->lane(), - 'replyCount' => max($this->commit->repliesCount ?? 0, count($this->replies)), + 'replyCount' => max($this->commit->repliesCount ?? 0, count($replies)), + 'replies' => $replies, + 'threadParts' => array_map(fn (Commit $part): string => $part->id, $parts), + 'threadMore' => $thread->hasMore, + 'threadPositions' => $this->threadPositions($thread, $partsAbove), + 'lastPart' => $lastPart, + 'lastPartReplies' => $lastPart === null ? [] : array_slice($this->partReplies[$lastPart->id] ?? [], 0, Client::RepliesPerPage), + 'lastPartMore' => $lastPart !== null && (count($this->partReplies[$lastPart->id] ?? []) > Client::RepliesPerPage || in_array($lastPart->id, $this->partsWithMore, true)), ]); } + + /** + * Each commit's place in its author's thread, by id, as the web marks them: the earlier parts above the + * commit, the commit, and the parts after it. None when the commit isn't part of a thread. + * + * A part known to follow the last one read counts, and a thread not read to its end gets the web's "+". + * + * @return array + */ + private function threadPositions(SelfThread $below, int $partsAbove): array + { + if ($this->commit === null) { + return []; + } + + $thread = [...array_slice($this->ancestors, count($this->ancestors) - $partsAbove, $partsAbove), $this->commit, ...$below->parts]; + $size = count($thread) + ($below->hasMore ? 1 : 0); + $positions = []; + + foreach ($thread as $index => $commit) { + $label = SelfThread::position($index + 1, $size, ! $below->hasEnded); + + if ($label !== null) { + $positions[$commit->id] = $label; + } + } + + return $positions; + } } diff --git a/app/NativeComponents/Concerns/ExpandsThreads.php b/app/NativeComponents/Concerns/ExpandsThreads.php index 2a5763ce..aed53c3c 100644 --- a/app/NativeComponents/Concerns/ExpandsThreads.php +++ b/app/NativeComponents/Concerns/ExpandsThreads.php @@ -4,6 +4,7 @@ use App\Devnull\Data\Commit; use App\Devnull\Data\Page; +use App\Devnull\SelfThread; /** * "› N replies" under a commit in a feed opens its replies in place, the way @@ -20,6 +21,11 @@ * and a thread longer than a page opens the commit's page instead. * * A thread opened before opens at once from the cache, and refreshes behind. + * + * The reply that carries on a thread its author wrote as replies to + * themselves isn't one of the replies, as on the web: it's the next part of + * that thread, which the commit's "Show thread" opens (see SelfThread). + * devnull's count of the replies already leaves it out. */ trait ExpandsThreads { @@ -44,6 +50,13 @@ trait ExpandsThreads */ public array $threadsWithMore = []; + /** + * Commits whose replies, opened, showed that their author carried them on as a thread, so they show "Show thread". + * + * @var list + */ + public array $threadsContinued = []; + public function toggleReplies(string $id): void { if (array_key_exists($id, $this->threads)) { @@ -122,6 +135,8 @@ private function takeThread(string $id, array $json): void */ private function openThread(string $id, Page $page): void { + $page = $this->withoutContinuation($id, $page); + // A thread whose last reply went closes, so its commit gets its hairline back. if ($page->items === []) { $this->closeThread($id); @@ -152,6 +167,28 @@ private function openThread(string $id, Page $page): void $this->threads[$id] = array_reverse($page->items); } + /** + * The page without the reply that carries the commit's thread on, which marks the commit as carried on instead. + * + * @param Page $page + * @return Page + */ + private function withoutContinuation(string $id, Page $page): Page + { + $commit = $this->shownCommit($id); + $next = $commit === null ? null : SelfThread::next($commit, $page->items); + + if ($next === null) { + return $page; + } + + if (! in_array($id, $this->threadsContinued, true)) { + $this->threadsContinued[] = $id; + } + + return new Page(SelfThread::others($commit, $page->items), $page->nextCursor); + } + private function closeThread(string $id): void { unset($this->threads[$id]); diff --git a/resources/icons/list-tree.svg b/resources/icons/list-tree.svg new file mode 100644 index 00000000..27294fa1 --- /dev/null +++ b/resources/icons/list-tree.svg @@ -0,0 +1 @@ + diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index ce9a027f..c3db9ecf 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -25,6 +25,10 @@ has its replies right under it, beside the rail running on, and the later parts follow. Everything around the commit is muted, and still opens its own page. A deleted reply's own replies open in place, one level in, five at a time too, since a deleted commit has no page. + + A thread its author wrote as replies to themselves carries on below the commit, on the same rail, as + the web reads it (see SelfThread): each part wears its place ("2/5"), ten show at a time with "Show + more of this thread" under them, and the replies of the last part hang under it as the commit's do. --}} @if ($earlierCount > 0) @include('native.partials.earlier-commits', ['count' => $earlierCount, 'lane' => $earlierLane]) @@ -35,23 +39,28 @@ above them leaves out its hairline, which runs from the text's edge, so the two don't stack up into a line and a half. Replies end with no hairline on a commit page, and "No replies yet" keeps the commit's. --}} - @php($noReplies = $commit && $replyCount === 0 && $repliesLoaded && $series === []) + @php($noReplies = $commit && $replyCount === 0 && $repliesLoaded && $series === [] && $threadParts === []) @php($relatedBelow = $commit && $related !== [] && ! $noReplies) @foreach ($rows as $row) @php($isFocused = $row->commit->id === $commit?->id) + @php($isLastPart = $lastPart !== null && $row->commit->id === $lastPart->id) @php($hasThread = $isFocused && $repliesShown && $replies !== []) + @php($partThread = $isLastPart && $lastPartReplies !== []) @include('native.partials.commit-row', [ 'commit' => $row->commit, 'previousLane' => $row->previousLane, 'continuesRun' => $row->continuesRun, 'continuesNext' => $isFocused ? ! $loop->last : null, - 'threadBelow' => $hasThread, + 'threadBelow' => $hasThread || $partThread, + 'repliesBelow' => $partThread, 'focused' => $isFocused, 'muted' => ! $isFocused, 'seriesExpanded' => true, - 'withTail' => ! $loop->last, - 'hairline' => ! ($loop->last && $relatedBelow), + 'withTail' => ! $loop->last || $threadMore, + 'hairline' => ! ($loop->last && $relatedBelow && ! $threadMore), + 'threadPosition' => $threadPositions[$row->commit->id] ?? null, + 'showsThread' => false, ]) @if ($isFocused && $repliesShown && $replies === [] && ! $repliesLoaded && $error === null) @@ -102,8 +111,29 @@ @endforeach @endforeach @endif + @if ($partThread) + @foreach ($lastPartReplies as $index => $threadReply) + @php($replyRow = [ + 'reply' => $threadReply, + 'lane' => $lastPart->lane(), + 'previousLane' => $index === 0 ? null : $lastPartReplies[$index - 1]->lane(), + 'hasNext' => ! $loop->last || $lastPartMore, + 'railLane' => null, + 'muted' => true, + 'thread' => $lastPart, + 'more' => $loop->last && $lastPartMore ? "openReplies('{$lastPart->id}')" : null, + 'last' => $loop->last, + ]) + @php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1])) + @php($replyRows->include('reply-'.$threadReply->id, \App\Devnull\RowInputs::for($threadReply, $rowScope), 'native.partials.thread-reply', $replyRow, $rowScope)) + @endforeach + @endif @endforeach + @if ($threadMore && $threadParts !== []) + @include('native.partials.thread-continues', ['lane' => $rows[array_key_last($rows)]->commit->lane()]) + @endif + @if ($noReplies) No replies yet. diff --git a/resources/views/native/partials/commit-row-content.blade.php b/resources/views/native/partials/commit-row-content.blade.php index 553ac21e..a3af40ec 100644 --- a/resources/views/native/partials/commit-row-content.blade.php +++ b/resources/views/native/partials/commit-row-content.blade.php @@ -11,6 +11,10 @@ which tapped says when in your timezone, its hash, and its replies behind a toggle in its action row. The commits around it ($muted) step back: smaller and in muted ink, with a smaller avatar and action row. They still open their own pages. + A commit in a thread its author wrote as replies to themselves wears its place in it ($threadPosition, "2/5"), and + one its author carried on that way links to that thread ($showsThread), as the web's "Show thread" does (see + SelfThread). $repliesBelow says its replies show under the row, so its action row leaves out "› N replies". + A commit you just made that devnull doesn't have yet is staged: dimmed, with the staged chip and no actions, until the real one takes its place (see SyncsOutbox). @@ -25,6 +29,9 @@ @php($withTail ??= ! $focused) @php($continuesNext ??= null) @php($threadBelow ??= false) +@php($threadPosition ??= null) +@php($showsThread ??= $commit->continuationId !== null) +@php($repliesBelow ??= false) @php($inFeed = $continuesNext !== null) @php($endsWithDot = $inFeed && ! $continuesRun && ! $continuesNext) @php($laterParts = $seriesExpanded ? 0 : $commit->laterSeriesParts()) @@ -48,6 +55,9 @@ @if ($commit->isSeriesPart()) @include('native.partials.series-position') @endif + @if ($threadPosition !== null) + @include('native.partials.thread-position') + @endif @unless ($commit->isApproved()) @include('native.partials.status-chip', ['status' => $commit->status]) @endunless @@ -75,6 +85,10 @@ @endif + @if ($showsThread && ! $focused) + @include('native.partials.show-thread') + @endif + @if ($focused) {{ $commit->shortHash }} @endif @@ -88,7 +102,7 @@ 'repliesCount' => $replyCount ?? $commit->repliesCount, ]) @else - @include('native.partials.commit-actions', ['compact' => $muted]) + @include('native.partials.commit-actions', ['compact' => $muted, 'withReplies' => ! $repliesBelow]) @endif diff --git a/resources/views/native/partials/feed.blade.php b/resources/views/native/partials/feed.blade.php index c85258e0..17298118 100644 --- a/resources/views/native/partials/feed.blade.php +++ b/resources/views/native/partials/feed.blade.php @@ -3,7 +3,7 @@ partials/who-to-follow) and commits on the rail. Under a commit hangs its thread, inside its row's hairline, as on the web: the newest reply devnull previews, with "Show more" when there are others, or the replies opened in place, with "Show more" to the commit's page when there are more than they show. The commit's rail runs on past them when - its author's run goes on below. + its author's run goes on below. A commit its author carried on in replies to themselves shows "Show thread". Given a $rowCache (see App\Devnull\RowCache), commits and replies that haven't changed since the last frame are drawn from it rather than built again. Given a $rowWindow (see App\Devnull\RowWindow), rows far from the screen @@ -56,6 +56,7 @@ 'continuesRun' => $row->continuesRun, 'continuesNext' => $row->continuesNext, 'threadBelow' => $threadReplies !== [], + 'showsThread' => $feedCommit->continuationId !== null || in_array($feedCommit->id, $threadsContinued ?? [], true), ]; @endphp @if (! $feedDraws) diff --git a/resources/views/native/partials/show-thread.blade.php b/resources/views/native/partials/show-thread.blade.php new file mode 100644 index 00000000..6a3e4aa6 --- /dev/null +++ b/resources/views/native/partials/show-thread.blade.php @@ -0,0 +1,8 @@ +{{-- + "Show thread" under a commit its author carried on in replies to themselves, as the web's ShowThreadLink: it opens + the commit's page, where the thread reads in order (see SelfThread). +--}} + + + Show thread + diff --git a/resources/views/native/partials/thread-continues.blade.php b/resources/views/native/partials/thread-continues.blade.php new file mode 100644 index 00000000..efe83068 --- /dev/null +++ b/resources/views/native/partials/thread-continues.blade.php @@ -0,0 +1,24 @@ +{{-- + "Show more of this thread" under the last part of an author's thread a commit page shows, as the web's: a tap shows + the next ten parts (see SelfThread). It mirrors "↑ N earlier commits" above the commit: the last part's rail comes + down solid to a hollow node in its lane, and a dashed Rail Gray line runs on below it to what's still to come. +--}} +@php($colour = 'bg-theme-'.\App\Devnull\Lane::token($lane)) + + + + + + + Show more of this thread + + + + + + + @include('native.partials.rail-node', ['lane' => $lane, 'filled' => false]) + + @include('native.partials.dashed-line', ['position' => 'top-[31] bottom-0', 'left' => 31.5, 'lane' => \App\Devnull\Lane::Rail]) + + diff --git a/resources/views/native/partials/thread-position.blade.php b/resources/views/native/partials/thread-position.blade.php new file mode 100644 index 00000000..0a9bb7dd --- /dev/null +++ b/resources/views/native/partials/thread-position.blade.php @@ -0,0 +1,4 @@ +{{-- A commit's place in its author's thread, like the web's ThreadPositionBadge: "2/5" in mono on a muted wash. --}} + + {{ $threadPosition }} + diff --git a/resources/views/native/partials/thread-reply.blade.php b/resources/views/native/partials/thread-reply.blade.php index 6a1d0a7c..29f95d96 100644 --- a/resources/views/native/partials/thread-reply.blade.php +++ b/resources/views/native/partials/thread-reply.blade.php @@ -16,6 +16,8 @@ A commit page draws its replies $muted, smaller and in muted ink, so the commit they answer stays the main thing. + A reply its author carried on in replies to themselves links to that thread, as on the web (see show-thread). + A reply you just sent that devnull doesn't have yet is staged: dimmed, with the staged chip and no actions. --}} @php($previousLane ??= null) @@ -83,6 +85,9 @@ @include('native.partials.commit-body', ['size' => $muted ? 'text-sm' : 'text-[15px]']) @include('native.partials.commit-media', ['withEmbeds' => false]) + @if ($reply->continuationId !== null) + @include('native.partials.show-thread') + @endif @unless ($reply->isStaged()) @include('native.partials.commit-actions', ['expandable' => false, 'withQuote' => false, 'compact' => $muted]) @endunless diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index 7e0360c4..ad9ef4b2 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -843,7 +843,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): it('stars the focused commit and its replies in place', function () { $grace = userJson(['id' => 'u3', 'handle' => 'grace', 'name' => 'Grace']); - fakeThread(['author' => $grace], replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'author' => $grace])], extra: [ + fakeThread(['author' => $grace], replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2'])], extra: [ 'POST /api/v1/commits/c2/star' => [['data' => commitJson(['id' => 'c2', 'stars_count' => 1, 'starred' => true])]], 'POST /api/v1/commits/r1/star' => [['data' => commitJson(['id' => 'r1', 'starred' => true])]], ]); diff --git a/tests/Feature/Screens/CommitMenuTest.php b/tests/Feature/Screens/CommitMenuTest.php index c07a7170..53ba2936 100644 --- a/tests/Feature/Screens/CommitMenuTest.php +++ b/tests/Feature/Screens/CommitMenuTest.php @@ -130,7 +130,7 @@ $deleted = true; }), 'GET /api/v1/commits/c2' => Http::response(commitPageJson(commitJson(['id' => 'c2', 'body' => 'Ada asks', 'replies_count' => $deleted ? 0 : 1, 'author' => userJson(['id' => 'u2', 'handle' => 'ada'])]))), - 'GET /api/v1/commits/c2/replies' => Http::response(pageJson($deleted ? [] : [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'Soon gone'])])), + 'GET /api/v1/commits/c2/replies' => Http::response(pageJson($deleted ? [] : [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'Soon gone', 'author' => userJson()])])), default => Http::response(['message' => 'No fake.'], 404), }; }); diff --git a/tests/Feature/Screens/SelfThreadTest.php b/tests/Feature/Screens/SelfThreadTest.php new file mode 100644 index 00000000..47a445e5 --- /dev/null +++ b/tests/Feature/Screens/SelfThreadTest.php @@ -0,0 +1,179 @@ + 'http://devnull.test']); + signIn(); +}); + +/** + * One of Ada's commits, $minutes ago, replying to $parent. + * + * @param array $overrides + * @return array + */ +function adaJson(string $id, ?string $parent = null, int $minutes = 30, array $overrides = []): array +{ + return commitJson([ + 'id' => $id, + 'parent_id' => $parent, + 'body' => "Ada's {$id}", + 'author' => userJson(['handle' => 'ada', 'name' => 'Ada', 'lane' => 2]), + 'created_at' => now()->subMinutes($minutes)->toIso8601ZuluString(), + ...$overrides, + ]); +} + +/** + * Serves a commit page and the replies of every commit in $replies, by id, and 404s anything else. + * + * @param array $commit + * @param list> $ancestors + * @param array>> $replies + */ +function serveSelfThread(array $commit, array $ancestors, array $replies): void +{ + Http::fake(function (Request $request) use ($commit, $ancestors, $replies) { + $path = (string) parse_url($request->url(), PHP_URL_PATH); + + if ($path === '/api/v1/commits/'.$commit['id']) { + return Http::response(commitPageJson($commit, $ancestors)); + } + + if (preg_match('#^/api/v1/commits/([^/]+)/replies$#', $path, $match) === 1 && array_key_exists($match[1], $replies)) { + return Http::response(pageJson($replies[$match[1]])); + } + + if (str_ends_with($path, '/related')) { + return Http::response(['data' => []]); + } + + return Http::response(['message' => 'No fake.'], 404); + }); +} + +/** + * The refs of the rows down a commit page, top to bottom. + * + * @return list + */ +function selfThreadRows(TestableComponent $screen): array +{ + return array_values(array_filter(childRefs($screen, 'thread-page'), fn (?string $ref): bool => $ref !== 'reply-bar-clearance')); +} + +/** + * The text of a commit's place in its thread. + */ +function threadPositionOf(TestableComponent $screen, string $id): string +{ + $text = findNode(nodeByRef($screen, 'thread-position-'.$id), fn (array $node): bool => ($node['type'] ?? null) === 'text'); + + return $text['props']['text'] ?? ''; +} + +it("reads an author's replies to themselves in order under the commit, as the web's thread", function () { + serveSelfThread(adaJson('c1', overrides: ['replies_count' => 2]), [], [ + 'c1' => [ + replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'Grace answers', 'created_at' => now()->subMinutes(28)->toIso8601ZuluString()]), + adaJson('p2', 'c1', 25), + adaJson('later', 'c1', 5, ['body' => 'Ada again, later']), + ], + 'p2' => [replyJson(['id' => 'x1', 'parent_id' => 'p2', 'body' => 'Under part two']), adaJson('p3', 'p2', 20)], + 'p3' => [replyJson(['id' => 'y1', 'parent_id' => 'p3', 'body' => 'Under the last part'])], + ]); + + $screen = Native::visit('/log/commits/c1') + ->assertSee("Ada's p2") + ->assertSee("Ada's p3") + ->assertSee('Under the last part') + ->assertDontSee('Under part two') + ->assertDontSee('Grace answers') + ->assertDontSee('No replies yet.'); + + expect(selfThreadRows($screen))->toBe(['focused-commit', 'commit-p2', 'commit-p3', 'thread-reply-y1']) + ->and(threadPositionOf($screen, 'c1'))->toBe('1/3') + ->and(threadPositionOf($screen, 'p2'))->toBe('2/3') + ->and(threadPositionOf($screen, 'p3'))->toBe('3/3') + ->and(railNode($screen, 'commit-p2'))->toBe('dot') + // The last part's replies show under it, so its action row doesn't offer them again. + ->and(findNode(nodeByRef($screen, 'commit-p3'), fn (array $node): bool => ($node['ref'] ?? null) === 'replies-p3'))->toBeNull(); + + // The commit's own replies leave out the part that carries it on, and keep its later replies to itself. + $screen->tap('replies-c1')->assertSee('Grace answers')->assertSee('Ada again, later'); + + expect(selfThreadRows($screen))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-later', 'commit-p2', 'commit-p3', 'thread-reply-y1']); +}); + +it('marks the earlier parts above a commit in the middle of its thread', function () { + serveSelfThread(adaJson('p2', 'c1', 20), [adaJson('c1', minutes: 30)], [ + 'c1' => [adaJson('p2', 'c1', 20)], + 'p2' => [], + ]); + + $screen = Native::visit('/log/commits/p2'); + + expect(threadPositionOf($screen, 'c1'))->toBe('1/2') + ->and(threadPositionOf($screen, 'p2'))->toBe('2/2'); +}); + +it("doesn't mark a commit its author replied to some other way first", function () { + serveSelfThread(adaJson('p2', 'c1', 10), [adaJson('c1', minutes: 30)], [ + 'c1' => [adaJson('first', 'c1', 20), adaJson('p2', 'c1', 10)], + 'p2' => [], + ]); + + $screen = Native::visit('/log/commits/p2')->assertSee("Ada's c1"); + + expect(findNode($screen->tree(), fn (array $node): bool => str_starts_with((string) ($node['ref'] ?? ''), 'thread-position-')))->toBeNull(); +}); + +it('shows ten parts at a time, and the rest from Show more of this thread', function () { + $replies = ['c1' => [adaJson('p2', 'c1', 29)]]; + + foreach (range(2, 11) as $part) { + $replies['p'.$part] = [adaJson('p'.($part + 1), 'p'.$part, 29 - $part)]; + } + + $replies['p12'] = []; + serveSelfThread(adaJson('c1', minutes: 30), [], $replies); + + $screen = Native::visit('/log/commits/c1') + ->assertSee("Ada's p11") + ->assertDontSee("Ada's p12"); + + expect(threadPositionOf($screen, 'c1'))->toBe('1/12+'); + + $screen->tap('more-thread')->assertSee("Ada's p12"); + + expect(threadPositionOf($screen, 'c1'))->toBe('1/12') + ->and(threadPositionOf($screen, 'p12'))->toBe('12/12') + ->and(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'more-thread'))->toBeNull(); +}); + +it("leaves the author's next part out of a thread opened on the Log, and links to the thread instead", function () { + Http::fake(fn (Request $request) => match (parse_url($request->url(), PHP_URL_PATH)) { + '/api/v1/log/following' => Http::response(pageJson([adaJson('c1', overrides: ['replies_count' => 1])])), + '/api/v1/commits/c1/replies' => Http::response(pageJson([adaJson('p2', 'c1', 25), replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'Grace answers'])])), + default => Http::response(['message' => 'No fake.'], 404), + }); + + $screen = Native::visit('/log')->assertDontSee('Show thread')->tap('replies-c1') + ->assertSee('Grace answers') + ->assertDontSee("Ada's p2") + ->assertSee('Show thread'); + + expect(array_map(fn ($reply): string => $reply->id, $screen->instance()->threads['c1']))->toBe(['r1']); + + $screen->tap('show-thread-c1')->assertNavigatedTo('/log/commits/c1'); +}); + +it('links to the thread when devnull says which reply carries it on', function () { + Http::fake(['devnull.test/api/v1/log/following*' => Http::response(pageJson([adaJson('c1', overrides: ['continuation_id' => 'p2'])]))]); + + Native::visit('/log')->assertSee('Show thread')->tap('show-thread-c1')->assertNavigatedTo('/log/commits/c1'); +}); diff --git a/tests/Pest.php b/tests/Pest.php index d1bf556c..42366d00 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -409,7 +409,8 @@ function userJson(array $overrides = []): array $username = $overrides['handle'] ?? 'local_dev'; return [ - 'id' => '0199e5c4-0000-7000-8000-000000000001', + // Someone else, named by a handle of their own, is someone else to the app too. + 'id' => $username === 'local_dev' ? '0199e5c4-0000-7000-8000-000000000001' : 'user-'.$username, 'handle' => $username, 'name' => 'Local Dev', 'avatar_url' => 'https://avatars.githubusercontent.com/u/1?v=4', @@ -426,6 +427,17 @@ function userJson(array $overrides = []): array ]; } +/** + * Someone replying to a commit, who isn't its author. + * + * @param array $overrides + * @return array + */ +function replierJson(array $overrides = []): array +{ + return userJson(['id' => '0199e5c4-0000-7000-8000-0000000000aa', 'handle' => 'replier', 'name' => 'Re Plier', 'lane' => 5, ...$overrides]); +} + /** * A user with their counts, as `/me`, a profile and a key sync send them. * @@ -525,14 +537,16 @@ function commitPageJson(array $commit, array $ancestors = [], array $series = [] /** * A reply as `GET /commits/{id}/replies` sends it: like any commit, but without - * stars_count or starred, which that list doesn't load. + * stars_count or starred, which that list doesn't load. It comes from someone + * other than the commit's author unless a test says who, since a reply of + * theirs carries their own thread on (see SelfThread). * * @param array $overrides * @return array */ function replyJson(array $overrides = []): array { - return array_diff_key(commitJson($overrides), array_flip(['stars_count', 'starred'])); + return array_diff_key(commitJson(['author' => replierJson(), ...$overrides]), array_flip(['stars_count', 'starred'])); } /** diff --git a/tests/Unit/Devnull/SelfThreadTest.php b/tests/Unit/Devnull/SelfThreadTest.php new file mode 100644 index 00000000..5f9cc7e6 --- /dev/null +++ b/tests/Unit/Devnull/SelfThreadTest.php @@ -0,0 +1,105 @@ + $overrides + */ +function threadCommit(string $id, string $handle = 'ada', ?string $parent = null, int $minutes = 10, array $overrides = []): Commit +{ + return Commit::fromArray(commitJson([ + 'id' => $id, + 'parent_id' => $parent, + 'author' => userJson(['handle' => $handle]), + 'created_at' => now()->subMinutes($minutes)->toIso8601ZuluString(), + ...$overrides, + ])); +} + +/** + * @param array> $replies + * @return Closure(Commit): (list|null) + */ +function repliesFrom(array $replies): Closure +{ + return fn (Commit $commit): ?array => $replies[$commit->id] ?? null; +} + +it("carries a commit on with its author's earliest reply to it", function () { + $commit = threadCommit('c1', minutes: 30); + $replies = [ + threadCommit('r1', 'grace', 'c1', 25), + threadCommit('p3', 'ada', 'c1', 10), + threadCommit('p2', 'ada', 'c1', 20), + ]; + + expect(SelfThread::next($commit, $replies)?->id)->toBe('p2') + ->and(array_map(fn (Commit $reply): string => $reply->id, SelfThread::others($commit, $replies)))->toBe(['r1', 'p3']); +}); + +it('never carries a commit on with a deleted reply, a quote, or a reply still on its way', function () { + $commit = threadCommit('c1', minutes: 30); + + expect(SelfThread::next($commit, [ + Commit::fromArray(['id' => 'gone', 'parent_id' => 'c1', 'deleted_at' => now()->toIso8601ZuluString()]), + threadCommit('quote', 'ada', null, 20, ['quoted_commit_id' => 'c1']), + threadCommit('staged', 'ada', 'c1', 1, ['status' => Commit::Staged]), + threadCommit('r1', 'grace', 'c1', 15), + ]))->toBeNull(); +}); + +it("takes devnull's word for which reply carries the thread on", function () { + $commit = threadCommit('c1', minutes: 30, overrides: ['continuation_id' => 'p3']); + + expect(SelfThread::next($commit, [threadCommit('p2', 'ada', 'c1', 20), threadCommit('p3', 'ada', 'c1', 10)])?->id)->toBe('p3'); +}); + +it('walks down the parts as far as their replies have come', function () { + $c1 = threadCommit('c1', minutes: 30); + $p2 = threadCommit('p2', 'ada', 'c1', 20); + $p3 = threadCommit('p3', 'ada', 'p2', 10); + + $waiting = SelfThread::below($c1, repliesFrom(['c1' => [$p2]])); + $ended = SelfThread::below($c1, repliesFrom(['c1' => [$p2], 'p2' => [$p3], 'p3' => [threadCommit('r1', 'grace', 'p3', 5)]])); + + expect(array_map(fn (Commit $part): string => $part->id, $waiting->parts))->toBe(['p2']) + ->and($waiting->waiting)->toBe('p2') + ->and($waiting->hasEnded)->toBeFalse() + ->and(array_map(fn (Commit $part): string => $part->id, $ended->parts))->toBe(['p2', 'p3']) + ->and($ended->hasEnded)->toBeTrue() + ->and($ended->waiting)->toBeNull(); +}); + +it('stops at the limit and says another part follows', function () { + $c1 = threadCommit('c1', minutes: 30); + $p2 = threadCommit('p2', 'ada', 'c1', 20); + $p3 = threadCommit('p3', 'ada', 'p2', 10); + + $thread = SelfThread::below($c1, repliesFrom(['c1' => [$p2], 'p2' => [$p3]]), limit: 1); + + expect(array_map(fn (Commit $part): string => $part->id, $thread->parts))->toBe(['p2']) + ->and($thread->hasMore)->toBeTrue() + ->and($thread->hasEnded)->toBeFalse(); +}); + +it('counts the earlier parts above a commit, only while each is the one its author carried on', function () { + $c1 = threadCommit('c1', minutes: 30); + $p2 = threadCommit('p2', 'ada', 'c1', 20); + $p3 = threadCommit('p3', 'ada', 'p2', 10); + $other = threadCommit('o1', 'ada', 'p2', 15); + + expect(SelfThread::above([$c1, $p2], $p3, repliesFrom(['c1' => [$p2], 'p2' => [$p3]])))->toBe([2, null]) + ->and(SelfThread::above([$c1, $p2], $p3, repliesFrom(['p2' => [$p3]])))->toBe([1, 'c1']) + // Ada's earliest reply to p2 is o1, so p3 isn't part of the thread. + ->and(SelfThread::above([$c1, $p2], $p3, repliesFrom(['p2' => [$other, $p3]])))->toBe([0, null]) + ->and(SelfThread::above([threadCommit('g1', 'grace')], threadCommit('p9', 'ada', 'g1'), repliesFrom([])))->toBe([0, null]); +}); + +it("writes a commit's place in its thread as the web does", function () { + expect(SelfThread::position(2, 5, false))->toBe('2/5') + ->and(SelfThread::position(1, 12, true))->toBe('1/12+') + ->and(SelfThread::position(1, 1, false))->toBeNull(); +}); From f03090c4b6512f0ff509bc0419f83b5ea6a0042d Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 02:14:29 +0000 Subject: [PATCH 05/18] Open every level of replies in place on the commit page, as the web does A reply's "N replies" on the commit page used to open that reply's own page. Now it opens its replies under it, and theirs under them, as deep as they go, the way the web's commit page does. Tapping a reply still opens its page. The rows come from #179's ThreadRows, now recursive, and the threads from ExpandsThreads, which replaces the page's separate mechanism for a deleted reply's replies. Indentation stops at the web's depth of three (maxIndentDepth in commit-thread.tsx). Replies at the third step hang on their own elbow off the line of the reply they answer, and deeper ones line up under them with no lines and a "replying to @handle" line. "Show more" is a row of its own on the page too, as on the Log, and says "to @handle" past that depth. The Log keeps opening only the commit's replies in place. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/RowInputs.php | 1 - app/Devnull/ThreadRows.php | 193 +++++++++++++----- app/NativeComponents/CommitDetail.php | 119 ++++------- .../Concerns/ExpandsThreads.php | 8 +- .../views/native/commit-detail.blade.php | 75 ++----- .../native/partials/related-commits.blade.php | 1 + .../native/partials/thread-links.blade.php | 33 +-- .../native/partials/thread-more-row.blade.php | 40 +++- .../native/partials/thread-more.blade.php | 17 -- .../native/partials/thread-reply.blade.php | 62 +++--- .../Feature/Screens/CommitDetailCacheTest.php | 2 +- tests/Feature/Screens/CommitDetailTest.php | 15 +- tests/Feature/Screens/NestedRepliesTest.php | 77 +++++++ tests/Feature/Screens/RowCacheScreensTest.php | 6 +- tests/Unit/Devnull/ThreadRowsTest.php | 86 ++++++++ 15 files changed, 457 insertions(+), 278 deletions(-) delete mode 100644 resources/views/native/partials/thread-more.blade.php create mode 100644 tests/Feature/Screens/NestedRepliesTest.php create mode 100644 tests/Unit/Devnull/ThreadRowsTest.php diff --git a/app/Devnull/RowInputs.php b/app/Devnull/RowInputs.php index 33d2f741..323d2265 100644 --- a/app/Devnull/RowInputs.php +++ b/app/Devnull/RowInputs.php @@ -40,7 +40,6 @@ public static function for(Commit $commit, array $scope): array 'continued' => in_array($commit->id, $scope['threadsContinued'] ?? [], true), 'popping' => [$scope['popping']['star-'.$commit->id] ?? null, $scope['popping']['pastel-'.$commit->id] ?? null], 'tombstones' => $scope['tombstones'] ?? false, - 'tombstoneReplies' => array_key_exists($commit->id, $scope['tombstoneReplies'] ?? []), 'shown' => [self::changing($commit), $commit->quotedCommit === null ? null : self::changing($commit->quotedCommit)], 'poll' => [$scope['pollChoices'][$commit->id] ?? null, in_array($commit->id, $scope['voting'] ?? [], true)], ]; diff --git a/app/Devnull/ThreadRows.php b/app/Devnull/ThreadRows.php index 337766d9..61e7042f 100644 --- a/app/Devnull/ThreadRows.php +++ b/app/Devnull/ThreadRows.php @@ -3,21 +3,35 @@ namespace App\Devnull; use App\Devnull\Data\Commit; +use Closure; /** - * The list rows of a commit's thread opened in a feed (see - * Concerns\ExpandsThreads), in order, each with what its partial draws. + * The rows of a commit's thread opened in place (see + * Concerns\ExpandsThreads), in order, each with what its partial draws: in a + * feed, and on a commit page under the commit and under the last part of its + * author's thread. * * Under the commit come its replies, each followed by its own replies when - * they're open, one step in, and "Show more" after the replies of a thread - * with more. Every row is a list row of its own, and the last one closes the - * commit's row with its hairline. + * they're open, and theirs, as deep as they go, with "Show more" after the + * replies of a thread with more. Every row is a row of its own, and in a feed + * the last one closes the commit's row with its hairline. * * The thread hangs off the rail in dashes, as on the web: the first reply on * an elbow from the commit's rail, each later one on a short link from the * line down from the reply above, which is in that reply's lane. A reply's - * own replies hang the same way off the line down from its avatar, which runs - * on past them ($spine) when another reply of the commit follows. + * own replies hang the same way off the line down from its avatar, one step + * in, and that line runs on past them ($spines) when another reply follows. + * + * The steps in stop at the web's depth (MaxIndentDepth). Replies at that + * depth each hang on an elbow of their own from the line of the reply they + * answer, as the web draws every reply, since their replies line up under + * them and a line down from one avatar to the next would run through those. + * Deeper replies are flattened: in the same column, with no lines, and a + * "↳ replying to @handle" line saying who they answer. + * + * In a feed only the commit's replies open theirs in place ($opensInPlace), + * and a reply's replies open their page. On a commit page every reply opens + * its replies in place. */ final class ThreadRows { @@ -35,67 +49,151 @@ final class ThreadRows */ public const int FirstReplyTop = 3; + /** + * How deep replies step in, as the web's maxIndentDepth: the commit's + * replies are 1, and deeper replies line up under those at this depth. + */ + public const int MaxIndentDepth = 3; + + /** + * How far in each step is, in points. + */ + public const int Step = 32; + /** * @param array> $threads Open threads, by the id of the commit or reply they answer. * @param array $cursors Where each open thread with more carries on. * @param array $shown How many of each open thread's replies show. * @param int|string|null $railLane The commit's rail running on past its thread, when its author's run carries on below. + * @param int $opensInPlace How deep a reply's replies button opens its replies in place rather than its page. + * @param bool $onPage On a commit page: replies muted, deleted ones open theirs in place, and no hairline under them. + * @param string|null $morePress What the commit's own "Show more" presses, when it isn't showMoreReplies. * @return list, reply: Commit|null}> */ - public static function under(Commit $commit, array $threads, array $cursors, array $shown, int|string|null $railLane = null): array - { + public static function under( + Commit $commit, + array $threads, + array $cursors, + array $shown, + int|string|null $railLane = null, + int $opensInPlace = 1, + bool $onPage = false, + ?string $morePress = null, + ): array { $thread = fn (string $id): array => array_slice($threads[$id] ?? [], 0, $shown[$id] ?? null); $hasMore = fn (string $id): bool => isset($cursors[$id]) || count($thread($id)) < count($threads[$id] ?? []); - $replies = $thread($commit->id); - if ($replies === []) { + $rows = []; + self::branch($rows, $commit, 1, [], $thread, $hasMore, [ + 'railLane' => $railLane, + 'opensInPlace' => $opensInPlace, + 'onPage' => $onPage, + 'morePress' => $morePress, + ]); + + if ($rows === []) { return []; } - $rows = []; - $more = $hasMore($commit->id); + $last = array_key_last($rows); + $rows[$last]['data']['last'] = true; + + return $rows; + } + + /** + * How far in replies at $depth start, past the commit's text. + */ + public static function indent(int $depth): int + { + return (min($depth, self::MaxIndentDepth) - 1) * self::Step; + } + + /** + * The x of the line down from the avatars of replies at $depth, or the commit's rail above them all. + */ + private static function lineAt(int $depth): float + { + return $depth === 0 ? 31.5 : 75.5 + self::indent($depth); + } + + /** + * The rows of $parent's replies at $depth, and theirs under each. + * + * @param list> $rows + * @param list $spines Lines from further up running on past these rows. + * @param Closure(string): list $thread + * @param Closure(string): bool $hasMore + * @param array{railLane: int|string|null, opensInPlace: int, onPage: bool, morePress: string|null} $options + */ + private static function branch(array &$rows, Commit $parent, int $depth, array $spines, Closure $thread, Closure $hasMore, array $options): void + { + $replies = $thread($parent->id); + + if ($replies === []) { + return; + } + + $more = $hasMore($parent->id); + $indent = self::indent($depth); + $hangs = $depth === self::MaxIndentDepth; + $flattened = $depth > self::MaxIndentDepth; + $parentLine = self::lineAt($depth - 1); + $onPage = $options['onPage']; foreach ($replies as $index => $reply) { - $nested = $reply->isDeleted() ? [] : $thread($reply->id); - $nestedMore = $nested !== [] && $hasMore($reply->id); + $nested = $reply->isDeleted() && ! $onPage ? [] : $thread($reply->id); $followed = $index < count($replies) - 1 || $more; + $top = ! $onPage && $depth === 1 && $index === 0 ? self::FirstReplyTop : 10; $rows[] = self::reply($reply, [ - 'lane' => $commit->lane(), - 'previousLane' => $index === 0 ? null : $replies[$index - 1]->lane(), - 'hasNext' => $followed || $nested !== [], - 'railLane' => $railLane, - 'thread' => $commit, - 'repliesInPlace' => true, - ...($index === 0 ? ['top' => self::FirstReplyTop] : []), + 'lane' => $parent->lane(), + 'previousLane' => $index === 0 || $hangs ? null : $replies[$index - 1]->lane(), + 'hasNext' => ! $hangs && ! $flattened && ($followed || $nested !== []), + 'links' => ! $flattened, + 'railLane' => $options['railLane'], + 'indent' => $indent, + 'top' => $top, + // At the deepest step the line of the reply answered runs on under the elbow to the next one. + 'spines' => [...$spines, ...($hangs && $followed ? [['left' => $parentLine, 'lane' => $parent->lane(), 'top' => $top + 12]] : [])], + 'replyingTo' => $flattened ? self::replyingTo($reply, $parent) : null, + 'repliesInPlace' => $depth <= $options['opensInPlace'], + 'muted' => $onPage, + 'tombstones' => $onPage, ]); - foreach ($nested as $nestedIndex => $nestedReply) { - $rows[] = self::reply($nestedReply, [ - 'lane' => $reply->lane(), - 'previousLane' => $nestedIndex === 0 ? null : $nested[$nestedIndex - 1]->lane(), - 'hasNext' => $nestedIndex < count($nested) - 1 || $nestedMore, - 'railLane' => $railLane, - 'indent' => 32, - 'spine' => $followed ? $reply->lane() : null, - 'thread' => $reply, - 'repliesInPlace' => false, - ]); - } - - if ($nestedMore) { - $rows[] = self::more($reply->id, $nested[array_key_last($nested)]->lane(), $railLane, 32, $followed ? $reply->lane() : null); - } + // The line that has to run on past this reply's own replies, to the next reply at this depth. + $through = match (true) { + ! $followed || $flattened => [], + $hangs => [['left' => $parentLine, 'lane' => $parent->lane()]], + default => [['left' => self::lineAt($depth), 'lane' => $reply->lane()]], + }; + + self::branch($rows, $reply, $depth + 1, [...$spines, ...$through], $thread, $hasMore, $options); } if ($more) { - $rows[] = self::more($commit->id, $replies[array_key_last($replies)]->lane(), $railLane); + $rows[] = self::more($parent, [ + 'lane' => $replies[array_key_last($replies)]->lane(), + 'parentLane' => $parent->lane(), + 'hangs' => $hangs, + 'links' => ! $flattened, + 'railLane' => $options['railLane'], + 'indent' => $indent, + 'spines' => $spines, + 'to' => $flattened && ! $parent->isDeleted() ? $parent->author->handle() : null, + 'hairline' => ! $onPage, + ...($depth === 1 && $options['morePress'] !== null ? ['press' => $options['morePress']] : []), + ]); } + } - $last = array_key_last($rows); - $rows[$last]['data']['last'] = true; - - return $rows; + /** + * "replying to @handle", or "quoting" when the reply quotes what it answers, as the web marks a flattened reply. + */ + private static function replyingTo(Commit $reply, Commit $parent): string + { + return ($reply->quotedCommitId === $parent->id ? 'quoting ' : 'replying to ').($parent->isDeleted() ? '[deleted]' : $parent->author->handle()); } /** @@ -107,7 +205,7 @@ private static function reply(Commit $reply, array $data): array return [ 'key' => 'thread-reply-'.$reply->id, 'partial' => 'native.partials.thread-reply', - 'data' => ['reply' => $reply, 'indent' => 0, 'spine' => null, 'last' => false, 'fades' => true, ...$data], + 'data' => ['reply' => $reply, 'last' => false, 'fades' => true, ...$data], 'reply' => $reply, ]; } @@ -115,14 +213,15 @@ private static function reply(Commit $reply, array $data): array /** * "Show more" at the foot of a thread, on a line down in the lane of the reply above it. * + * @param array $data * @return array{key: string, partial: string, data: array, reply: null} */ - private static function more(string $threadId, int|string $lane, int|string|null $railLane, int $indent = 0, int|string|null $spine = null): array + private static function more(Commit $parent, array $data): array { return [ - 'key' => 'thread-more-'.$threadId, + 'key' => 'thread-more-'.$parent->id, 'partial' => 'native.partials.thread-more-row', - 'data' => ['threadId' => $threadId, 'lane' => $lane, 'railLane' => $railLane, 'indent' => $indent, 'spine' => $spine, 'last' => false], + 'data' => ['threadId' => $parent->id, 'last' => false, ...$data], 'reply' => null, ]; } diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index b2d1a490..d7dd120f 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -23,6 +23,7 @@ use App\Devnull\Toasts; use App\Icons\Lucide; use App\Models\PendingWrite; +use App\NativeComponents\Concerns\ExpandsThreads; use App\NativeComponents\Concerns\OpensInTab; use App\NativeComponents\Concerns\OpensLiveStream; use App\NativeComponents\Concerns\RedrawsOnAppearanceChange; @@ -46,7 +47,11 @@ * "› N replies", each opened in place. Opened from a "› N replies" button * ($data['replies']), its replies already show. They come ten at a time * (see Client::RepliesPerPage), and "Show more" under the last asks for the - * next ten, as it does under a deleted reply's replies opened in place. + * next ten. + * + * Each reply's own replies open in place under it, and theirs under them, as + * deep as they go, as the web's commit page does (see ExpandsThreads and + * App\Devnull\ThreadRows). Tapping a reply still opens its page. * * It opens on the commit as it was last time, or opened from a row, on what * the row knew of it, then asks devnull for the rest behind it and fills it in. @@ -87,6 +92,10 @@ */ class CommitDetail extends NativeComponent { + use ExpandsThreads { + toggleReplies as private toggleThread; + showMoreReplies as private showMoreThreadReplies; + } use OpensInTab; use OpensLiveStream; use RedrawsOnAppearanceChange; @@ -190,20 +199,6 @@ class CommitDetail extends NativeComponent */ public bool $repliesLoaded = false; - /** - * The replies of deleted replies that were opened in place, by the deleted reply's id. - * - * @var array> - */ - public array $tombstoneReplies = []; - - /** - * Where the next page of each deleted reply's replies starts, by the deleted reply's id, or null when they're all shown. - * - * @var array - */ - public array $tombstoneCursors = []; - public string $reply = ''; /** @@ -313,7 +308,7 @@ public function load(): void protected function revalidate(): void { - $this->refresh($this->threadPath(), [], fn (array $json) => $this->takeThread($json)); + $this->refresh($this->threadPath(), [], fn (array $json) => $this->takeCommitThread($json)); $this->refresh($this->threadPath().'/replies', [], fn (array $json) => $this->takeReplies($json)); $this->refresh($this->threadPath().'/related', [], fn (array $json) => $this->takeRelated($json), quiet: true, failed: function (): void { $this->related = []; @@ -324,19 +319,7 @@ protected function revalidate(): void $this->refreshPartReplies((string) $id); } - foreach (array_keys($this->tombstoneReplies) as $id) { - $id = (string) $id; - - $this->refresh('commits/'.rawurlencode($id).'/replies', [], function (array $json) use ($id): void { - if (array_key_exists($id, $this->tombstoneReplies)) { - [$this->tombstoneReplies[$id], $this->tombstoneCursors[$id]] = self::withFirstPage( - $this->tombstoneReplies[$id], - $this->tombstoneCursors[$id] ?? null, - Page::fromArray($json, Commit::fromArray(...)), - ); - } - }); - } + $this->refreshThreads(); } protected function showsContent(): bool @@ -364,11 +347,32 @@ public function replyTapped(): void } /** - * "› N replies" under the commit opens them in place, and "Hide replies" folds them away. + * "› N replies" under the commit opens them in place, and "Hide replies" folds them away. Under a reply, at any + * depth, it opens that reply's replies in place under it (see ExpandsThreads). + */ + public function toggleReplies(string $id = ''): void + { + if ($id === '' || $id === $this->id) { + $this->repliesShown = ! $this->repliesShown; + + return; + } + + $this->toggleThread($id); + } + + /** + * "Show more" under a reply's replies opened in place. The commit's own go on from loadMoreReplies(). */ - public function toggleReplies(): void + public function showMoreReplies(string $id): void { - $this->repliesShown = ! $this->repliesShown; + if ($id === $this->id) { + $this->loadMoreReplies(); + + return; + } + + $this->showMoreThreadReplies($id); } /** @@ -445,39 +449,6 @@ public function toggleRelated(): void Beat::dispatch(self::RelatedFade)->finished($closed)->failed($closed); } - /** - * A deleted reply has no page of its own, so its replies open in place below it. - */ - public function toggleTombstone(string $id): void - { - if (array_key_exists($id, $this->tombstoneReplies)) { - unset($this->tombstoneReplies[$id], $this->tombstoneCursors[$id]); - - return; - } - - $this->loadTombstoneReplies($id); - } - - /** - * "Show more" under a deleted reply's replies: its next five, in place. - */ - public function loadMoreTombstoneReplies(string $id): void - { - $cursor = $this->tombstoneCursors[$id] ?? null; - - if ($cursor === null) { - return; - } - - $page = $this->attempt(fn ($devnull) => $devnull->replies($id, $cursor)); - - if ($page !== null && array_key_exists($id, $this->tombstoneReplies)) { - $this->tombstoneReplies[$id] = [...$this->tombstoneReplies[$id], ...$page->items]; - $this->tombstoneCursors[$id] = $page->nextCursor; - } - } - public function loadMoreReplies(): void { if ($this->repliesCursor === null) { @@ -740,7 +711,7 @@ protected function updateShownCommits(Closure $update): void $this->replies = array_map($update, $this->replies); $this->partReplies = array_map(fn (array $replies): array => array_map($update, $replies), $this->partReplies); $this->related = array_map($update, $this->related); - $this->tombstoneReplies = array_map(fn (array $replies): array => array_map($update, $replies), $this->tombstoneReplies); + $this->threads = array_map(fn (array $replies): array => array_map($update, $replies), $this->threads); } /** @@ -748,7 +719,7 @@ protected function updateShownCommits(Closure $update): void */ protected function shownCommits(): iterable { - return [...($this->commit === null ? [] : [$this->commit]), ...$this->ancestors, ...$this->series, ...$this->replies, ...array_merge([], ...array_values($this->partReplies)), ...$this->related, ...array_merge([], ...array_values($this->tombstoneReplies))]; + return [...($this->commit === null ? [] : [$this->commit]), ...$this->ancestors, ...$this->series, ...$this->replies, ...array_merge([], ...array_values($this->partReplies)), ...$this->related, ...$this->threadCommits()]; } /** @@ -799,7 +770,7 @@ private function keepStagedReplies(): void private function showKept(): void { if (($thread = $this->cached($this->threadPath())) !== null) { - $this->takeThread($thread); + $this->takeCommitThread($thread); } elseif ($this->commit === null && ($commit = $this->data('commit')) instanceof Commit && $commit->id === $this->id) { $this->commit = $commit; $this->ancestors = $commit->parent === null ? [] : [$commit->parent]; @@ -825,7 +796,7 @@ private function takeRelated(array $json): void /** * @param array $json */ - private function takeThread(array $json): void + private function takeCommitThread(array $json): void { $thread = CommitThread::fromArray($json); @@ -949,16 +920,6 @@ private function threadPath(): string return 'commits/'.rawurlencode($this->id); } - private function loadTombstoneReplies(string $id): void - { - $page = $this->attempt(fn ($devnull) => $devnull->replies($id)); - - if ($page !== null) { - $this->tombstoneReplies[$id] = $page->items; - $this->tombstoneCursors[$id] = $page->nextCursor; - } - } - /** * Whether the commit is yours, or an organization's you're in, which puts Delete in the nav bar (see Ownership). */ diff --git a/app/NativeComponents/Concerns/ExpandsThreads.php b/app/NativeComponents/Concerns/ExpandsThreads.php index 3be3d314..8a31f599 100644 --- a/app/NativeComponents/Concerns/ExpandsThreads.php +++ b/app/NativeComponents/Concerns/ExpandsThreads.php @@ -19,9 +19,11 @@ * asked for once they're all showing. * * A reply opened in place has the same button under its own actions, which - * opens its replies in place too, one step in. A reply that deep opens its - * replies on its page. Every thread is kept by the id of the commit or reply - * it answers, so a reply's replies sit in $threads beside its commit's. + * opens its replies in place too, one step in. In a feed a reply that deep + * opens its replies on its page. On a commit page every reply opens its + * replies in place, as deep as they go (see CommitDetail and + * App\Devnull\ThreadRows). Every thread is kept by the id of the commit or + * reply it answers, so a reply's replies sit in $threads beside its commit's. * * EDGE can't animate a row coming into a list or going out of it, so replies * fade: a page that opens is drawn see-through ($fadedRows) and drawn again diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index 278706ea..df6150b2 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -23,8 +23,9 @@ their avatar once. The replies hang under it on the thread's dashed lines, with the rail ending in a dot above them, ten at a time with "Show more" under the last. A part of a series with more parts after it has its replies right under it, beside the rail running on, and the later parts follow. Everything - around the commit is muted, and still opens its own page. A deleted reply's own replies open in place, - one level in, ten at a time too, since a deleted commit has no page. + around the commit is muted, and still opens its own page. Every reply's own replies open in place under + it, ten at a time too, as deep as they go, as on the web: they step in up to the web's depth and line up + under the deepest step past it, saying who they answer (see App\Devnull\ThreadRows). A thread its author wrote as replies to themselves carries on below the commit, on the same rail, as the web reads it (see SelfThread): each part wears its place ("2/5"), ten show at a time with "Show @@ -61,73 +62,23 @@ 'hairline' => ! ($loop->last && $relatedBelow && ! $threadMore), 'threadPosition' => $threadPositions[$row->commit->id] ?? null, 'showsThread' => false, + 'expandable' => false, ]) @if ($isFocused && $repliesShown && $replies === [] && ! $repliesLoaded && $error === null) @endif - @if ($hasThread) - @php($railLane = $loop->last ? null : $commit->lane()) - @foreach ($replies as $index => $threadReply) - @php($nested = $tombstoneReplies[$threadReply->id] ?? []) - @php($nestedMore = ($tombstoneCursors[$threadReply->id] ?? null) !== null) - @php($hasNext = ! $loop->last || $repliesCursor !== null) - @php($replyRow = [ - 'reply' => $threadReply, - 'lane' => $commit->lane(), - 'previousLane' => $index === 0 ? null : $replies[$index - 1]->lane(), - 'hasNext' => $hasNext, - 'railLane' => $railLane, - 'tombstones' => true, - 'muted' => true, - 'thread' => $commit, - 'more' => $loop->last && $nested === [] && $repliesCursor !== null ? 'loadMoreReplies' : null, - 'last' => $loop->last && $nested === [], - ]) + {{-- The replies, and theirs opened in place under them as deep as they go (see App\Devnull\ThreadRows). --}} + @php($pageThread = match (true) { $hasThread => \App\Devnull\ThreadRows::under($commit, [...$threads, $commit->id => $replies], array_filter([...$threadCursors, $commit->id => $repliesCursor]), $threadShown, $loop->last ? null : $commit->lane(), opensInPlace: PHP_INT_MAX, onPage: true, morePress: 'loadMoreReplies'), $partThread => \App\Devnull\ThreadRows::under($lastPart, [...$threads, $lastPart->id => $lastPartReplies], array_filter([...$threadCursors, $lastPart->id => $lastPartMore ? 'more' : null]), $threadShown, opensInPlace: PHP_INT_MAX, onPage: true, morePress: "openReplies('{$lastPart->id}')"), default => [] }) + @foreach ($pageThread as $threadRow) + @if ($threadRow['reply'] === null) + @include($threadRow['partial'], $threadRow['data']) + @else @php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1])) - @php($replyRows->include('reply-'.$threadReply->id, \App\Devnull\RowInputs::for($threadReply, $rowScope), 'native.partials.thread-reply', $replyRow, $rowScope)) - @foreach ($nested as $nestedIndex => $nestedReply) - @php($nestedRow = [ - 'reply' => $nestedReply, - 'lane' => \App\Devnull\Lane::Rail, - 'previousLane' => $nestedIndex === 0 ? null : $nested[$nestedIndex - 1]->lane(), - 'hasNext' => ! $loop->last || $nestedMore, - 'railLane' => $railLane, - 'indent' => 32, - 'spine' => $hasNext ? $threadReply->lane() : null, - 'muted' => true, - 'thread' => $nestedMore ? $threadReply : $commit, - 'more' => match (true) { - ! $loop->last => null, - $nestedMore => "loadMoreTombstoneReplies('{$threadReply->id}')", - $loop->parent->last && $repliesCursor !== null => 'loadMoreReplies', - default => null, - }, - 'last' => $loop->last && $loop->parent->last, - ]) - @php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1])) - @php($replyRows->include('reply-'.$nestedReply->id, \App\Devnull\RowInputs::for($nestedReply, $rowScope), 'native.partials.thread-reply', $nestedRow, $rowScope)) - @endforeach - @endforeach - @endif - @if ($partThread) - @foreach ($lastPartReplies as $index => $threadReply) - @php($replyRow = [ - 'reply' => $threadReply, - 'lane' => $lastPart->lane(), - 'previousLane' => $index === 0 ? null : $lastPartReplies[$index - 1]->lane(), - 'hasNext' => ! $loop->last || $lastPartMore, - 'railLane' => null, - 'muted' => true, - 'thread' => $lastPart, - 'more' => $loop->last && $lastPartMore ? "openReplies('{$lastPart->id}')" : null, - 'last' => $loop->last, - ]) - @php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1])) - @php($replyRows->include('reply-'.$threadReply->id, \App\Devnull\RowInputs::for($threadReply, $rowScope), 'native.partials.thread-reply', $replyRow, $rowScope)) - @endforeach - @endif + @php($replyRows->include('reply-'.$threadRow['reply']->id, \App\Devnull\RowInputs::for($threadRow['reply'], $rowScope), $threadRow['partial'], $threadRow['data'], $rowScope)) + @endif + @endforeach @endforeach @if ($threadMore && $threadParts !== []) diff --git a/resources/views/native/partials/related-commits.blade.php b/resources/views/native/partials/related-commits.blade.php index 452eaedf..af215186 100644 --- a/resources/views/native/partials/related-commits.blade.php +++ b/resources/views/native/partials/related-commits.blade.php @@ -28,6 +28,7 @@ 'seriesExpanded' => false, 'threadBelow' => false, 'withTail' => ! $loop->last, + 'expandable' => false, ]) @endforeach diff --git a/resources/views/native/partials/thread-links.blade.php b/resources/views/native/partials/thread-links.blade.php index 8f2c9084..9f547262 100644 --- a/resources/views/native/partials/thread-links.blade.php +++ b/resources/views/native/partials/thread-links.blade.php @@ -1,23 +1,28 @@ {{-- - The lines beside a reply in a feed's thread (see thread-reply), drawn last in its row so they sit on top: the - commit's rail running on past, the elbow or the link from the reply above, and the line on down to the next one. + The lines beside a reply in a thread (see thread-reply and App\Devnull\ThreadRows), drawn last in its row so they + sit on top: the commit's rail running on past, the lines from further up running on past ($spines, each from its + `top` or the row's top), the elbow or the link from the reply above, and the line on down to the next one. A + flattened reply, past the web's depth, has no links of its own ($links). --}} +@php($spines ??= []) +@php($links ??= true) @if ($railLane !== null) @include('native.partials.rail', ['previous' => $railLane]) @endif -@if ($spine !== null) - @include('native.partials.dashed-line', ['position' => 'top-0 bottom-0', 'left' => 75.5, 'lane' => $spine]) -@endif +@foreach ($spines as $spineLine) + @include('native.partials.dashed-line', ['position' => (isset($spineLine['top']) ? 'top-['.$spineLine['top'].']' : 'top-0').' bottom-0', 'left' => $spineLine['left'], 'lane' => $spineLine['lane']]) +@endforeach -@if ($previousLane === null) - @include('native.partials.thread-elbow', ['lane' => $lane, 'from' => $indent > 0 ? 75.5 : 31.5, 'to' => 64 + $indent, 'level' => $top + 12]) -@else - @include('native.partials.dashed-line', ['position' => 'top-0 h-['.($top - 4).']', 'left' => $avatarLine - 0.5, 'lane' => $previousLane]) -@endif +@if ($links) + @if ($previousLane === null) + @include('native.partials.thread-elbow', ['lane' => $lane, 'from' => $indent > 0 ? 43.5 + $indent : 31.5, 'to' => 64 + $indent, 'level' => $top + 12]) + @else + @include('native.partials.dashed-line', ['position' => 'top-0 h-['.($top - 4).']', 'left' => $avatarLine - 0.5, 'lane' => $previousLane]) + @endif -@if ($hasNext) - {{-- From 4pt under the avatar down to the next reply, or to the top of Show more's dot: 12pt under it, its padding - and the hairline below. --}} - @include('native.partials.dashed-line', ['position' => 'top-['.($top + 28).'] '.($more !== null ? 'bottom-[34]' : 'bottom-0'), 'left' => $avatarLine - 0.5, 'lane' => $reply->lane()]) + @if ($hasNext) + {{-- From 4pt under the avatar down to the next row, which carries it on. --}} + @include('native.partials.dashed-line', ['position' => 'top-['.($top + 28).'] bottom-0', 'left' => $avatarLine - 0.5, 'lane' => $reply->lane()]) + @endif @endif diff --git a/resources/views/native/partials/thread-more-row.blade.php b/resources/views/native/partials/thread-more-row.blade.php index d35dc8f2..4b77ced3 100644 --- a/resources/views/native/partials/thread-more-row.blade.php +++ b/resources/views/native/partials/thread-more-row.blade.php @@ -1,18 +1,28 @@ {{-- - "Show more" at the foot of a thread opened in a feed (see App\Devnull\ThreadRows), as a list row of its own: a muted - rail dot where the next avatar would be, on the dashed line down from the reply above ($lane), and the words. - Tapped, the thread's next page opens under what's showing. $indent puts it one step in, under a reply's own replies. + "Show more" at the foot of a thread opened in place (see App\Devnull\ThreadRows), as a row of its own: a muted rail + dot where the next avatar would be, on the dashed line down from the reply above ($lane), and the words. Tapped, + the thread's next page opens under what's showing, or whatever $press says. $indent puts it as far in as the + replies above it, and $spines carry the lines from further up on past it. + + At the web's deepest step the dot hangs on an elbow from the line of the reply the thread answers ($hangs, in + $parentLane), as those replies do. Past it there are no lines ($links), and it says whose replies these are ($to). It's 44pt tall, as tall as the list's shortest row, so the list never pads it out under its hairline. The dot sits - in its middle, so the line from above stops at the top of the dot, 13pt down. + in its middle, so the line from above stops at the top of the dot, 13pt down. In a feed the $last closes the + commit's row with its hairline; on a commit page ($hairline false) nothing does. --}} @php($indent ??= 0) -@php($spine ??= null) +@php($spines ??= []) @php($railLane ??= null) +@php($hangs ??= false) +@php($links ??= true) +@php($to ??= null) +@php($hairline ??= true) +@php($press ??= "showMoreReplies('{$threadId}')") @php($faded = in_array('more-'.$threadId, $fadedRows ?? [], true)) - + - + @@ -20,14 +30,22 @@ - Show more + @if ($to === null) + Show more + @else + Show more to {{ $to }} + @endif @if ($railLane !== null) @include('native.partials.rail', ['previous' => $railLane]) @endif - @if ($spine !== null) - @include('native.partials.dashed-line', ['position' => 'top-0 bottom-0', 'left' => 75.5, 'lane' => $spine]) + @foreach ($spines as $spineLine) + @include('native.partials.dashed-line', ['position' => (isset($spineLine['top']) ? 'top-['.$spineLine['top'].']' : 'top-0').' bottom-0', 'left' => $spineLine['left'], 'lane' => $spineLine['lane']]) + @endforeach + @if ($links && $hangs) + @include('native.partials.thread-elbow', ['lane' => $parentLane, 'from' => 43.5 + $indent, 'to' => 64 + $indent, 'level' => 22]) + @elseif ($links) + @include('native.partials.dashed-line', ['position' => 'top-0 h-[13]', 'left' => 75.5 + $indent, 'lane' => $lane]) @endif - @include('native.partials.dashed-line', ['position' => 'top-0 h-[13]', 'left' => 75.5 + $indent, 'lane' => $lane]) diff --git a/resources/views/native/partials/thread-more.blade.php b/resources/views/native/partials/thread-more.blade.php deleted file mode 100644 index 6ed4afba..00000000 --- a/resources/views/native/partials/thread-more.blade.php +++ /dev/null @@ -1,17 +0,0 @@ -{{-- - "Show more" at the foot of a thread, as the web's: a muted rail dot where the next avatar would be, and the words. - It sits inside the last reply's row, under the reply, so the rail beside it never breaks: a row of its own is - shorter than the list's shortest, and the list pads it out under its hairline. ---}} - - - - - - - - - - Show more - - diff --git a/resources/views/native/partials/thread-reply.blade.php b/resources/views/native/partials/thread-reply.blade.php index ff5bea8c..aba96aec 100644 --- a/resources/views/native/partials/thread-reply.blade.php +++ b/resources/views/native/partials/thread-reply.blade.php @@ -1,18 +1,18 @@ {{-- - A reply in the thread under a commit in a feed, like a reply in the web's thread: a 24pt avatar lined up with the - commit's text, the name and time, the body and its actions. The thread hangs off the rail in dashes of each - author's lane, as upstream's #121 draws it: the first reply on an elbow from the rail ($lane is the commit's), each - later one on a short link from the reply above ($previousLane), and a line on down from its avatar when another - reply, or "Show more", follows ($hasNext). $railLane runs the commit's own rail on past, solid, when its author's - run goes on below the thread. A deleted reply keeps its place with a dashed ring. In a feed the $last closes the - commit's row with its hairline. On a commit page nothing follows the thread, so there's no hairline. + A reply in a thread opened in place (see App\Devnull\ThreadRows), like a reply in the web's thread: a 24pt avatar + lined up with the commit's text, or $indent further in, the name and time, the body and its actions. The thread + hangs off the rail in dashes of each author's lane, as upstream's #121 draws it: the first reply on an elbow from + the line of what it answers ($lane is that one's), each later one on a short link from the reply above + ($previousLane), and a line on down from its avatar when another reply, its own replies, or "Show more", follows + ($hasNext). $spines carry lines from further up on past it, and $railLane runs the commit's own rail on past, + solid, when its author's run goes on below the thread (see thread-links). A deleted reply keeps its place with a + dashed ring. In a feed the $last closes the commit's row with its hairline. On a commit page nothing follows the + thread, so there's no hairline. - On a commit page a deleted reply's own replies open in place ($tombstones), since it has no page of their own, - one level in ($indent 32), hanging off a dashed spine from its ring as the web nests them. $spine carries the - thread's line on past a nested reply when the deleted one has another reply after it. + Past the web's depth a reply is flattened: it lines up under the reply it answers, with no lines of its own + ($links), and says who it answers on a line under its name ($replyingTo), as the web does. - The last reply carries the thread's "Show more" when there's more ($more, what it presses), with the line from its - avatar running down to it. + On a commit page a deleted reply's own replies open in place too ($tombstones), with "N replies" under its ring. $top is the space above the avatar, 10pt, less for the first reply in a feed, which sits under the commit row's bottom padding (see ThreadRows::FirstReplyTop). The lines beside it are placed from the avatar, so they move with it. @@ -24,29 +24,31 @@ A reply you just sent that devnull doesn't have yet is staged: dimmed, with the staged chip and no actions. - In a feed a reply's replies button opens them under it ($repliesInPlace, see App\Devnull\ThreadRows); deeper in, - or on a commit page, it opens the reply's page. A feed's thread rows fade in as they open and out as they close - ($fades): drawn see-through and nudged up while they're in $fadedRows (see Concerns\ExpandsThreads), and eased - to where they belong. Only what's beside the rail fades, so the commit's rail running past never blinks. + A reply's replies button opens them under it ($repliesInPlace): on a commit page at every depth, in a feed only for + the commit's own replies, and a reply's replies there open its page. Tapping the reply itself opens its page. The + rows fade in as they open and out as they close ($fades): drawn see-through and nudged up while they're in + $fadedRows (see Concerns\ExpandsThreads), and eased to where they belong. Only what's beside the rail fades, so + the commit's rail running past never blinks. --}} @php($previousLane ??= null) @php($muted ??= false) @php($railLane ??= null) @php($indent ??= 0) -@php($spine ??= null) +@php($spines ??= []) +@php($links ??= true) +@php($replyingTo ??= null) @php($tombstones ??= false) -@php($more ??= null) @php($avatarLine = 76 + $indent) @php($repliesInPlace ??= false) @php($fades ??= false) @php($top ??= 10) @php($faded = $fades && in_array($reply->id, $fadedRows ?? [], true)) @if ($reply->isDeleted()) - @php($opened = $tombstones && array_key_exists($reply->id, $tombstoneReplies ?? [])) + @php($opened = $tombstones && array_key_exists($reply->id, $threads ?? []) && ! in_array($reply->id, $closingThreads ?? [], true)) - + @include('native.partials.dashed-ring', ['size' => 24, 'lane' => \App\Devnull\Lane::Rail]) @@ -55,7 +57,7 @@ [deleted] This commit was deleted. @if ($tombstones && $reply->repliesCount > 0) - + {{ $opened ? 'Hide replies' : \App\Devnull\Display::count($reply->repliesCount, 'reply', 'replies') }} @@ -64,18 +66,11 @@ @endif - @if ($more !== null) - @include('native.partials.thread-more', ['commit' => $thread ?? $reply]) - @endif @if ($last && ! $muted) @endif @include('native.partials.thread-links') - @if ($opened && ($tombstoneReplies[$reply->id] ?? []) !== []) - {{-- The spine its own replies hang off, down from its ring. --}} - @include('native.partials.dashed-line', ['position' => 'top-['.($top + 28).'] bottom-0', 'left' => $avatarLine - 0.5, 'lane' => \App\Devnull\Lane::Rail]) - @endif @else @php($commit = $reply) @@ -83,7 +78,7 @@ - + @include('native.partials.rail-avatar', ['user' => $reply->author, 'lane' => $reply->lane(), 'size' => 24, 'staged' => false]) @@ -96,6 +91,12 @@ @include('native.partials.status-chip', ['status' => $reply->status]) @endunless + @if ($replyingTo !== null) + + + {{ $replyingTo }} + + @endif @include('native.partials.commit-body', ['size' => $muted ? 'text-sm' : 'text-[15px]']) @include('native.partials.commit-media', ['withEmbeds' => false]) @if ($reply->continuationId !== null || in_array($reply->id, $threadsContinued ?? [], true)) @@ -106,9 +107,6 @@ @endunless - @if ($more !== null) - @include('native.partials.thread-more', ['commit' => $thread ?? $reply]) - @endif @if ($last && ! $muted) @endif diff --git a/tests/Feature/Screens/CommitDetailCacheTest.php b/tests/Feature/Screens/CommitDetailCacheTest.php index 145eaedf..1694cf61 100644 --- a/tests/Feature/Screens/CommitDetailCacheTest.php +++ b/tests/Feature/Screens/CommitDetailCacheTest.php @@ -140,7 +140,7 @@ function serveThread(): void 'GET /api/v1/commits/d1/replies' => [pageJson([replyJson(['id' => 'r9', 'parent_id' => 'd1', 'body' => 'Under a deleted reply'])])], ]); - $screen = Native::visit('/log/commits/c1')->tap('replies-c1')->call('toggleTombstone', 'd1')->assertSee('Under a deleted reply'); + $screen = Native::visit('/log/commits/c1')->tap('replies-c1')->call('toggleReplies', 'd1')->assertSee('Under a deleted reply'); $screen->call('load'); diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index 4da73df3..c25d0645 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -526,29 +526,28 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): $screen->tap('replies-c2')->assertDontSee('First reply')->assertSee('1 reply'); expect($chevron('replies-c2')['props'])->toMatchArray(['name' => 'custom:chevron-right', 'rotate' => 0.0, 'animate-duration' => 220.0]); - // A reply's button opens its page rather than its replies in place, so its chevron stays put. + // A reply's button opens its replies in place too, so its chevron turns the same way. $screen->tap('replies-c2'); - expect($chevron('replies-r1')['props'])->not->toHaveKey('rotate'); + expect($chevron('replies-r1')['props'])->toMatchArray(['rotate' => 0.0, 'animate-duration' => 220.0]); })->with(['ios', 'android']); it('opens with its replies showing from a replies button', function () { fakeThread(['replies_count' => 1], replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'First reply', 'replies_count' => 1])], extra: [ 'GET /api/v1/commits/r1' => [commitPageJson(replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'First reply', 'replies_count' => 1]))], - 'GET /api/v1/commits/r1/replies' => [pageJson([replyJson(['id' => 'r2', 'parent_id' => 'r1', 'body' => 'Answering the reply'])])], + // Someone other than r1's author, whose reply to themselves would carry r1 on as a thread instead. + 'GET /api/v1/commits/r1/replies' => [pageJson([replyJson(['id' => 'r2', 'parent_id' => 'r1', 'body' => 'Answering the reply', 'author' => userJson(['id' => 'u3', 'handle' => 'grace', 'name' => 'Grace'])])])], ]); Native::visit('/log/commits/c2', ['replies' => true]) ->assertSee('First reply') ->assertSee('Hide replies'); - // A reply's replies don't open in place on a commit page, so its button opens its page with them showing. + // A reply's replies open in place under it, as on the web, rather than on its page. Native::visit('/log/commits/c2') ->tap('replies-c2') ->tap('replies-r1') - ->assertNavigatedTo('/log/commits/r1') - ->follow() - ->assertSee('Answering the reply') - ->assertSee('Hide replies'); + ->assertNoNavigation() + ->assertSee('Answering the reply'); }); it('asks for the replies a page at a time, and the next page from Show more', function () { diff --git a/tests/Feature/Screens/NestedRepliesTest.php b/tests/Feature/Screens/NestedRepliesTest.php new file mode 100644 index 00000000..9d208b7a --- /dev/null +++ b/tests/Feature/Screens/NestedRepliesTest.php @@ -0,0 +1,77 @@ + 'http://devnull.test']); + signIn(); +}); + +/** + * A commit page for c2 whose replies chain five deep: r1 answers c2, r2 answers r1, and so on, each from someone + * other than the one they answer, so none of them carries a thread on. + */ +function fakeDeepThread(): void +{ + $handles = ['grace', 'linus', 'alan', 'edsger', 'ken']; + $reply = fn (int $depth): array => replyJson([ + 'id' => "r{$depth}", + 'parent_id' => $depth === 1 ? 'c2' : 'r'.($depth - 1), + 'body' => "Reply at depth {$depth}", + 'replies_count' => $depth < 5 ? 1 : 0, + 'author' => userJson(['handle' => $handles[$depth - 1], 'name' => ucfirst($handles[$depth - 1]), 'lane' => $depth]), + ]); + + Http::fake(function (Request $request) use ($reply) { + $path = parse_url($request->url(), PHP_URL_PATH); + + return match (true) { + $path === '/api/v1/commits/c2' => Http::response(commitPageJson(commitJson(['id' => 'c2', 'body' => 'The focused commit', 'replies_count' => 1]))), + $path === '/api/v1/commits/c2/related' => Http::response(['data' => []]), + $path === '/api/v1/commits/c2/replies' => Http::response(pageJson([$reply(1)])), + (bool) preg_match('#^/api/v1/commits/r(\d)/replies$#', $path, $match) => Http::response(pageJson((int) $match[1] < 5 ? [$reply((int) $match[1] + 1)] : [])), + default => Http::response(['message' => 'No fake.'], 404), + }; + }); +} + +it('opens replies of replies in place on a commit page, as deep as they go, without leaving the page', function () { + fakeDeepThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true])->assertSee('Reply at depth 1'); + + foreach (range(1, 4) as $depth) { + $screen->tap("replies-r{$depth}")->assertSee('Reply at depth '.($depth + 1)); + } + + $screen->assertNoNavigation()->assertSee('Reply at depth 5'); + + // Hiding a reply's replies takes the ones opened under them away too. + $screen->tap('replies-r2')->assertDontSee('Reply at depth 3'); + finishRefreshes($screen)->assertDontSee('Reply at depth 5'); + + // Tapping a reply itself still opens its page. + $screen->tap('thread-reply-r2')->assertNavigatedTo('/log/commits/r2'); +}); + +it('steps replies in up to the third level, and lines deeper ones up under it saying who they answer', function () { + fakeDeepThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + + foreach (range(1, 4) as $depth) { + $screen->tap("replies-r{$depth}"); + } + + // The left padding of the row the reply's avatar sits in, past the commit's 64pt gutter. + $indent = fn (string $id): float => (float) (findNode(nodeByRef($screen, "thread-reply-{$id}"), fn (array $node): bool => ($node['type'] ?? null) === 'row' && isset($node['layout']['padding']))['layout']['padding'][3] ?? 0); + $elbow = fn (string $id): bool => findNode(nodeByRef($screen, "thread-reply-{$id}"), fn (array $node): bool => ($node['ref'] ?? null) === 'thread-elbow') !== null; + + expect([$indent('r1'), $indent('r2'), $indent('r3'), $indent('r4'), $indent('r5')])->toEqual([0, 32, 64, 64, 64]) + ->and([$elbow('r1'), $elbow('r2'), $elbow('r3'), $elbow('r4'), $elbow('r5')])->toBe([true, true, true, false, false]) + ->and(rendersRef($screen, 'replying-to-r3'))->toBeFalse(); + + $screen->assertSee('replying to @alan')->assertSee('replying to @edsger'); +}); diff --git a/tests/Feature/Screens/RowCacheScreensTest.php b/tests/Feature/Screens/RowCacheScreensTest.php index 902cbd0d..d7c547cd 100644 --- a/tests/Feature/Screens/RowCacheScreensTest.php +++ b/tests/Feature/Screens/RowCacheScreensTest.php @@ -88,10 +88,10 @@ function expectKeptRowsMatchFreshOnes(TestableComponent $screen, string $class, }); $screen = Native::visit('/log/commits/c2')->tap('replies-c2')->assertSee('Second reply'); - // The commits above the replies read what the screen shows of the thread, so they're built every time. The last - // reply of a page changes when the next page comes, since it no longer carries "more". + // The commits above the replies read what the screen shows of the thread, so they're built every time. "Show + // more" is a row of its own, so the last reply of a page stays as it was when the next page comes. expect(rowsBuiltBy(fn () => $screen->call('navTitle')))->toBe(['c2']) - ->and(rowsBuiltBy(fn () => $screen->call('loadMoreReplies')->assertSee('Third reply')))->toBe(['c2', 'r2', 'r3']); + ->and(rowsBuiltBy(fn () => $screen->call('loadMoreReplies')->assertSee('Third reply')))->toBe(['c2', 'r3']); expectKeptRowsMatchFreshOnes($screen, CommitDetail::class, 'replyRows', null); }); diff --git a/tests/Unit/Devnull/ThreadRowsTest.php b/tests/Unit/Devnull/ThreadRowsTest.php new file mode 100644 index 00000000..dfad7144 --- /dev/null +++ b/tests/Unit/Devnull/ThreadRowsTest.php @@ -0,0 +1,86 @@ + $id, 'parent_id' => $parent, 'author' => userJson(['handle' => $handle, 'lane' => strlen($handle)]), ...$overrides])); +} + +/** + * The rows of a chain five replies deep under c1, with a second reply at the deepest step (r3b), each opened. + * + * @return array> + */ +function deepRows(int $opensInPlace = PHP_INT_MAX): array +{ + $commit = Commit::fromArray(commitJson(['id' => 'c1', 'author' => userJson(['handle' => 'ada'])])); + $threads = [ + 'c1' => [nestedReply('r1', 'c1', 'grace')], + 'r1' => [nestedReply('r2', 'r1', 'linus')], + 'r2' => [nestedReply('r3', 'r2', 'alan'), nestedReply('r3b', 'r2', 'barbara')], + 'r3' => [nestedReply('r4', 'r3', 'edsger', ['quoted_commit_id' => 'r3'])], + 'r4' => [nestedReply('r5', 'r4', 'ken')], + ]; + + $rows = ThreadRows::under($commit, $threads, ['r4' => 'next'], [], opensInPlace: $opensInPlace, onPage: true); + + return array_column(array_map(fn (array $row): array => [$row['key'], $row['data']], $rows), 1, 0); +} + +it('steps replies in up to the web\'s depth of three, and lines deeper ones up under the third', function () { + $rows = deepRows(); + + expect(array_keys($rows))->toBe(['thread-reply-r1', 'thread-reply-r2', 'thread-reply-r3', 'thread-reply-r4', 'thread-reply-r5', 'thread-more-r4', 'thread-reply-r3b']) + ->and(array_map(fn (array $row): int => $row['indent'], $rows))->toBe([ + 'thread-reply-r1' => 0, + 'thread-reply-r2' => 32, + 'thread-reply-r3' => 64, + 'thread-reply-r4' => 64, + 'thread-reply-r5' => 64, + 'thread-more-r4' => 64, + 'thread-reply-r3b' => 64, + ]); +}); + +it('says who a flattened reply answers, and draws it no lines of its own', function () { + $rows = deepRows(); + + expect($rows['thread-reply-r3']['replyingTo'])->toBeNull() + ->and($rows['thread-reply-r3']['links'])->toBeTrue() + ->and($rows['thread-reply-r4']['replyingTo'])->toBe('quoting @alan') + ->and($rows['thread-reply-r5']['replyingTo'])->toBe('replying to @edsger') + ->and($rows['thread-reply-r4']['links'])->toBeFalse() + ->and($rows['thread-reply-r4']['hasNext'])->toBeFalse() + ->and($rows['thread-more-r4']['links'])->toBeFalse() + ->and($rows['thread-more-r4']['to'])->toBe('@edsger'); +}); + +it('hangs each reply at the deepest step on its own elbow, with the line of the reply it answers running on past', function () { + $rows = deepRows(); + $lane = $rows['thread-reply-r3b']['lane']; + + // r3 and r3b both answer r2, so both hang on elbows off r2's line, which runs past r3's own replies to r3b. + expect($rows['thread-reply-r3']['previousLane'])->toBeNull() + ->and($rows['thread-reply-r3b']['previousLane'])->toBeNull() + ->and($rows['thread-reply-r3']['hasNext'])->toBeFalse() + ->and($rows['thread-reply-r3']['spines'])->toBe([['left' => 107.5, 'lane' => $lane, 'top' => 22]]) + ->and($rows['thread-reply-r4']['spines'])->toBe([['left' => 107.5, 'lane' => $lane]]) + ->and($rows['thread-more-r4']['spines'])->toBe([['left' => 107.5, 'lane' => $lane]]) + ->and($rows['thread-reply-r3b']['spines'])->toBe([]) + // Above that the replies chain from avatar to avatar as before. + ->and($rows['thread-reply-r2']['hasNext'])->toBeTrue() + ->and($rows['thread-reply-r3b']['last'])->toBeTrue(); +}); + +it('opens replies in place as deep as the caller allows', function () { + $inPlace = fn (array $rows): array => array_map(fn (array $row): bool => $row['repliesInPlace'], array_filter($rows, fn (array $row): bool => isset($row['repliesInPlace']))); + + expect($inPlace(deepRows()))->each->toBeTrue() + ->and($inPlace(deepRows(opensInPlace: 1))) + ->toBe(['thread-reply-r1' => true, 'thread-reply-r2' => false, 'thread-reply-r3' => false, 'thread-reply-r4' => false, 'thread-reply-r5' => false, 'thread-reply-r3b' => false]); +}); From a0032d3abd580323af32e536bd4ff1eb9f5a842d Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 02:21:57 +0000 Subject: [PATCH 06/18] Move the commit page to a commit in its tree instead of pushing another Tapping an ancestor, a part of the series or the author's thread, or a reply at any depth used to push a new commit screen. Now the same page moves to it: the commit becomes the one the page is about, with what's above it as its ancestors and its replies showing below, built from what the page already has so nothing goes blank. The commit it was on keeps its replies opened, so going back up shows where you came from. Reply on a commit in the tree retargets the reply bar the same way. Commits outside the tree still push. Back still leaves the screen, as Simon asked. There's no history of the commits the page moved through. The scroll view's rows are its own children now, so auto-scroll-to can bring the commit into view. Both platforms jump on the first request and animate later ones. Deleting a commit the page moved to takes the page back to its parent. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/CommitDetail.php | 259 +++++++++++++++++- .../views/native/commit-detail.blade.php | 12 +- tests/Feature/Screens/CommitDetailTest.php | 37 +-- tests/Feature/Screens/NestedRepliesTest.php | 58 +++- tests/Feature/Screens/RelatedCommitsTest.php | 6 +- tests/Feature/Screens/SelfThreadTest.php | 2 +- tests/Feature/Screens/SeriesTest.php | 3 +- 7 files changed, 347 insertions(+), 30 deletions(-) diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index d7dd120f..2eb2380f 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -51,7 +51,11 @@ * * Each reply's own replies open in place under it, and theirs under them, as * deep as they go, as the web's commit page does (see ExpandsThreads and - * App\Devnull\ThreadRows). Tapping a reply still opens its page. + * App\Devnull\ThreadRows). + * + * Tapping a commit in the tree, above the commit, below it or among the + * replies at any depth, moves this page to it rather than pushing another + * (see refocus()). Back still leaves the page. * * It opens on the commit as it was last time, or opened from a row, on what * the row knew of it, then asks devnull for the rest behind it and fills it in. @@ -101,6 +105,9 @@ class CommitDetail extends NativeComponent use RedrawsOnAppearanceChange; use RefreshesInBackground; use ShowsCommits { + openCommit as private openCommitPage; + openReplies as private openRepliesPage; + replyTo as private replyOnPage; reopenFailedCommit as private reopenFailedCommitInSheet; editFailedCommit as private editFailedCommitInSheet; mentionFields as private sheetMentionFields; @@ -239,6 +246,17 @@ class CommitDetail extends NativeComponent */ public int $scrollKey = 0; + /** + * Which of the scroll view's rows it brings into view, the commit's, once tapping another commit in the tree + * moved the page to it (see refocus()). Null until then, so the page opens at the top as it always has. + */ + public ?int $scrollTarget = null; + + /** + * The commit the page opened on, before tapping others in its tree moved it (see refocus()). + */ + public string $openedId = ''; + /** * The replies from the last frame, so a render only builds the replies that changed, as the Log does its rows. */ @@ -255,6 +273,7 @@ class CommitDetail extends NativeComponent public function mount(): void { + $this->openedId = $this->id; $this->focusReply = $this->data('reply', false) === true; $this->repliesShown = $this->data('replies', false) === true; $draft = app(Stash::class)->get($this->me()?->id, $this->replyStashName()); @@ -343,9 +362,237 @@ public function showEarlier(): void public function replyTapped(): void { $this->earlierShown = false; + $this->scrollTarget = null; $this->scrollKey++; } + /** + * A commit in the tree this page shows moves the page to it, rather than + * pushing another commit page (see refocus()). Anything else opens its page. + */ + public function openCommit(string $id): void + { + if (! $this->refocus($id)) { + $this->openCommitPage($id); + } + } + + /** + * "Show more" under the last part of a thread, or "› N replies" on a commit in the tree: the page moves to it with + * its replies showing. + */ + public function openReplies(string $id): void + { + if (! $this->refocus($id)) { + $this->openRepliesPage($id); + } + } + + /** + * Reply on a commit in the tree moves the page to it, with the reply bar answering it and its keyboard up. + */ + public function replyTo(string $id): void + { + if ($id === $this->id) { + $this->focusReply = true; + + return; + } + + if ($this->refocus($id)) { + $this->focusReply = true; + + return; + } + + $this->replyOnPage($id); + } + + /** + * Moves the page to a commit already in its tree: an ancestor, a part of + * the author's thread or series, or a reply at any depth. It becomes the + * commit the page is about, with what's above it as its ancestors and its + * replies showing below, all from what the page already has, so nothing + * goes blank, and devnull is asked for the rest behind it. Replies opened + * in place stay open, and the commit the page was on keeps its replies, so + * moving up shows where you came from opened under its parent. + * + * The page stays one screen: Back still leaves it, as Simon asked, rather + * than stepping back through the commits it moved to. The scroll view + * brings the commit into view, with every ancestor showing above it. + * + * False, changing nothing, for a commit that isn't in the tree, or one + * that's staged or deleted, which has no page of its own. + */ + private function refocus(string $id): bool + { + if ($this->commit === null || $id === $this->id) { + return false; + } + + $target = $this->treeCommit($id); + $ancestors = $target === null || $target->isStaged() || $target->isDeleted() ? null : $this->ancestorsInTree($target); + + if ($ancestors === null) { + return false; + } + + $line = [...$this->ancestors, $this->commit]; + $below = array_slice($line, count($ancestors) + 1); + + // What the page was on keeps its replies, opened in place, for when it's back in the tree. + if ($this->repliesShown && $this->repliesLoaded && $this->replies !== []) { + $this->threads[$this->id] = array_values(array_filter($this->replies, fn (Commit $reply): bool => ! $reply->isStaged())); + $this->keepCursor($this->id, $this->repliesCursor); + unset($this->threadShown[$this->id]); + } + + // Moving up, the commits between keep their replies open, so the one the page was on shows under them. + foreach ($below as $between) { + if ($between->id !== $this->id && ! array_key_exists($between->id, $this->threads) && ($kept = $this->cached('commits/'.rawurlencode($between->id).'/replies')) !== null) { + $this->takeThread($between->id, $kept); + } + } + + $this->id = $id; + $this->commit = $target; + $this->ancestors = $ancestors; + $this->series = []; + $this->related = []; + $this->relatedShown = false; + $this->threadLimit = SelfThread::PerPage; + $this->takeOwnReplies($id); + + if (($thread = $this->cached($this->threadPath())) !== null) { + $this->takeCommitThread($thread); + } + + $this->takeRelated($this->cached($this->threadPath().'/related') ?? []); + $this->repliesShown = true; + $this->earlierShown = true; + $this->takeReplyDraft(); + $this->error = null; + + // The commit's row is the one after its ancestors. A request the scroll view already went to does nothing, + // so going back to the top a second time mounts it again, at the top. + $target = count($this->ancestors); + + if ($target === $this->scrollTarget) { + $this->scrollKey++; + } + + $this->scrollTarget = $target; + $this->forgetRefreshes(); + $this->revalidate(); + $this->followThread(); + + return true; + } + + /** + * The commit's own replies, as the page knows them: opened in place, read for its author's thread, or kept from + * before. Until one of those, they show as loading. + */ + private function takeOwnReplies(string $id): void + { + $this->replies = []; + $this->repliesCursor = null; + $this->repliesLoaded = false; + + if (array_key_exists($id, $this->threads)) { + $this->replies = $this->threads[$id]; + $this->repliesCursor = $this->threadCursors[$id] ?? null; + $this->repliesLoaded = true; + unset($this->threads[$id], $this->threadCursors[$id], $this->threadShown[$id]); + $this->pagedThreads = array_values(array_diff($this->pagedThreads, [$id])); + } elseif (($kept = $this->cached($this->threadPath().'/replies')) !== null) { + $this->takeReplies($kept); + + return; + } elseif (array_key_exists($id, $this->partReplies)) { + $this->replies = $this->partReplies[$id]; + $this->repliesLoaded = true; + } + + $this->keepStagedReplies(); + } + + /** + * The reply bar takes up the draft kept for the commit the page is on now. + */ + private function takeReplyDraft(): void + { + $draft = app(Stash::class)->get($this->me()?->id, $this->replyStashName()); + $this->reply = $draft->body; + $this->replyImages = $draft->images; + $this->replyRestored = ! $draft->isEmpty(); + $this->replyAuthor = null; + $this->replyPreviewing = false; + $this->replyPreview = null; + $this->focusReply = false; + } + + /** + * A commit the page draws in its tree, by id: around the commit, in its author's thread, or among the replies. + */ + private function treeCommit(string $id): ?Commit + { + $lastPart = $this->commit === null ? null : $this->selfThread()->parts; + $tree = [ + ...$this->ancestors, + ...$this->series, + ...($lastPart ?? []), + ...$this->replies, + ...$this->threadCommits(), + ...array_merge([], ...array_values($this->partReplies)), + ]; + + foreach ($tree as $commit) { + if ($commit->id === $id) { + return $commit; + } + } + + return null; + } + + /** + * What's above $target in the tree, in order: the page's line of ancestors as far as the one it hangs from, then + * the replies, parts or series between. Null when it doesn't hang from that line. + * + * @return list|null + */ + private function ancestorsInTree(Commit $target): ?array + { + $line = [...$this->ancestors, ...($this->commit === null ? [] : [$this->commit])]; + $lineIds = array_map(fn (Commit $commit): string => $commit->id, $line); + $at = array_search($target->id, $lineIds, true); + + if ($at !== false) { + return array_slice($line, 0, $at); + } + + $between = []; + $parentId = $target->parentId; + + while ($parentId !== null && ! in_array($parentId, $lineIds, true)) { + $parent = $this->treeCommit($parentId); + + if ($parent === null || in_array($parent, $between, true)) { + return null; + } + + array_unshift($between, $parent); + $parentId = $parent->parentId; + } + + if ($parentId === null) { + return null; + } + + return [...array_slice($line, 0, array_search($parentId, $lineIds, true) + 1), ...$between]; + } + /** * "› N replies" under the commit opens them in place, and "Hide replies" folds them away. Under a reply, at any * depth, it opens that reply's replies in place under it (see ExpandsThreads). @@ -694,6 +941,16 @@ protected function commitSheetGone(string $view): void */ protected function showDeleted(string $id): void { + // The page moved here from a commit above it, so it goes back there rather than leaving. + $parent = $this->ancestors === [] ? null : end($this->ancestors); + + if ($id === $this->id && $id !== $this->openedId && $parent !== null && $this->refocus($parent->id)) { + $this->threads = array_map(fn (array $replies): array => array_values(array_filter($replies, fn (Commit $reply): bool => $reply->id !== $id)), $this->threads); + $this->replies = array_values(array_filter($this->replies, fn (Commit $reply): bool => $reply->id !== $id)); + + return; + } + if ($id === $this->id) { $this->back(); diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index df6150b2..fd7b2a75 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -7,8 +7,12 @@ {{-- The stack around the page holds the fade over its foot, just above the reply bar (see partials/composer-fade). --}} - - + {{-- + Each row is a child of the scroll view itself, so it can bring one into view: the commit the page is on, after + tapping another commit in the tree moves the page to it (see CommitDetail::refocus() and $scrollTarget). The + first move jumps and later ones animate, as auto-scroll-to does on both platforms. + --}} + @if (! $commit && $error === null) @@ -23,7 +27,8 @@ their avatar once. The replies hang under it on the thread's dashed lines, with the rail ending in a dot above them, ten at a time with "Show more" under the last. A part of a series with more parts after it has its replies right under it, beside the rail running on, and the later parts follow. Everything - around the commit is muted, and still opens its own page. Every reply's own replies open in place under + around the commit is muted. Tapping any commit in the tree moves the page to it rather than pushing + another (see CommitDetail::refocus()). Every reply's own replies open in place under it, ten at a time too, as deep as they go, as on the web: they step in up to the web's depth and line up under the deepest step past it, saying who they answer (see App\Devnull\ThreadRows). @@ -103,7 +108,6 @@ @if ($commit) @endif - @if ($commit && ! \App\Devnull\Display::fadesInBar()) diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index c25d0645..cf451876 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -51,19 +51,19 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->assertSee('Reply to @local_dev'); // The commit comes after the one it replies to, and the row standing in for what that replies to. - expect(childRefs($screen, 'thread-page'))->toBe(['earlier-commits', 'commit-c1', 'focused-commit', 'reply-bar-clearance']); + expect(childRefs($screen, 'thread-scroll'))->toBe(['earlier-commits', 'commit-c1', 'focused-commit', 'reply-bar-clearance']); $screen->tap('earlier-commits') ->assertSee('The root commit') ->assertDontSee('1 earlier commit'); - expect(childRefs($screen, 'thread-page'))->toBe(['commit-c0', 'commit-c1', 'focused-commit', 'reply-bar-clearance']); + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c0', 'commit-c1', 'focused-commit', 'reply-bar-clearance']); $screen->tap('replies-c2') ->assertSee('First reply') ->assertSee('Hide replies'); - expect(childRefs($screen, 'thread-page'))->toBe(['commit-c0', 'commit-c1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']); + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c0', 'commit-c1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']); $screen->tap('replies-c2') ->assertDontSee('First reply') @@ -84,7 +84,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->assertSee('The parent commit') ->assertDontSee('The root commit'); - expect(childRefs($screen, 'thread-page'))->toBe(['earlier-commits', 'commit-c1', 'focused-commit', 'reply-bar-clearance']) + expect(childRefs($screen, 'thread-scroll'))->toBe(['earlier-commits', 'commit-c1', 'focused-commit', 'reply-bar-clearance']) ->and(nodeByRef($screen, 'thread-scroll')['id'])->not->toBe($before); }); @@ -347,7 +347,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): $staged = $screen->instance()->replies[1]->id; - expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'thread-reply-r1', "thread-reply-{$staged}", 'reply-bar-clearance']) + expect(childRefs($screen, 'thread-scroll'))->toBe(['focused-commit', 'thread-reply-r1', "thread-reply-{$staged}", 'reply-bar-clearance']) ->and(PendingWrite::query()->count())->toBe(1); finishRefreshes($screen) @@ -355,7 +355,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->assertSee('pending') ->assertDontSee('staged'); - expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-r9', 'reply-bar-clearance']) + expect(childRefs($screen, 'thread-scroll'))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-r9', 'reply-bar-clearance']) ->and(PendingWrite::query()->count())->toBe(0) ->and(collect(Http::recorded())->filter(fn (array $sent): bool => $sent[0]->method() === 'POST'))->toHaveCount(1); }); @@ -383,7 +383,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->call('loadMoreReplies') ->assertSet('repliesCursor', null); - expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-r2', 'thread-reply-r9', 'reply-bar-clearance']); + expect(childRefs($screen, 'thread-scroll'))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-r2', 'thread-reply-r9', 'reply-bar-clearance']); }); it('marks a reply waiting for approval as pending on its row', function () { @@ -504,10 +504,11 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): }); it('opens ancestors, replies and profiles', function () { - fakeThread(replies: [replyJson(['id' => 'r1'])]); + fakeThread(replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2'])]); - Native::visit('/log/commits/c2')->tap('earlier-commits')->tap('commit-c1')->assertNavigatedTo('/log/commits/c1'); - Native::visit('/log/commits/c2')->tap('replies-c2')->tap('thread-reply-r1')->assertNavigatedTo('/log/commits/r1'); + // Commits in the tree move the page to them, and anything else opens its own page. + Native::visit('/log/commits/c2')->tap('earlier-commits')->tap('commit-c1')->assertNoNavigation()->assertSet('id', 'c1'); + Native::visit('/log/commits/c2')->tap('replies-c2')->tap('thread-reply-r1')->assertNoNavigation()->assertSet('id', 'r1'); Native::visit('/log/commits/c2')->call('openProfile', 'ada')->assertNavigatedTo('/log/users/ada'); }); @@ -664,7 +665,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): // One level in, on an elbow off the deleted reply's spine. expect(findNode(nodeByRef($screen, 'thread-reply-r3'), fn (array $node): bool => ($node['ref'] ?? null) === 'thread-elbow'))->not->toBeNull(); - $screen->tap('thread-reply-r3')->assertNavigatedTo('/log/commits/r3'); + $screen->tap('thread-reply-r3')->assertNoNavigation()->assertSet('id', 'r3'); Native::visit('/log/commits/c2') ->tap('replies-c2') @@ -792,7 +793,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): expect(app(Account::class)->user())->toBeNull(); }); -it('reloads when you come back from a reply you deleted', function () { +it('moves back to the parent when you delete a reply the page moved to', function () { $replyDeleted = false; Http::fake(function (Request $request) use (&$replyDeleted) { @@ -809,15 +810,15 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): }; }); - $reply = Native::visit('/log/commits/c2') + // The page moved to the reply, so deleting it moves the page back to its parent, asked for again. + Native::visit('/log/commits/c2') ->tap('replies-c2') ->assertSee('Soon gone') ->tap('thread-reply-r1') - ->follow() + ->assertSet('id', 'r1') ->call('deleteCommit', 'r1') - ->assertWentBack(); - - $reply->goBack() + ->assertNoNavigation() + ->assertSet('id', 'c2') ->assertSee('Parent') ->assertDontSee('Soon gone') ->assertSee('No replies yet.'); @@ -952,7 +953,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): $screen = Native::visit('/log/commits/c2', platform: 'ios'); $scroller = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'scroll_view'); - $page = $scroller['children'][0]['children']; + $page = $scroller['children']; // The clearance is the last thing on the page, under the last reply: the fade, the bar and the home indicator. $bar = 24 + Display::ComposerFadeHeight + Display::ComposerBoxBarHeight + 34; diff --git a/tests/Feature/Screens/NestedRepliesTest.php b/tests/Feature/Screens/NestedRepliesTest.php index 9d208b7a..14a41698 100644 --- a/tests/Feature/Screens/NestedRepliesTest.php +++ b/tests/Feature/Screens/NestedRepliesTest.php @@ -52,8 +52,8 @@ function fakeDeepThread(): void $screen->tap('replies-r2')->assertDontSee('Reply at depth 3'); finishRefreshes($screen)->assertDontSee('Reply at depth 5'); - // Tapping a reply itself still opens its page. - $screen->tap('thread-reply-r2')->assertNavigatedTo('/log/commits/r2'); + // Tapping a reply itself moves the page to it. + $screen->tap('thread-reply-r2')->assertNoNavigation()->assertSet('id', 'r2'); }); it('steps replies in up to the third level, and lines deeper ones up under it saying who they answer', function () { @@ -75,3 +75,57 @@ function fakeDeepThread(): void $screen->assertSee('replying to @alan')->assertSee('replying to @edsger'); }); + +it('moves the page to a reply in its tree rather than pushing another, keeping what was open', function () { + fakeDeepThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + + foreach (range(1, 3) as $depth) { + $screen->tap("replies-r{$depth}"); + } + + $screen->tap('thread-reply-r3') + ->assertNoNavigation() + ->assertSet('id', 'r3') + ->assertSet('scrollTarget', 3); + + // The reply is the commit the page is on, under the commits above it, with its replies showing at once. + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c2', 'commit-r1', 'commit-r2', 'focused-commit', 'thread-reply-r4', 'reply-bar-clearance']) + ->and(nodeByRef($screen, 'thread-scroll')['props']['auto_scroll_to'])->toBe(3); + + // Back up at the top, the reply the page was on is still open under its parents. + $screen->tap('commit-c2') + ->assertNoNavigation() + ->assertSet('id', 'c2') + ->assertSet('scrollTarget', 0) + ->assertSee('Reply at depth 4'); + + expect(childRefs($screen, 'thread-scroll'))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-r2', 'thread-reply-r3', 'thread-reply-r4', 'reply-bar-clearance']); +}); + +it('answers a reply in the tree from the bar, on the same page', function () { + fakeDeepThread(); + + Native::visit('/log/commits/c2', ['replies' => true]) + ->call('replyTo', 'r1') + ->assertNoNavigation() + ->assertSet('id', 'r1') + ->assertSet('focusReply', true); +}); + +it('still pushes a page for a commit outside the tree', function () { + fakeDeepThread(); + + Native::visit('/log/commits/c2', ['replies' => true]) + ->call('openCommit', 'q9') + ->assertNavigatedTo('/log/commits/q9'); +}); + +it('opens at the top with no scroll asked for until the page moves', function () { + fakeDeepThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + + expect(nodeByRef($screen, 'thread-scroll')['props'] ?? [])->not->toHaveKey('auto_scroll_to'); +}); diff --git a/tests/Feature/Screens/RelatedCommitsTest.php b/tests/Feature/Screens/RelatedCommitsTest.php index d493ad73..b3f9a350 100644 --- a/tests/Feature/Screens/RelatedCommitsTest.php +++ b/tests/Feature/Screens/RelatedCommitsTest.php @@ -85,7 +85,7 @@ function openRelated(TestableComponent $screen): TestableComponent ->assertSee('Next match') ->assertSee('Third match'); - expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'thread-reply-r1', 'related-commits', 'reply-bar-clearance']) + expect(childRefs($screen, 'thread-scroll'))->toBe(['focused-commit', 'thread-reply-r1', 'related-commits', 'reply-bar-clearance']) ->and(childRefs($screen, 'related-commits'))->toBe(['related-commits-toggle', 'related-c9', 'related-c3', 'related-c7']) ->and(childRefs($screen, 'related-c9'))->toBe(['commit-c9']) ->and(railNode($screen, 'commit-c9'))->toBe('avatar') @@ -255,13 +255,13 @@ function openRelated(TestableComponent $screen): TestableComponent $relatedLine = fn (): float => (float) (nodeByRef($screen, 'related-commits')['props']['border_t'] ?? 0); // Shut, the commit sits right on the section, whose line is the only one. - expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'related-commits', 'reply-bar-clearance']) + expect(childRefs($screen, 'thread-scroll'))->toBe(['focused-commit', 'related-commits', 'reply-bar-clearance']) ->and($commitLine())->toBe(0.0) ->and($relatedLine())->toBe(1.0); // Open, the last reply ends with no hairline of its own, so the section's line is still the only one. $screen->tap('replies-c1')->assertSee('A reply'); - expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'thread-reply-r1', 'related-commits', 'reply-bar-clearance']) + expect(childRefs($screen, 'thread-scroll'))->toBe(['focused-commit', 'thread-reply-r1', 'related-commits', 'reply-bar-clearance']) ->and($commitLine())->toBe(0.0) ->and(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'thread-end-r1'))->toBeNull() ->and($relatedLine())->toBe(1.0); diff --git a/tests/Feature/Screens/SelfThreadTest.php b/tests/Feature/Screens/SelfThreadTest.php index 6c3b53fd..b78153cc 100644 --- a/tests/Feature/Screens/SelfThreadTest.php +++ b/tests/Feature/Screens/SelfThreadTest.php @@ -63,7 +63,7 @@ function serveSelfThread(array $commit, array $ancestors, array $replies): void */ function selfThreadRows(TestableComponent $screen): array { - return array_values(array_filter(childRefs($screen, 'thread-page'), fn (?string $ref): bool => $ref !== 'reply-bar-clearance')); + return array_values(array_filter(childRefs($screen, 'thread-scroll'), fn (?string $ref): bool => $ref !== 'reply-bar-clearance')); } /** diff --git a/tests/Feature/Screens/SeriesTest.php b/tests/Feature/Screens/SeriesTest.php index ad0ff31a..cd6027f9 100644 --- a/tests/Feature/Screens/SeriesTest.php +++ b/tests/Feature/Screens/SeriesTest.php @@ -131,7 +131,8 @@ function railRunsOn(TestableComponent $screen, string $ref): bool ->and(railRunsOn($screen, 'focused-commit'))->toBeTrue() ->and(railRunsOn($screen, 'commit-p3'))->toBeFalse(); - $screen->tap('commit-p3')->assertNavigatedTo('/log/commits/p3'); + // A part in the tree moves the page to it rather than pushing another. + $screen->tap('commit-p3')->assertNoNavigation()->assertSet('id', 'p3'); }); it('puts a part\'s replies under it, above the later parts, as on the web', function () { From 10cca475869305352f4e9d6cd7b4c3f5e76619ef Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 03:05:46 +0000 Subject: [PATCH 07/18] Animate the commit page's move to another commit in its tree The scroll view now has animate-layout, so the rows the page keeps slide to their new places and the ones it adds or drops fade, and auto-scroll-animated, so the first move animates too. The focused commit is keyed commit-, as it is among the commits above it, so moving up the tree slides that row rather than redrawing it. Going back to a row the scroll view already went to used to mount the scroll view again, which would make every row new. It now passes a new auto-scroll-token instead. These need NativePHP/mobile-air#736 and NativePHP/mobile-ui#225. Without them the move jumps, as before, and asking for the same row twice in a row doesn't scroll. The test that reads the new props skips until vendor has them (Tests\Support\LayoutAnimation). Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/CommitDetail.php | 19 +++++---- .../views/native/commit-detail.blade.php | 10 +++-- .../native/partials/commit-row.blade.php | 2 +- tests/Feature/Screens/NestedRepliesTest.php | 41 +++++++++++++++++++ tests/Support/LayoutAnimation.php | 25 +++++++++++ 5 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 tests/Support/LayoutAnimation.php diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index 2eb2380f..5f58d4c4 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -252,6 +252,12 @@ class CommitDetail extends NativeComponent */ public ?int $scrollTarget = null; + /** + * Counts the moves refocus() made. The scroll view takes it as its auto-scroll-token, so asking for the same row + * as last time (going back to the top twice) scrolls again rather than doing nothing. + */ + public int $scrollRequest = 0; + /** * The commit the page opened on, before tapping others in its tree moved it (see refocus()). */ @@ -473,15 +479,10 @@ private function refocus(string $id): bool $this->takeReplyDraft(); $this->error = null; - // The commit's row is the one after its ancestors. A request the scroll view already went to does nothing, - // so going back to the top a second time mounts it again, at the top. - $target = count($this->ancestors); - - if ($target === $this->scrollTarget) { - $this->scrollKey++; - } - - $this->scrollTarget = $target; + // The commit's row is the one after its ancestors. A new token asks again even when that's the row the + // scroll view went to last time. The scroll view keeps its key, so its rows slide to their new places. + $this->scrollTarget = count($this->ancestors); + $this->scrollRequest++; $this->forgetRefreshes(); $this->revalidate(); $this->followThread(); diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index fd7b2a75..3b111325 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -9,10 +9,14 @@ {{-- Each row is a child of the scroll view itself, so it can bring one into view: the commit the page is on, after - tapping another commit in the tree moves the page to it (see CommitDetail::refocus() and $scrollTarget). The - first move jumps and later ones animate, as auto-scroll-to does on both platforms. + tapping another commit in the tree moves the page to it (see CommitDetail::refocus() and $scrollTarget). Every + move animates (auto-scroll-animated), and $scrollRequest as the token makes asking for the same row again scroll + again. With animate-layout the rows the page keeps slide to their new places, and the ones it adds or drops + fade. That needs the scroll view's key, and each row's, to stay the same across the move: the focused commit + is keyed commit-, as the commits above it are. These need NativePHP/mobile-air#736 and + NativePHP/mobile-ui#225; without them the move jumps and a repeat of the same row doesn't scroll. --}} - + @if (! $commit && $error === null) diff --git a/resources/views/native/partials/commit-row.blade.php b/resources/views/native/partials/commit-row.blade.php index 209350f2..528a20d1 100644 --- a/resources/views/native/partials/commit-row.blade.php +++ b/resources/views/native/partials/commit-row.blade.php @@ -13,7 +13,7 @@ @if ($commit->isDeleted()) @include('native.partials.commit-tombstone') @elseif ($focused) - + @include('native.partials.commit-row-content') @else diff --git a/tests/Feature/Screens/NestedRepliesTest.php b/tests/Feature/Screens/NestedRepliesTest.php index 14a41698..d94e12a8 100644 --- a/tests/Feature/Screens/NestedRepliesTest.php +++ b/tests/Feature/Screens/NestedRepliesTest.php @@ -3,6 +3,7 @@ use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Http; use Native\Mobile\Testing\Native; +use Tests\Support\LayoutAnimation; beforeEach(function () { config(['devnull.url' => 'http://devnull.test']); @@ -129,3 +130,43 @@ function fakeDeepThread(): void expect(nodeByRef($screen, 'thread-scroll')['props'] ?? [])->not->toHaveKey('auto_scroll_to'); }); + +it('keeps the commit row and the scroll view the same nodes when the page moves', function () { + fakeDeepThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + $screen->tap('replies-r1'); + $screen->tap('thread-reply-r2'); + $scroller = nodeByRef($screen, 'thread-scroll')['id']; + $ancestor = nodeByRef($screen, 'commit-c2')['id']; + + // The commit the page moves to keeps the node it had above the focus, so its row slides into place. The scroll + // view keeps its node too: a new one would make every row in it new. + $screen->tap('commit-c2')->assertSet('id', 'c2'); + + expect(nodeByRef($screen, 'focused-commit')['id'])->toBe($ancestor) + ->and(nodeByRef($screen, 'thread-scroll')['id'])->toBe($scroller); +}); + +it('animates the move and asks again for a row it went to before', function () { + LayoutAnimation::skipUnlessSupported(); + fakeDeepThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + $props = fn (): array => nodeByRef($screen, 'thread-scroll')['props']; + + expect($props())->toHaveKey('animate_layout', true) + ->and($props())->toHaveKey('auto_scroll_animated', true) + ->and($props())->toHaveKey('auto_scroll_token', '0'); + + $screen->tap('replies-r1'); + $screen->tap('thread-reply-r1')->assertSet('scrollTarget', 1); + $screen->tap('commit-c2')->assertSet('scrollTarget', 0); + $first = $props()['auto_scroll_token']; + $screen->tap('thread-reply-r1'); + $screen->tap('commit-c2')->assertSet('scrollTarget', 0); + + // The same row as two moves ago, under a new token, so the scroll view goes back to it. + expect($props()['auto_scroll_to'])->toBe(0) + ->and($props()['auto_scroll_token'])->not->toBe($first); +}); diff --git a/tests/Support/LayoutAnimation.php b/tests/Support/LayoutAnimation.php new file mode 100644 index 00000000..155686c8 --- /dev/null +++ b/tests/Support/LayoutAnimation.php @@ -0,0 +1,25 @@ +markTestSkipped('Needs a mobile-air with layout animation (NativePHP/mobile-air#736)'); + } + } +} From 5c5d26b78fa34bdac63cc23eb8578b0f98ba3ba8 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 03:13:16 +0000 Subject: [PATCH 08/18] Move the commit page's short hash to the top right of the commit It sat under the commit's text. Now it ends the row with the name, handle and time, pushed right by a spacer, in the same size and ink. Only the focused commit shows a hash, so no other rows change. Co-Authored-By: Claude Opus 5.5 --- .../native/partials/commit-row-content.blade.php | 11 ++++++----- tests/Feature/Screens/CommitDetailTest.php | 9 +++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/resources/views/native/partials/commit-row-content.blade.php b/resources/views/native/partials/commit-row-content.blade.php index 94482f11..382e6c66 100644 --- a/resources/views/native/partials/commit-row-content.blade.php +++ b/resources/views/native/partials/commit-row-content.blade.php @@ -11,7 +11,7 @@ row is fixed here, so they meet it on both platforms. On a commit page the commit it's about ($focused) is the main thing: a larger name and body in full ink, its time, - which tapped says when in your timezone, its hash, and its replies behind a toggle in its action row. The commits around it ($muted) step back: + which tapped says when in your timezone, its hash at the top right, and its replies behind a toggle in its action row. The commits around it ($muted) step back: smaller and in muted ink, with a smaller avatar and action row. They still open their own pages. A commit in a thread its author wrote as replies to themselves wears its place in it ($threadPosition, "2/5"), and @@ -75,6 +75,11 @@ @unless ($commit->isApproved()) @include('native.partials.status-chip', ['status' => $commit->status]) @endunless + @if ($focused) + {{-- Its short hash, at the top right of the row, as the web has it at the right of the page's header. --}} + + {{ $commit->shortHash }} + @endif @if ($commit->parent?->isDeleted()) @@ -103,10 +108,6 @@ @include('native.partials.show-thread') @endif - @if ($focused) - {{ $commit->shortHash }} - @endif - @if ($commit->isStaged()) @elseif ($focused) @include('native.partials.commit-actions', [ diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index cf451876..267e1a7d 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -287,7 +287,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->and(findNode($screen->tree(), fn (array $node): bool => str_starts_with((string) ($node['ref'] ?? ''), 'thread-end-')))->toBeNull(); }); -it('shows the short hash under the focused commit, without the full date', function () { +it('shows the short hash at the top right of the focused commit, without the full date', function () { fakeThread(['created_at' => '2026-10-14T20:13:05Z']); $screen = Native::visit('/log/commits/c2') @@ -295,8 +295,13 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): ->assertDontSee('+0000'); $hash = nodeByRef($screen, 'focused-hash'); + // The row with the name, the handle and the time, with a spacer pushing the hash to its end. + $nameRow = findNode(nodeByRef($screen, 'focused-commit'), fn (array $node): bool => ($node['type'] ?? null) === 'row' && in_array('focused-time', array_map(fn (array $child): ?string => $child['ref'] ?? null, $node['children'] ?? []), true)); + $children = $nameRow['children'] ?? []; - expect($hash['text'] ?? $hash['props']['text'] ?? null)->toBe('c2'); + expect($hash['text'] ?? $hash['props']['text'] ?? null)->toBe('c2') + ->and($children[array_key_last($children)]['ref'] ?? null)->toBe('focused-hash') + ->and($children[count($children) - 2]['type'] ?? null)->toBe('spacer'); }); it('says when the commit was made, in your timezone, when its time is tapped, as the web does on hover', function (?string $chosen, string $toast) { From 16f38391eaae72e01148ecf7aeeec628d8ad8ed4 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 03:13:16 +0000 Subject: [PATCH 09/18] Open the replies of the commits above the commit in place The commits above the one the page is on keep their "N replies" button, and it now opens their replies in place under them, like the commit's and every reply's, instead of moving the page there. The reply on the line down to the commit is left out of the list and of the count, since it already shows below. Closing an ancestor's replies leaves the replies of the commits on the line open (drawsOnItsOwn in ExpandsThreads). After a move the scroll target counts the rows opened above the commit, and opening or closing them later doesn't scroll. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/CommitDetail.php | 64 ++++++++++++-- .../Concerns/ExpandsThreads.php | 15 +++- .../views/native/commit-detail.blade.php | 20 +++-- tests/Feature/Screens/NestedRepliesTest.php | 85 +++++++++++++++++++ 4 files changed, 171 insertions(+), 13 deletions(-) diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index 5f58d4c4..b35ce09c 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -19,6 +19,7 @@ use App\Devnull\RowCache; use App\Devnull\SelfThread; use App\Devnull\Stash; +use App\Devnull\ThreadRows; use App\Devnull\Timeline; use App\Devnull\Toasts; use App\Icons\Lucide; @@ -51,7 +52,8 @@ * * Each reply's own replies open in place under it, and theirs under them, as * deep as they go, as the web's commit page does (see ExpandsThreads and - * App\Devnull\ThreadRows). + * App\Devnull\ThreadRows). So do the commits above the commit, less the one + * on the line down to it, which already shows (see ancestorThreads()). * * Tapping a commit in the tree, above the commit, below it or among the * replies at any depth, moves this page to it rather than pushing another @@ -479,9 +481,10 @@ private function refocus(string $id): bool $this->takeReplyDraft(); $this->error = null; - // The commit's row is the one after its ancestors. A new token asks again even when that's the row the - // scroll view went to last time. The scroll view keeps its key, so its rows slide to their new places. - $this->scrollTarget = count($this->ancestors); + // The commit's row is the one after its ancestors and the replies opened under them. A new token asks again + // even when that's the row the scroll view went to last time. The scroll view keeps its key, so its rows + // slide to their new places. Opening an ancestor's replies later leaves the target be, so it doesn't scroll. + $this->scrollTarget = count($this->ancestors) + array_sum(array_map(fn (array $thread): int => count($thread['rows']), $this->ancestorThreads($this->ancestors))); $this->scrollRequest++; $this->forgetRefreshes(); $this->revalidate(); @@ -594,9 +597,59 @@ private function ancestorsInTree(Commit $target): ?array return [...array_slice($line, 0, array_search($parentId, $lineIds, true) + 1), ...$between]; } + /** + * The replies of each commit above the commit, as its "› N replies" opens them in place under it, the same as a + * reply's (see ExpandsThreads), and how many that button counts. The commit under it on the page, when that's + * one of its replies, is left out of both: it's already showing, on the line down to the commit. The web leaves + * out only the part of a self-thread that carries it on (see SelfThread), so there the rest of the line would + * show twice. devnull's count already leaves that part out. + * + * @param list $above + * @return array, reply: Commit|null}>}> + */ + private function ancestorThreads(array $above): array + { + if ($this->commit === null) { + return []; + } + + $line = [...$above, $this->commit]; + $threads = []; + + foreach ($above as $index => $ancestor) { + $next = $line[$index + 1]; + $onLine = $next->parentId === $ancestor->id && $ancestor->continuationId !== $next->id; + $replies = array_values(array_filter($this->threads[$ancestor->id] ?? [], fn (Commit $reply): bool => $reply->id !== $next->id)); + + $threads[$ancestor->id] = [ + 'count' => max(0, $ancestor->repliesCount - ($onLine ? 1 : 0)), + 'rows' => $ancestor->isDeleted() || $replies === [] ? [] : ThreadRows::under( + $ancestor, + [...$this->threads, $ancestor->id => $replies], + $this->threadCursors, + $this->threadShown, + $ancestor->lane(), + opensInPlace: PHP_INT_MAX, + onPage: true, + ), + ]; + } + + return $threads; + } + + /** + * The commits on the page's line, above the commit and the commit itself, draw rows of their own, so closing the + * replies they're among leaves their own replies open. + */ + protected function drawsOnItsOwn(string $id): bool + { + return $id === $this->id || in_array($id, array_map(fn (Commit $ancestor): string => $ancestor->id, $this->ancestors), true); + } + /** * "› N replies" under the commit opens them in place, and "Hide replies" folds them away. Under a reply, at any - * depth, it opens that reply's replies in place under it (see ExpandsThreads). + * depth, or a commit above the commit, it opens that one's replies in place under it (see ExpandsThreads). */ public function toggleReplies(string $id = ''): void { @@ -1211,6 +1264,7 @@ public function render(): View laneAbove: $earlier === [] ? null : end($earlier)->lane(), ), 'relatedRows' => Timeline::thread($this->related), + 'ancestorThreads' => $this->ancestorThreads($above), 'earlierCount' => $this->commit === null ? 0 : count($earlier), 'earlierLane' => $earlier === [] ? null : end($earlier)->lane(), 'replyCount' => max($this->commit->repliesCount ?? 0, count($replies)), diff --git a/app/NativeComponents/Concerns/ExpandsThreads.php b/app/NativeComponents/Concerns/ExpandsThreads.php index 8a31f599..cbd8830d 100644 --- a/app/NativeComponents/Concerns/ExpandsThreads.php +++ b/app/NativeComponents/Concerns/ExpandsThreads.php @@ -267,7 +267,9 @@ private function keepCursor(string $id, ?string $cursor): void private function closeThread(string $id): void { foreach ($this->threads[$id] ?? [] as $reply) { - $this->closeThread($reply->id); + if (! $this->drawsOnItsOwn($reply->id)) { + $this->closeThread($reply->id); + } } unset($this->threads[$id], $this->threadCursors[$id], $this->threadShown[$id]); @@ -360,7 +362,7 @@ private function rowsInside(string $id): array $rows = $this->rowsOf($id, $this->shownReplies($id)); foreach ($this->shownReplies($id) as $reply) { - if (array_key_exists($reply->id, $this->threads)) { + if (array_key_exists($reply->id, $this->threads) && ! $this->drawsOnItsOwn($reply->id)) { $rows = [...$rows, ...$this->rowsInside($reply->id)]; } } @@ -368,6 +370,15 @@ private function rowsInside(string $id): array return $rows; } + /** + * Whether the screen draws a reply in a row of its own rather than in the thread it's in, so its own replies + * stay open when that thread closes. A commit page draws the commits on its line that way (see CommitDetail). + */ + protected function drawsOnItsOwn(string $id): bool + { + return false; + } + /** * @return list */ diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index 3b111325..9cbd7358 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -31,7 +31,8 @@ their avatar once. The replies hang under it on the thread's dashed lines, with the rail ending in a dot above them, ten at a time with "Show more" under the last. A part of a series with more parts after it has its replies right under it, beside the rail running on, and the later parts follow. Everything - around the commit is muted. Tapping any commit in the tree moves the page to it rather than pushing + around the commit is muted, and the commits above it open their other replies in place under them, as the + commit does. Tapping any commit in the tree moves the page to it rather than pushing another (see CommitDetail::refocus()). Every reply's own replies open in place under it, ten at a time too, as deep as they go, as on the web: they step in up to the web's depth and line up under the deepest step past it, saying who they answer (see App\Devnull\ThreadRows). @@ -57,12 +58,14 @@ @php($isLastPart = $lastPart !== null && $row->commit->id === $lastPart->id) @php($hasThread = $isFocused && $repliesShown && $replies !== []) @php($partThread = $isLastPart && $lastPartReplies !== []) + @php($aboveThread = $ancestorThreads[$row->commit->id] ?? null) + @php($aboveOpen = ($aboveThread['rows'] ?? []) !== []) @include('native.partials.commit-row', [ 'commit' => $row->commit, 'previousLane' => $row->previousLane, 'continuesRun' => $row->continuesRun, - 'continuesNext' => $isFocused ? ! $loop->last : null, - 'threadBelow' => $hasThread || $partThread, + 'continuesNext' => $isFocused || $aboveOpen ? ! $loop->last : null, + 'threadBelow' => $hasThread || $partThread || $aboveOpen, 'repliesBelow' => $partThread, 'focused' => $isFocused, 'muted' => ! $isFocused, @@ -71,15 +74,20 @@ 'hairline' => ! ($loop->last && $relatedBelow && ! $threadMore), 'threadPosition' => $threadPositions[$row->commit->id] ?? null, 'showsThread' => false, - 'expandable' => false, + 'expandable' => $aboveThread !== null, + 'repliesCount' => $aboveThread['count'] ?? null, ]) @if ($isFocused && $repliesShown && $replies === [] && ! $repliesLoaded && $error === null) @endif - {{-- The replies, and theirs opened in place under them as deep as they go (see App\Devnull\ThreadRows). --}} - @php($pageThread = match (true) { $hasThread => \App\Devnull\ThreadRows::under($commit, [...$threads, $commit->id => $replies], array_filter([...$threadCursors, $commit->id => $repliesCursor]), $threadShown, $loop->last ? null : $commit->lane(), opensInPlace: PHP_INT_MAX, onPage: true, morePress: 'loadMoreReplies'), $partThread => \App\Devnull\ThreadRows::under($lastPart, [...$threads, $lastPart->id => $lastPartReplies], array_filter([...$threadCursors, $lastPart->id => $lastPartMore ? 'more' : null]), $threadShown, opensInPlace: PHP_INT_MAX, onPage: true, morePress: "openReplies('{$lastPart->id}')"), default => [] }) + {{-- + The replies, and theirs opened in place under them as deep as they go (see App\Devnull\ThreadRows). + A commit above the commit opens its replies in place under it too, all but the one on the line down + to the commit, which already shows (see CommitDetail::ancestorThreads()). + --}} + @php($pageThread = match (true) { $aboveThread !== null => $aboveThread['rows'], $hasThread => \App\Devnull\ThreadRows::under($commit, [...$threads, $commit->id => $replies], array_filter([...$threadCursors, $commit->id => $repliesCursor]), $threadShown, $loop->last ? null : $commit->lane(), opensInPlace: PHP_INT_MAX, onPage: true, morePress: 'loadMoreReplies'), $partThread => \App\Devnull\ThreadRows::under($lastPart, [...$threads, $lastPart->id => $lastPartReplies], array_filter([...$threadCursors, $lastPart->id => $lastPartMore ? 'more' : null]), $threadShown, opensInPlace: PHP_INT_MAX, onPage: true, morePress: "openReplies('{$lastPart->id}')"), default => [] }) @foreach ($pageThread as $threadRow) @if ($threadRow['reply'] === null) @include($threadRow['partial'], $threadRow['data']) diff --git a/tests/Feature/Screens/NestedRepliesTest.php b/tests/Feature/Screens/NestedRepliesTest.php index d94e12a8..75a30403 100644 --- a/tests/Feature/Screens/NestedRepliesTest.php +++ b/tests/Feature/Screens/NestedRepliesTest.php @@ -170,3 +170,88 @@ function fakeDeepThread(): void expect($props()['auto_scroll_to'])->toBe(0) ->and($props()['auto_scroll_token'])->not->toBe($first); }); + +/** + * A commit page for c2, which answers c1. c1 has another reply, x1, and x1 has one of its own, x2. c2 has one reply, r1. + */ +function fakeAncestorThread(): void +{ + $person = fn (string $handle, int $lane): array => userJson(['handle' => $handle, 'name' => ucfirst($handle), 'lane' => $lane]); + $c1 = commitJson(['id' => 'c1', 'body' => 'The commit above', 'replies_count' => 2, 'author' => $person('ada', 1)]); + $c2 = commitJson(['id' => 'c2', 'parent_id' => 'c1', 'body' => 'The focused commit', 'replies_count' => 1, 'author' => $person('grace', 2)]); + $x1 = replyJson(['id' => 'x1', 'parent_id' => 'c1', 'body' => 'Another reply above', 'replies_count' => 1, 'author' => $person('linus', 4)]); + $x2 = replyJson(['id' => 'x2', 'parent_id' => 'x1', 'body' => 'A reply to the other reply', 'author' => $person('alan', 5)]); + $r1 = replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'A reply below', 'author' => $person('ken', 6)]); + + Http::fake(function (Request $request) use ($c1, $c2, $x1, $x2, $r1) { + $path = parse_url($request->url(), PHP_URL_PATH); + + return match ($path) { + '/api/v1/commits/c2' => Http::response(commitPageJson($c2, [$c1])), + '/api/v1/commits/c1' => Http::response(commitPageJson($c1)), + '/api/v1/commits/r1' => Http::response(commitPageJson($r1, [$c1, $c2])), + '/api/v1/commits/c1/related', '/api/v1/commits/c2/related', '/api/v1/commits/r1/related' => Http::response(['data' => []]), + '/api/v1/commits/c1/replies' => Http::response(pageJson([$c2, $x1])), + '/api/v1/commits/c2/replies' => Http::response(pageJson([$r1])), + '/api/v1/commits/x1/replies' => Http::response(pageJson([$x2])), + '/api/v1/commits/r1/replies', '/api/v1/commits/x2/replies' => Http::response(pageJson([])), + default => Http::response(['message' => 'No fake.'], 404), + }; + }); +} + +it('opens the replies of a commit above the commit in place, leaving out the one on the way down', function () { + fakeAncestorThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + + // c1 has two replies, and one of them is the commit the page is on, so its button counts the other. + expect(nodeByRef($screen, 'replies-c1')['props']['a11y_label'] ?? null)->toBe('1 reply'); + + $screen->tap('replies-c1')->assertNoNavigation()->assertSee('Another reply above'); + + // The other reply opens under c1, and the commit the page is on shows once, as the commit. + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'thread-reply-x1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']); + + // Its replies open in place too, at any depth. + $screen->tap('replies-x1')->assertNoNavigation()->assertSee('A reply to the other reply'); + + $screen->tap('replies-c1'); + finishRefreshes($screen)->assertDontSee('Another reply above')->assertDontSee('A reply to the other reply'); + + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']); +}); + +it('counts the replies opened above the commit in the row it scrolls to after a move', function () { + fakeAncestorThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + $screen->tap('replies-c1'); + $screen->tap('thread-reply-r1')->assertSet('id', 'r1')->assertSet('scrollTarget', 3); + + // r1 has no replies, so "No replies yet" follows it. + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'thread-reply-x1', 'commit-c2', 'focused-commit', null, 'reply-bar-clearance']) + ->and(rendersRef($screen, 'replies-c2'))->toBeFalse(); + + // Closing the replies of a commit above it later doesn't scroll the page again. + $screen->tap('replies-c1')->assertSet('scrollTarget', 3); +}); + +it('keeps the replies of the commits on the line open when the replies of one above them close', function () { + fakeDeepThread(); + + $screen = Native::visit('/log/commits/c2', ['replies' => true]); + $screen->tap('replies-r1'); + $screen->tap('replies-r2'); + $screen->tap('thread-reply-r3')->assertSet('id', 'r3'); + + // Each commit above r3 has one reply, the one on the way down, so none of them has a replies button. + expect(rendersRef($screen, 'replies-c2'))->toBeFalse() + ->and(rendersRef($screen, 'replies-r1'))->toBeFalse(); + + // Closing c2's replies, which the page kept open from when it was on c2, leaves r1's and r2's be. + $screen->call('toggleReplies', 'c2'); + finishRefreshes($screen); + + expect($screen->get('threads'))->toHaveKeys(['r1', 'r2']); +}); From d204792fdb664e8097bd3e2de6b79d53486180a5 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 09:17:13 +0000 Subject: [PATCH 10/18] Fold the replies of the commits above the commit on every move The commits above the one the page is on now start with their replies folded behind "N replies", whether the page opened on a reply or moved down to one. Before, moving down kept the replies of the commit the page left open under it, and any opened on a commit above stayed open. Moving up, the commit the page moves to shows its replies with the way back down opened, as before. The scroll target after a move is just the ancestor count again, since nothing is open above the commit then. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/CommitDetail.php | 23 ++++++--- .../views/native/commit-detail.blade.php | 2 +- tests/Feature/Screens/NestedRepliesTest.php | 51 +++++++++++++++---- 3 files changed, 56 insertions(+), 20 deletions(-) diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index b35ce09c..7e9292d5 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -421,9 +421,11 @@ public function replyTo(string $id): void * the author's thread or series, or a reply at any depth. It becomes the * commit the page is about, with what's above it as its ancestors and its * replies showing below, all from what the page already has, so nothing - * goes blank, and devnull is asked for the rest behind it. Replies opened - * in place stay open, and the commit the page was on keeps its replies, so - * moving up shows where you came from opened under its parent. + * goes blank, and devnull is asked for the rest behind it. The commits + * above it start with their replies folded, showing only "› N replies", + * as when the page opens on a reply. Moving up, the commit the page was on + * keeps its replies, and so do the commits between, so the commit you + * move to shows the way back down to where you came from opened under it. * * The page stays one screen: Back still leaves it, as Simon asked, rather * than stepping back through the commits it moved to. The scroll view @@ -448,7 +450,7 @@ private function refocus(string $id): bool $line = [...$this->ancestors, $this->commit]; $below = array_slice($line, count($ancestors) + 1); - // What the page was on keeps its replies, opened in place, for when it's back in the tree. + // What the page was on keeps its replies, opened in place, when it ends up below the commit the page moves to. if ($this->repliesShown && $this->repliesLoaded && $this->replies !== []) { $this->threads[$this->id] = array_values(array_filter($this->replies, fn (Commit $reply): bool => ! $reply->isStaged())); $this->keepCursor($this->id, $this->repliesCursor); @@ -471,6 +473,11 @@ private function refocus(string $id): bool $this->threadLimit = SelfThread::PerPage; $this->takeOwnReplies($id); + // The commits above it fold their replies, the commit the page was on among them when the page moved down. + foreach ($this->ancestors as $ancestor) { + $this->closeThread($ancestor->id); + } + if (($thread = $this->cached($this->threadPath())) !== null) { $this->takeCommitThread($thread); } @@ -481,10 +488,10 @@ private function refocus(string $id): bool $this->takeReplyDraft(); $this->error = null; - // The commit's row is the one after its ancestors and the replies opened under them. A new token asks again - // even when that's the row the scroll view went to last time. The scroll view keeps its key, so its rows - // slide to their new places. Opening an ancestor's replies later leaves the target be, so it doesn't scroll. - $this->scrollTarget = count($this->ancestors) + array_sum(array_map(fn (array $thread): int => count($thread['rows']), $this->ancestorThreads($this->ancestors))); + // The commit's row is the one after its ancestors, whose replies are folded. A new token asks again even when + // that's the row the scroll view went to last time. The scroll view keeps its key, so its rows slide to their + // new places. Opening an ancestor's replies later leaves the target be, so it doesn't scroll. + $this->scrollTarget = count($this->ancestors); $this->scrollRequest++; $this->forgetRefreshes(); $this->revalidate(); diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index 9cbd7358..7d28ab78 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -32,7 +32,7 @@ above them, ten at a time with "Show more" under the last. A part of a series with more parts after it has its replies right under it, beside the rail running on, and the later parts follow. Everything around the commit is muted, and the commits above it open their other replies in place under them, as the - commit does. Tapping any commit in the tree moves the page to it rather than pushing + commit does, from their "N replies", which starts folded, even after the page moves. Tapping any commit in the tree moves the page to it rather than pushing another (see CommitDetail::refocus()). Every reply's own replies open in place under it, ten at a time too, as deep as they go, as on the web: they step in up to the web's depth and line up under the deepest step past it, saying who they answer (see App\Devnull\ThreadRows). diff --git a/tests/Feature/Screens/NestedRepliesTest.php b/tests/Feature/Screens/NestedRepliesTest.php index 75a30403..1e9e4c79 100644 --- a/tests/Feature/Screens/NestedRepliesTest.php +++ b/tests/Feature/Screens/NestedRepliesTest.php @@ -222,19 +222,43 @@ function fakeAncestorThread(): void expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']); }); -it('counts the replies opened above the commit in the row it scrolls to after a move', function () { +it('folds the replies of the commits above when the page moves down to a reply', function () { fakeAncestorThread(); $screen = Native::visit('/log/commits/c2', ['replies' => true]); - $screen->tap('replies-c1'); - $screen->tap('thread-reply-r1')->assertSet('id', 'r1')->assertSet('scrollTarget', 3); + $screen->tap('replies-c1')->assertSee('Another reply above'); + $screen->tap('thread-reply-r1')->assertSet('id', 'r1')->assertSet('scrollTarget', 2)->assertDontSee('Another reply above'); - // r1 has no replies, so "No replies yet" follows it. - expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'thread-reply-x1', 'commit-c2', 'focused-commit', null, 'reply-bar-clearance']) + // c1 is back to its button, still leaving out c2 on the way down. r1 has no replies, so "No replies yet" follows it. + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'commit-c2', 'focused-commit', null, 'reply-bar-clearance']) + ->and(nodeByRef($screen, 'replies-c1')['props']['a11y_label'] ?? null)->toBe('1 reply') ->and(rendersRef($screen, 'replies-c2'))->toBeFalse(); - // Closing the replies of a commit above it later doesn't scroll the page again. - $screen->tap('replies-c1')->assertSet('scrollTarget', 3); + // Opening them again later doesn't scroll the page. + $screen->tap('replies-c1')->assertSee('Another reply above')->assertSet('scrollTarget', 2); +}); + +it('folds the replies of the commit the page was on when it moves down to one of them, and opens them again moving back up', function () { + fakeAncestorThread(); + + $screen = Native::visit('/log/commits/c1', ['replies' => true])->assertSee('Another reply above'); + $screen->tap('thread-reply-c2')->assertNoNavigation()->assertSet('id', 'c2')->assertDontSee('Another reply above'); + + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']) + ->and(nodeByRef($screen, 'replies-c1')['props']['a11y_label'] ?? null)->toBe('1 reply'); + + // Back up on c1, its replies show as the commit's do, with c2's still open under it. + $screen->tap('commit-c1')->assertSet('id', 'c1')->assertSee('Another reply above')->assertSee('A reply below'); +}); + +it('opens on a reply with the replies of the commits above it folded', function () { + fakeAncestorThread(); + + $screen = Native::visit('/log/commits/r1')->call('showEarlier')->assertDontSee('Another reply above'); + + expect(nodeByRef($screen, 'replies-c1')['props']['a11y_label'] ?? null)->toBe('1 reply') + ->and(rendersRef($screen, 'replies-c2'))->toBeFalse() + ->and($screen->get('threads'))->toBe([]); }); it('keeps the replies of the commits on the line open when the replies of one above them close', function () { @@ -245,13 +269,18 @@ function fakeAncestorThread(): void $screen->tap('replies-r2'); $screen->tap('thread-reply-r3')->assertSet('id', 'r3'); - // Each commit above r3 has one reply, the one on the way down, so none of them has a replies button. - expect(rendersRef($screen, 'replies-c2'))->toBeFalse() + // The commits above r3 fold their replies. Each has one, the one on the way down, so none of them has a button. + expect($screen->get('threads'))->toBe([]) + ->and(rendersRef($screen, 'replies-c2'))->toBeFalse() ->and(rendersRef($screen, 'replies-r1'))->toBeFalse(); - // Closing c2's replies, which the page kept open from when it was on c2, leaves r1's and r2's be. + // Opened again, closing c2's replies leaves r1's be, since r1 draws a row of its own. + $screen->call('toggleReplies', 'c2'); + $screen->call('toggleReplies', 'r1'); + expect($screen->get('threads'))->toHaveKeys(['c2', 'r1']); + $screen->call('toggleReplies', 'c2'); finishRefreshes($screen); - expect($screen->get('threads'))->toHaveKeys(['r1', 'r2']); + expect($screen->get('threads'))->toHaveKey('r1')->not->toHaveKey('c2'); }); From 056deb8f608883051342db1e28783eb81b24573d Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 09:17:13 +0000 Subject: [PATCH 11/18] Hold the mention suggestions to six rows and scroll the rest With more than six people and organizations to suggest, the rows sit in a scroll view six rows tall inside the suggestions, so the list can't push the field and the bar's buttons down under the keyboard. Six or fewer are drawn as before, as tall as their rows. The slot around the list keeps its place, so the field's row doesn't move among its siblings. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/Display.php | 8 ++++++ .../partials/mention-suggestions.blade.php | 17 +++++++++++-- tests/Feature/Screens/CommitMentionsTest.php | 25 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/app/Devnull/Display.php b/app/Devnull/Display.php index 3897e633..82f003d9 100644 --- a/app/Devnull/Display.php +++ b/app/Devnull/Display.php @@ -27,6 +27,14 @@ final class Display public const int ReplyBarDescriptionHeight = 100; + /** + * The people to mention above a field (see partials/mention-suggestions): a row's height, and how many rows show + * before the rest scroll inside the list. + */ + public const int MentionRowHeight = 44; + + public const int MentionRowsShown = 6; + /** * A bar holding partials/composer-box with one line of draft, as drawn on an iPhone: the bar's padding, then the * field over the row of tools and the send button. diff --git a/resources/views/native/partials/mention-suggestions.blade.php b/resources/views/native/partials/mention-suggestions.blade.php index 1f0a4e29..5ed8a646 100644 --- a/resources/views/native/partials/mention-suggestions.blade.php +++ b/resources/views/native/partials/mention-suggestions.blade.php @@ -4,15 +4,25 @@ colour. $heading, when there is one, heads them: Members for a bare "@" in an org thread. A tap puts "@handle " in the field in place of what was typed. Above a bar's field on iOS they sit on glass of their own, like the reply strip; $class says otherwise. + + At most six rows show (Display::MentionRowsShown). Past that the rows scroll inside a list that tall, so the list + never pushes the field and the bar's buttons down under the keyboard. Fewer, and it's only as tall as its rows. + Each row is then exactly a row's height (Display::MentionRowHeight), so six fill the list. The rows sit inside the + list's own column, so the slot around it, and the field's row beside that, stay where they are. --}} @if (($mention['field'] ?? null) === $field && ($mentionPeople !== [] || $mentionOrganizations !== [])) @if ($heading ?? null) {{ $heading }} @endif - @foreach ([...array_map(fn ($user) => [$user, true], $mentionPeople), ...array_map(fn ($user) => [$user, false], $mentionOrganizations)] as [$user, $person]) + @php($mentionRows = [...array_map(fn ($user) => [$user, true], $mentionPeople), ...array_map(fn ($user) => [$user, false], $mentionOrganizations)]) + @php($mentionScrolls = count($mentionRows) > \App\Devnull\Display::MentionRowsShown) + @if ($mentionScrolls) + + @endif + @foreach ($mentionRows as [$user, $person]) - + @include('native.partials.avatar', ['user' => $user, 'size' => 28]) {{ $user->name }} @@ -26,5 +36,8 @@ @endforeach + @if ($mentionScrolls) + + @endif @endif diff --git a/tests/Feature/Screens/CommitMentionsTest.php b/tests/Feature/Screens/CommitMentionsTest.php index 4d35f14f..b728402d 100644 --- a/tests/Feature/Screens/CommitMentionsTest.php +++ b/tests/Feature/Screens/CommitMentionsTest.php @@ -95,6 +95,31 @@ function mentionsComposer(bool $quoting = false): TestableComponent ->assertMissingElement('column', fn (array $node): bool => ($node['ref'] ?? null) === 'mention-suggestions'); }); +it('holds the reply bar\'s suggestions to six rows and scrolls the rest inside the list', function () { + $people = array_map(fn (int $n): array => userJson(['id' => "u{$n}", 'handle' => "ada{$n}", 'name' => "Ada {$n}"]), range(1, 7)); + $screen = mentionsCommitPage([['data' => $people, 'organizations' => [['handle' => 'adaptive', 'name' => 'Adaptive', 'avatar_url' => null]]]]) + ->input('reply-input', '@ada', 4); + + // Eight rows, so they sit in a list six rows tall, which scrolls. The slot and the field's row around it stay put. + $list = nodeByRef($screen, 'mention-scroll'); + + expect(childRefs($screen, 'mention-suggestions'))->toBe(['mention-scroll']) + ->and($list['type'])->toBe('scroll_view') + ->and($list['layout']['height'] ?? null)->toEqual(6 * 44) + ->and(childRefs($screen, 'mention-scroll'))->toBe([...array_map(fn (int $n): string => "mention-ada{$n}", range(1, 7)), 'mention-adaptive']) + ->and(childRefs($screen, 'reply-rows'))->toBe(['reply-mention-slot', 'reply-photos-slot', 'reply-row']); + + $screen->tap('mention-ada7')->assertSet('reply', '@ada7 '); +}); + +it('leaves six suggestions or fewer as tall as their rows, with no list to scroll', function () { + $people = array_map(fn (int $n): array => userJson(['id' => "u{$n}", 'handle' => "ada{$n}", 'name' => "Ada {$n}"]), range(1, 6)); + $screen = mentionsCommitPage([['data' => $people]])->input('reply-input', '@ada', 4); + + expect(childRefs($screen, 'mention-suggestions'))->toBe(array_map(fn (int $n): string => "mention-ada{$n}", range(1, 6))) + ->and(rendersRef($screen, 'mention-scroll'))->toBeFalse(); +}); + it('puts the person picked in the reply where the @ was, with the caret after them', function () { $screen = mentionsCommitPage() ->input('reply-input', 'cc @adfor review', 6) From f9832b557bb57d5fe2e1f6c8aa2a3aa3ca22ba13 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sat, 21 Nov 2026 10:59:08 +0000 Subject: [PATCH 12/18] Let a caller that scrolls the mention list itself turn off its inner scroll The composer sheet in #198 sizes its mention list and scrolls it. With more than six rows the partial's own six-row scroll view sat inside that one, so a short phone showed two scroll bars. 'scrolls' => false draws every row as tall as it is with no scroll view inside. It defaults to true, so the reply bar and the conversation bar keep their six-row list. Co-Authored-By: Claude Opus 5.5 --- .../partials/mention-suggestions.blade.php | 6 ++- .../Screens/MentionSuggestionsTest.php | 54 +++++++++++++++++++ .../views/mention-suggestions.blade.php | 4 ++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tests/Feature/Screens/MentionSuggestionsTest.php create mode 100644 tests/Fixtures/views/mention-suggestions.blade.php diff --git a/resources/views/native/partials/mention-suggestions.blade.php b/resources/views/native/partials/mention-suggestions.blade.php index 5ed8a646..93dbf174 100644 --- a/resources/views/native/partials/mention-suggestions.blade.php +++ b/resources/views/native/partials/mention-suggestions.blade.php @@ -8,7 +8,9 @@ At most six rows show (Display::MentionRowsShown). Past that the rows scroll inside a list that tall, so the list never pushes the field and the bar's buttons down under the keyboard. Fewer, and it's only as tall as its rows. Each row is then exactly a row's height (Display::MentionRowHeight), so six fill the list. The rows sit inside the - list's own column, so the slot around it, and the field's row beside that, stay where they are. + list's own column, so the slot around it, and the field's row beside that, stay where they are. A caller that + scrolls the list itself (the composer sheet sizes and scrolls its own) passes 'scrolls' => false, and every row is + drawn as tall as it is, with no scroll view inside. --}} @if (($mention['field'] ?? null) === $field && ($mentionPeople !== [] || $mentionOrganizations !== [])) @@ -16,7 +18,7 @@ {{ $heading }} @endif @php($mentionRows = [...array_map(fn ($user) => [$user, true], $mentionPeople), ...array_map(fn ($user) => [$user, false], $mentionOrganizations)]) - @php($mentionScrolls = count($mentionRows) > \App\Devnull\Display::MentionRowsShown) + @php($mentionScrolls = ($scrolls ?? true) && count($mentionRows) > \App\Devnull\Display::MentionRowsShown) @if ($mentionScrolls) @endif diff --git a/tests/Feature/Screens/MentionSuggestionsTest.php b/tests/Feature/Screens/MentionSuggestionsTest.php new file mode 100644 index 00000000..04a7eb65 --- /dev/null +++ b/tests/Feature/Screens/MentionSuggestionsTest.php @@ -0,0 +1,54 @@ + 'body', 'start' => 0, 'query' => 'ada', 'text' => '@ada']; + + /** @var list */ + public array $mentionPeople = []; + + /** @var list */ + public array $mentionOrganizations = []; + + /** @var array */ + public array $options = []; + + public function mount(int $rows = 8, array $options = []): void + { + $this->mentionPeople = array_map(fn (int $n): User => User::fromArray(userJson(['id' => "u{$n}", 'handle' => "ada{$n}", 'name' => "Ada {$n}"])), range(1, $rows)); + $this->options = $options; + } + + public function pickMention(string $field, string $username): void {} + + public function render(): View + { + return view('fixtures::mention-suggestions', ['options' => $this->options]); + } +} + +beforeEach(fn () => view()->addNamespace('fixtures', base_path('tests/Fixtures/views'))); + +it('scrolls more than six rows inside the list by default', function () { + $screen = Native::test(MentionSuggestionsFixture::class, ['rows' => 8]); + + expect(childRefs($screen, 'mention-suggestions'))->toBe(['mention-scroll']) + ->and(nodeByRef($screen, 'mention-scroll')['type'])->toBe('scroll_view'); +}); + +it('draws every row with no scroll view inside when the caller scrolls the list itself', function () { + $screen = Native::test(MentionSuggestionsFixture::class, ['rows' => 8, 'options' => ['scrolls' => false]]); + + expect(rendersRef($screen, 'mention-scroll'))->toBeFalse() + ->and(childRefs($screen, 'mention-suggestions'))->toBe(array_map(fn (int $n): string => "mention-ada{$n}", range(1, 8))) + ->and(nodeByRef($screen, 'mention-ada8')['children'][0]['layout']['height'] ?? null)->toBeNull(); +}); diff --git a/tests/Fixtures/views/mention-suggestions.blade.php b/tests/Fixtures/views/mention-suggestions.blade.php new file mode 100644 index 00000000..d29b0fbf --- /dev/null +++ b/tests/Fixtures/views/mention-suggestions.blade.php @@ -0,0 +1,4 @@ +{{-- The mention list alone, for MentionSuggestionsTest: the partial with whatever options the test passes. --}} + + @include('native.partials.mention-suggestions', ['field' => 'body', ...$options]) + From 89bff8d99142f2081904b012c69b0634af6144fa Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 22 Nov 2026 10:24:54 +0000 Subject: [PATCH 13/18] Count the replies of the commits above from their own pages devnull sends the ancestors on a commit's page without replies_count, so a commit above only showed its "N replies" if the page had moved through it before. Each ancestor that shows now reads its count from its own page, kept from before at once and asked for behind, once per refresh. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/Data/Commit.php | 8 +++ app/NativeComponents/CommitDetail.php | 64 ++++++++++++++++++- .../Feature/Screens/CommitDetailCacheTest.php | 3 +- tests/Feature/Screens/NestedRepliesTest.php | 49 ++++++++++++++ 4 files changed, 122 insertions(+), 2 deletions(-) diff --git a/app/Devnull/Data/Commit.php b/app/Devnull/Data/Commit.php index 28b52bbf..4a2f608d 100644 --- a/app/Devnull/Data/Commit.php +++ b/app/Devnull/Data/Commit.php @@ -169,6 +169,14 @@ public function withMorePasteis(int $change): self return new self(...[...get_object_vars($this), 'pasteisCount' => max(0, $this->pasteisCount + $change)]); } + /** + * This commit with the count of replies its own page gives, for a copy that came without one. + */ + public function withRepliesCount(int $repliesCount): self + { + return new self(...[...get_object_vars($this), 'repliesCount' => max(0, $repliesCount)]); + } + public function withPinned(bool $isPinned): self { return new self(...[...get_object_vars($this), 'isPinned' => $isPinned]); diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index 7e9292d5..9dd73f7f 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -279,6 +279,13 @@ class CommitDetail extends NativeComponent */ protected bool $forceFullFrames = true; + /** + * The commits above whose own page was asked for their count since the page last asked devnull again. + * + * @var list + */ + protected array $countedAncestors = []; + public function mount(): void { $this->openedId = $this->id; @@ -335,6 +342,7 @@ public function load(): void protected function revalidate(): void { + $this->countedAncestors = []; $this->refresh($this->threadPath(), [], fn (array $json) => $this->takeCommitThread($json)); $this->refresh($this->threadPath().'/replies', [], fn (array $json) => $this->takeReplies($json)); $this->refresh($this->threadPath().'/related', [], fn (array $json) => $this->takeRelated($json), quiet: true, failed: function (): void { @@ -347,6 +355,7 @@ protected function revalidate(): void } $this->refreshThreads(); + $this->countAncestorReplies(); } protected function showsContent(): bool @@ -360,6 +369,7 @@ protected function showsContent(): bool public function showEarlier(): void { $this->earlierShown = true; + $this->countAncestorReplies(); } /** @@ -1121,9 +1131,61 @@ private function takeCommitThread(array $json): void $this->commit = $thread->commit; $this->ancestors = $thread->ancestors; $this->series = $thread->series; + $this->countAncestorReplies(); $this->followThread(); } + /** + * The commits above the commit that show: its parent, or every one once "↑ N earlier commits" opened them. + * + * @return list + */ + private function shownAncestors(): array + { + return $this->earlierShown ? $this->ancestors : array_slice($this->ancestors, -1); + } + + /** + * devnull sends the commits above the commit without their counts, so on their own a commit above never shows + * its "› N replies". Each one showing takes its count from its own page instead: kept from before at once, and + * asked for behind. That also keeps its page, so tapping it moves there with nothing blank. + */ + private function countAncestorReplies(): void + { + foreach ($this->shownAncestors() as $ancestor) { + if ($ancestor->isStaged() || $ancestor->isDeleted()) { + continue; + } + + $id = $ancestor->id; + $path = 'commits/'.rawurlencode($id); + + if (($kept = $this->cached($path)) !== null) { + $this->takeAncestorCount($id, $kept); + } + + // The commit's page landing draws its ancestors again, and they were asked for once already. + if (! in_array($id, $this->countedAncestors, true)) { + $this->countedAncestors[] = $id; + $this->refresh($path, [], fn (array $json) => $this->takeAncestorCount($id, $json), quiet: true); + } + } + } + + /** + * @param array $json + */ + private function takeAncestorCount(string $id, array $json): void + { + $page = CommitThread::fromArray($json)->commit; + + if ($page->id !== $id) { + return; + } + + $this->ancestors = array_map(fn (Commit $ancestor): Commit => $ancestor->id === $id ? $ancestor->withRepliesCount($page->repliesCount) : $ancestor, $this->ancestors); + } + /** * A fresh first page of replies. Pages loaded after it stay, past what it holds. * @@ -1249,7 +1311,7 @@ public function isOwn(): bool public function render(): View { $earlier = $this->earlierShown ? [] : array_slice($this->ancestors, 0, -1); - $above = $this->earlierShown ? $this->ancestors : array_slice($this->ancestors, -1); + $above = $this->shownAncestors(); $viewer = $this->me(); $this->replyRows ??= new RowCache; $this->replyRows->startFrame(); diff --git a/tests/Feature/Screens/CommitDetailCacheTest.php b/tests/Feature/Screens/CommitDetailCacheTest.php index 1694cf61..afc3e075 100644 --- a/tests/Feature/Screens/CommitDetailCacheTest.php +++ b/tests/Feature/Screens/CommitDetailCacheTest.php @@ -48,7 +48,8 @@ function serveThread(): void finishRefreshes($screen)->assertSee('A compiler'); - expect(count(Http::recorded()))->toBe(3); + // The commit, its replies, what's related, and c0's own page for how many replies it has. + expect(count(Http::recorded()))->toBe(4); }); it('opens from a row on what the row knew, then fills in the replies and what it replies to', function () { diff --git a/tests/Feature/Screens/NestedRepliesTest.php b/tests/Feature/Screens/NestedRepliesTest.php index 1e9e4c79..2c9024d9 100644 --- a/tests/Feature/Screens/NestedRepliesTest.php +++ b/tests/Feature/Screens/NestedRepliesTest.php @@ -284,3 +284,52 @@ function fakeAncestorThread(): void expect($screen->get('threads'))->toHaveKey('r1')->not->toHaveKey('c2'); }); + +/** + * c3 answers c2, which answers c1, shaped like devnull's API: the ancestors on c3's page come without their counts, + * since CommitAncestorsQuery doesn't load them. Only a commit's own page says how many replies it has. c2 has two + * besides c3, and c1 has one besides c2. Neither page was opened before. + */ +function fakeUncountedAncestors(): void +{ + $person = fn (string $handle, int $lane): array => userJson(['handle' => $handle, 'name' => ucfirst($handle), 'lane' => $lane]); + $uncounted = fn (array $commit): array => array_diff_key($commit, array_flip(['replies_count', 'stars_count'])); + $c1 = commitJson(['id' => 'c1', 'body' => 'The first commit', 'replies_count' => 2, 'author' => $person('ada', 1)]); + $c2 = commitJson(['id' => 'c2', 'parent_id' => 'c1', 'body' => 'The commit above', 'replies_count' => 3, 'author' => $person('grace', 2)]); + $c3 = commitJson(['id' => 'c3', 'parent_id' => 'c2', 'body' => 'The focused commit', 'author' => $person('ken', 3)]); + $y1 = replyJson(['id' => 'y1', 'parent_id' => 'c1', 'body' => 'Another reply to the first', 'author' => $person('linus', 4)]); + $x1 = replyJson(['id' => 'x1', 'parent_id' => 'c2', 'body' => 'Another reply above', 'author' => $person('alan', 5)]); + $x2 = replyJson(['id' => 'x2', 'parent_id' => 'c2', 'body' => 'One more reply above', 'author' => $person('edsger', 6)]); + + Http::fake(function (Request $request) use ($uncounted, $c1, $c2, $c3, $x1, $x2, $y1) { + return match (parse_url($request->url(), PHP_URL_PATH)) { + '/api/v1/commits/c3' => Http::response(commitPageJson($c3, [$uncounted($c1), $uncounted($c2)])), + '/api/v1/commits/c2' => Http::response(commitPageJson($c2, [$uncounted($c1)])), + '/api/v1/commits/c1' => Http::response(commitPageJson($c1)), + '/api/v1/commits/c1/related', '/api/v1/commits/c2/related', '/api/v1/commits/c3/related' => Http::response(['data' => []]), + '/api/v1/commits/c1/replies' => Http::response(pageJson([$c2, $y1])), + '/api/v1/commits/c2/replies' => Http::response(pageJson([$c3, $x1, $x2])), + '/api/v1/commits/c3/replies', '/api/v1/commits/x1/replies', '/api/v1/commits/x2/replies', '/api/v1/commits/y1/replies' => Http::response(pageJson([])), + default => Http::response(['message' => 'No fake.'], 404), + }; + }); +} + +it('shows the folded replies of a commit above that was never opened, from that commit\'s own page', function () { + fakeUncountedAncestors(); + + $screen = finishRefreshes(Native::visit('/log/commits/c3')); + + // c2's page says it has three replies, and c3 is one of them, on the way down. + expect(nodeByRef($screen, 'replies-c2')['props']['a11y_label'] ?? null)->toBe('2 replies') + ->and($screen->get('threads'))->toBe([]); + + $screen->tap('replies-c2')->assertNoNavigation()->assertSee('Another reply above')->assertSee('One more reply above'); + + // The earlier commits get theirs once they show. + expect(rendersRef($screen, 'replies-c1'))->toBeFalse(); + + finishRefreshes($screen->call('showEarlier')); + + expect(nodeByRef($screen, 'replies-c1')['props']['a11y_label'] ?? null)->toBe('1 reply'); +}); From f3e4adb086d81a0e78cac60dc0caf337b2062e7a Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 22 Nov 2026 10:25:30 +0000 Subject: [PATCH 14/18] Keep the asked-for ancestor counts with the ancestors Moves the new property away from $forceFullFrames, which the phone build removes, so the two merge cleanly. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/CommitDetail.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index 9dd73f7f..7b2d94e9 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -127,6 +127,13 @@ class CommitDetail extends NativeComponent /** @var list */ public array $ancestors = []; + /** + * The commits above whose own page was asked for their count since the page last asked devnull again. + * + * @var list + */ + protected array $countedAncestors = []; + /** * The parts of its series after the commit, in order. * @@ -279,13 +286,6 @@ class CommitDetail extends NativeComponent */ protected bool $forceFullFrames = true; - /** - * The commits above whose own page was asked for their count since the page last asked devnull again. - * - * @var list - */ - protected array $countedAncestors = []; - public function mount(): void { $this->openedId = $this->id; From 820a1756e1b20ced863bf17fc8c087d6f56acf76 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 22 Nov 2026 12:23:46 +0000 Subject: [PATCH 15/18] Suggest every matching org member in Remotes, scrolling past six Org threads ranked members on the phone and kept the first six, so the list never scrolled. Now every member who matches is listed, and the list scrolls past six rows like the reply bar's. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/Concerns/SuggestsMentions.php | 6 +++--- tests/Feature/Screens/ConversationTest.php | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/NativeComponents/Concerns/SuggestsMentions.php b/app/NativeComponents/Concerns/SuggestsMentions.php index 9166bcf4..138b82ec 100644 --- a/app/NativeComponents/Concerns/SuggestsMentions.php +++ b/app/NativeComponents/Concerns/SuggestsMentions.php @@ -31,7 +31,6 @@ trait SuggestsMentions */ public const string MentionBeforeCaret = '/(?:^|[^\p{L}\p{N}_.\/@-])@([A-Za-z0-9][A-Za-z0-9-]{0,38}|)$/u'; - public const int MaxMentionSuggestions = 6; /** * The "@handle" the caret is after: the field it's in, where its "@" is, in code points, what follows it, and the @@ -199,7 +198,8 @@ private static function mentionEnd(array $mention, string $text): ?int } /** - * An org's members to suggest for what's typed after the "@", best first. + * An org's members to suggest for what's typed after the "@", best first. All of them: past six the list scrolls + * (see partials/mention-suggestions), as the reply bar's does. * * @param list $members * @return list @@ -236,6 +236,6 @@ private static function rankMembers(array $members, string $query, ?User $viewer usort($ranked, fn (array $a, array $b): int => [$a['tier'], ! $a['followed'], $a['user']->username] <=> [$b['tier'], ! $b['followed'], $b['user']->username]); - return array_column(array_slice($ranked, 0, self::MaxMentionSuggestions), 'user'); + return array_column($ranked, 'user'); } } diff --git a/tests/Feature/Screens/ConversationTest.php b/tests/Feature/Screens/ConversationTest.php index 4a22b9cc..40806fa2 100644 --- a/tests/Feature/Screens/ConversationTest.php +++ b/tests/Feature/Screens/ConversationTest.php @@ -1281,7 +1281,7 @@ function orgWithMembers(array $people): array ->assertMissingElement('column', fn (array $node): bool => ($node['ref'] ?? null) === 'mention-suggestions'); }); -it('filters org members as the web ranks them: exact handle, handle prefix, name prefix, then the rest, followed first, six at most', function () { +it('filters org members as the web ranks them: exact handle, handle prefix, name prefix, then the rest, followed first, all of them in a list that scrolls past six', function () { serveOrgThread(orgWithMembers([ ['grace', 'Grace Hopper'], ['tobias', 'Ada Tobias'], @@ -1295,7 +1295,8 @@ function orgWithMembers(array $people): array $screen = finishRefreshes(Native::visit('/remotes/orgs/org-1'))->input('message-input', '@ADA', 4); - expect(childRefs($screen, 'mention-suggestions'))->toBe(['mention-ada', 'mention-adams', 'mention-adamant', 'mention-tobias', 'mention-bada', 'mention-cada']); + expect(childRefs($screen, 'mention-scroll'))->toBe(['mention-ada', 'mention-adams', 'mention-adamant', 'mention-tobias', 'mention-bada', 'mention-cada', 'mention-dada']) + ->and(nodeByRef($screen, 'mention-scroll')['layout']['height'])->toEqual(Display::MentionRowsShown * Display::MentionRowHeight); }); it('never suggests you, or a member devnull says not to, and suggests nothing in a thread with one person', function () { From b5ecbf738ec6c0ef3b5f107b5be7c80cf086b037 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 22 Nov 2026 12:24:01 +0000 Subject: [PATCH 16/18] Tidy a blank line left by the last commit Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/Concerns/SuggestsMentions.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/NativeComponents/Concerns/SuggestsMentions.php b/app/NativeComponents/Concerns/SuggestsMentions.php index 138b82ec..4dd2f05e 100644 --- a/app/NativeComponents/Concerns/SuggestsMentions.php +++ b/app/NativeComponents/Concerns/SuggestsMentions.php @@ -31,7 +31,6 @@ trait SuggestsMentions */ public const string MentionBeforeCaret = '/(?:^|[^\p{L}\p{N}_.\/@-])@([A-Za-z0-9][A-Za-z0-9-]{0,38}|)$/u'; - /** * The "@handle" the caret is after: the field it's in, where its "@" is, in code points, what follows it, and the * field's text when the caret was there. Null while there's none. From 3b582bb6e5af45fb7f6d3015dee8be268e442990 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 22 Nov 2026 12:32:33 +0000 Subject: [PATCH 17/18] Scroll to a reply you just sent on a commit page Sending a reply from the bar or the composer sheet now scrolls the page to the staged reply. The scroll view counts its direct children, so the page's rows are now listed by CommitDetail::pageRows() and the view draws exactly that list. The component looks the staged reply up in the same list, so the index can't drift from what's drawn. When devnull's reply replaces the staged one it lands on the same row, so the target and token stay put and the page doesn't move again. The one case where it moves is a reply to your own commit that becomes the next part of your thread; the page follows it there. Co-Authored-By: Claude Opus 5.5 --- app/NativeComponents/CommitDetail.php | 150 ++++++++++++++++-- .../views/native/commit-detail.blade.php | 61 ++----- tests/Feature/Screens/ScrollToReplyTest.php | 129 +++++++++++++++ 3 files changed, 284 insertions(+), 56 deletions(-) create mode 100644 tests/Feature/Screens/ScrollToReplyTest.php diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index 7b2d94e9..edcb88fa 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -80,7 +80,8 @@ * * A reply goes at once: the bar empties and the reply shows staged under the * commit while it goes to devnull from the outbox (see SyncsOutbox), then the - * real one takes its place. If devnull turns it down, it leaves, and what you + * real one takes its place. The page scrolls to it as it shows, and stays + * there when the real one comes (see scrollToRow()). If devnull turns it down, it leaves, and what you * wrote is back in the bar, or in the sheet with its photos. Edit, on the * toast of a reply or a quote turned down after you'd left, opens its commit * here with it ($data['edit']). @@ -256,17 +257,24 @@ class CommitDetail extends NativeComponent public int $scrollKey = 0; /** - * Which of the scroll view's rows it brings into view, the commit's, once tapping another commit in the tree - * moved the page to it (see refocus()). Null until then, so the page opens at the top as it always has. + * Which of the scroll view's rows it brings into view: the commit's, once tapping another commit in the tree + * moved the page to it (see refocus()), or the reply you just sent (see scrollToRow()). Null until one of those, + * so the page opens at the top as it always has. */ public ?int $scrollTarget = null; /** - * Counts the moves refocus() made. The scroll view takes it as its auto-scroll-token, so asking for the same row + * Counts the moves refocus() and scrollToRow() made. The scroll view takes it as its auto-scroll-token, so asking for the same row * as last time (going back to the top twice) scrolls again rather than doing nothing. */ public int $scrollRequest = 0; + /** + * The key of the row scrollToRow() brought into view last, so a reply you sent can be followed when devnull's + * takes its place (see showCommitWent()). + */ + private ?string $scrolledToRow = null; + /** * The commit the page opened on, before tapping others in its tree moved it (see refocus()). */ @@ -821,6 +829,7 @@ public function sendReply(): void $this->updatedReply(); $this->repliesShown = true; $this->keepStagedReplies(); + $this->scrollToRow('thread-reply-'.PendingWrite::stagedId($write->client_id)); $this->sendFromOutbox($write); } @@ -886,6 +895,7 @@ protected function showCommitted(Commit $commit): void $this->replyRestored = false; $this->repliesShown = true; $this->keepStagedReplies(); + $this->scrollToRow('thread-reply-'.$commit->id); } /** @@ -897,6 +907,31 @@ protected function showCommitWent(PendingWrite $write, Commit $commit): void $this->replies = array_map(fn (Commit $reply): Commit => $reply->id === $staged ? $commit : $reply, $this->replies); $this->followThread(); + $this->followSentReply('thread-reply-'.$staged, $commit); + } + + /** + * The page scrolled to a reply you sent, staged, and devnull's reply has taken its place. That's the same row, + * so the scroll view is left be. Only when the reply has moved, as the next part of your thread below the + * commit's replies, does the page follow it there. + */ + private function followSentReply(string $stagedKey, Commit $commit): void + { + if ($this->scrolledToRow !== $stagedKey) { + return; + } + + $keys = array_column($this->pageRows($this->viewData()), 'key'); + $at = array_search('thread-reply-'.$commit->id, $keys, true); + $at = $at === false ? array_search('commit-'.$commit->id, $keys, true) : $at; + + if ($at === false || $at === $this->scrollTarget) { + $this->scrolledToRow = null; + + return; + } + + $this->scrollToRow($keys[$at]); } /** @@ -1309,20 +1344,31 @@ public function isOwn(): bool } public function render(): View + { + $this->replyRows ??= new RowCache; + $this->replyRows->startFrame(); + $data = $this->viewData(); + + return view('native.commit-detail', [...$data, 'replyRows' => $this->replyRows, 'pageRows' => $this->pageRows($data)]); + } + + /** + * What the page's view draws from, besides the component's own properties. + * + * @return array + */ + private function viewData(): array { $earlier = $this->earlierShown ? [] : array_slice($this->ancestors, 0, -1); $above = $this->shownAncestors(); $viewer = $this->me(); - $this->replyRows ??= new RowCache; - $this->replyRows->startFrame(); $thread = $this->selfThread(); $parts = $thread->parts; $partsAbove = $this->commit === null ? 0 : SelfThread::above($this->ancestors, $this->commit, $this->repliesOf())[0]; $lastPart = $thread->hasEnded && $parts !== [] ? end($parts) : null; $replies = $this->commit === null ? $this->replies : SelfThread::others($this->commit, $this->replies); - return view('native.commit-detail', [ - 'replyRows' => $this->replyRows, + return [ 'myColour' => $this->myColour(), 'viewer' => $viewer, 'ownership' => $this->ownership(), @@ -1344,7 +1390,93 @@ public function render(): View 'lastPart' => $lastPart, 'lastPartReplies' => $lastPart === null ? [] : array_slice($this->partReplies[$lastPart->id] ?? [], 0, Client::RepliesPerPage), 'lastPartMore' => $lastPart !== null && (count($this->partReplies[$lastPart->id] ?? []) > Client::RepliesPerPage || in_array($lastPart->id, $this->partsWithMore, true)), - ]); + ]; + } + + /** + * The scroll view's rows from the top down to the end of the thread, in the order the view draws them, each one + * child of the scroll view: "↑ N earlier commits", then each commit with what hangs under it, its replies opened + * in place and theirs (see App\Devnull\ThreadRows). The view draws exactly these, so a row's place here is its + * place among the scroll view's children, which auto-scroll-to counts in (see scrollToRow()). What comes after + * the thread, the related commits and the room for the reply bar, the view draws on its own. + * + * @param array $data What viewData() gave. + * @return list, reply: Commit|null}> + */ + private function pageRows(array $data): array + { + $commit = $this->commit; + $rows = $data['rows']; + $replies = $data['replies']; + $lastPart = $data['lastPart']; + $noReplies = $commit !== null && $data['replyCount'] === 0 && $this->repliesLoaded && $this->series === [] && $data['threadParts'] === []; + $relatedBelow = $commit !== null && $this->related !== [] && ! $noReplies; + $pageRows = []; + + if ($data['earlierCount'] > 0) { + $pageRows[] = ['key' => 'earlier-commits', 'partial' => 'native.partials.earlier-commits', 'data' => ['count' => $data['earlierCount'], 'lane' => $data['earlierLane']], 'reply' => null]; + } + + foreach ($rows as $index => $row) { + $last = $index === array_key_last($rows); + $isFocused = $row->commit->id === $commit?->id; + $isLastPart = $lastPart !== null && $row->commit->id === $lastPart->id; + $hasThread = $isFocused && $this->repliesShown && $replies !== []; + $partThread = $isLastPart && $data['lastPartReplies'] !== []; + $aboveThread = $data['ancestorThreads'][$row->commit->id] ?? null; + $aboveOpen = ($aboveThread['rows'] ?? []) !== []; + + $pageRows[] = ['key' => 'commit-'.$row->commit->id, 'partial' => 'native.partials.commit-row', 'reply' => null, 'data' => [ + 'commit' => $row->commit, + 'previousLane' => $row->previousLane, + 'continuesRun' => $row->continuesRun, + 'continuesNext' => $isFocused || $aboveOpen ? ! $last : null, + 'threadBelow' => $hasThread || $partThread || $aboveOpen, + 'repliesBelow' => $partThread, + 'focused' => $isFocused, + 'muted' => ! $isFocused, + 'seriesExpanded' => true, + 'withTail' => ! $last || $data['threadMore'], + 'hairline' => ! ($last && $relatedBelow && ! $data['threadMore']), + 'threadPosition' => $data['threadPositions'][$row->commit->id] ?? null, + 'showsThread' => false, + 'expandable' => $aboveThread !== null, + 'repliesCount' => $aboveThread['count'] ?? null, + ]]; + + if ($isFocused && $this->repliesShown && $replies === [] && ! $this->repliesLoaded && $this->error === null) { + $pageRows[] = ['key' => 'loading-replies', 'partial' => null, 'data' => [], 'reply' => null]; + } + + // The replies, and theirs opened in place under them as deep as they go. A commit above the commit opens + // its replies in place under it too, all but the one on the line down to the commit, which already shows + // (see ancestorThreads()). + array_push($pageRows, ...match (true) { + $aboveThread !== null => $aboveThread['rows'], + $hasThread => ThreadRows::under($commit, [...$this->threads, $commit->id => $replies], array_filter([...$this->threadCursors, $commit->id => $this->repliesCursor]), $this->threadShown, $last ? null : $commit->lane(), opensInPlace: PHP_INT_MAX, onPage: true, morePress: 'loadMoreReplies'), + $partThread => ThreadRows::under($lastPart, [...$this->threads, $lastPart->id => $data['lastPartReplies']], array_filter([...$this->threadCursors, $lastPart->id => $data['lastPartMore'] ? 'more' : null]), $this->threadShown, opensInPlace: PHP_INT_MAX, onPage: true, morePress: "openReplies('{$lastPart->id}')"), + default => [], + }); + } + + return $pageRows; + } + + /** + * Brings the row keyed $key into view, animated, under a new token so it goes even when that's the row it went to + * last time. Nothing happens for a row the page doesn't draw. + */ + private function scrollToRow(string $key): void + { + $at = array_search($key, array_column($this->pageRows($this->viewData()), 'key'), true); + + if ($at === false) { + return; + } + + $this->scrollTarget = $at; + $this->scrollRequest++; + $this->scrolledToRow = $key; } /** diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index 7d28ab78..ff7bf65b 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -41,61 +41,28 @@ the web reads it (see SelfThread): each part wears its place ("2/5"), ten show at a time with "Show more of this thread" under them, and the replies of the last part hang under it as the commit's do. --}} - @if ($earlierCount > 0) - @include('native.partials.earlier-commits', ['count' => $earlierCount, 'lane' => $earlierLane]) - @endif - {{-- - Related commits start with a full-width line of their own (see partials/related-commits). The last row - above them leaves out its hairline, which runs from the text's edge, so the two don't stack up into a - line and a half. Replies end with no hairline on a commit page, and "No replies yet" keeps the commit's. + The rows down to the end of the thread come from CommitDetail::pageRows(), each one child of the scroll + view, in the order it lists them, so the place it gives a row is the row auto-scroll-to brings into + view: the reply you just sent, say (see CommitDetail::scrollToRow()). A row drawn here and not there + would put every row below it one out. Related commits start with a full-width line of their own (see + partials/related-commits), so the last row above them leaves out its hairline, which runs from the + text's edge, and the two don't stack up into a line and a half. Replies end with no hairline on a + commit page, and "No replies yet" keeps the commit's. --}} @php($noReplies = $commit && $replyCount === 0 && $repliesLoaded && $series === [] && $threadParts === []) - @php($relatedBelow = $commit && $related !== [] && ! $noReplies) - @foreach ($rows as $row) - @php($isFocused = $row->commit->id === $commit?->id) - @php($isLastPart = $lastPart !== null && $row->commit->id === $lastPart->id) - @php($hasThread = $isFocused && $repliesShown && $replies !== []) - @php($partThread = $isLastPart && $lastPartReplies !== []) - @php($aboveThread = $ancestorThreads[$row->commit->id] ?? null) - @php($aboveOpen = ($aboveThread['rows'] ?? []) !== []) - @include('native.partials.commit-row', [ - 'commit' => $row->commit, - 'previousLane' => $row->previousLane, - 'continuesRun' => $row->continuesRun, - 'continuesNext' => $isFocused || $aboveOpen ? ! $loop->last : null, - 'threadBelow' => $hasThread || $partThread || $aboveOpen, - 'repliesBelow' => $partThread, - 'focused' => $isFocused, - 'muted' => ! $isFocused, - 'seriesExpanded' => true, - 'withTail' => ! $loop->last || $threadMore, - 'hairline' => ! ($loop->last && $relatedBelow && ! $threadMore), - 'threadPosition' => $threadPositions[$row->commit->id] ?? null, - 'showsThread' => false, - 'expandable' => $aboveThread !== null, - 'repliesCount' => $aboveThread['count'] ?? null, - ]) - @if ($isFocused && $repliesShown && $replies === [] && ! $repliesLoaded && $error === null) + @foreach ($pageRows as $pageRow) + @if ($pageRow['key'] === 'loading-replies') + @elseif ($pageRow['reply'] === null) + @include($pageRow['partial'], $pageRow['data']) + @else + @php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1])) + @php($replyRows->include('reply-'.$pageRow['reply']->id, \App\Devnull\RowInputs::for($pageRow['reply'], $rowScope), $pageRow['partial'], $pageRow['data'], $rowScope)) @endif - {{-- - The replies, and theirs opened in place under them as deep as they go (see App\Devnull\ThreadRows). - A commit above the commit opens its replies in place under it too, all but the one on the line down - to the commit, which already shows (see CommitDetail::ancestorThreads()). - --}} - @php($pageThread = match (true) { $aboveThread !== null => $aboveThread['rows'], $hasThread => \App\Devnull\ThreadRows::under($commit, [...$threads, $commit->id => $replies], array_filter([...$threadCursors, $commit->id => $repliesCursor]), $threadShown, $loop->last ? null : $commit->lane(), opensInPlace: PHP_INT_MAX, onPage: true, morePress: 'loadMoreReplies'), $partThread => \App\Devnull\ThreadRows::under($lastPart, [...$threads, $lastPart->id => $lastPartReplies], array_filter([...$threadCursors, $lastPart->id => $lastPartMore ? 'more' : null]), $threadShown, opensInPlace: PHP_INT_MAX, onPage: true, morePress: "openReplies('{$lastPart->id}')"), default => [] }) - @foreach ($pageThread as $threadRow) - @if ($threadRow['reply'] === null) - @include($threadRow['partial'], $threadRow['data']) - @else - @php($rowScope = array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1])) - @php($replyRows->include('reply-'.$threadRow['reply']->id, \App\Devnull\RowInputs::for($threadRow['reply'], $rowScope), $threadRow['partial'], $threadRow['data'], $rowScope)) - @endif - @endforeach @endforeach @if ($threadMore && $threadParts !== []) diff --git a/tests/Feature/Screens/ScrollToReplyTest.php b/tests/Feature/Screens/ScrollToReplyTest.php new file mode 100644 index 00000000..be04ecf7 --- /dev/null +++ b/tests/Feature/Screens/ScrollToReplyTest.php @@ -0,0 +1,129 @@ + 'http://devnull.test']); + signIn(); +}); + +/** + * A commit page for c2, under c1 and c0, with a first page of ten replies and more after them. r1 has a reply of + * its own, n1. Everything is kept from before, so the page shows it at once and holds its refreshes, the reply + * you post among them, until the test lets them go. + * + * @param array $commit + */ +function fakeLongThread(array $commit = [], array $posted = []): void +{ + holdRefreshes(); + + $grace = userJson(['handle' => 'grace', 'name' => 'Grace']); + $c0 = commitJson(['id' => 'c0', 'body' => 'The root commit', 'author' => userJson(['handle' => 'ada', 'name' => 'Ada'])]); + $c1 = commitJson(['id' => 'c1', 'parent_id' => 'c0', 'body' => 'The parent commit', 'author' => userJson(['handle' => 'linus', 'name' => 'Linus'])]); + $c2 = commitJson(['id' => 'c2', 'parent_id' => 'c1', 'body' => 'The focused commit', 'replies_count' => 11, 'author' => $grace, ...$commit]); + $replies = array_map(fn (int $n): array => replyJson(['id' => "r{$n}", 'parent_id' => 'c2', 'body' => "Reply {$n}", 'replies_count' => $n === 1 ? 1 : 0]), range(1, 10)); + $repliesPage = pageJson($replies, 'page2', 'http://devnull.test/api/v1/commits/c2/replies'); + $nested = pageJson([replyJson(['id' => 'n1', 'parent_id' => 'r1', 'body' => 'A reply to the first reply', 'author' => userJson(['handle' => 'alan', 'name' => 'Alan'])])]); + + keep('commits/c2', commitPageJson($c2, [$c0, $c1])); + keep('commits/c2/replies', $repliesPage); + keep('commits/r1/replies', $nested); + + fakeApi([ + 'GET /api/v1/commits/c2' => [commitPageJson($c2, [$c0, $c1])], + 'GET /api/v1/commits/c2/replies' => [$repliesPage], + 'GET /api/v1/commits/c2/related' => [['data' => []]], + 'GET /api/v1/commits/r1/replies' => [$nested], + 'POST /api/v1/commits' => [['data' => commitJson(['id' => 'r99', 'parent_id' => 'c2', 'body' => 'My fresh reply', ...$posted])], 201], + ]); +} + +/** + * Where the scroll view is asked to go: the ref of the child at auto-scroll-to, and the request it's under, which + * the scroll view takes as its auto-scroll-token where mobile-ui has it. + * + * @return array{0: string|null, 1: int} + */ +function scrolledTo(TestableComponent $screen): array +{ + $index = nodeByRef($screen, 'thread-scroll')['props']['auto_scroll_to'] ?? -1; + + return [childRefs($screen, 'thread-scroll')[$index] ?? null, $screen->instance()->scrollRequest]; +} + +function stagedReplyId(TestableComponent $screen): string +{ + /** @var CommitDetail $page */ + $page = $screen->instance(); + + return collect($page->replies)->first(fn ($reply): bool => $reply->isStaged())->id; +} + +it('scrolls to a reply sent from the bar, under the commits above and past ten replies', function () { + fakeLongThread(); + + $screen = Native::visit('/log/commits/c2')->assertSet('scrollRequest', 0); + + $screen->input('reply-input', 'My fresh reply')->tap('send-reply')->assertSet('repliesShown', true); + + $staged = stagedReplyId($screen); + $children = childRefs($screen, 'thread-scroll'); + + expect($children)->toBe([ + 'earlier-commits', 'commit-c1', 'focused-commit', + ...array_map(fn (int $n): string => "thread-reply-r{$n}", range(1, 10)), + "thread-reply-{$staged}", null, 'reply-bar-clearance', + ]) + ->and($screen->instance()->scrollTarget)->toBe(array_search("thread-reply-{$staged}", $children, true)) + ->and(scrolledTo($screen))->toBe(["thread-reply-{$staged}", 1]); + + // devnull's reply takes the staged one's place, on the same row, and the page doesn't scroll again. + finishRefreshes($screen)->assertDontSee('staged'); + + expect(scrolledTo($screen))->toBe(['thread-reply-r99', 1]); +}); + +it('scrolls to a reply sent from the sheet, past replies opened in place under the ones before it', function () { + fakeLongThread(); + + $screen = Native::visit('/log/commits/c2') + ->tap('earlier-commits') + ->tap('replies-c2') + ->tap('replies-r1'); + + finishRefreshes($screen) + ->assertSee('A reply to the first reply') + ->assertSet('scrollRequest', 0); + + $screen->call('replyInSheet', 'c2')->input('sheet-body', 'My fresh reply')->tap('sheet-commit'); + + $staged = stagedReplyId($screen); + $children = childRefs($screen, 'thread-scroll'); + + expect(array_slice($children, 0, 5))->toBe(['commit-c0', 'commit-c1', 'focused-commit', 'thread-reply-r1', 'thread-reply-n1']) + ->and(scrolledTo($screen))->toBe(["thread-reply-{$staged}", 1]) + ->and($screen->instance()->scrollTarget)->toBe(14); + + finishRefreshes($screen); + + expect(scrolledTo($screen))->toBe(['thread-reply-r99', 1]); +}); + +it('follows a reply to your own commit when devnull has it carry your thread on', function () { + // The commit is yours, and so is the reply, so once devnull has it, it's the next part of your thread, below the + // commit's replies, rather than one of them. + fakeLongThread(commit: ['author' => userJson()]); + + $screen = Native::visit('/log/commits/c2'); + $screen->input('reply-input', 'My fresh reply')->tap('send-reply'); + + expect(scrolledTo($screen))->toBe(['thread-reply-'.stagedReplyId($screen), 1]); + + finishRefreshes($screen); + + // It moved a row down, past "Show more" under the replies, so the page goes after it. + expect(scrolledTo($screen))->toBe(['commit-r99', 2]); +}); From 942a74cc92b6a8dccd12af28ccb3fc5232494cca Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 22 Nov 2026 13:12:48 +0000 Subject: [PATCH 18/18] Draw the hairline under replies that another commit follows A commit row gives its hairline up when its replies open under it, and on a commit page the last reply never drew one. So the replies of a commit above the focused one ran straight into the next commit with no line between them. The same happened under the focused commit when later parts of its series follow. ThreadRows::under() takes a hairline flag now. Ancestor threads always end on the line, and the focused commit's replies do when it isn't the last row. Replies at the foot of the page still end without one. Co-Authored-By: Claude Opus 5.5 --- app/Devnull/ThreadRows.php | 14 ++++++++++---- app/NativeComponents/CommitDetail.php | 7 +++++-- .../views/native/partials/thread-reply.blade.php | 10 ++++++---- tests/Feature/Screens/NestedRepliesTest.php | 11 +++++++++-- tests/Feature/Screens/SeriesTest.php | 9 +++++++-- 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/app/Devnull/ThreadRows.php b/app/Devnull/ThreadRows.php index 61e7042f..6d26c2b5 100644 --- a/app/Devnull/ThreadRows.php +++ b/app/Devnull/ThreadRows.php @@ -14,7 +14,8 @@ * Under the commit come its replies, each followed by its own replies when * they're open, and theirs, as deep as they go, with "Show more" after the * replies of a thread with more. Every row is a row of its own, and in a feed - * the last one closes the commit's row with its hairline. + * the last one closes the commit's row with its hairline. On a commit page it + * does only when another commit's row follows the thread. * * The thread hangs off the rail in dashes, as on the web: the first reply on * an elbow from the commit's rail, each later one on a short link from the @@ -66,8 +67,10 @@ final class ThreadRows * @param array $shown How many of each open thread's replies show. * @param int|string|null $railLane The commit's rail running on past its thread, when its author's run carries on below. * @param int $opensInPlace How deep a reply's replies button opens its replies in place rather than its page. - * @param bool $onPage On a commit page: replies muted, deleted ones open theirs in place, and no hairline under them. + * @param bool $onPage On a commit page: replies muted, deleted ones open theirs in place, and no hairline under them by default. * @param string|null $morePress What the commit's own "Show more" presses, when it isn't showMoreReplies. + * @param bool|null $hairline Whether the last row closes the thread with a hairline: in a feed it does, and on a + * commit page only when another commit's row comes next. * @return list, reply: Commit|null}> */ public static function under( @@ -79,6 +82,7 @@ public static function under( int $opensInPlace = 1, bool $onPage = false, ?string $morePress = null, + ?bool $hairline = null, ): array { $thread = fn (string $id): array => array_slice($threads[$id] ?? [], 0, $shown[$id] ?? null); $hasMore = fn (string $id): bool => isset($cursors[$id]) || count($thread($id)) < count($threads[$id] ?? []); @@ -89,6 +93,7 @@ public static function under( 'opensInPlace' => $opensInPlace, 'onPage' => $onPage, 'morePress' => $morePress, + 'hairline' => $hairline ?? ! $onPage, ]); if ($rows === []) { @@ -124,7 +129,7 @@ private static function lineAt(int $depth): float * @param list $spines Lines from further up running on past these rows. * @param Closure(string): list $thread * @param Closure(string): bool $hasMore - * @param array{railLane: int|string|null, opensInPlace: int, onPage: bool, morePress: string|null} $options + * @param array{railLane: int|string|null, opensInPlace: int, onPage: bool, morePress: string|null, hairline: bool} $options */ private static function branch(array &$rows, Commit $parent, int $depth, array $spines, Closure $thread, Closure $hasMore, array $options): void { @@ -160,6 +165,7 @@ private static function branch(array &$rows, Commit $parent, int $depth, array $ 'repliesInPlace' => $depth <= $options['opensInPlace'], 'muted' => $onPage, 'tombstones' => $onPage, + 'hairline' => $options['hairline'], ]); // The line that has to run on past this reply's own replies, to the next reply at this depth. @@ -182,7 +188,7 @@ private static function branch(array &$rows, Commit $parent, int $depth, array $ 'indent' => $indent, 'spines' => $spines, 'to' => $flattened && ! $parent->isDeleted() ? $parent->author->handle() : null, - 'hairline' => ! $onPage, + 'hairline' => $options['hairline'], ...($depth === 1 && $options['morePress'] !== null ? ['press' => $options['morePress']] : []), ]); } diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index edcb88fa..44239e01 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -656,6 +656,8 @@ private function ancestorThreads(array $above): array $ancestor->lane(), opensInPlace: PHP_INT_MAX, onPage: true, + // The next commit on the line follows them, so they end on the hairline the ancestor's row gave up. + hairline: true, ), ]; } @@ -1450,10 +1452,11 @@ private function pageRows(array $data): array // The replies, and theirs opened in place under them as deep as they go. A commit above the commit opens // its replies in place under it too, all but the one on the line down to the commit, which already shows - // (see ancestorThreads()). + // (see ancestorThreads()). Replies with another commit's row after them end on the hairline the row above + // them gave up; at the foot of the page they end on none. array_push($pageRows, ...match (true) { $aboveThread !== null => $aboveThread['rows'], - $hasThread => ThreadRows::under($commit, [...$this->threads, $commit->id => $replies], array_filter([...$this->threadCursors, $commit->id => $this->repliesCursor]), $this->threadShown, $last ? null : $commit->lane(), opensInPlace: PHP_INT_MAX, onPage: true, morePress: 'loadMoreReplies'), + $hasThread => ThreadRows::under($commit, [...$this->threads, $commit->id => $replies], array_filter([...$this->threadCursors, $commit->id => $this->repliesCursor]), $this->threadShown, $last ? null : $commit->lane(), opensInPlace: PHP_INT_MAX, onPage: true, morePress: 'loadMoreReplies', hairline: ! $last), $partThread => ThreadRows::under($lastPart, [...$this->threads, $lastPart->id => $data['lastPartReplies']], array_filter([...$this->threadCursors, $lastPart->id => $data['lastPartMore'] ? 'more' : null]), $this->threadShown, opensInPlace: PHP_INT_MAX, onPage: true, morePress: "openReplies('{$lastPart->id}')"), default => [], }); diff --git a/resources/views/native/partials/thread-reply.blade.php b/resources/views/native/partials/thread-reply.blade.php index aba96aec..9e225242 100644 --- a/resources/views/native/partials/thread-reply.blade.php +++ b/resources/views/native/partials/thread-reply.blade.php @@ -6,8 +6,9 @@ ($previousLane), and a line on down from its avatar when another reply, its own replies, or "Show more", follows ($hasNext). $spines carry lines from further up on past it, and $railLane runs the commit's own rail on past, solid, when its author's run goes on below the thread (see thread-links). A deleted reply keeps its place with a - dashed ring. In a feed the $last closes the commit's row with its hairline. On a commit page nothing follows the - thread, so there's no hairline. + dashed ring. In a feed the $last closes the commit's row with its hairline. On a commit page it has one only when + another commit's row comes next ($hairline): under the replies of a commit above the commit, say, but not at the + foot of the page. Past the web's depth a reply is flattened: it lines up under the reply it answers, with no lines of its own ($links), and says who it answers on a line under its name ($replyingTo), as the web does. @@ -32,6 +33,7 @@ --}} @php($previousLane ??= null) @php($muted ??= false) +@php($hairline ??= ! $muted) @php($railLane ??= null) @php($indent ??= 0) @php($spines ??= []) @@ -66,7 +68,7 @@ @endif - @if ($last && ! $muted) + @if ($last && $hairline) @endif @@ -107,7 +109,7 @@ @endunless - @if ($last && ! $muted) + @if ($last && $hairline) @endif diff --git a/tests/Feature/Screens/NestedRepliesTest.php b/tests/Feature/Screens/NestedRepliesTest.php index 2c9024d9..57fa618e 100644 --- a/tests/Feature/Screens/NestedRepliesTest.php +++ b/tests/Feature/Screens/NestedRepliesTest.php @@ -211,11 +211,18 @@ function fakeAncestorThread(): void $screen->tap('replies-c1')->assertNoNavigation()->assertSee('Another reply above'); // The other reply opens under c1, and the commit the page is on shows once, as the commit. - expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'thread-reply-x1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']); + expect(childRefs($screen, 'thread-scroll'))->toBe(['commit-c1', 'thread-reply-x1', 'focused-commit', 'thread-reply-r1', 'reply-bar-clearance']) + // c1 gives up its hairline to its replies, and the last of them ends on it above the commit. The commit's own + // replies end the page, so they end on none. + ->and(rendersRef($screen, 'thread-end-x1'))->toBeTrue() + ->and(rendersRef($screen, 'thread-end-r1'))->toBeFalse(); - // Its replies open in place too, at any depth. + // Its replies open in place too, at any depth, and the hairline moves down under the last of them. $screen->tap('replies-x1')->assertNoNavigation()->assertSee('A reply to the other reply'); + expect(rendersRef($screen, 'thread-end-x2'))->toBeTrue() + ->and(rendersRef($screen, 'thread-end-x1'))->toBeFalse(); + $screen->tap('replies-c1'); finishRefreshes($screen)->assertDontSee('Another reply above')->assertDontSee('A reply to the other reply'); diff --git a/tests/Feature/Screens/SeriesTest.php b/tests/Feature/Screens/SeriesTest.php index cd6027f9..07829c2b 100644 --- a/tests/Feature/Screens/SeriesTest.php +++ b/tests/Feature/Screens/SeriesTest.php @@ -155,7 +155,10 @@ function railRunsOn(TestableComponent $screen, string $ref): bool ->assertSee('Agreed') ->assertDontSee('2 replies'); - expect(threadRows($screen))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-r2', 'commit-p2', 'commit-p3']); + expect(threadRows($screen))->toBe(['focused-commit', 'thread-reply-r1', 'thread-reply-r2', 'commit-p2', 'commit-p3']) + // The focused part gave up its hairline to its replies, and the later parts follow, so the last reply ends on it. + ->and(rendersRef($screen, 'thread-end-r2'))->toBeTrue() + ->and(rendersRef($screen, 'thread-end-r1'))->toBeFalse(); }); it('keeps replies at the foot of the last part\'s page', function () { @@ -168,7 +171,9 @@ function railRunsOn(TestableComponent $screen, string $ref): bool ->assertSee('The end'); expect(threadRows($screen))->toBe(['commit-p1', 'commit-p2', 'focused-commit', 'thread-reply-r1']) - ->and(railRunsOn($screen, 'focused-commit'))->toBeFalse(); + ->and(railRunsOn($screen, 'focused-commit'))->toBeFalse() + // Nothing follows the replies at the foot of the page, so they end on no hairline. + ->and(rendersRef($screen, 'thread-end-r1'))->toBeFalse(); }); it('keeps a deleted part in its place in the series', function () {