Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Rename some files and variables (#5587)

* Move composer reducers together

* videoUploadState -> videoState

* Inline videoDispatch

authored by

dan and committed by
GitHub
2aa365b5 03704e2b

+64 -81
+1 -1
src/lib/api/index.ts
··· 24 24 threadgateAllowUISettingToAllowRecordValue, 25 25 writeThreadgateRecord, 26 26 } from '#/state/queries/threadgate' 27 - import {ComposerState} from '#/view/com/composer/state' 27 + import {ComposerState} from '#/view/com/composer/state/composer' 28 28 import {LinkMeta} from '../link-meta/link-meta' 29 29 import {uploadBlob} from './upload-blob' 30 30
+1 -1
src/lib/media/video/compress.ts
··· 2 2 import {ImagePickerAsset} from 'expo-image-picker' 3 3 4 4 import {SUPPORTED_MIME_TYPES, SupportedMimeTypes} from '#/lib/constants' 5 - import {extToMime} from '#/state/queries/video/util' 6 5 import {CompressedVideo} from './types' 6 + import {extToMime} from './util' 7 7 8 8 const MIN_SIZE_FOR_COMPRESSION = 25 // 25mb 9 9
src/state/queries/video/util.ts src/lib/media/video/util.ts
src/state/queries/video/video-upload.shared.ts src/lib/media/video/upload.shared.ts
+2 -2
src/state/queries/video/video-upload.ts src/lib/media/video/upload.ts
··· 7 7 import {AbortError} from '#/lib/async/cancelable' 8 8 import {ServerError} from '#/lib/media/video/errors' 9 9 import {CompressedVideo} from '#/lib/media/video/types' 10 - import {createVideoEndpointUrl, mimeToExt} from '#/state/queries/video/util' 11 - import {getServiceAuthToken, getVideoUploadLimits} from './video-upload.shared' 10 + import {createVideoEndpointUrl, mimeToExt} from './util' 11 + import {getServiceAuthToken, getVideoUploadLimits} from './upload.shared' 12 12 13 13 export async function uploadVideo({ 14 14 video,
+2 -2
src/state/queries/video/video-upload.web.ts src/lib/media/video/upload.web.ts
··· 7 7 import {AbortError} from '#/lib/async/cancelable' 8 8 import {ServerError} from '#/lib/media/video/errors' 9 9 import {CompressedVideo} from '#/lib/media/video/types' 10 - import {createVideoEndpointUrl, mimeToExt} from '#/state/queries/video/util' 11 - import {getServiceAuthToken, getVideoUploadLimits} from './video-upload.shared' 10 + import {createVideoEndpointUrl, mimeToExt} from './util' 11 + import {getServiceAuthToken, getVideoUploadLimits} from './upload.shared' 12 12 13 13 export async function uploadVideo({ 14 14 video,
+2 -2
src/state/queries/video/video.ts src/view/com/composer/state/video.ts
··· 4 4 import {I18n} from '@lingui/core' 5 5 import {msg} from '@lingui/macro' 6 6 7 + import {createVideoAgent} from '#/lib/media/video/util' 8 + import {uploadVideo} from '#/lib/media/video/upload' 7 9 import {AbortError} from '#/lib/async/cancelable' 8 10 import {compressVideo} from '#/lib/media/video/compress' 9 11 import { ··· 13 15 } from '#/lib/media/video/errors' 14 16 import {CompressedVideo} from '#/lib/media/video/types' 15 17 import {logger} from '#/logger' 16 - import {createVideoAgent} from '#/state/queries/video/util' 17 - import {uploadVideo} from '#/state/queries/video/video-upload' 18 18 19 19 export type VideoAction = 20 20 | {
+54 -66
src/view/com/composer/Composer.tsx
··· 82 82 import {Gif} from '#/state/queries/tenor' 83 83 import {ThreadgateAllowUISetting} from '#/state/queries/threadgate' 84 84 import {threadgateViewToAllowUISetting} from '#/state/queries/threadgate/util' 85 - import {NO_VIDEO, NoVideoState} from '#/state/queries/video/video' 86 - import { 87 - processVideo, 88 - VideoAction, 89 - VideoState, 90 - VideoState as VideoUploadState, 91 - } from '#/state/queries/video/video' 92 85 import {useAgent, useSession} from '#/state/session' 93 86 import {useComposerControls} from '#/state/shell/composer' 94 87 import {ComposerOpts} from '#/state/shell/composer' ··· 123 116 import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times' 124 117 import * as Prompt from '#/components/Prompt' 125 118 import {Text as NewText} from '#/components/Typography' 126 - import {composerReducer, createComposerState} from './state' 119 + import {composerReducer, createComposerState} from './state/composer' 120 + import {NO_VIDEO, NoVideoState, processVideo, VideoState} from './state/video' 127 121 128 122 const MAX_IMAGES = 4 129 123 ··· 200 194 createComposerState, 201 195 ) 202 196 203 - let videoUploadState: VideoState | NoVideoState = NO_VIDEO 197 + let videoState: VideoState | NoVideoState = NO_VIDEO 204 198 if (composerState.embed.media?.type === 'video') { 205 - videoUploadState = composerState.embed.media.video 199 + videoState = composerState.embed.media.video 206 200 } 207 - const videoDispatch = useCallback( 208 - (videoAction: VideoAction) => { 209 - dispatch({type: 'embed_update_video', videoAction}) 210 - }, 211 - [dispatch], 212 - ) 213 201 214 202 const selectVideo = React.useCallback( 215 203 (asset: ImagePickerAsset) => { ··· 217 205 dispatch({type: 'embed_add_video', asset, abortController}) 218 206 processVideo( 219 207 asset, 220 - videoDispatch, 208 + videoAction => dispatch({type: 'embed_update_video', videoAction}), 221 209 agent, 222 210 currentDid, 223 211 abortController.signal, 224 212 _, 225 213 ) 226 214 }, 227 - [_, videoDispatch, agent, currentDid], 215 + [_, agent, currentDid], 228 216 ) 229 217 230 218 // Whenever we receive an initial video uri, we should immediately run compression if necessary ··· 235 223 }, [initVideoUri, selectVideo]) 236 224 237 225 const clearVideo = React.useCallback(() => { 238 - videoUploadState.abortController.abort() 226 + videoState.abortController.abort() 239 227 dispatch({type: 'embed_remove_video'}) 240 - }, [videoUploadState.abortController, dispatch]) 228 + }, [videoState.abortController, dispatch]) 241 229 242 230 const updateVideoDimensions = useCallback( 243 231 (width: number, height: number) => { 244 - videoDispatch({ 245 - type: 'update_dimensions', 246 - width, 247 - height, 248 - signal: videoUploadState.abortController.signal, 232 + dispatch({ 233 + type: 'embed_update_video', 234 + videoAction: { 235 + type: 'update_dimensions', 236 + width, 237 + height, 238 + signal: videoState.abortController.signal, 239 + }, 249 240 }) 250 241 }, 251 - [videoUploadState.abortController, videoDispatch], 242 + [videoState.abortController], 252 243 ) 253 244 254 - const hasVideo = Boolean(videoUploadState.asset || videoUploadState.video) 245 + const hasVideo = Boolean(videoState.asset || videoState.video) 255 246 256 247 const [publishOnUpload, setPublishOnUpload] = useState(false) 257 248 ··· 288 279 graphemeLength > 0 || 289 280 images.length !== 0 || 290 281 extGif || 291 - videoUploadState.status !== 'idle' 282 + videoState.status !== 'idle' 292 283 ) { 293 284 closeAllDialogs() 294 285 Keyboard.dismiss() ··· 303 294 closeAllDialogs, 304 295 discardPromptControl, 305 296 onClose, 306 - videoUploadState.status, 297 + videoState.status, 307 298 ]) 308 299 309 300 useImperativeHandle(cancelRef, () => ({onPressCancel})) ··· 400 391 401 392 if ( 402 393 !finishedUploading && 403 - videoUploadState.asset && 404 - videoUploadState.status !== 'done' 394 + videoState.asset && 395 + videoState.status !== 'done' 405 396 ) { 406 397 setPublishOnUpload(true) 407 398 return ··· 414 405 images.length === 0 && 415 406 !extLink && 416 407 !quote && 417 - videoUploadState.status === 'idle' 408 + videoState.status === 'idle' 418 409 ) { 419 410 setError(_(msg`Did you want to say anything?`)) 420 411 return ··· 442 433 onStateChange: setProcessingState, 443 434 langs: toPostLanguages(langPrefs.postLanguage), 444 435 video: 445 - videoUploadState.status === 'done' 436 + videoState.status === 'done' 446 437 ? { 447 - blobRef: videoUploadState.pendingPublish.blobRef, 438 + blobRef: videoState.pendingPublish.blobRef, 448 439 altText: videoAltText, 449 440 captions: captions, 450 441 aspectRatio: { 451 - width: videoUploadState.asset.width, 452 - height: videoUploadState.asset.height, 442 + width: videoState.asset.width, 443 + height: videoState.asset.height, 453 444 }, 454 445 } 455 446 : undefined, ··· 550 541 setLangPrefs, 551 542 threadgateAllowUISettings, 552 543 videoAltText, 553 - videoUploadState.asset, 554 - videoUploadState.pendingPublish, 555 - videoUploadState.status, 544 + videoState.asset, 545 + videoState.pendingPublish, 546 + videoState.status, 556 547 ], 557 548 ) 558 549 559 550 React.useEffect(() => { 560 - if (videoUploadState.pendingPublish && publishOnUpload) { 561 - if (!videoUploadState.pendingPublish.mutableProcessed) { 562 - videoUploadState.pendingPublish.mutableProcessed = true 551 + if (videoState.pendingPublish && publishOnUpload) { 552 + if (!videoState.pendingPublish.mutableProcessed) { 553 + videoState.pendingPublish.mutableProcessed = true 563 554 onPressPublish(true) 564 555 } 565 556 } 566 - }, [onPressPublish, publishOnUpload, videoUploadState.pendingPublish]) 557 + }, [onPressPublish, publishOnUpload, videoState.pendingPublish]) 567 558 568 559 const canPost = useMemo( 569 560 () => graphemeLength <= MAX_GRAPHEME_LENGTH && !isAltTextRequiredAndMissing, ··· 576 567 const canSelectImages = 577 568 images.length < MAX_IMAGES && 578 569 !extLink && 579 - videoUploadState.status === 'idle' && 580 - !videoUploadState.video 570 + videoState.status === 'idle' && 571 + !videoState.video 581 572 const hasMedia = 582 - images.length > 0 || Boolean(extLink) || Boolean(videoUploadState.video) 573 + images.length > 0 || Boolean(extLink) || Boolean(videoState.video) 583 574 584 575 const onEmojiButtonPress = useCallback(() => { 585 576 openEmojiPicker?.(textInput.current?.getCursorPosition()) ··· 694 685 size="small" 695 686 style={[a.rounded_full, a.py_sm]} 696 687 onPress={() => onPressPublish()} 697 - disabled={ 698 - videoUploadState.status !== 'idle' && publishOnUpload 699 - }> 688 + disabled={videoState.status !== 'idle' && publishOnUpload}> 700 689 <ButtonText style={[a.text_md]}> 701 690 {replyTo ? ( 702 691 <Trans context="action">Reply</Trans> ··· 732 721 )} 733 722 <ErrorBanner 734 723 error={error} 735 - videoUploadState={videoUploadState} 724 + videoState={videoState} 736 725 clearError={() => setError('')} 737 726 clearVideo={clearVideo} 738 727 /> ··· 798 787 style={[a.w_full, a.mt_lg]} 799 788 entering={native(ZoomIn)} 800 789 exiting={native(ZoomOut)}> 801 - {videoUploadState.asset && 802 - (videoUploadState.status === 'compressing' ? ( 790 + {videoState.asset && 791 + (videoState.status === 'compressing' ? ( 803 792 <VideoTranscodeProgress 804 - asset={videoUploadState.asset} 805 - progress={videoUploadState.progress} 793 + asset={videoState.asset} 794 + progress={videoState.progress} 806 795 clear={clearVideo} 807 796 /> 808 - ) : videoUploadState.video ? ( 797 + ) : videoState.video ? ( 809 798 <VideoPreview 810 - asset={videoUploadState.asset} 811 - video={videoUploadState.video} 799 + asset={videoState.asset} 800 + video={videoState.video} 812 801 setDimensions={updateVideoDimensions} 813 802 clear={clearVideo} 814 803 /> ··· 854 843 t.atoms.border_contrast_medium, 855 844 styles.bottomBar, 856 845 ]}> 857 - {videoUploadState.status !== 'idle' && 858 - videoUploadState.status !== 'done' ? ( 859 - <VideoUploadToolbar state={videoUploadState} /> 846 + {videoState.status !== 'idle' && videoState.status !== 'done' ? ( 847 + <VideoUploadToolbar state={videoState} /> 860 848 ) : ( 861 849 <ToolbarWrapper style={[a.flex_row, a.align_center, a.gap_xs]}> 862 850 <SelectPhotoBtn ··· 1121 1109 1122 1110 function ErrorBanner({ 1123 1111 error: standardError, 1124 - videoUploadState, 1112 + videoState, 1125 1113 clearError, 1126 1114 clearVideo, 1127 1115 }: { 1128 1116 error: string 1129 - videoUploadState: VideoUploadState | NoVideoState 1117 + videoState: VideoState | NoVideoState 1130 1118 clearError: () => void 1131 1119 clearVideo: () => void 1132 1120 }) { ··· 1134 1122 const {_} = useLingui() 1135 1123 1136 1124 const videoError = 1137 - videoUploadState.status === 'error' ? videoUploadState.error : undefined 1125 + videoState.status === 'error' ? videoState.error : undefined 1138 1126 const error = standardError || videoError 1139 1127 1140 1128 const onClearError = () => { ··· 1176 1164 <ButtonIcon icon={X} /> 1177 1165 </Button> 1178 1166 </View> 1179 - {videoError && videoUploadState.jobId && ( 1167 + {videoError && videoState.jobId && ( 1180 1168 <NewText 1181 1169 style={[ 1182 1170 {paddingLeft: 28}, ··· 1185 1173 a.leading_snug, 1186 1174 t.atoms.text_contrast_low, 1187 1175 ]}> 1188 - <Trans>Job ID: {videoUploadState.jobId}</Trans> 1176 + <Trans>Job ID: {videoState.jobId}</Trans> 1189 1177 </NewText> 1190 1178 )} 1191 1179 </View> ··· 1211 1199 ) 1212 1200 } 1213 1201 1214 - function VideoUploadToolbar({state}: {state: VideoUploadState}) { 1202 + function VideoUploadToolbar({state}: {state: VideoState}) { 1215 1203 const t = useTheme() 1216 1204 const {_} = useLingui() 1217 1205 const progress = state.progress
+1 -1
src/view/com/composer/photos/Gallery.tsx
··· 21 21 import {Text} from '#/view/com/util/text/Text' 22 22 import {useTheme} from '#/alf' 23 23 import * as Dialog from '#/components/Dialog' 24 - import {ComposerAction} from '../state' 24 + import {ComposerAction} from '../state/composer' 25 25 import {EditImageDialog} from './EditImageDialog' 26 26 import {ImageAltTextDialog} from './ImageAltTextDialog' 27 27
+1 -6
src/view/com/composer/state.ts src/view/com/composer/state/composer.ts
··· 1 1 import {ImagePickerAsset} from 'expo-image-picker' 2 2 3 3 import {ComposerImage, createInitialImages} from '#/state/gallery' 4 - import { 5 - createVideoState, 6 - VideoAction, 7 - videoReducer, 8 - VideoState, 9 - } from '#/state/queries/video/video' 10 4 import {ComposerOpts} from '#/state/shell/composer' 5 + import {createVideoState, VideoAction, videoReducer, VideoState} from './video' 11 6 12 7 type PostRecord = { 13 8 uri: string