Skip to content

Commit

Permalink
refactor: ready for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Jul 29, 2022
1 parent 92f8f1b commit 7edb278
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 37 deletions.
21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,13 @@ More information for this feature of the plugin can be found on Mux's [documenta
To enable [static MP4 renditions](https://docs.mux.com/guides/video/enable-static-mp4-renditions), add `mp4_support: 'standard'` to the `options` of your `mux.video` schema type.

js```
{
title: "Video blog post",
name: "videoBlogPost",
type: "document",
fields: [
{ title: "Title", name: "title", type: "string" },
{
title: "Video file",
name: "video",
type: "mux.video",
options: {mp4_support: 'standard'}
}
]
}
import {muxInput} from 'sanity-plugin-mux-input'

export deafult createConfig({
plugins: [muxInput({
mp4_support: "standard"
})]
})

```
Expand Down
2 changes: 1 addition & 1 deletion src/components/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const MuxVideo = ({asset, buttons, readOnly, onChange, dialogState, setDialogSta
progress={100}
filename={asset?.filename}
text={(isLoading !== true && isLoading) || 'Waiting for Mux to complete the file'}
onCancel={readOnly ? undefined : () => handleCancelUpload().catch(setError)}
onCancel={readOnly ? undefined : () => handleCancelUpload()}
/>
)
}
Expand Down
33 changes: 11 additions & 22 deletions src/components/Preview.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
import React, {useMemo} from 'react'
import React from 'react'
import {SanityDefaultPreview} from 'sanity/_unstable'

import type {MuxAsset, VideoAssetDocument} from '../util/types'
import {useAssetDocumentValues} from '../hooks/useAssetDocumentValues'
import {VideoThumbnail} from './VideoSource.styled'

export interface MuxVideoPreviewProps {
value: {
playbackId?: VideoAssetDocument['playbackId']
status?: VideoAssetDocument['status']
thumbTime?: VideoAssetDocument['thumbTime']
filename?: VideoAssetDocument['filename']
duration?: MuxAsset['duration']
playbackIds?: MuxAsset['playback_ids']
asset: {
_type: 'reference'
_ref: string
}
}
}
const MuxVideoPreview = ({value = {}}: MuxVideoPreviewProps) => {
const asset = useMemo(() => {
if (!value || value.status !== 'ready' || !value.playbackId || !value.playbackIds) return null
const MuxVideoPreview = ({value}: MuxVideoPreviewProps) => {
const assetDocumentValues = useAssetDocumentValues(value?.asset!)

return {
playbackId: value.playbackId,
status: value.status,
thumbTime: value.thumbTime,
filename: value.filename,
duration: value.duration,
data: {playback_ids: value.playbackIds},
}
}, [value])
if (asset) {
return <VideoThumbnail asset={asset} width={640} />
if (assetDocumentValues.value) {
return <VideoThumbnail asset={assetDocumentValues.value} width={640} />
}

// @ts-expect-error
const {filename, playbackId, status} = value ?? {}

return (
Expand Down
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const muxInput = createPlugin<Partial<Config> | void>((userConfig) => {
if (isMuxInputPreviewProps(props)) {
return (
<AspectRatioCard>
{/* @ts-expect-error */}
<Preview {...props} />
</AspectRatioCard>
)
Expand Down

0 comments on commit 7edb278

Please sign in to comment.