From 3436948ee850e4c991a682379bd1575b1adc427c Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Mon, 16 Nov 2026 00:23:34 +0000 Subject: [PATCH 1/2] 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 2/2] 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]); } }