Rename variable for consistency

This commit is contained in:
Dan Abramov
2024-10-27 14:06:58 +00:00
parent 405f55fb1d
commit eceb04a8cb
+28 -23
View File
@@ -169,16 +169,16 @@ export const ComposePost = ({
// TODO: Display drafts for other posts in the thread. // TODO: Display drafts for other posts in the thread.
const thread = composerState.thread const thread = composerState.thread
const draft = thread.posts[composerState.activePostIndex] const activePost = thread.posts[composerState.activePostIndex]
const dispatch = useCallback( const dispatch = useCallback(
(postAction: PostAction) => { (postAction: PostAction) => {
composerDispatch({ composerDispatch({
type: 'update_post', type: 'update_post',
postId: draft.id, // Active post postId: activePost.id,
postAction, postAction,
}) })
}, },
[draft.id], [activePost.id],
) )
const selectVideo = React.useCallback( const selectVideo = React.useCallback(
@@ -216,7 +216,7 @@ export const ComposePost = ({
const onInitVideo = useNonReactiveCallback(() => { const onInitVideo = useNonReactiveCallback(() => {
if (initVideoUri) { if (initVideoUri) {
selectVideo(draft.id, initVideoUri) selectVideo(activePost.id, initVideoUri)
} }
}) })
@@ -475,6 +475,8 @@ export const ComposePost = ({
} }
}, [thread.posts, onPressPublish, publishOnUpload]) }, [thread.posts, onPressPublish, publishOnUpload])
// TODO: It might make more sense to display this error per-post.
// Right now we're just displaying the first one.
let erroredVideoPostId: string | undefined let erroredVideoPostId: string | undefined
let erroredVideo: VideoState | NoVideoState = NO_VIDEO let erroredVideo: VideoState | NoVideoState = NO_VIDEO
for (let i = 0; i < thread.posts.length; i++) { for (let i = 0; i < thread.posts.length; i++) {
@@ -485,6 +487,7 @@ export const ComposePost = ({
) { ) {
erroredVideoPostId = post.id erroredVideoPostId = post.id
erroredVideo = post.embed.media.video erroredVideo = post.embed.media.video
break
} }
} }
@@ -544,34 +547,37 @@ export const ComposePost = ({
onLayout={onScrollViewLayout}> onLayout={onScrollViewLayout}>
{replyTo ? <ComposerReplyTo replyTo={replyTo} /> : undefined} {replyTo ? <ComposerReplyTo replyTo={replyTo} /> : undefined}
<ComposerPost <ComposerPost
draft={draft} key={activePost.id}
post={activePost}
dispatch={composerDispatch} dispatch={composerDispatch}
textInput={textInput} textInput={textInput}
isReply={!!replyTo} isReply={!!replyTo}
canRemoveQuote={!initQuote} canRemoveQuote={!initQuote}
onSelectVideo={asset => selectVideo(draft.id, asset)} onSelectVideo={asset => selectVideo(activePost.id, asset)}
onClearVideo={() => clearVideo(draft.id)} onClearVideo={() => clearVideo(activePost.id)}
onPublish={() => onPressPublish(false)} onPublish={() => onPressPublish(false)}
onError={setError} onError={setError}
/> />
</Animated.ScrollView> </Animated.ScrollView>
<SuggestedLanguage text={draft.richtext.text} /> <SuggestedLanguage text={activePost.richtext.text} />
<ComposerPills <ComposerPills
key={activePost.id}
isReply={!!replyTo} isReply={!!replyTo}
post={draft} post={activePost}
thread={composerState.thread} thread={composerState.thread}
dispatch={composerDispatch} dispatch={composerDispatch}
bottomBarAnimatedStyle={bottomBarAnimatedStyle} bottomBarAnimatedStyle={bottomBarAnimatedStyle}
/> />
<ComposerFooter <ComposerFooter
draft={draft} key={activePost.id}
post={activePost}
dispatch={dispatch} dispatch={dispatch}
onError={setError} onError={setError}
onEmojiButtonPress={onEmojiButtonPress} onEmojiButtonPress={onEmojiButtonPress}
onSelectVideo={asset => selectVideo(draft.id, asset)} onSelectVideo={asset => selectVideo(activePost.id, asset)}
/> />
</View> </View>
@@ -589,7 +595,7 @@ export const ComposePost = ({
} }
function ComposerPost({ function ComposerPost({
draft, post,
dispatch, dispatch,
textInput, textInput,
isReply, isReply,
@@ -599,7 +605,7 @@ function ComposerPost({
onError, onError,
onPublish, onPublish,
}: { }: {
draft: PostDraft post: PostDraft
dispatch: (action: ComposerAction) => void dispatch: (action: ComposerAction) => void
textInput: React.Ref<TextInputRef> textInput: React.Ref<TextInputRef>
isReply: boolean isReply: boolean
@@ -613,9 +619,8 @@ function ComposerPost({
const currentDid = currentAccount!.did const currentDid = currentAccount!.did
const {_} = useLingui() const {_} = useLingui()
const {data: currentProfile} = useProfileQuery({did: currentDid}) const {data: currentProfile} = useProfileQuery({did: currentDid})
const richtext = draft.richtext const richtext = post.richtext
const isTextOnly = const isTextOnly = !post.embed.link && !post.embed.quote && !post.embed.media
!draft.embed.link && !draft.embed.quote && !draft.embed.media
const forceMinHeight = isWeb && isTextOnly const forceMinHeight = isWeb && isTextOnly
const selectTextInputPlaceholder = isReply const selectTextInputPlaceholder = isReply
? _(msg`Write your reply`) ? _(msg`Write your reply`)
@@ -625,11 +630,11 @@ function ComposerPost({
(action: PostAction) => { (action: PostAction) => {
dispatch({ dispatch({
type: 'update_post', type: 'update_post',
postId: draft.id, postId: post.id,
postAction: action, postAction: action,
}) })
}, },
[dispatch, draft.id], [dispatch, post.id],
) )
const onImageAdd = useCallback( const onImageAdd = useCallback(
@@ -696,7 +701,7 @@ function ComposerPost({
<ComposerEmbeds <ComposerEmbeds
canRemoveQuote={canRemoveQuote} canRemoveQuote={canRemoveQuote}
embed={draft.embed} embed={post.embed}
dispatch={dispatchPost} dispatch={dispatchPost}
clearVideo={onClearVideo} clearVideo={onClearVideo}
/> />
@@ -983,13 +988,13 @@ function ComposerPills({
} }
function ComposerFooter({ function ComposerFooter({
draft, post,
dispatch, dispatch,
onEmojiButtonPress, onEmojiButtonPress,
onError, onError,
onSelectVideo, onSelectVideo,
}: { }: {
draft: PostDraft post: PostDraft
dispatch: (action: PostAction) => void dispatch: (action: PostAction) => void
onEmojiButtonPress: () => void onEmojiButtonPress: () => void
onError: (error: string) => void onError: (error: string) => void
@@ -999,7 +1004,7 @@ function ComposerFooter({
const {_} = useLingui() const {_} = useLingui()
const {isMobile} = useWebMediaQueries() const {isMobile} = useWebMediaQueries()
const media = draft.embed.media const media = post.embed.media
const images = media?.type === 'images' ? media.images : [] const images = media?.type === 'images' ? media.images : []
const video = media?.type === 'video' ? media.video : null const video = media?.type === 'video' ? media.video : null
const isMaxImages = images.length >= MAX_IMAGES const isMaxImages = images.length >= MAX_IMAGES
@@ -1071,7 +1076,7 @@ function ComposerFooter({
<View style={[a.flex_row, a.align_center, a.justify_between]}> <View style={[a.flex_row, a.align_center, a.justify_between]}>
<SelectLangBtn /> <SelectLangBtn />
<CharProgress <CharProgress
count={draft.shortenedGraphemeLength} count={post.shortenedGraphemeLength}
style={{width: 65}} style={{width: 65}}
/> />
</View> </View>