The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { useGT } from "gt-react-native"; |
| 2 | import { createContext, useContext } from "react"; |
| 3 | import { MediaVideoPlayer } from "../../components/MediaVideoPlayer"; |
| 4 | import { useAssetUrlState, useRefreshAssetUrl } from "../../state/assets"; |
| 5 | import { |
| 6 | mediaVideoPreviewUri, |
| 7 | mediaVideoThumbnailKey, |
| 8 | type MediaVideoPreviewSource, |
| 9 | } from "../../lib/videoPreviewSource"; |
| 10 | |
| 11 | export const ThreadMediaVisibleContext = createContext(false); |
| 12 | /** Asks the feed to keep this row out of list recycling while its media holds playback state. */ |
| 13 | export const ThreadMediaRetainContext = createContext<(retained: boolean) => void>(() => {}); |
| 14 | |
| 15 | export function ThreadMarkdownVideo(props: { |
| 16 | readonly source: MediaVideoPreviewSource; |
| 17 | /** Keeps the player and its poster across source changes that show the same video. */ |
| 18 | readonly thumbnailKey?: string; |
| 19 | readonly thumbnailVisible?: boolean; |
| 20 | readonly onPlaybackStart?: () => void; |
| 21 | readonly borderRadius?: number; |
| 22 | }) { |
| 23 | const gt = useGT(); |
| 24 | const { source } = props; |
| 25 | const feedVisible = useContext(ThreadMediaVisibleContext); |
| 26 | const visible = props.thumbnailVisible ?? feedVisible; |
| 27 | const thumbnailKey = props.thumbnailKey ?? mediaVideoThumbnailKey(source); |
| 28 | const asset = useAssetUrlState( |
| 29 | "environmentId" in source ? source.environmentId : null, |
| 30 | "resource" in source ? source.resource : null, |
| 31 | ); |
| 32 | const refreshAssetUrl = useRefreshAssetUrl( |
| 33 | "environmentId" in source ? source.environmentId : null, |
| 34 | "resource" in source ? source.resource : null, |
| 35 | ); |
| 36 | const uri = mediaVideoPreviewUri(source, asset._tag === "Success" ? asset.url : null); |
| 37 | return ( |
| 38 | <MediaVideoPlayer |
| 39 | key={thumbnailKey} |
| 40 | uri={uri} |
| 41 | resolvePlaybackUri={ |
| 42 | "resource" in source |
| 43 | ? async () => mediaVideoPreviewUri(source, await refreshAssetUrl()) |
| 44 | : undefined |
| 45 | } |
| 46 | name={source.name} |
| 47 | thumbnailKey={thumbnailKey} |
| 48 | thumbnailVisible={visible} |
| 49 | visible={visible} |
| 50 | onPlaybackStart={props.onPlaybackStart} |
| 51 | unavailable={"resource" in source && asset._tag === "Failure"} |
| 52 | unavailableDetail={ |
| 53 | asset._tag === "Failure" && asset.reason === "missing-file-access" |
| 54 | ? gt("This connection cannot read host files. Pair again with a new link to view it.") |
| 55 | : undefined |
| 56 | } |
| 57 | actionsSource={source.actionsSource} |
| 58 | borderRadius={props.borderRadius} |
| 59 | /> |
| 60 | ); |
| 61 | } |