Check video state for the entire thread (#5957)

* Switch to using post ID for post actions

* Pass post-bound dispatch to ComposerPost

* Check video state for entire thread

* Always bind post actions to an ID

* Rename variable for consistency

* Fix clashing keys
This commit is contained in:
dan
2024-11-01 03:37:30 +00:00
committed by GitHub
parent 68bb451051
commit 4c31403330
3 changed files with 162 additions and 76 deletions
+18 -5
View File
@@ -1,5 +1,6 @@
import {ImagePickerAsset} from 'expo-image-picker'
import {AppBskyFeedPostgate, RichText} from '@atproto/api'
import {nanoid} from 'nanoid/non-secure'
import {SelfLabel} from '#/lib/moderation'
import {insertMentionAt} from '#/lib/strings/mention-manip'
@@ -49,6 +50,7 @@ export type EmbedDraft = {
}
export type PostDraft = {
id: string
richtext: RichText
labels: SelfLabel[]
embed: EmbedDraft
@@ -89,7 +91,11 @@ export type ComposerState = {
export type ComposerAction =
| {type: 'update_postgate'; postgate: AppBskyFeedPostgate.Record}
| {type: 'update_threadgate'; threadgate: ThreadgateAllowUISetting[]}
| {type: 'update_post'; postAction: PostAction}
| {
type: 'update_post'
postId: string
postAction: PostAction
}
export const MAX_IMAGES = 4
@@ -117,11 +123,17 @@ export function composerReducer(
}
}
case 'update_post': {
const nextPosts = [...state.thread.posts]
nextPosts[state.activePostIndex] = postReducer(
state.thread.posts[state.activePostIndex],
action.postAction,
let nextPosts = state.thread.posts
const postIndex = state.thread.posts.findIndex(
p => p.id === action.postId,
)
if (postIndex !== -1) {
nextPosts = state.thread.posts.slice()
nextPosts[postIndex] = postReducer(
state.thread.posts[postIndex],
action.postAction,
)
}
return {
...state,
thread: {
@@ -427,6 +439,7 @@ export function createComposerState({
thread: {
posts: [
{
id: nanoid(),
richtext: initRichText,
shortenedGraphemeLength: 0,
labels: [],
+1 -2
View File
@@ -132,7 +132,7 @@ type DoneState = {
asset: ImagePickerAsset
video: CompressedVideo
jobId?: undefined
pendingPublish: {blobRef: BlobRef; mutableProcessed: boolean}
pendingPublish: {blobRef: BlobRef}
altText: string
captions: CaptionsTrack[]
}
@@ -250,7 +250,6 @@ export function videoReducer(
video: state.video,
pendingPublish: {
blobRef: action.blobRef,
mutableProcessed: false,
},
altText: state.altText,
captions: state.captions,