3
3
AppBskyEmbedImages ,
4
4
AppBskyEmbedRecord ,
5
5
AppBskyEmbedRecordWithMedia ,
6
+ AppBskyEmbedVideo ,
6
7
AppBskyFeedDefs ,
7
8
AppBskyFeedPost ,
8
9
AppBskyGraphDefs ,
@@ -14,6 +15,7 @@ import {ComponentChildren, h} from 'preact'
14
15
import { useMemo } from 'preact/hooks'
15
16
16
17
import infoIcon from '../../assets/circleInfo_stroke2_corner0_rounded.svg'
18
+ import playIcon from '../../assets/play_filled_corner2_rounded.svg'
17
19
import starterPackIcon from '../../assets/starterPack.svg'
18
20
import { CONTENT_LABELS , labelsToInfo } from '../labels'
19
21
import { getRkey } from '../utils'
@@ -160,7 +162,12 @@ export function Embed({
160
162
return null
161
163
}
162
164
163
- // Case 4: Record with media
165
+ // Case 4: Video
166
+ if ( AppBskyEmbedVideo . isView ( content ) ) {
167
+ return < VideoEmbed content = { content } />
168
+ }
169
+
170
+ // Case 5: Record with media
164
171
if (
165
172
AppBskyEmbedRecordWithMedia . isView ( content ) &&
166
173
AppBskyEmbedRecord . isViewRecord ( content . record . record )
@@ -354,6 +361,31 @@ function GenericWithImageEmbed({
354
361
)
355
362
}
356
363
364
+ // just the thumbnail and a play button
365
+ function VideoEmbed ( { content} : { content : AppBskyEmbedVideo . View } ) {
366
+ let aspectRatio = 1
367
+
368
+ if ( content . aspectRatio ) {
369
+ const { width, height} = content . aspectRatio
370
+ aspectRatio = clamp ( width / height , 1 / 1 , 3 / 1 )
371
+ }
372
+
373
+ return (
374
+ < div
375
+ className = "w-full overflow-hidden rounded-lg aspect-square"
376
+ style = { { aspectRatio : `${ aspectRatio } / 1` } } >
377
+ < img
378
+ src = { content . thumbnail }
379
+ alt = { content . alt }
380
+ className = "object-cover size-full"
381
+ />
382
+ < div className = "size-24 absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-full bg-black/50 flex items-center justify-center" >
383
+ < img src = { playIcon } className = "object-cover size-3/5" />
384
+ </ div >
385
+ </ div >
386
+ )
387
+ }
388
+
357
389
function StarterPackEmbed ( {
358
390
content,
359
391
} : {
@@ -410,3 +442,7 @@ function getStarterPackHref(
410
442
const handleOrDid = starterPack . creator . handle || starterPack . creator . did
411
443
return `/starter-pack/${ handleOrDid } /${ rkey } `
412
444
}
445
+
446
+ function clamp ( num : number , min : number , max : number ) {
447
+ return Math . max ( min , Math . min ( num , max ) )
448
+ }
0 commit comments