Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 2,046 Bytes
e40bd21 f42b4a1 e40bd21 3d4392e e40bd21 f42b4a1 e40bd21 ac7030c e40bd21 3d4392e e40bd21 ac7030c e40bd21 3d4392e e40bd21 ac7030c e40bd21 ac7030c e40bd21 ac7030c e40bd21 ac7030c e40bd21 ac7030c e40bd21 ac7030c e40bd21 3d4392e ac7030c e40bd21 ac7030c e40bd21 ac7030c e40bd21 ac7030c e40bd21 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
"use client"
import { useEffect, useTransition } from "react"
import { useStore } from "@/app/state/useStore"
import { cn } from "@/lib/utils/cn"
import { MediaPlayer } from "@/components/interface/media-player"
import { countNewMediaView } from "@/app/api/actions/stats"
export function PublicMediaEmbedView() {
const [_pending, startTransition] = useTransition()
// current time in the media
// note: this is used to *set* the current time, not to read it
// EDIT: you know what, let's do this the dirty way for now
// const [desiredCurrentTime, setDesiredCurrentTime] = useState()
const media = useStore(s => s.publicMedia)
const mediaId = `${media?.id || ""}`
const setPublicMedia = useStore(s => s.setPublicMedia)
// we inject the current mediaId in the URL, if it's not already present
// this is a hack for Hugging Face iframes
useEffect(() => {
const queryString = new URL(location.href).search
const searchParams = new URLSearchParams(queryString)
if (mediaId) {
// "v" is the legacy parameter, for when we only worked on videos
if (searchParams.get("m") !== mediaId || searchParams.get("v") !== mediaId) {
console.log(`current mediaId "${mediaId}" isn't set in the URL query params.. TODO we should set it`)
// searchParams.set("v", mediaoId)
// location.search = searchParams.toString()
}
} else {
// searchParams.delete("v")
// location.search = searchParams.toString()
}
}, [mediaId])
useEffect(() => {
startTransition(async () => {
if (!media || !media.id) {
return
}
const numberOfViews = await countNewMediaView(mediaId)
setPublicMedia({
...media,
numberOfViews
})
})
}, [media?.id])
if (!media) { return null }
return (
<div className={cn(
`w-full`,
`flex flex-col`
)}>
<MediaPlayer
className="rounded-xl overflow-hidden"
media={media}
enableShortcuts={false}
/>
</div>
)
}
|