Simplify the after-post logic to avoid a UI bug (#1105)
parent
b154d3ea21
commit
c4459ec4e8
|
@ -8,7 +8,7 @@ import AwaitLock from 'await-lock'
|
||||||
import {bundleAsync} from 'lib/async/bundle'
|
import {bundleAsync} from 'lib/async/bundle'
|
||||||
import {RootStoreModel} from '../root-store'
|
import {RootStoreModel} from '../root-store'
|
||||||
import {cleanError} from 'lib/strings/errors'
|
import {cleanError} from 'lib/strings/errors'
|
||||||
import {FeedTuner, FeedViewPostsSlice} from 'lib/api/feed-manip'
|
import {FeedTuner} from 'lib/api/feed-manip'
|
||||||
import {PostsFeedSliceModel} from './posts-slice'
|
import {PostsFeedSliceModel} from './posts-slice'
|
||||||
import {track} from 'lib/analytics/analytics'
|
import {track} from 'lib/analytics/analytics'
|
||||||
|
|
||||||
|
@ -286,27 +286,13 @@ export class PostsFeedModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the given post and adds it to the top
|
* Updates the UI after the user has created a post
|
||||||
* Used by the composer to add their new posts
|
|
||||||
*/
|
*/
|
||||||
async addPostToTop(uri: string) {
|
onPostCreated() {
|
||||||
if (!this.slices.length) {
|
if (!this.slices.length) {
|
||||||
return this.refresh()
|
return this.refresh()
|
||||||
}
|
} else {
|
||||||
try {
|
this.setHasNewLatest(true)
|
||||||
const res = await this.rootStore.agent.app.bsky.feed.getPosts({
|
|
||||||
uris: [uri],
|
|
||||||
})
|
|
||||||
const toPrepend = new PostsFeedSliceModel(
|
|
||||||
this.rootStore,
|
|
||||||
uri,
|
|
||||||
new FeedViewPostsSlice(res.data.posts.map(post => ({post}))),
|
|
||||||
)
|
|
||||||
runInAction(() => {
|
|
||||||
this.slices = [toPrepend].concat(this.slices)
|
|
||||||
})
|
|
||||||
} catch (e) {
|
|
||||||
this.rootStore.log.error('Failed to load post to prepend', {e})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,9 +163,8 @@ export const ComposePost = observer(function ComposePost({
|
||||||
|
|
||||||
setIsProcessing(true)
|
setIsProcessing(true)
|
||||||
|
|
||||||
let createdPost
|
|
||||||
try {
|
try {
|
||||||
createdPost = await apilib.post(store, {
|
await apilib.post(store, {
|
||||||
rawText: rt.text,
|
rawText: rt.text,
|
||||||
replyTo: replyTo?.uri,
|
replyTo: replyTo?.uri,
|
||||||
images: gallery.images,
|
images: gallery.images,
|
||||||
|
@ -193,7 +192,7 @@ export const ComposePost = observer(function ComposePost({
|
||||||
if (replyTo && replyTo.uri) track('Post:Reply')
|
if (replyTo && replyTo.uri) track('Post:Reply')
|
||||||
}
|
}
|
||||||
if (!replyTo) {
|
if (!replyTo) {
|
||||||
await store.me.mainFeed.addPostToTop(createdPost.uri)
|
store.me.mainFeed.onPostCreated()
|
||||||
}
|
}
|
||||||
onPost?.()
|
onPost?.()
|
||||||
onClose()
|
onClose()
|
||||||
|
|
Loading…
Reference in New Issue