Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions resources/views/native/partials/commit-media.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{--
What hangs under a commit's body on the web: its images, its poll, the commit it quotes, then the link preview, or
for a YouTube link the player devnull offers (see partials/commit-embed). Other players keep the preview for now.
for a YouTube link the player devnull offers (see partials/commit-embed). Other players keep the preview for now, and
so does a video under the commit's own images, as a compact row with no picture of its own.
A Nata Nu//ers high score has its card first, which the web doesn't draw (see partials/score-card).
A reply in a thread shows only its images and link preview ($withEmbeds false), as the web's thread does.
Images hold their space at their aspect ratio on a wash, so one that fails to load leaves the row as it was. Each is
Expand Down Expand Up @@ -42,23 +43,33 @@
@include('native.partials.quoted-commit')
@endif

@if ($commit->linkPreview?->embed?->isYouTube())
@if ($images === [] && $commit->linkPreview?->embed?->isYouTube())
@include('native.partials.commit-embed', ['preview' => $commit->linkPreview])
@elseif ($commit->linkPreview?->isReady())
@php($preview = $commit->linkPreview)
{{-- A compact row, not a card: a small image, the mono site, then the title and description. --}}
<native:pressable ref="link-preview-{{ $commit->id }}" @press="openLinkPreview('{{ $commit->id }}')" class="w-full mt-2" a11y-label="{{ $preview->title }}, {{ $preview->site() }}">
{{-- A compact row, not a card: a small image, the mono site, then the title and description. Under the commit's own
images it has no image of its own, and a video is this row rather than its player. A YouTube video's row names
the video and its channel, as its card does (see VideoDetails), rather than YouTube's own page title and blurb. --}}
@if ($preview->embed?->isYouTube())
@php($card = \App\Devnull\VideoDetails::card($preview))
@php($rowTitle = $card['title'] ?? $preview->title)
@php($rowDescription = $card['author'])
@else
@php($rowTitle = $preview->title)
@php($rowDescription = $preview->description)
@endif
<native:pressable ref="link-preview-{{ $commit->id }}" @press="openLinkPreview('{{ $commit->id }}')" class="w-full mt-2" a11y-label="{{ $rowTitle }}, {{ $preview->site() }}">
<native:row class="w-full gap-3 p-2 items-center rounded-lg border border-theme-hairline">
@if ($preview->imageUrl)
@if ($preview->imageUrl && $images === [])
<native:column :width="56" :height="56" class="rounded-md bg-theme-wash">
<native:image :src="\App\Devnull\ImageCache::src($preview->imageUrl)" :width="56" :height="56" :fit="2" class="rounded-md" />
</native:column>
@endif
<native:column class="flex-1 gap-[2] pr-1">
<native:text font="mono" class="text-[13px] text-theme-ink-muted" :max-lines="1">{{ $preview->site() }}</native:text>
<native:text font="semibold" class="text-sm leading-snug text-theme-ink" :max-lines="2">{{ $preview->title }}</native:text>
@if ($preview->description)
<native:text class="text-[13px] leading-snug text-theme-ink-muted" :max-lines="1">{{ $preview->description }}</native:text>
<native:text font="semibold" class="text-sm leading-snug text-theme-ink" :max-lines="2">{{ $rowTitle }}</native:text>
@if ($rowDescription)
<native:text class="text-[13px] leading-snug text-theme-ink-muted" :max-lines="1">{{ $rowDescription }}</native:text>
@endif
</native:column>
</native:row>
Expand Down
74 changes: 74 additions & 0 deletions tests/Feature/Screens/CommitEmbedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,77 @@ function imagesIn(array $node): array
expect(findNode($screen->tree(), fn (array $node): bool => ($node['ref'] ?? null) === 'embed-play-c1'))->toBeNull()
->and(nodeByRef($screen, 'link-preview-c1'))->not->toBeEmpty();
});

it("shows a video as a compact link row with no picture under the commit's own images", function () {
Http::fake(['www.youtube.com/oembed*' => Http::response(null, 404), 'devnull.test/*' => Http::response(pageJson([commitJson([
'id' => 'c1',
'body' => 'Watch https://www.youtube.com/watch?v=E9Zx6rx0bWk',
'images' => [['id' => 7, 'width' => 400, 'height' => 300, 'description' => null, 'url' => 'https://img.test/7']],
'link_preview' => [
'url' => 'https://youtu.be/E9Zx6rx0bWk',
'title' => 'The episode',
'description' => null,
'image_url' => 'https://i.ytimg.com/vi/E9Zx6rx0bWk/hqdefault.jpg',
'site_name' => 'YouTube',
'embed' => [
'provider' => 'YouTube',
'kind' => 'video',
'src' => 'https://www.youtube-nocookie.com/embed/E9Zx6rx0bWk?autoplay=1',
'aspect_ratio' => '16 / 9',
'height' => null,
'poster' => 'https://i.ytimg.com/vi/E9Zx6rx0bWk/hqdefault.jpg',
],
],
])]))]);

$screen = Native::visit('/log')->assertSee('The episode');

$screen->assertMissingElement('pressable', fn (array $node): bool => ($node['ref'] ?? null) === 'embed-play-c1');

expect(imagesIn(nodeByRef($screen, 'link-preview-c1')))->toBe([])
->and(array_column(array_column(imagesIn(nodeByRef($screen, 'image-7')), 'props'), 'src'))->toHaveCount(1);
});

it("leaves a link preview's picture out under the commit's own images", function () {
Http::fake(['devnull.test/*' => Http::response(pageJson([commitJson([
'id' => 'c1',
'body' => 'Read https://example.com/post',
'images' => [['id' => 7, 'width' => 400, 'height' => 300, 'description' => null, 'url' => 'https://img.test/7']],
'link_preview' => ['url' => 'https://example.com/post', 'title' => 'The post', 'description' => null, 'image_url' => 'https://example.com/og.png', 'site_name' => null],
])]))]);

$screen = Native::visit('/log')->assertSee('The post');

expect(imagesIn(nodeByRef($screen, 'link-preview-c1')))->toBe([]);
});

it("names the video and its channel in the compact row under the commit's own images", function () {
VideoDetails::remember('https://youtu.be/bod7JDMeF-0', 'Side Projects Got Me Hired', 'Shruti Balasa');

Http::fake(['devnull.test/*' => Http::response(pageJson([commitJson([
'id' => 'c1',
'body' => 'Watch https://youtu.be/bod7JDMeF-0',
'images' => [['id' => 7, 'width' => 400, 'height' => 300, 'description' => null, 'url' => 'https://img.test/7']],
'link_preview' => [
'url' => 'https://youtu.be/bod7JDMeF-0',
'title' => '- YouTube',
'description' => 'Enjoy the videos and music you love, upload original content.',
'image_url' => null,
'site_name' => 'YouTube',
'embed' => [
'provider' => 'YouTube',
'kind' => 'video',
'src' => 'https://www.youtube-nocookie.com/embed/bod7JDMeF-0?autoplay=1',
'aspect_ratio' => '16 / 9',
'height' => null,
'poster' => null,
],
],
])]))]);

Native::visit('/log')
->assertSee('Side Projects Got Me Hired')
->assertSee('Shruti Balasa')
->assertDontSee('- YouTube')
->assertDontSee('Enjoy the videos and music you love');
});
Loading