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/ComposerMenu.php b/app/Devnull/ComposerMenu.php index 71e5716e..533a0303 100644 --- a/app/Devnull/ComposerMenu.php +++ b/app/Devnull/ComposerMenu.php @@ -28,6 +28,20 @@ public static function items(bool $photosFull, bool $voiceNotesGoAlone, string $ ]; } + /** + * What the photo button in the reply bar on a commit's page opens: the photo library, or the camera, as the + * composer sheet's two photo buttons do. + * + * @return list + */ + public static function photoItems(): array + { + return [ + self::item('reply-pick-photos', 'Choose photos', Lucide::ImagePlus, 'pickPhotos'), + self::item('reply-take-photo', 'Take a photo', Lucide::Camera, 'takePhoto'), + ]; + } + private static function item(string $ref, string $label, Lucide $icon, string $method, bool $disabled = false): TopBarAction { return NavAction::make($ref) diff --git a/app/Devnull/Display.php b/app/Devnull/Display.php index e07528b6..a6aeb0bb 100644 --- a/app/Devnull/Display.php +++ b/app/Devnull/Display.php @@ -13,21 +13,19 @@ final class Display { /** - * The commit page's reply bar with one line of draft: its hairline, the - * field and the padding around them, as drawn on an iPhone. + * How much a line of draft adds to a composer bar's field. */ - public const int ReplyBarHeight = 53; - public const int ReplyBarLineHeight = 21; public const int ReplyBarMaxLines = 5; - public const int ReplyBarCharactersPerLine = 34; - /** - * The row under the reply bar's field that marks a restored draft (see partials/stash-label) and counts its photos. + * The photos on a reply's draft, above the field in the reply bar (see partials/composer-photos), and the + * description of one under them while it's open. */ - public const int ReplyBarStashLabelHeight = 28; + public const int ReplyBarPhotosHeight = 88; + + public const int ReplyBarDescriptionHeight = 100; /** * A bar holding partials/composer-box with one line of draft, as drawn on an iPhone: the bar's padding, then the @@ -47,8 +45,7 @@ final class Display public const int ComposerGlassTint = 40; /** - * About how many characters fit on a line of the box's field. It runs the width of the box, so more fit than - * beside the reply bar's tools and button. + * About how many characters fit on a line of the box's field, which runs the width of the box. */ public const int ComposerBoxCharactersPerLine = 46; @@ -240,16 +237,21 @@ public static function maskedKey(string $openSsh): string * How far a commit page has to scroll past its last reply to clear the * reply bar. A pushed screen is drawn under its bottom bar and the home * indicator, with no inset for either, so the page pads its own end: the - * bar as the draft grows to its five lines, and the indicator below it. - * With the keyboard up the bar sits on the keyboard instead, which only - * leaves a little more room. A restored draft, or one with photos, adds - * the row under the field ($draftRow). + * fade over its foot (partials/composer-fade), the bar + * (partials/composer-box) as the draft grows to its five lines, and the + * indicator below it. With the keyboard up the bar sits on the keyboard + * instead, which only leaves a little more room. Photos on the draft add + * their row above the field ($hasPhotos), and an open description of one + * its box under them ($describing). A link too long for devnull adds the + * line that says so. */ - public static function replyBarClearance(string $draft, bool $draftRow = false): int + public static function replyBarClearance(string $draft, bool $hasPhotos = false, bool $describing = false): int { - return self::ReplyBarHeight - + (min(self::ReplyBarMaxLines, self::lineCount($draft, self::ReplyBarCharactersPerLine)) - 1) * self::ReplyBarLineHeight - + ($draftRow ? self::ReplyBarStashLabelHeight : 0) + return self::ComposerFadeHeight + + self::ComposerBoxBarHeight + + self::composerBoxGrowth($draft) + + ($hasPhotos ? self::ReplyBarPhotosHeight : 0) + + ($hasPhotos && $describing ? self::ReplyBarDescriptionHeight : 0) + (CommitBody::hasOversizedUrl($draft) ? 3 * self::ReplyBarLineHeight : 0) + self::HomeIndicatorHeight; } diff --git a/app/Icons/Lucide.php b/app/Icons/Lucide.php index 06a56187..3df5fa55 100644 --- a/app/Icons/Lucide.php +++ b/app/Icons/Lucide.php @@ -73,7 +73,6 @@ enum Lucide case Eye; case EyeOff; case Plus; - case Maximize2; case Vibrate; // The achievement badges, named as devnull names their icons (see forBadge()). @@ -213,7 +212,6 @@ public function custom(bool $filled = false): string self::Eye => 'eye', self::EyeOff => 'eye-off', self::Plus => 'plus', - self::Maximize2 => 'maximize-2', self::Vibrate => 'vibrate', self::Terminal => 'terminal', self::FileCode => 'file-code', diff --git a/app/NativeComponents/CommitDetail.php b/app/NativeComponents/CommitDetail.php index f20c88a3..169606fd 100644 --- a/app/NativeComponents/CommitDetail.php +++ b/app/NativeComponents/CommitDetail.php @@ -3,6 +3,7 @@ namespace App\NativeComponents; use App\Devnull\Account; +use App\Devnull\Beat; use App\Devnull\Client; use App\Devnull\Data\Commit; use App\Devnull\Data\CommitThread; @@ -17,10 +18,12 @@ use App\Devnull\RowCache; use App\Devnull\Stash; use App\Devnull\Timeline; +use App\Devnull\Toasts; use App\Icons\Lucide; use App\Models\PendingWrite; use App\NativeComponents\Concerns\OpensInTab; use App\NativeComponents\Concerns\OpensLiveStream; +use App\NativeComponents\Concerns\RedrawsOnAppearanceChange; use App\NativeComponents\Concerns\RefreshesInBackground; use App\NativeComponents\Concerns\ShowsCommits; use App\NativeComponents\Concerns\TalksToDevnull; @@ -48,13 +51,19 @@ * * The reply is stashed as you type, per commit, as on the web (see Stash), so * leaving the page keeps it, and it's in the reply bar again, marked as - * restored, when you come back to the commit. + * restored, when you come back to the commit. Drop throws it away whenever + * there's anything in it. * - * The reply bar has no room for photos or a preview, so its expand button - * opens the reply in the composer sheet, which has them (see replyInSheet()). - * The draft goes with it, and back to the bar if the sheet closes unsent. - * Photos left in it show as a count under the bar's field, which opens the - * sheet on them, and Reply in the bar sends them with the text. + * The reply bar does everything the composer sheet did for a reply, so a + * reply never needs the sheet: presenting one takes the keyboard down and + * puts it back up on both platforms, however soon its field takes focus. + * Photos come from the library or the camera into the bar, above the field, + * each with its ✕ and ALT (see AttachesPhotos), and Preview shows the reply + * as it will look in the field's place (see toggleReplyPreview()). Reply in + * the bar sends them all. + * + * Related commits wait under a header with their count, closed, and open + * in place when it's tapped (see toggleRelated()). * * A reply goes at once: the bar empties and the reply shows staged under the * commit while it goes to devnull from the outbox (see SyncsOutbox), then the @@ -67,11 +76,16 @@ class CommitDetail extends NativeComponent { use OpensInTab; use OpensLiveStream; + use RedrawsOnAppearanceChange; use RefreshesInBackground; use ShowsCommits { reopenFailedCommit as private reopenFailedCommitInSheet; editFailedCommit as private editFailedCommitInSheet; mentionFields as private sheetMentionFields; + attachedPhotos as private sheetPhotos; + photosChanged as private sheetPhotosChanged; + takesPhotos as private sheetTakesPhotos; + photoFailed as private sheetPhotoFailed; } use TalksToDevnull; @@ -101,6 +115,43 @@ class CommitDetail extends NativeComponent */ public array $related = []; + /** + * Whether the reply bar shows the reply as it will look, in the field's place. + */ + public bool $replyPreviewing = false; + + /** + * What devnull sent back for the reply's body, with the body it was for under `draft`. + * + * @var array|null + */ + public ?array $replyPreview = null; + + /** + * Whether the related commits show under their header. + */ + public bool $relatedShown = false; + + /** + * Whether the related commits are drawn see-through: about to fade in, or fading out on their way to closing. + */ + public bool $relatedFaded = false; + + /** + * Whether the related commits are fading out, still drawn until they have. + */ + public bool $relatedClosing = false; + + /** + * How long the related commits take to fade in or out, in milliseconds, as a Log thread's replies do. + */ + public const int RelatedFade = 220; + + /** + * How much later each related commit starts fading in than the one above it, in milliseconds. + */ + public const int RelatedStagger = 40; + /** * Whether the replies have been kept or fetched. Until then they show as loading. */ @@ -278,6 +329,71 @@ public function toggleReplies(): void $this->repliesShown = ! $this->repliesShown; } + /** + * The web's preview toggle, in the reply bar: the reply shows as it will + * look in the field's place, at once, and devnull is asked for its body, + * with its code and mentions, unless it already said for this one. The + * keyboard goes down with the field. Pressed again, the field comes back + * with the keyboard. + */ + public function toggleReplyPreview(): void + { + $this->replyPreviewing = ! $this->replyPreviewing; + $this->describing = null; + + if (! $this->replyPreviewing) { + $this->focusReply = true; + + return; + } + + $body = trim($this->reply); + + if ($body === '' || ($this->replyPreview['draft'] ?? null) === $body) { + return; + } + + $this->writeInBackground('POST', Client::PreviewPath, ['body' => $body], function (array $json) use ($body): void { + if (is_array($json['data'] ?? null)) { + $this->replyPreview = [...$json['data'], 'draft' => $body]; + } + }, fn (): null => null); + } + + /** + * The related commits' header opens them, and closes them again. EDGE + * can't animate a node coming into the page or leaving it, so they're + * drawn see-through first and shown once a Beat comes back, which each + * row fades and slides to, a little after the one above. Closing fades + * them out the same way, then takes them out. + */ + public function toggleRelated(): void + { + if ($this->relatedClosing) { + return; + } + + if (! $this->relatedShown) { + $this->relatedShown = true; + $this->relatedFaded = true; + $shown = fn () => $this->relatedFaded = false; + + Beat::dispatch(Beat::Step)->finished($shown)->failed($shown); + + return; + } + + $this->relatedFaded = true; + $this->relatedClosing = true; + $closed = function (): void { + $this->relatedShown = false; + $this->relatedFaded = false; + $this->relatedClosing = false; + }; + + Beat::dispatch(self::RelatedFade)->finished($closed)->failed($closed); + } + /** * A deleted reply has no page of its own, so its replies open in place below it. */ @@ -357,6 +473,8 @@ public function sendReply(): void $this->reply = ''; $this->replyImages = []; + $this->replyPreviewing = false; + $this->replyPreview = null; $this->forgetMention('reply'); $this->updatedReply(); $this->repliesShown = true; @@ -390,13 +508,17 @@ public function updatedReply(): void } /** - * The web's drop, beside a restored reply: it's thrown away, photos too, and the field starts again empty. + * The web's drop, beside the reply while there's anything in it: it's thrown away, photos too, and the field + * starts again empty. */ public function dropReplyStash(): void { app(DraftImages::class)->discard($this->replyImages); $this->reply = ''; $this->replyImages = []; + $this->replyPreviewing = false; + $this->replyPreview = null; + $this->describing = null; $this->updatedReply(); } @@ -469,6 +591,57 @@ protected function editFailedCommit(PendingWrite $write): void $this->takeFailedReply($write); } + /** + * The photos on the draft being written: the sheet's while it's up, otherwise the reply bar's. + * + * @return list + */ + protected function attachedPhotos(): array + { + return $this->sheetOpen ? $this->sheetPhotos() : $this->replyImages; + } + + /** + * Photos added in the reply bar, or taken off it, go in the reply's stash with its text. + * + * @param list $photos + */ + protected function photosChanged(array $photos): void + { + if ($this->sheetOpen) { + $this->sheetPhotosChanged($photos); + + return; + } + + $this->replyImages = $photos; + $this->updatedReply(); + } + + /** + * A reply can have photos, as on the web, unless its commit has gone. + */ + protected function takesPhotos(): bool + { + return $this->sheetOpen ? $this->sheetTakesPhotos() : $this->commit !== null && ! $this->commit->isDeleted(); + } + + /** + * Why a photo won't do comes as a toast, from the top, clear of the reply bar, as it does in Remotes. + */ + protected function photoFailed(?string $error): void + { + if ($this->sheetOpen) { + $this->sheetPhotoFailed($error); + + return; + } + + if ($error !== null) { + Toasts::failed($error); + } + } + /** * The reply bar takes back the draft it handed the sheet, as it was left there, photos too. */ diff --git a/resources/icons/maximize-2.svg b/resources/icons/maximize-2.svg deleted file mode 100644 index 12b88ce8..00000000 --- a/resources/icons/maximize-2.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/resources/views/native/commit-detail.blade.php b/resources/views/native/commit-detail.blade.php index c633a3d0..3667a822 100644 --- a/resources/views/native/commit-detail.blade.php +++ b/resources/views/native/commit-detail.blade.php @@ -5,7 +5,9 @@ @include('native.partials.live-stream-sheet') @include('native.partials.stargazers-sheet') - + {{-- The stack around the page holds the fade over its foot, just above the reply bar (see partials/composer-fade). --}} + + @if (! $commit && $error === null) @@ -105,71 +107,86 @@ {{-- A pushed screen runs under its bottom bar, so the page clears the reply bar itself (see - Display::replyBarClearance): the last reply and its actions end above the bar, keyboard up or down. + Display::replyBarClearance): the last reply and its actions end above the fade and the bar, keyboard + up or down. --}} @if ($commit) - + @endif + @if ($commit && ! \App\Devnull\Display::fadesInBar()) + @include('native.partials.composer-fade', ['ref' => 'reply-fade']) + @endif + + @if ($commit) {{-- - The bar is painted from its first child's background: native:bottom-bar takes no classes of its own, so - the surface and the hairline above it belong to this column, or the replies show through. On iOS the bar - is bare and the field is a Liquid Glass plate instead, the way the HIG floats controls over content; the - hairline stays as a clear 1pt so the bar keeps the height Display::ReplyBarHeight counts on. + The reply bar, drawn as the Remotes composer is: the field across the top and a row under it with the + tools on the left and the round send button on the right (see partials/composer-box), with the page fading + out above it (see partials/composer-fade). On iOS the bar is Liquid Glass, faded in at the top, so the page + shows through it blurred (see Display::composerBarGlass()). On Android it's the surface, painted from this + column. Either fills the strip under the home indicator. + + The bar does everything the composer sheet did for a reply, so a reply never needs the sheet, whose + presenting takes the keyboard down and back up on both platforms. The photo button adds photos from the + library or the camera, which show above the field with their ✕ and ALT. Preview shows the reply as it will + look in the field's place, and pressed again brings the field back. Beside the send button, drop throws + the draft away whenever there's anything in it, after the web's stash@{0} when the draft came back from + the stash, then how long the reply is near the limit. - The expand button opens the reply in the composer sheet, which has the photos and preview the bar has no - room for. It sits where partials/composer-plate puts a composer's tools: inside the plate on iOS, ahead of - the field on Android. + A "post as" avatar, for people in a GitHub organization, goes at the start of the row as composer-box's + $lead. --}} - - - + + + @if (\App\Devnull\Display::fadesInBar()) + @include('native.partials.composer-fade', ['ref' => 'reply-fade', 'inBar' => true]) + @endif + {{-- - The people to mention keep a slot above the field, empty and no height when there's no one, so the - field's row never moves. Android rebuilds a row that moves among its siblings, field and all, which - drops the keyboard. + The people to mention and the photos on the reply keep a slot each above the field, empty and + 0.1pt tall when there's nothing in it, so the field's row never moves. Android rebuilds a row that + moves among its siblings, field and all, which drops the keyboard. On iOS an empty slot would + otherwise take 10pt of the bar, and EDGE drops a height of 0. --}} @php($mentioning = ($mention['field'] ?? null) === 'reply' && ($mentionPeople !== [] || $mentionOrganizations !== [])) - + @include('native.partials.mention-suggestions', ['field' => 'reply', 'label' => 'Mention a developer']) - - @include('native.partials.composer-plate', [ + @php($showsPhotos = $replyImages !== [] && ! $replyPreviewing) + + @if ($showsPhotos) + @include('native.partials.composer-photos', ['photos' => $replyImages, 'photoRef' => 'reply-photo']) + @endif + + + @php($hasDraft = trim($reply) !== '' || $replyImages !== []) + @php($photosFull = count($replyImages) >= \App\Devnull\DraftImages::MaxImages) + @include('native.partials.composer-box', [ 'ref' => 'reply', - 'field' => 'native.partials.reply-field', - 'tools' => [['ref' => 'reply-expand', 'icon' => \App\Icons\Lucide::Maximize2, 'label' => 'Reply with photos or a preview', 'press' => "replyInSheet('{$commit->id}')"]], + 'field' => $replyPreviewing ? 'native.partials.reply-preview' : 'native.partials.reply-field', + 'tools' => [ + ['ref' => 'reply-add-photos', 'icon' => \App\Icons\Lucide::ImagePlus, 'label' => $photosFull ? 'A reply can have up to 3 photos' : 'Add photos', 'menu' => $photosFull ? null : \App\Devnull\ComposerMenu::photoItems(), 'disabled' => $photosFull], + ['ref' => 'reply-preview', 'icon' => \App\Icons\Lucide::Eye, 'label' => $replyPreviewing ? 'Edit' : 'Preview', 'press' => 'toggleReplyPreview', 'active' => $replyPreviewing], + ], + 'trail' => [ + ...($hasDraft ? [['native.partials.stash-label', ['ref' => 'reply-stash', 'drop' => 'dropReplyStash', 'size' => 'text-xs', 'restored' => $replyRestored]]] : []), + ['native.partials.body-counter', ['body' => $reply, 'ref' => 'reply-budget']], + ], + 'send' => [ + 'ref' => 'send-reply', + 'label' => 'Reply', + 'press' => 'sendReply', + 'disabled' => ! \App\Devnull\Data\Draft::canCommit($reply, $replyImages), + ], ]) - @include('native.partials.body-counter', ['body' => $reply, 'ref' => 'reply-budget']) - Reply @if (\App\Devnull\Data\CommitBody::hasOversizedUrl($reply)) Each link must not be greater than {{ \App\Devnull\Data\BodyLink::MaxLength }} characters. @endif - {{-- - A reply stashed when you left the commit comes back with the web's stash@{0} and drop under it. - Photos attached in the sheet show as a count on the left, which opens the sheet on them, and Reply - sends them. - --}} - @if ($replyRestored || $replyImages !== []) - - @if ($replyImages !== []) - @php($photoCount = \App\Devnull\Display::count(count($replyImages), 'photo', 'photos')) - - - - {{ $photoCount }} - - - - @endif - @if ($replyRestored) - @include('native.partials.stash-label', ['ref' => 'reply-stash', 'drop' => 'dropReplyStash', 'size' => 'text-xs']) - @endif - - @endif + @endif diff --git a/resources/views/native/partials/commit-sheet.blade.php b/resources/views/native/partials/commit-sheet.blade.php index 97a5b0b1..d30a12ee 100644 --- a/resources/views/native/partials/commit-sheet.blade.php +++ b/resources/views/native/partials/commit-sheet.blade.php @@ -79,7 +79,15 @@ @endif @if ($previewing) - @include('native.partials.composer-preview') + @include('native.partials.composer-preview', [ + 'ref' => 'sheet-draft', + 'body' => $sheetBody, + 'preview' => $sheetPreview, + 'images' => $sheetImages, + 'poll' => $replying ? null : $sheetPoll, + 'pollLength' => $sheetPollLength, + 'quoted' => $quoting ? $sheetCommit : null, + ]) @else - @include($field) - @if ($toolsInField) - @foreach ($tools as $tool) - @include('native.partials.composer-tool', $tool) - @endforeach - @endif - diff --git a/resources/views/native/partials/composer-preview.blade.php b/resources/views/native/partials/composer-preview.blade.php index 7959f818..b061d41a 100644 --- a/resources/views/native/partials/composer-preview.blade.php +++ b/resources/views/native/partials/composer-preview.blade.php @@ -1,23 +1,27 @@ {{-- - The draft in the composer as the commit it would become, in place of the field, as the web's ComposerPreviewBody: - its body as devnull would keep it, with its code and mentions once devnull has said, then its photos, its poll's - options and how long it runs once published, and the commit it quotes. With nothing to show yet, it says so. + A draft as the commit it would become, in place of the field, as the web's ComposerPreviewBody: its body as devnull + would keep it, with its code and mentions once devnull has said, then its photos, its poll's options and how long it + runs once published, and the commit it quotes. With nothing to show yet, it says so. + + The composer sheet and the reply bar on a commit's page both show one. $ref names it ("{$ref}-preview", and + "{$ref}-poll" for the poll), $body is the draft, $preview what devnull said of it (see AttachesToCommits), $images + its photos, $poll its options or null, $pollLength how long the poll runs, and $quoted the commit it quotes or null. --}} -@php($draftCommit = \App\Devnull\Data\Draft::asCommit($me ?? app(\App\Devnull\Account::class)->user() ?? \App\Devnull\Data\User::fromArray([]), $sheetBody, $sheetPreview, $sheetImages, $sheetView === 'reply' ? null : $sheetPoll, $sheetView === 'quote' ? $sheetCommit : null)) - - @if (trim($sheetBody) === '' && $sheetImages === [] && $sheetPoll === null) +@php($draftCommit = \App\Devnull\Data\Draft::asCommit($me ?? app(\App\Devnull\Account::class)->user() ?? \App\Devnull\Data\User::fromArray([]), $body, $preview, $images, $poll, $quoted)) + + @if (trim($body) === '' && $images === [] && $poll === null) Nothing to preview yet. @else @include('native.partials.commit-body', ['commit' => $draftCommit, 'focused' => true, 'static' => true]) @include('native.partials.commit-media', ['commit' => $draftCommit, 'withEmbeds' => false, 'scoreAction' => false]) @if ($draftCommit->poll) - + @foreach ($draftCommit->poll->options as $option) {{ $option->label }} @endforeach - {{ \App\Devnull\Data\PollDraft::runs($sheetPollLength) }} + {{ \App\Devnull\Data\PollDraft::runs($pollLength) }} @endif @if ($draftCommit->quotedCommit) diff --git a/resources/views/native/partials/composer-tool.blade.php b/resources/views/native/partials/composer-tool.blade.php index 92027763..6ae256f4 100644 --- a/resources/views/native/partials/composer-tool.blade.php +++ b/resources/views/native/partials/composer-tool.blade.php @@ -1,11 +1,13 @@ {{-- One of the composer's tools, as the web's ghost icon buttons: a 44pt target with the icon in muted ink, on Blue Wash in Commit Blue while it's on ($active). While it can't be used ($disabled), it's faded, with nothing to press. - With $menu (TopBarAction items), a tap opens that menu instead of pressing. + With $menu (TopBarAction items), a tap opens that menu instead of pressing. With $text, the icon is smaller and the + words follow it in muted ink, as the reply box counts the photos on its draft. --}} @php($active ??= false) @php($disabled ??= false) @php($menu ??= null) +@php($text ??= null) @if ($menu !== null) {{-- iOS's menu reads its icon to VoiceOver rather than the pressable's label, so the icon carries it too. --}} @@ -17,6 +19,13 @@ +@elseif ($text !== null) + + + + {{ $text }} + + @else diff --git a/resources/views/native/partials/related-commits.blade.php b/resources/views/native/partials/related-commits.blade.php index a7398456..452eaedf 100644 --- a/resources/views/native/partials/related-commits.blade.php +++ b/resources/views/native/partials/related-commits.blade.php @@ -1,19 +1,35 @@ -{{-- Other threads, in relevance order, on a fresh rail below this thread as on the web. --}} +{{-- + Other threads, in relevance order, on a fresh rail below this thread as on the web. They start closed under a + header with their count, which opens them in place and closes them again, its chevron turning as they do (see + CommitDetail::toggleRelated()). Each commit fades and slides into place a little after the one above it, and fades + out together as they close. The header is the whole row, so it's an easy target at the foot of the page. +--}} +@php($relatedOpen = $relatedShown && ! $relatedClosing) +@php($relatedLabel = \App\Devnull\Display::count(count($relatedRows), 'related commit', 'related commits')) - - Related commits - - @foreach ($relatedRows as $relatedRow) - @include('native.partials.commit-row', [ - 'commit' => $relatedRow->commit, - 'previousLane' => $relatedRow->previousLane, - 'continuesRun' => $relatedRow->continuesRun, - 'continuesNext' => null, - 'focused' => false, - 'muted' => false, - 'seriesExpanded' => false, - 'threadBelow' => false, - 'withTail' => ! $loop->last, - ]) - @endforeach + + + Related commits + {{ count($relatedRows) }} + + + + + @if ($relatedShown) + @foreach ($relatedRows as $relatedRow) + + @include('native.partials.commit-row', [ + 'commit' => $relatedRow->commit, + 'previousLane' => $relatedRow->previousLane, + 'continuesRun' => $relatedRow->continuesRun, + 'continuesNext' => null, + 'focused' => false, + 'muted' => false, + 'seriesExpanded' => false, + 'threadBelow' => false, + 'withTail' => ! $loop->last, + ]) + + @endforeach + @endif diff --git a/resources/views/native/partials/reply-field.blade.php b/resources/views/native/partials/reply-field.blade.php index 04f37457..1879f43a 100644 --- a/resources/views/native/partials/reply-field.blade.php +++ b/resources/views/native/partials/reply-field.blade.php @@ -1,11 +1,12 @@ {{-- - The reply bar's field on a commit's page (see partials/composer-plate). EDGE sends no focus event, so a press on the - field is how the page learns you're replying. The expand button is beside it rather than in it, so pressing it + The reply bar's field on a commit's page, across the top of partials/composer-box. EDGE sends no focus event, so a + press on the field is how the page learns you're replying. The tools are in the row under it, so pressing them doesn't count. Where the caret is goes to the page as it moves, for the "@" suggestions above the bar (see SuggestsMentions). It keeps the keyboard up through presses elsewhere on the page (keep-focus), as the Remotes - field does, so picking someone to mention leaves you typing after them. + field does, so picking someone to mention leaves you typing after them. It grows with the reply to five lines and + then scrolls, sized by the field itself, not by the page. --}} - + diff --git a/resources/views/native/partials/reply-preview.blade.php b/resources/views/native/partials/reply-preview.blade.php new file mode 100644 index 00000000..31ba70ad --- /dev/null +++ b/resources/views/native/partials/reply-preview.blade.php @@ -0,0 +1,19 @@ +{{-- + The reply as it will look, in the reply bar's field's place, while Preview is on (see CommitDetail::toggleReplyPreview()): + its body as devnull keeps it, with its photos. Held to about half a screen, and scrolls past that, so a long reply + doesn't push the commit off the top. +--}} + + + @include('native.partials.composer-preview', [ + 'ref' => 'reply-draft', + 'body' => $reply, + 'preview' => $replyPreview, + 'images' => $replyImages, + 'poll' => null, + 'pollLength' => \App\Devnull\Data\PollDraft::DefaultLength, + 'quoted' => null, + 'me' => $viewer, + ]) + + diff --git a/resources/views/native/partials/stash-label.blade.php b/resources/views/native/partials/stash-label.blade.php index b455da5c..a91815bb 100644 --- a/resources/views/native/partials/stash-label.blade.php +++ b/resources/views/native/partials/stash-label.blade.php @@ -1,11 +1,15 @@ {{-- The web's StashLabel, beside a draft that was stashed and has come back: stash@{0} in mono, then drop, which throws - the draft away. $drop is what drop presses, and drop is a full 44pt target. + the draft away. $drop is what drop presses, and drop is a full 44pt target. With $restored false, the draft is one + you're writing now, so there's no stash@{0}, only drop. --}} @php($size ??= 'text-[13px]') +@php($restored ??= true) - {{ 'stash@{0}' }} - + @if ($restored) + {{ 'stash@{0}' }} + @endif + drop diff --git a/tests/Feature/Screens/CommitDetailTest.php b/tests/Feature/Screens/CommitDetailTest.php index fc0da284..8b692e51 100644 --- a/tests/Feature/Screens/CommitDetailTest.php +++ b/tests/Feature/Screens/CommitDetailTest.php @@ -1,6 +1,8 @@ and(idsDownTo($screen->tree(), 'reply-input'))->toBe($field); }); -it('puts the expand button inside the reply field on iOS, and ahead of it on Android', function (string $platform, array $row, array $plate) { +it('draws the reply bar with the field over the photo and preview buttons and a round Reply, on both platforms', function (string $platform) { fakeThread(); $screen = Native::visit('/log/commits/c2', platform: $platform); + $actions = childRefs($screen, 'reply-actions'); - expect(childRefs($screen, 'reply-row'))->toBe($row) - ->and(childRefs($screen, 'reply-plate'))->toBe($plate); -})->with([ - 'iOS' => ['ios', ['reply-plate', 'send-reply'], ['reply-field', 'reply-expand']], - 'Android' => ['android', ['reply-expand', 'reply-plate', 'send-reply'], ['reply-field']], -]); + expect(childRefs($screen, 'reply-row'))->toBe(['reply-box']) + ->and(childRefs($screen, 'reply-box'))->toBe(['reply-field-row', 'reply-actions']) + ->and(childRefs($screen, 'reply-field-row'))->toBe(['reply-field']) + ->and(array_slice($actions, 0, 2))->toBe(['reply-add-photos', 'reply-preview']) + ->and(end($actions))->toBe('send-reply') + ->and(array_column(menuItems($screen, 'reply-add-photos'), 0))->toBe(['reply-pick-photos', 'reply-take-photo']) + ->and(nodeByRef($screen, 'send-reply')['props']['a11y_label'] ?? nodeByRef($screen, 'send-reply')['a11y_label'] ?? null)->toBe('Reply') + ->and(rendersRef($screen, 'reply-expand'))->toBeFalse() + ->and(canSend($screen, 'send-reply'))->toBeFalse(); + + $screen->input('reply-input', 'Ready'); + + expect(canSend($screen, 'send-reply'))->toBeTrue(); +})->with(['ios', 'android']); + +it('keeps the same field, up to five lines and then scrolling, however long the reply grows', function (string $platform) { + fakeThread(); + + $screen = Native::visit('/log/commits/c2', platform: $platform)->input('reply-input', 'A short one'); + $field = idsDownTo($screen->tree(), 'reply-input'); + + $screen->input('reply-input', str_repeat("A line of a long reply\n", 12)); + + // The field sizes itself: the page only says how many lines it can take, which never changes as you type. + expect(idsDownTo($screen->tree(), 'reply-input'))->toBe($field) + ->and(nodeByRef($screen, 'reply-input')['props']['max_lines'])->toBe(Display::ReplyBarMaxLines) + ->and(nodeByRef($screen, 'reply-input')['props']['min_lines'] ?? null)->toBeNull() + ->and(nodeByRef($screen, 'sheet')['props']['visible'] ?? false)->toBeFalse(); +})->with(['ios', 'android']); + +it('previews the reply in the field\'s place, with the body devnull keeps, and brings the field back with the keyboard', function () { + fakeThread(extra: ['POST /api/v1/commits/preview' => [['data' => [ + 'body' => 'Shipped 🚀 with @ada', + 'body_segments' => [['type' => 'text', 'text' => 'Shipped 🚀 with @ada']], + 'preview_segments' => null, + 'mentions' => [['handle' => 'ada', 'offset' => 15, 'length' => 4]], + ]]]]); + $screen = Native::visit('/log/commits/c2')->input('reply-input', 'Shipped :rocket: with @ada'); + holdRefreshes(); + $screen->tap('reply-preview'); + + // At once, the reply as written, in the field's place, while devnull is asked. The sheet never opens. + expect(rendersRef($screen, 'reply-input'))->toBeFalse() + ->and(childRefs($screen, 'reply-field-row'))->toBe(['reply-preview-pane']) + ->and(nodeByRef($screen, 'reply-preview')['props']['a11y_label'])->toBe('Edit') + ->and(treeShows(nodeByRef($screen, 'reply-draft-preview'), 'Shipped :rocket: with @ada'))->toBeTrue() + ->and(nodeByRef($screen, 'sheet')['props']['visible'] ?? false)->toBeFalse(); + + finishRefreshes($screen); + + expect(treeShows(nodeByRef($screen, 'reply-draft-preview'), 'Shipped 🚀 with '))->toBeTrue() + ->and(canSend($screen, 'send-reply'))->toBeTrue(); + + Http::assertSent(fn (Request $request): bool => str_ends_with($request->url(), '/api/v1/commits/preview') + && $request->body() === '{"body":"Shipped :rocket: with @ada"}'); + + $screen->tap('reply-preview'); + + expect(nodeByRef($screen, 'reply-input')['props'])->toMatchArray(['value' => 'Shipped :rocket: with @ada', 'autofocus' => true]) + ->and(nodeByRef($screen, 'reply-preview')['props']['a11y_label'])->toBe('Preview'); +}); + +it('shows a drop beside Reply as soon as the reply has anything in it, which throws it away', function () { + fakeThread(); + + $screen = Native::visit('/log/commits/c2'); + + expect(rendersRef($screen, 'reply-stash'))->toBeFalse(); + + $screen->input('reply-input', 'Not this after all'); + $actions = childRefs($screen, 'reply-actions'); + + // A draft you're writing now has drop alone. Only one that came back from the stash says stash@{0}. + expect(array_slice($actions, -2))->toBe(['reply-stash', 'send-reply']) + ->and(childRefs($screen, 'reply-stash'))->toBe(['reply-stash-drop']) + ->and(nodeByRef($screen, 'reply-stash-drop')['props']['a11y_label'] ?? null)->toBe('Discard the draft'); + + $screen->tap('reply-stash-drop'); + + expect($screen->instance()->reply)->toBe('') + ->and(nodeByRef($screen, 'reply-input')['props']['value'])->toBe('') + ->and(rendersRef($screen, 'reply-stash'))->toBeFalse() + ->and(app(Stash::class)->names(app(Account::class)->user()?->id))->toBe([]); +}); + +it('says nothing about a long reply being folded in feeds, beside Reply or in the sheet, and still counts down near the limit', function () { + fakeThread(); + + $screen = Native::visit('/log/commits/c2')->input('reply-input', str_repeat('a', 281)); + + expect(rendersRef($screen, 'reply-budget-fold'))->toBeFalse() + ->and(rendersRef($screen, 'reply-budget'))->toBeFalse(); + + $screen->input('reply-input', str_repeat('a', Commit::MaxLength - 20)); + + expect(nodeByRef($screen, 'reply-budget')['props']['text'])->toBe('20'); + + $screen->call('replyInSheet', 'c2'); + + expect(rendersRef($screen, 'sheet-budget-fold'))->toBeFalse() + ->and(nodeByRef($screen, 'sheet-budget')['props']['text'])->toBe('20'); +}); it('runs the rail from the folded ancestors into the parent, which shows its avatar', function () { $ada = userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada', 'lane' => 1]); @@ -320,7 +419,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): Native::visit('/log/commits/c2') ->input('reply-input', ' ') - ->tap('send-reply') + ->call('sendReply') ->input('reply-input', str_repeat('a', 4000)) ->assertElement('text', fn (array $node): bool => ($node['ref'] ?? null) === 'reply-budget' && ($node['text'] ?? $node['props']['text'] ?? null) === '0' @@ -333,7 +432,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): fakeThread(extra: ['POST /api/v1/commits' => [['data' => replyJson(['id' => 'r9', 'parent_id' => 'c2', 'body' => $body])], 201]]); $screen = Native::visit('/log/commits/c2')->input('reply-input', $body); - expect(nodeByRef($screen, 'send-reply')['props']['disabled'] ?? false)->toBeFalse() + expect(canSend($screen, 'send-reply'))->toBeTrue() ->and(nodeByRef($screen, 'reply-input')['props']['max_length'])->toBe(40000); $screen->tap('send-reply')->assertSet('reply', ''); @@ -344,7 +443,7 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): fakeThread(); $screen = Native::visit('/log/commits/c2')->input('reply-input', 'https://example.com/'.str_repeat('x', 2030)) ->assertSee('Each link must not be greater than 2048 characters.'); - expect(nodeByRef($screen, 'send-reply')['props']['disabled'])->toBeTrue(); + expect(canSend($screen, 'send-reply'))->toBeFalse(); $screen->call('sendReply'); Http::assertNotSent(fn (Request $request): bool => $request->method() === 'POST'); }); @@ -766,30 +865,41 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): expect(pressFeedbackInScroller($screen))->toBe([]); }); -it('paints the reply bar solid on Android, with its hairline, so the replies never show through', function () { - fakeThread(); - - $screen = Native::visit('/log/commits/c2', platform: 'android'); - $bar = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'bottom_bar'); - - expect($bar['children'][0]['ref'] ?? null)->toBe('reply-bar') - ->and($bar['children'][0]['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.surface')) - ->and($bar['children'][0]['props']['dark_bg_color'] ?? null)->toBe(config('native-ui.theme.dark.surface')) - ->and($bar['children'][0]['children'][0]['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.hairline')) - ->and(nodeByRef($screen, 'reply-plate')['props']['glass'] ?? null)->toBeNull(); -}); - -it('leaves the reply bar bare on iOS and floats the field on Liquid Glass', function () { +it('puts the reply bar on glass on iOS and the surface on Android, with no line, and fades the page out above it', function (string $platform) { fakeThread(); - $screen = Native::visit('/log/commits/c2', platform: 'ios'); - $bar = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'bottom_bar'); - - expect($bar['children'][0]['ref'] ?? null)->toBe('reply-bar') - ->and($bar['children'][0]['style']['bg_color'] ?? null)->toBeNull() - ->and($bar['children'][0]['children'][0]['style']['bg_color'] ?? null)->toBeNull() - ->and(nodeByRef($screen, 'reply-plate')['props']['glass'] ?? null)->toBe(1); -}); + $screen = Native::visit('/log/commits/c2', platform: $platform); + $bottomBar = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'bottom_bar'); + $bar = $bottomBar['children'][0]; + $surface = substr(strtoupper(config('native-ui.theme.light.surface')), 1); + $darkSurface = substr(strtoupper(config('native-ui.theme.dark.surface')), 1); + + expect($bar['ref'] ?? null)->toBe('reply-bar') + ->and($bar['props']['glass'] ?? null)->toBeNull() + ->and(childRefs($screen, 'reply-rows')[0])->toBe('reply-mention-slot'); + + if ($platform === 'ios') { + // The page runs on under the bar, which is glass, so it shows through blurred. The bar draws the fade at its + // top, ending at the glass's tint, and its rows carry the tint. The bar itself has no background, which iOS + // would paint behind the fade. + expect($bottomBar['props']['glass'] ?? null)->toBe(1) + ->and($bar['style']['bg_color'] ?? null)->toBeNull() + ->and(nodeByRef($screen, 'reply-rows')['style']['bg_color'] ?? null)->toBe('#66'.$surface) + ->and(nodeByRef($screen, 'reply-rows')['props']['dark_bg_color'] ?? null)->toBe('#66'.$darkSurface) + ->and(nodeByRef($screen, 'reply-fade')['props']['gradient_stops'] ?? null)->toBe('#00'.$surface.',#66'.$surface) + ->and(childRefs($screen, 'reply-bar'))->toBe(['reply-fade', 'reply-rows']) + ->and(childRefs($screen, 'thread-stack'))->toBe(['thread-scroll']); + } else { + // No glass on Android. The page stops at the bar, which is the surface, and the fade lies over its foot. + expect($bottomBar['props']['glass'] ?? null)->toBeNull() + ->and($bar['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.surface')) + ->and(nodeByRef($screen, 'reply-rows')['style']['bg_color'] ?? null)->toBe(config('native-ui.theme.light.surface')) + ->and(nodeByRef($screen, 'reply-rows')['props']['dark_bg_color'] ?? null)->toBe(config('native-ui.theme.dark.surface')) + ->and(str_ends_with(nodeByRef($screen, 'reply-fade')['props']['gradient_stops'] ?? '', ',#'.$surface))->toBeTrue() + ->and(childRefs($screen, 'reply-bar'))->toBe(['reply-rows']) + ->and(childRefs($screen, 'thread-stack'))->toBe(['thread-scroll', 'reply-fade']); + } +})->with(['ios', 'android']); it('ends the page above the reply bar, and further as the draft grows', function () { fakeThread(replies: [replyJson(['id' => 'r1', 'parent_id' => 'c2', 'body' => 'The last reply'])]); @@ -798,15 +908,17 @@ function fakeThread(array $commit = [], array $replies = [], array $extra = []): $scroller = findNode($screen->tree(), fn (array $node): bool => ($node['type'] ?? null) === 'scroll_view'); $page = $scroller['children'][0]['children']; - // The clearance is the last thing on the page, under the last reply: the bar's line and the home indicator. + // The clearance is the last thing on the page, under the last reply: the fade, the bar and the home indicator. + $bar = 24 + Display::ComposerFadeHeight + Display::ComposerBoxBarHeight + 34; + expect(end($page)['ref'] ?? null)->toBe('reply-bar-clearance') - ->and(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual(24 + 53 + 34); + ->and(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($bar); $screen->input('reply-input', "Three lines\nof a\ndraft"); - expect(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual(24 + 53 + 2 * 21 + 34); + expect(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($bar + 2 * 21); $screen->input('reply-input', str_repeat("A line\n", 12)); - expect(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual(24 + 53 + 4 * 21 + 34); + expect(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($bar + 4 * 21); }); diff --git a/tests/Feature/Screens/ComposerPhotosTest.php b/tests/Feature/Screens/ComposerPhotosTest.php index 9338fce8..9a0fa6e1 100644 --- a/tests/Feature/Screens/ComposerPhotosTest.php +++ b/tests/Feature/Screens/ComposerPhotosTest.php @@ -228,105 +228,106 @@ function isTool(TestableComponent $screen, string $ref): bool ->and(app(Stash::class)->names(app(Account::class)->user()?->id))->toBe([]); }); -it('opens a commit\'s reply in the sheet with what the reply bar had, and replies with photos', function () { +/** + * The commit page for c2, by Ada, which a reply can be sent to. + */ +function replyPage(string $platform = 'ios'): TestableComponent +{ serveApi([ 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2', 'body' => 'The focused commit', 'author' => userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada'])]))], 'GET /api/v1/commits/c2/replies' => [pageJson([])], - 'POST /api/v1/commits' => [['data' => replyJson(['id' => 'r9', 'parent_id' => 'c2', 'body' => 'Here it is'])], 201], + 'POST /api/v1/commits' => [['data' => replyJson(['id' => 'r9', 'parent_id' => 'c2', 'body' => 'Look'])], 201], ]); - $screen = Native::visit('/log/commits/c2') - ->input('reply-input', 'Here it') - ->tap('reply-expand') - ->assertSee('Reply to @ada'); - - expect(nodeByRef($screen, 'sheet-body')['props'])->toMatchArray(['value' => 'Here it', 'placeholder' => 'Reply to @ada']) - ->and(nodeByRef($screen, 'quote-card')['props']['a11y_label'])->toBe('Replying to Ada') - ->and(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'sheet-stash'))->toBeNull() - ->and(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'sheet-poll'))->toBeNull() - ->and(nodeByRef($screen, 'sheet-commit')['props']['a11y_label'] ?? null)->toBe('Reply'); - - photosPicked($screen, [testPhoto()]) - ->input('sheet-body', 'Here it is') - ->tap('sheet-commit') - ->dismissSheet('sheet') - ->assertSee('Here it is'); + return Native::visit('/log/commits/c2', platform: $platform); +} - Http::assertSent(fn (Request $request): bool => $request->method() === 'POST' && multipartParts($request)[0]['contents'] === '{"body":"Here it is","parent_id":"c2"}'); +it('adds photos to a reply from the bar, from the library or the camera, without the sheet', function () { + $screen = replyPage()->input('reply-input', 'Look')->tap('reply-pick-photos'); - expect(array_map(fn ($reply): string => $reply->id, $screen->instance()->replies))->toBe(['r9']) - ->and($screen->instance()->reply)->toBe('') - ->and(nodeByRef($screen, 'reply-input')['props']['value'])->toBe(''); -}); + $screen->assertNativeCalled('Camera.PickMedia', fn (array $params): bool => $params['mediaType'] === 'images' && $params['multiple'] === true && $params['maxItems'] === 3); -it('hands the reply back to the reply bar when the sheet goes unsent', function () { - serveApi([ - 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2', 'author' => userJson(['id' => 'u2', 'handle' => 'ada'])]))], - 'GET /api/v1/commits/c2/replies' => [pageJson([])], - ]); + photosPicked($screen, [testPhoto()])->tap('reply-take-photo')->assertNativeCalled('Camera.GetPhoto'); + $screen->emitNative(PhotoTaken::class, ['path' => testPhoto('jpg', 30, 40), 'mimeType' => 'image/jpeg']); - $screen = Native::visit('/log/commits/c2') - ->input('reply-input', 'Half') - ->tap('reply-expand') - ->input('sheet-body', 'Half a reply') - ->dismissSheet('sheet'); + // They show above the field, which keeps its place, and go in the reply's stash with its text. + expect($screen->instance()->replyImages)->toHaveCount(2) + ->and(childRefs($screen, 'reply-rows'))->toBe(['reply-mention-slot', 'reply-photos-slot', 'reply-row']) + ->and(nodeByRef($screen, 'reply-photo-0'))->not->toBeNull() + ->and(nodeByRef($screen, 'reply-photo-1'))->not->toBeNull() + ->and(nodeByRef($screen, 'sheet')['props']['visible'] ?? false)->toBeFalse() + ->and(app(Stash::class)->get(app(Account::class)->user()?->id, 'reply-c2')->images)->toHaveCount(2); - expect(nodeByRef($screen, 'reply-input')['props']['value'])->toBe('Half a reply') - ->and(app(Stash::class)->get(app(Account::class)->user()?->id, 'reply-c2')->body)->toBe('Half a reply'); + // A third fills it, and the button can't add more. + photosPicked($screen, [testPhoto()]); - Http::assertNotSent(fn (Request $request): bool => $request->method() === 'POST'); + expect(menuItems($screen, 'reply-add-photos'))->toBe([]) + ->and(nodeByRef($screen, 'reply-add-photos')['a11y_label'] ?? nodeByRef($screen, 'reply-add-photos')['props']['a11y_label'] ?? null)->toBe('A reply can have up to 3 photos'); }); -it('hands the reply\'s photos back to the reply bar too, which counts them, keeps them and replies with them', function () { - serveApi([ - 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2', 'author' => userJson(['id' => 'u2', 'handle' => 'ada'])]))], - 'GET /api/v1/commits/c2/replies' => [pageJson([])], - 'POST /api/v1/commits' => [['data' => replyJson(['id' => 'r9', 'parent_id' => 'c2', 'body' => 'Look'])], 201], - ]); +it('takes a photo off the reply in the bar with its ✕, and off the phone', function () { + $screen = photosPicked(replyPage(), [testPhoto(), testPhoto()]); + $removed = $screen->instance()->replyImages[0]->path; - $screen = photosPicked(Native::visit('/log/commits/c2')->input('reply-input', 'Look')->tap('reply-expand'), [testPhoto()]) - ->dismissSheet('sheet'); - $path = $screen->instance()->replyImages[0]->path; + $screen->tap('reply-photo-0-remove'); + + expect($screen->instance()->replyImages)->toHaveCount(1) + ->and(file_exists($removed))->toBeFalse() + ->and(app(Stash::class)->get(app(Account::class)->user()?->id, 'reply-c2')->images)->toHaveCount(1); +}); - expect(treeShows(nodeByRef($screen, 'reply-photos'), '1 photo'))->toBeTrue() - ->and(nodeByRef($screen, 'reply-photos')['props']['a11y_label'] ?? null)->toBe('1 photo attached'); +it('keeps a reply\'s photos for when you come back to the commit, and replies with them', function () { + photosPicked(replyPage()->input('reply-input', 'Look'), [testPhoto()]); - // Coming back to the commit, the bar has them still. $screen = Native::visit('/log/commits/c2'); + $path = $screen->instance()->replyImages[0]->path; expect($screen->instance()->reply)->toBe('Look') - ->and($screen->instance()->replyImages)->toHaveCount(1) + ->and(nodeByRef($screen, 'reply-photo-0'))->not->toBeNull() ->and(nodeByRef($screen, 'reply-stash'))->not->toBeNull(); - // The count opens the sheet on them. - $screen->tap('reply-photos'); - - expect(nodeByRef($screen, 'sheet')['props']['visible'])->toBeTrue() - ->and($screen->instance()->sheetImages[0]->path)->toBe($path); - - $screen->dismissSheet('sheet')->tap('send-reply')->assertSee('Look'); + $screen->tap('send-reply')->assertSee('Look'); Http::assertSent(fn (Request $request): bool => $request->method() === 'POST' && multipartParts($request)[0]['contents'] === '{"body":"Look","parent_id":"c2"}' && multipartParts($request)[1]['name'] === 'images[]'); expect($screen->instance()->replyImages)->toBe([]) - ->and(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'reply-photos'))->toBeNull() + ->and(rendersRef($screen, 'reply-photo-0'))->toBeFalse() ->and(file_exists($path))->toBeFalse() ->and(app(Stash::class)->names(app(Account::class)->user()?->id))->toBe([]); }); -it('hands the reply and its photos back to the reply bar when Cancel closes the sheet on Android, which never says it has gone', function () { - serveApi([ - 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2', 'author' => userJson(['id' => 'u2', 'handle' => 'ada'])]))], - 'GET /api/v1/commits/c2/replies' => [pageJson([])], - ]); +it('previews a reply with its photos in the bar', function () { + $screen = photosPicked(replyPage()->input('reply-input', 'Look'), [testPhoto()])->tap('reply-preview'); - $screen = photosPicked(Native::visit('/log/commits/c2', platform: 'android')->input('reply-input', 'Half')->tap('reply-expand'), [testPhoto()]) - ->input('sheet-body', 'Half a reply') - ->tap('sheet-cancel') - ->input('reply-input', 'Half a reply, and more'); + // The photos move into the preview, as the reply will show them, and their row above the field goes. + expect(treeShows(nodeByRef($screen, 'reply-draft-preview'), 'Look'))->toBeTrue() + ->and(findNode(nodeByRef($screen, 'reply-draft-preview'), fn (array $node): bool => ($node['type'] ?? null) === 'image'))->not->toBeNull() + ->and(rendersRef($screen, 'reply-photo-0'))->toBeFalse(); +}); - expect($screen->instance()->replyImages)->toHaveCount(1) - ->and(app(Stash::class)->get(app(Account::class)->user()?->id, 'reply-c2')->images)->toHaveCount(1); +it('drops a reply\'s photos with it, off the phone', function () { + $screen = photosPicked(replyPage(), [testPhoto()]); + $path = $screen->instance()->replyImages[0]->path; + + $screen->tap('reply-stash-drop'); + + expect($screen->instance()->replyImages)->toBe([]) + ->and(file_exists($path))->toBeFalse() + ->and(app(Stash::class)->names(app(Account::class)->user()?->id))->toBe([]); }); + +it('hands a reply opened in the sheet back to the reply bar, photos too, when the sheet goes unsent', function (string $platform) { + $screen = replyPage($platform)->input('reply-input', 'Half')->call('replyInSheet', 'c2'); + + photosPicked($screen, [testPhoto()])->input('sheet-body', 'Half a reply'); + + $platform === 'ios' ? $screen->dismissSheet('sheet') : $screen->tap('sheet-cancel'); + + expect(nodeByRef($screen, 'reply-input')['props']['value'])->toBe('Half a reply') + ->and($screen->instance()->replyImages)->toHaveCount(1) + ->and(app(Stash::class)->get(app(Account::class)->user()?->id, 'reply-c2')->images)->toHaveCount(1); + + Http::assertNotSent(fn (Request $request): bool => $request->method() === 'POST'); +})->with(['ios', 'android']); diff --git a/tests/Feature/Screens/DraftStashTest.php b/tests/Feature/Screens/DraftStashTest.php index 46baedf4..a346e29d 100644 --- a/tests/Feature/Screens/DraftStashTest.php +++ b/tests/Feature/Screens/DraftStashTest.php @@ -3,7 +3,6 @@ use App\Devnull\Account; use App\Devnull\Data\Pasteis; use App\Devnull\Data\StashedDraft; -use App\Devnull\Display; use App\Devnull\Stash; use Carbon\CarbonImmutable; use Illuminate\Http\Client\Request; @@ -199,16 +198,18 @@ function stashLabel(TestableComponent $screen, string $ref): array $screen = Native::visit('/log/commits/c2')->input('reply-input', 'A reply in progress'); $clearance = nodeByRef($screen, 'reply-bar-clearance')['layout']['height']; + // While you write it, there's only drop. expect(stashed('reply-c2'))->toBe('A reply in progress') - ->and(showsRef($screen, 'reply-stash'))->toBeFalse(); + ->and(stashLabel($screen, 'reply-stash'))->toBe(['drop', 'Discard the draft']); $screen = Native::visit('/log/commits/c2'); expect(nodeByRef($screen, 'reply-input')['props']['value'])->toBe('A reply in progress') ->and(stashLabel($screen, 'reply-stash'))->toBe(['stash@{0}', 'Discard the restored draft']) - ->and(nodeByRef($screen, 'send-reply')['props']['disabled'] ?? false)->toBeFalse() - // The page ends above the row that marks it, too. - ->and(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($clearance + Display::ReplyBarStashLabelHeight); + ->and(canSend($screen, 'send-reply'))->toBeTrue() + // It's marked in the row under the field, beside Reply, so the bar is no taller for it. + ->and(array_slice(childRefs($screen, 'reply-actions'), -2))->toBe(['reply-stash', 'send-reply']) + ->and(nodeByRef($screen, 'reply-bar-clearance')['layout']['height'])->toEqual($clearance); }); it("forgets a reply's stash once it's sent", function () { diff --git a/tests/Feature/Screens/LaneButtonsTest.php b/tests/Feature/Screens/LaneButtonsTest.php index 3e966d04..40689705 100644 --- a/tests/Feature/Screens/LaneButtonsTest.php +++ b/tests/Feature/Screens/LaneButtonsTest.php @@ -72,14 +72,6 @@ function laneLog(): TestableComponent return Native::visit('/log/users/ada/followers'); }, 'follow-grace'], - 'Reply' => [function (): TestableComponent { - serveApi([ - 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2']))], - 'GET /api/v1/commits/c2/replies' => [pageJson([])], - ]); - - return Native::visit('/log/commits/c2'); - }, 'send-reply'], 'Edit on GitHub, on the Account screen' => [function (): TestableComponent { serveApi(['GET /api/v1/me' => [currentUserJson(['lane' => app(Account::class)->user()?->lane()])]]); @@ -115,6 +107,27 @@ function laneLog(): TestableComponent 'rose, checked in white' => 4, ]); +it("fills the reply bar's round Reply with your lane, with an arrow that reads on it", function (int $lane) { + signIn(['lane' => $lane]); + serveApi([ + 'GET /api/v1/commits/c2' => [commitPageJson(commitJson(['id' => 'c2']))], + 'GET /api/v1/commits/c2/replies' => [pageJson([])], + ]); + + $circle = nodeByRef(Native::visit('/log/commits/c2')->input('reply-input', 'Agreed'), 'send-reply-circle'); + $icon = findNode($circle, fn (array $node): bool => $node['type'] === 'icon')['props']; + + expect(array_map(strtolower(...), [$circle['style']['bg_color'], $circle['props']['dark_bg_color'], $icon['color'], $icon['dark_color']]))->toBe(array_map(strtolower(...), [ + config("native-ui.theme.light.lane-{$lane}"), + config("native-ui.theme.dark.lane-{$lane}"), + config("native-ui.theme.light.on-lane-{$lane}"), + config("native-ui.theme.dark.on-lane-{$lane}"), + ])); +})->with([ + 'green, an arrow in ink' => 1, + 'rose, a white arrow' => 4, +]); + it('draws the tab underline in your lane, in its light and dark shades', function (string $path, int $lane) { signIn(['lane' => $lane]); Http::fake(['devnull.test/*' => Http::response(pageJson([]))]); diff --git a/tests/Feature/Screens/RelatedCommitsTest.php b/tests/Feature/Screens/RelatedCommitsTest.php index a6265735..9e8f15b6 100644 --- a/tests/Feature/Screens/RelatedCommitsTest.php +++ b/tests/Feature/Screens/RelatedCommitsTest.php @@ -1,9 +1,13 @@ 'http://devnull.test']); @@ -25,6 +29,45 @@ function serveRelatedThread(array $related = [], array $extra = []): void ]); } +/** + * Lets every Beat the screen has dispatched come back, as the phone would once it had drawn the step before, and + * leaves any other task (a held refresh) where it is. Like finishBeats() in LogThreadTest, except that it opens a + * task's sealed payload without reading it through AsyncTaskTransport::readPayload(), which deletes it, so a held + * refresh would have nothing left for finishRefreshes() to run. + */ +function landBeats(TestableComponent $screen): TestableComponent +{ + $done = []; + + while (true) { + $beats = array_filter($screen->bridge()->callsTo('AsyncTask.Dispatch'), function (array $call) use (&$done): bool { + $id = $call['params']['id']; + $path = AsyncTaskTransport::directory('payload').DIRECTORY_SEPARATOR.$id.'.task'; + $unseal = Closure::bind(fn (string $id, string $sealed): ?string => static::unseal($id, $sealed), null, AsyncTaskTransport::class); + + return ! isset($done[$id]) && is_file($path) && str_contains((string) $unseal($id, (string) file_get_contents($path)), serialize(Beat::class)); + }); + + if ($beats === []) { + return $screen; + } + + foreach ($beats as $call) { + $done[$call['params']['id']] = true; + AsyncTaskTransport::forgetPayload($call['params']['id']); + $screen->emitNative(AsyncTaskFinished::class, ['id' => $call['params']['id'], 'result' => true]); + } + } +} + +/** + * Opens the related commits under their header, and lets them fade in. + */ +function openRelated(TestableComponent $screen): TestableComponent +{ + return landBeats($screen->tap('related-commits-toggle')); +} + it('shows related commits below the thread in relevance order on their own rail', function (string $platform) { serveRelatedThread([ commitJson(['id' => 'c9', 'body' => 'Closest match', 'author' => userJson(['id' => 'u2', 'handle' => 'ada', 'name' => 'Ada'])]), @@ -34,7 +77,7 @@ function serveRelatedThread(array $related = [], array $extra = []): void 'GET /api/v1/commits/c1/replies' => [pageJson([replyJson(['id' => 'r1', 'parent_id' => 'c1', 'body' => 'A reply'])])], ]); - $screen = Native::visit('/log/commits/c1', ['replies' => true], platform: $platform) + $screen = openRelated(Native::visit('/log/commits/c1', ['replies' => true], platform: $platform)) ->assertSee('The focused commit') ->assertSee('A reply') ->assertSee('Related commits') @@ -43,7 +86,8 @@ function serveRelatedThread(array $related = [], array $extra = []): void ->assertSee('Third match'); expect(childRefs($screen, 'thread-page'))->toBe(['focused-commit', 'thread-reply-r1', 'related-commits', 'reply-bar-clearance']) - ->and(childRefs($screen, 'related-commits'))->toBe(['related-commits-heading', 'commit-c9', 'commit-c3', 'commit-c7']) + ->and(childRefs($screen, 'related-commits'))->toBe(['related-commits-toggle', 'related-c9', 'related-c3', 'related-c7']) + ->and(childRefs($screen, 'related-c9'))->toBe(['commit-c9']) ->and(railNode($screen, 'commit-c9'))->toBe('avatar') ->and(pressFeedbackInScroller($screen))->toBe([]); @@ -73,7 +117,7 @@ function serveRelatedThread(array $related = [], array $extra = []): void Http::assertNothingSent(); - finishRefreshes($screen)->assertSee('Closest match')->input('reply-input', 'A draft'); + openRelated(finishRefreshes($screen))->assertSee('Closest match')->input('reply-input', 'A draft'); expect(collect(Http::recorded())->filter(fn (array $sent): bool => str_ends_with($sent[0]->url(), '/related')))->toHaveCount(1); }); @@ -84,7 +128,7 @@ function serveRelatedThread(array $related = [], array $extra = []): void keep('commits/c1/related', ['data' => [commitJson(['id' => 'c9', 'body' => 'Old match'])]]); serveRelatedThread([commitJson(['id' => 'c3', 'body' => 'Fresh match'])]); - $screen = Native::visit('/log/commits/c1')->assertSee('Old match'); + $screen = openRelated(Native::visit('/log/commits/c1'))->assertSee('Old match'); finishRefreshes($screen)->assertSee('Fresh match')->assertDontSee('Old match'); @@ -128,7 +172,7 @@ function serveRelatedThread(array $related = [], array $extra = []): void 'GET /api/v1/commits/c9/replies' => [pageJson([replyJson(['id' => 'r9', 'parent_id' => 'c9', 'body' => 'Answer to the match'])])], ]); - Native::visit("/{$tab}/commits/c1") + openRelated(Native::visit("/{$tab}/commits/c1")) ->tap($ref) ->assertNavigatedTo("/{$tab}/commits/c9") ->follow() @@ -146,7 +190,7 @@ function serveRelatedThread(array $related = [], array $extra = []): void 'POST /api/v1/commits/c9/star' => [['data' => [...$related, 'starred' => true, 'stars_count' => 1]]], ]); - $screen = Native::visit('/log/commits/c1')->tap('star-c9'); + $screen = openRelated(Native::visit('/log/commits/c1'))->tap('star-c9'); expect($screen->instance()->related[0]->starred)->toBeTrue() ->and(kept('commits/c1/related')['data'][0]['starred'])->toBeTrue() @@ -158,7 +202,7 @@ function serveRelatedThread(array $related = [], array $extra = []): void 'POST /api/v1/commits/c9/star' => [['message' => 'Cannot star now.'], 422], ]); - $screen = Native::visit('/log/commits/c1')->tap('star-c9'); + $screen = openRelated(Native::visit('/log/commits/c1'))->tap('star-c9'); expect($screen->instance()->related[0]->starred)->toBeFalse() ->and(kept('commits/c1/related')['data'][0]['starred'])->toBeFalse(); @@ -169,8 +213,67 @@ function serveRelatedThread(array $related = [], array $extra = []): void keep('commits/c1', commitPageJson(commitJson(['id' => 'c1', 'body' => 'The focused commit']))); keep('commits/c1/related', ['data' => [commitJson(['id' => 'c9', 'body' => 'Closest match'])]]); - $screen = Native::visit('/log/commits/c1')->assertSee('Closest match'); + $screen = openRelated(Native::visit('/log/commits/c1'))->assertSee('Closest match'); app(ResponseCache::class)->commitDeleted('c9'); $screen->call('onResume')->assertDontSee('Closest match')->assertDontSee('Related commits'); }); + +it('keeps related commits closed under a header with their count until it is tapped', function (string $platform) { + serveRelatedThread([ + commitJson(['id' => 'c9', 'body' => 'Closest match']), + commitJson(['id' => 'c3', 'body' => 'Next match']), + ]); + + $screen = Native::visit('/log/commits/c1', platform: $platform) + ->assertSee('Related commits') + ->assertDontSee('Closest match') + ->assertDontSee('Next match'); + + expect(childRefs($screen, 'related-commits'))->toBe(['related-commits-toggle']) + ->and(nodeByRef($screen, 'related-commits-count')['props']['text'])->toBe('2') + ->and(nodeByRef($screen, 'related-commits-toggle')['props']['a11y_label'] ?? null)->toBe('2 related commits') + ->and(nodeByRef($screen, 'related-commits-chevron')['props']['rotate'] ?? 0.0)->toEqual(0.0); + + openRelated($screen)->assertSee('Closest match')->assertSee('Next match'); + + expect(nodeByRef($screen, 'related-commits-chevron')['props']['rotate'])->toEqual(90.0); + + landBeats($screen->tap('related-commits-toggle'))->assertDontSee('Closest match')->assertSee('Related commits'); + + expect(nodeByRef($screen, 'related-commits-chevron')['props']['rotate'] ?? 0.0)->toEqual(0.0); +})->with(['ios', 'android']); + +it('fades related commits in one after another as they open, and out together as they close', function () { + holdRefreshes(); + serveRelatedThread([ + commitJson(['id' => 'c9', 'body' => 'Closest match']), + commitJson(['id' => 'c3', 'body' => 'Next match']), + ]); + + $screen = finishRefreshes(Native::visit('/log/commits/c1', platform: 'ios')); + + // Drawn see-through and nudged up first, with the animation each eases in by, the second a beat later. + $screen->tap('related-commits-toggle'); + expect(nodeByRef($screen, 'related-c9')['style']['opacity'] ?? null)->toBe(0.0) + ->and(nodeByRef($screen, 'related-c9')['props']['translate-y'] ?? null)->toBe(-8.0) + ->and(nodeByRef($screen, 'related-c9')['props']['animate-duration'] ?? null)->toBe(220.0) + ->and(nodeByRef($screen, 'related-c9')['props']['animate-delay'] ?? 0.0)->toEqual(0.0) + ->and(nodeByRef($screen, 'related-c3')['props']['animate-delay'] ?? null)->toEqual(40.0) + ->and(nodeByRef($screen, 'related-commits-chevron')['props']['rotate'])->toEqual(90.0) + ->and(nodeByRef($screen, 'related-commits-chevron')['props']['animate-duration'] ?? null)->toBe(220.0); + + landBeats($screen); + expect(nodeByRef($screen, 'related-c9')['style']['opacity'] ?? 1.0)->toBe(1.0) + ->and(nodeByRef($screen, 'related-c9')['props']['translate-y'] ?? null)->toBe(0.0); + + // Closing fades them out together, chevron back first, and they go once that's done. A tap meanwhile does nothing. + $screen->tap('related-commits-toggle')->tap('related-commits-toggle')->assertSee('Closest match'); + expect(nodeByRef($screen, 'related-c9')['style']['opacity'] ?? null)->toBe(0.0) + ->and(nodeByRef($screen, 'related-c3')['props']['animate-delay'] ?? 0.0)->toEqual(0.0) + ->and(nodeByRef($screen, 'related-commits-chevron')['props']['rotate'] ?? 0.0)->toEqual(0.0); + + landBeats($screen)->assertDontSee('Closest match'); + expect($screen->instance()->relatedShown)->toBeFalse() + ->and($screen->instance()->relatedFaded)->toBeFalse(); +});