Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix post thread title

+43 -23
+8 -18
src/view/com/post-thread/PostThread.tsx
··· 10 10 import {PostThreadItem} from './PostThreadItem' 11 11 import {ErrorMessage} from '../util/ErrorMessage' 12 12 13 - export const PostThread = observer(function PostThread({uri}: {uri: string}) { 13 + export const PostThread = observer(function PostThread({ 14 + uri, 15 + view, 16 + }: { 17 + uri: string 18 + view: PostThreadViewModel 19 + }) { 14 20 const store = useStores() 15 - const [view, setView] = useState<PostThreadViewModel | undefined>() 16 - 17 - useEffect(() => { 18 - if (view?.params.uri === uri) { 19 - console.log('Post thread doing nothing') 20 - return // no change needed? or trigger refresh? 21 - } 22 - console.log('Fetching post thread', uri) 23 - const newView = new PostThreadViewModel(store, {uri}) 24 - setView(newView) 25 - newView.setup().catch(err => console.error('Failed to fetch thread', err)) 26 - }, [uri, view?.params.uri, store]) 27 21 28 22 const onPressShare = (uri: string) => { 29 23 store.shell.openModal(new SharePostModel(uri)) ··· 34 28 35 29 // loading 36 30 // = 37 - if ( 38 - !view || 39 - (view.isLoading && !view.isRefreshing) || 40 - view.params.uri !== uri 41 - ) { 31 + if ((view.isLoading && !view.isRefreshing) || view.params.uri !== uri) { 42 32 return ( 43 33 <View> 44 34 <ActivityIndicator />
+35 -5
src/view/screens/PostThread.tsx
··· 1 - import React, {useEffect} from 'react' 1 + import React, {useEffect, useMemo, useState} from 'react' 2 2 import {View} from 'react-native' 3 3 import {makeRecordUri} from '../lib/strings' 4 4 import {ViewHeader} from '../com/util/ViewHeader' 5 5 import {PostThread as PostThreadComponent} from '../com/post-thread/PostThread' 6 + import {PostThreadViewModel} from '../../state/models/post-thread-view' 6 7 import {ScreenParams} from '../routes' 7 8 import {useStores} from '../../state' 8 9 9 10 export const PostThread = ({navIdx, visible, params}: ScreenParams) => { 10 11 const store = useStores() 11 12 const {name, rkey} = params 13 + const [viewSubtitle, setViewSubtitle] = useState<string>(`by ${name}`) 12 14 const uri = makeRecordUri(name, 'app.bsky.feed.post', rkey) 15 + const view = useMemo<PostThreadViewModel>( 16 + () => new PostThreadViewModel(store, {uri}), 17 + [uri], 18 + ) 13 19 20 + const setTitle = () => { 21 + const author = view.thread?.author 22 + const niceName = author?.handle || name 23 + setViewSubtitle(`by ${niceName}`) 24 + store.nav.setTitle(navIdx, `Post by ${niceName}`) 25 + } 14 26 useEffect(() => { 15 - if (visible) { 16 - store.nav.setTitle(navIdx, `Post by ${name}`) 27 + let aborted = false 28 + if (!visible) { 29 + return 30 + } 31 + setTitle() 32 + if (!view.hasLoaded && !view.isLoading) { 33 + console.log('Fetching post thread', uri) 34 + view.setup().then( 35 + () => { 36 + if (!aborted) { 37 + setTitle() 38 + } 39 + }, 40 + err => { 41 + console.error('Failed to fetch thread', err) 42 + }, 43 + ) 44 + } 45 + return () => { 46 + aborted = true 17 47 } 18 48 }, [visible, store.nav, name]) 19 49 20 50 return ( 21 51 <View style={{flex: 1}}> 22 - <ViewHeader title="Post" subtitle={`by ${name}`} /> 52 + <ViewHeader title="Post" subtitle={viewSubtitle} /> 23 53 <View style={{flex: 1}}> 24 - <PostThreadComponent uri={uri} /> 54 + <PostThreadComponent uri={uri} view={view} /> 25 55 </View> 26 56 </View> 27 57 )