Remove ability for Post component to load from URI (close #1302) (#1317)

zio/stable
Paul Frazee 2023-08-28 17:08:21 -07:00 committed by GitHub
parent c77fd588e9
commit e2f0770b88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 33 deletions

View File

@ -122,7 +122,7 @@ export const FeedItem = observer(function ({
} }
if (item.isReply || item.isMention || item.isQuote) { if (item.isReply || item.isMention || item.isQuote) {
if (item.additionalPost?.error) { if (!item.additionalPost || item.additionalPost?.error) {
// hide errors - it doesnt help the user to show them // hide errors - it doesnt help the user to show them
return <View /> return <View />
} }
@ -134,8 +134,7 @@ export const FeedItem = observer(function ({
noFeedback noFeedback
accessible={false}> accessible={false}>
<Post <Post
uri={item.uri} view={item.additionalPost}
initView={item.additionalPost}
style={ style={
item.isRead item.isRead
? undefined ? undefined

View File

@ -1,4 +1,4 @@
import React, {useEffect, useState, useMemo} from 'react' import React, {useState, useMemo} from 'react'
import { import {
ActivityIndicator, ActivityIndicator,
Linking, Linking,
@ -32,35 +32,19 @@ import {getTranslatorLink, isPostInLanguage} from '../../../locale/helpers'
import {makeProfileLink} from 'lib/routes/links' import {makeProfileLink} from 'lib/routes/links'
export const Post = observer(function Post({ export const Post = observer(function Post({
uri, view,
initView,
showReplyLine, showReplyLine,
hideError, hideError,
style, style,
}: { }: {
uri: string view: PostThreadModel
initView?: PostThreadModel
showReplyLine?: boolean showReplyLine?: boolean
hideError?: boolean hideError?: boolean
style?: StyleProp<ViewStyle> style?: StyleProp<ViewStyle>
}) { }) {
const pal = usePalette('default') const pal = usePalette('default')
const store = useStores()
const [view, setView] = useState<PostThreadModel | undefined>(initView)
const [deleted, setDeleted] = useState(false) const [deleted, setDeleted] = useState(false)
useEffect(() => {
if (initView || view?.params.uri === uri) {
if (initView !== view) {
setView(initView)
}
return
}
const newView = new PostThreadModel(store, {uri, depth: 0})
setView(newView)
newView.setup().catch(err => store.log.error('Failed to fetch post', err))
}, [initView, setView, uri, view, view?.params.uri, store])
// deleted // deleted
// = // =
if (deleted) { if (deleted) {
@ -69,11 +53,7 @@ export const Post = observer(function Post({
// loading // loading
// = // =
if ( if (!view.hasContent && view.isLoading) {
!view ||
(!view.hasContent && view.isLoading) ||
view.params.uri !== uri
) {
return ( return (
<View style={pal.view}> <View style={pal.view}>
<ActivityIndicator /> <ActivityIndicator />

View File

@ -72,12 +72,7 @@ const PostResults = observer(({model}: {model: SearchUIModel}) => {
return ( return (
<ScrollView style={[pal.view]}> <ScrollView style={[pal.view]}>
{model.posts.map(post => ( {model.posts.map(post => (
<Post <Post key={post.resolvedUri} view={post} hideError />
key={post.resolvedUri}
uri={post.resolvedUri}
initView={post}
hideError
/>
))} ))}
<View style={s.footerSpacer} /> <View style={s.footerSpacer} />
<View style={s.footerSpacer} /> <View style={s.footerSpacer} />