This commit is contained in:
Hailey
2024-09-03 14:26:05 -07:00
parent 0bd0146efb
commit fe38c751d1
2 changed files with 185 additions and 138 deletions
+12 -6
View File
@@ -25,7 +25,7 @@ type Action =
| {type: 'SetDimensions'; width: number; height: number} | {type: 'SetDimensions'; width: number; height: number}
| {type: 'SetVideo'; video: CompressedVideo} | {type: 'SetVideo'; video: CompressedVideo}
| {type: 'SetJobStatus'; jobStatus: AppBskyVideoDefs.JobStatus} | {type: 'SetJobStatus'; jobStatus: AppBskyVideoDefs.JobStatus}
| {type: 'SetBlobRef'; blobRef: BlobRef} | {type: 'SetComplete'; blobRef: BlobRef}
export interface State { export interface State {
status: Status status: Status
@@ -36,6 +36,7 @@ export interface State {
blobRef?: BlobRef blobRef?: BlobRef
error?: string error?: string
abortController: AbortController abortController: AbortController
pendingPublish?: {blobRef: BlobRef; mutableProcessed: boolean}
} }
function reducer(queryClient: QueryClient) { function reducer(queryClient: QueryClient) {
@@ -77,8 +78,15 @@ function reducer(queryClient: QueryClient) {
updatedState = {...state, video: action.video, status: 'uploading'} updatedState = {...state, video: action.video, status: 'uploading'}
} else if (action.type === 'SetJobStatus') { } else if (action.type === 'SetJobStatus') {
updatedState = {...state, jobStatus: action.jobStatus} updatedState = {...state, jobStatus: action.jobStatus}
} else if (action.type === 'SetBlobRef') { } else if (action.type === 'SetComplete') {
updatedState = {...state, blobRef: action.blobRef, status: 'done'} updatedState = {
...state,
pendingPublish: {
blobRef: action.blobRef,
mutableProcessed: false,
},
status: 'done',
}
} }
return updatedState return updatedState
} }
@@ -86,7 +94,6 @@ function reducer(queryClient: QueryClient) {
export function useUploadVideo({ export function useUploadVideo({
setStatus, setStatus,
onSuccess,
}: { }: {
setStatus: (status: string) => void setStatus: (status: string) => void
onSuccess: () => void onSuccess: () => void
@@ -112,10 +119,9 @@ export function useUploadVideo({
}, },
onSuccess: blobRef => { onSuccess: blobRef => {
dispatch({ dispatch({
type: 'SetBlobRef', type: 'SetComplete',
blobRef, blobRef,
}) })
onSuccess()
}, },
}) })
+44 -3
View File
@@ -190,6 +190,7 @@ export const ComposePost = observer(function ComposePost({
} }
}, },
}) })
const [publishOnUpload, setPublishOnUpload] = useState(false) const [publishOnUpload, setPublishOnUpload] = useState(false)
const {extLink, setExtLink} = useExternalLinkFetch({setQuote, setError}) const {extLink, setExtLink} = useExternalLinkFetch({setQuote, setError})
@@ -303,7 +304,8 @@ export const ComposePost = observer(function ComposePost({
return false return false
}, [gallery.needsAltText, extLink, extGif, requireAltTextEnabled]) }, [gallery.needsAltText, extLink, extGif, requireAltTextEnabled])
const onPressPublish = async (finishedUploading?: boolean) => { const onPressPublish = React.useCallback(
async (finishedUploading?: boolean) => {
if (isProcessing || graphemeLength > MAX_GRAPHEME_LENGTH) { if (isProcessing || graphemeLength > MAX_GRAPHEME_LENGTH) {
return return
} }
@@ -353,9 +355,9 @@ export const ComposePost = observer(function ComposePost({
postgate, postgate,
onStateChange: setProcessingState, onStateChange: setProcessingState,
langs: toPostLanguages(langPrefs.postLanguage), langs: toPostLanguages(langPrefs.postLanguage),
video: videoUploadState.blobRef video: videoUploadState.pendingPublish?.blobRef
? { ? {
blobRef: videoUploadState.blobRef, blobRef: videoUploadState.pendingPublish.blobRef,
altText: videoAltText, altText: videoAltText,
captions: captions, captions: captions,
aspectRatio: videoUploadState.asset aspectRatio: videoUploadState.asset
@@ -443,7 +445,46 @@ export const ComposePost = observer(function ComposePost({
? _(msg`Your reply has been published`) ? _(msg`Your reply has been published`)
: _(msg`Your post has been published`), : _(msg`Your post has been published`),
) )
},
[
_,
agent,
captions,
extLink,
gallery.images,
gallery.isEmpty,
gallery.size,
graphemeLength,
isAltTextRequiredAndMissing,
isProcessing,
labels,
langPrefs.postLanguage,
onClose,
onPost,
postgate,
quote,
quoteCount,
replyTo,
richtext.text,
setExtLink,
setLangPrefs,
threadgateAllowUISettings,
track,
videoAltText,
videoUploadState.asset,
videoUploadState.pendingPublish,
videoUploadState.status,
],
)
React.useEffect(() => {
if (videoUploadState.pendingPublish && publishOnUpload) {
if (!videoUploadState.pendingPublish.mutableProcessed) {
videoUploadState.pendingPublish.mutableProcessed = true
onPressPublish(true)
} }
}
}, [onPressPublish, publishOnUpload, videoUploadState.pendingPublish])
const canPost = useMemo( const canPost = useMemo(
() => graphemeLength <= MAX_GRAPHEME_LENGTH && !isAltTextRequiredAndMissing, () => graphemeLength <= MAX_GRAPHEME_LENGTH && !isAltTextRequiredAndMissing,