Update feeds on post created (#2085)

This commit is contained in:
Paul Frazee 2023-12-04 17:58:45 -08:00 committed by GitHub
parent bdb2bfdd83
commit 48f5cebc80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 14 deletions

View file

@ -14,7 +14,7 @@ import {
import {useSafeAreaInsets} from 'react-native-safe-area-context'
import LinearGradient from 'react-native-linear-gradient'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {RichText} from '@atproto/api'
import {AppBskyFeedGetPosts, RichText} from '@atproto/api'
import {useAnalytics} from 'lib/analytics/analytics'
import {useIsKeyboardVisible} from 'lib/hooks/useIsKeyboardVisible'
import {ExternalEmbed} from './ExternalEmbed'
@ -59,6 +59,8 @@ import {
import {useSession, getAgent} from '#/state/session'
import {useProfileQuery} from '#/state/queries/profile'
import {useComposerControls} from '#/state/shell/composer'
import {until} from '#/lib/async/until'
import {emitPostCreated} from '#/state/events'
type Props = ComposerOpts
export const ComposePost = observer(function ComposePost({
@ -208,17 +210,20 @@ export const ComposePost = observer(function ComposePost({
setIsProcessing(true)
let postUri
try {
await apilib.post(getAgent(), {
rawText: richtext.text,
replyTo: replyTo?.uri,
images: gallery.images,
quote,
extLink,
labels,
onStateChange: setProcessingState,
langs: toPostLanguages(langPrefs.postLanguage),
})
postUri = (
await apilib.post(getAgent(), {
rawText: richtext.text,
replyTo: replyTo?.uri,
images: gallery.images,
quote,
extLink,
labels,
onStateChange: setProcessingState,
langs: toPostLanguages(langPrefs.postLanguage),
})
).uri
} catch (e: any) {
if (extLink) {
setExtLink({
@ -236,8 +241,10 @@ export const ComposePost = observer(function ComposePost({
})
if (replyTo && replyTo.uri) track('Post:Reply')
}
if (!replyTo) {
// TODO onPostCreated
if (postUri && !replyTo) {
whenAppViewReady(postUri).then(() => {
emitPostCreated()
})
}
setLangPrefs.savePostLanguageToHistory()
onPost?.()
@ -533,3 +540,15 @@ const styles = StyleSheet.create({
borderTopWidth: 1,
},
})
async function whenAppViewReady(uri: string) {
await until(
5, // 5 tries
1e3, // 1s delay between tries
(res: AppBskyFeedGetPosts.Response) => !!res.data.posts[0],
() =>
getAgent().getPosts({
uris: [uri],
}),
)
}