Switch to using post ID for post actions
This commit is contained in:
@@ -172,6 +172,7 @@ export const ComposePost = ({
|
|||||||
const dispatch = useCallback((postAction: PostAction) => {
|
const dispatch = useCallback((postAction: PostAction) => {
|
||||||
composerDispatch({
|
composerDispatch({
|
||||||
type: 'update_post',
|
type: 'update_post',
|
||||||
|
postId: undefined, // Active post
|
||||||
postAction,
|
postAction,
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
@@ -898,6 +899,7 @@ function ComposerPills({
|
|||||||
onChange={nextLabels => {
|
onChange={nextLabels => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'update_post',
|
type: 'update_post',
|
||||||
|
postId: post.id,
|
||||||
postAction: {
|
postAction: {
|
||||||
type: 'update_labels',
|
type: 'update_labels',
|
||||||
labels: nextLabels,
|
labels: nextLabels,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import {ImagePickerAsset} from 'expo-image-picker'
|
import {ImagePickerAsset} from 'expo-image-picker'
|
||||||
import {AppBskyFeedPostgate, RichText} from '@atproto/api'
|
import {AppBskyFeedPostgate, RichText} from '@atproto/api'
|
||||||
|
import {nanoid} from 'nanoid/non-secure'
|
||||||
|
|
||||||
import {SelfLabel} from '#/lib/moderation'
|
import {SelfLabel} from '#/lib/moderation'
|
||||||
import {insertMentionAt} from '#/lib/strings/mention-manip'
|
import {insertMentionAt} from '#/lib/strings/mention-manip'
|
||||||
@@ -49,6 +50,7 @@ export type EmbedDraft = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type PostDraft = {
|
export type PostDraft = {
|
||||||
|
id: string
|
||||||
richtext: RichText
|
richtext: RichText
|
||||||
labels: SelfLabel[]
|
labels: SelfLabel[]
|
||||||
embed: EmbedDraft
|
embed: EmbedDraft
|
||||||
@@ -89,7 +91,11 @@ export type ComposerState = {
|
|||||||
export type ComposerAction =
|
export type ComposerAction =
|
||||||
| {type: 'update_postgate'; postgate: AppBskyFeedPostgate.Record}
|
| {type: 'update_postgate'; postgate: AppBskyFeedPostgate.Record}
|
||||||
| {type: 'update_threadgate'; threadgate: ThreadgateAllowUISetting[]}
|
| {type: 'update_threadgate'; threadgate: ThreadgateAllowUISetting[]}
|
||||||
| {type: 'update_post'; postAction: PostAction}
|
| {
|
||||||
|
type: 'update_post'
|
||||||
|
postId: string | undefined // If undefined, updates active post
|
||||||
|
postAction: PostAction
|
||||||
|
}
|
||||||
|
|
||||||
export const MAX_IMAGES = 4
|
export const MAX_IMAGES = 4
|
||||||
|
|
||||||
@@ -117,11 +123,20 @@ export function composerReducer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'update_post': {
|
case 'update_post': {
|
||||||
const nextPosts = [...state.thread.posts]
|
let nextPosts = state.thread.posts
|
||||||
nextPosts[state.activePostIndex] = postReducer(
|
let postIndex = -1
|
||||||
state.thread.posts[state.activePostIndex],
|
if (action.postId !== undefined) {
|
||||||
action.postAction,
|
postIndex = state.thread.posts.findIndex(p => p.id === action.postId)
|
||||||
)
|
} else {
|
||||||
|
postIndex = state.activePostIndex
|
||||||
|
}
|
||||||
|
if (postIndex !== -1) {
|
||||||
|
nextPosts = state.thread.posts.slice()
|
||||||
|
nextPosts[postIndex] = postReducer(
|
||||||
|
state.thread.posts[postIndex],
|
||||||
|
action.postAction,
|
||||||
|
)
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
thread: {
|
thread: {
|
||||||
@@ -427,6 +442,7 @@ export function createComposerState({
|
|||||||
thread: {
|
thread: {
|
||||||
posts: [
|
posts: [
|
||||||
{
|
{
|
||||||
|
id: nanoid(),
|
||||||
richtext: initRichText,
|
richtext: initRichText,
|
||||||
shortenedGraphemeLength: 0,
|
shortenedGraphemeLength: 0,
|
||||||
labels: [],
|
labels: [],
|
||||||
|
|||||||
Reference in New Issue
Block a user