diff --git a/src/actions/upload.ts b/src/actions/upload.ts index fb9aaef1..341776f9 100644 --- a/src/actions/upload.ts +++ b/src/actions/upload.ts @@ -6,7 +6,7 @@ import {type Observable, concat, defer, from, of, throwError} from 'rxjs' import {catchError, mergeMap, mergeMapTo, switchMap} from 'rxjs/operators' import {createUpChunkObservable} from '../clients/upChunkObservable' -import type {MuxAsset, Config} from '../util/types' +import type {Config, MuxAsset} from '../util/types' import {getAsset} from './assets' import {testSecretsObservable} from './secrets' diff --git a/src/components/ConfigContext.tsx b/src/components/ConfigContext.tsx deleted file mode 100644 index bbbbd061..00000000 --- a/src/components/ConfigContext.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import React, {createContext, useContext} from 'react' - -import type {Config} from '../util/types' - -const ConfigContext = createContext(null) - -export function useConfig() { - return useContext(ConfigContext) -} diff --git a/src/components/ConfigureApi.tsx b/src/components/ConfigureApi.tsx index fefb14d7..a9754986 100644 --- a/src/components/ConfigureApi.tsx +++ b/src/components/ConfigureApi.tsx @@ -106,7 +106,7 @@ function ConfigureApi({secrets, setDialogState}: Props) { }, [firstField]) return ( - } width={1}> + } width={0}>
diff --git a/src/components/Input.styles.tsx b/src/components/Input.styles.tsx deleted file mode 100644 index 7d5b4cac..00000000 --- a/src/components/Input.styles.tsx +++ /dev/null @@ -1,6 +0,0 @@ -import {FormField} from 'sanity/form' -import styled from 'styled-components' - -export const StyledFormField = styled(FormField)` - display: inline-block; -` diff --git a/src/components/Input.tsx b/src/components/Input.tsx index 38c1177d..d7eba213 100644 --- a/src/components/Input.tsx +++ b/src/components/Input.tsx @@ -1,15 +1,15 @@ import React, {memo} from 'react' import {useClient} from 'sanity' -import {useDocumentPreviewStore} from 'sanity/_unstable' import {useAssetDocumentValues} from '../hooks/useAssetDocumentValues' import {useDialogState} from '../hooks/useDialogState' import {useMuxPolling} from '../hooks/useMuxPolling' import {useSecretsDocumentValues} from '../hooks/useSecretsDocumentValues' import type {Config, MuxInputProps} from '../util/types' -import InputLegacy from './__legacy__Input' +import Uploader from './__legacy__Uploader' import ConfigureApi from './ConfigureApi' import {InputFallback} from './Input.styled' +import Onboard from './Onboard' export interface InputProps extends MuxInputProps { config: Config @@ -39,16 +39,20 @@ const Input = (props: InputProps) => { ) : ( <> - + {secretDocumentValues.value.needsSetup && !assetDocumentValues.value ? ( + + ) : ( + + )} + {dialogState === 'secrets' && ( setDialogState('secrets'), [setDialogState]) + + return ( + <> +
+ + + + +
+ +
+
+ + + Upload and preview videos directly from your studio. + + + +
+ + ) +} diff --git a/src/components/Player.tsx b/src/components/Player.tsx index 06429e88..8fe4f95c 100644 --- a/src/components/Player.tsx +++ b/src/components/Player.tsx @@ -1,5 +1,5 @@ import {type PlaybackEngine, generatePlayerInitTime, initialize} from '@mux-elements/playback-core' -import {Card, Stack, Text} from '@sanity/ui' +import {Card, Text} from '@sanity/ui' import { MediaControlBar, MediaController, @@ -71,7 +71,6 @@ const MuxVideo = ({asset, buttons, readOnly, onChange, dialogState, setDialogSta (event) => setError(event.currentTarget.error), [] ) - const [isDeletedOnMux, setDeletedOnMux] = useState(false) const playRef = useRef(null) const muteRef = useRef(null) const video = useRef(null) @@ -109,23 +108,24 @@ const MuxVideo = ({asset, buttons, readOnly, onChange, dialogState, setDialogSta playbackEngineRef.current = nextPlaybackEngineRef }, [videoSrc, isLoading, playerInitTime]) + useEffect(() => { + if (asset?.status === 'errored') { + handleCancelUpload() + // eslint-disable-next-line no-warning-comments + // @TODO use better error handling + throw new Error(asset.data?.errors?.messages?.join(' ')) + } + }, [asset.data?.errors?.messages, asset?.status, handleCancelUpload]) + + if (error) { + // @TODO better error handling + throw error + } + if (!asset || !asset.status) { return null } - /* - if (assetDocument && assetDocument.status === 'errored') { - // eslint-disable-next-line no-warning-comments - // todo: use client.observable - return this.handleRemoveVideo().then(() => { - this.setState({ - isLoading: false, - error: new Error(assetDocument.data?.errors?.messages?.join(' ')), - }) - }) - } -// */ - if (isLoading) { return ( - {error && ( - - - There was an error loading this video ({error.type}). - {isDeletedOnMux && The video is deleted on Mux} - - - )} - {isPreparingStaticRenditions && ( void -} -export default function SetupButton({ - onClose, - onSave, - onSetup, - isLoading, - showSetup, - needsSetup, - secrets, -}: Props) { - const renderSetup = !isLoading && showSetup - return ( - -
- ) - } - return ( - - - {message} - - - ) -} - interface UploadProgressProps { progress: number error?: Error | null @@ -98,6 +68,7 @@ const cmdKey = 91 const UploadCardWithFocusRing = withFocusRing(Card) interface UploadCardProps { + tone?: CardTone children: React.ReactNode onPaste: React.ClipboardEventHandler onFocus: React.FocusEventHandler @@ -109,7 +80,7 @@ interface UploadCardProps { } export const UploadCard = forwardRef( ( - {children, onPaste, onFocus, onBlur, onDrop, onDragEnter, onDragLeave, onDragOver}, + {children, tone, onPaste, onFocus, onBlur, onDrop, onDragEnter, onDragLeave, onDragOver}, forwardedRef ) => { const ctrlDown = useRef(false) @@ -131,10 +102,11 @@ export const UploadCard = forwardRef( return ( { /> ) } - -interface UploadButtonGridProps { - asset: VideoAssetDocument - getCurrentTime: () => number - onBrowse: () => void - onRemove: () => void - onUpload: FileInputButtonProps['onSelect'] -} -export const UploadButtonGrid = ({ - asset, - getCurrentTime, - onBrowse, - onRemove, - onUpload, -}: UploadButtonGridProps) => { - const [open, setOpen] = useState<'thumbnail' | false>(false) - const handleClose = useCallback(() => setOpen(false), []) - - return ( - <> - - -