Implement validation and proper type detection
This commit is contained in:
parent
1acef14a1c
commit
b9b0965000
7 changed files with 114 additions and 30 deletions
|
@ -221,14 +221,14 @@ function AdditionalPostText({
|
|||
additionalPost?: PostThreadViewModel
|
||||
}) {
|
||||
const pal = usePalette('default')
|
||||
if (!additionalPost) {
|
||||
if (!additionalPost || !additionalPost.thread?.postRecord) {
|
||||
return <View />
|
||||
}
|
||||
if (additionalPost.error) {
|
||||
return <ErrorMessage message={additionalPost.error} />
|
||||
}
|
||||
return (
|
||||
<Text style={pal.textLight}>{additionalPost.thread?.post.record.text}</Text>
|
||||
<Text style={pal.textLight}>{additionalPost.thread?.postRecord.text}</Text>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ import {observer} from 'mobx-react-lite'
|
|||
import {StyleSheet, View} from 'react-native'
|
||||
import Clipboard from '@react-native-clipboard/clipboard'
|
||||
import {AtUri} from '../../../third-party/uri'
|
||||
import {AppBskyFeedPost} from '@atproto/api'
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||
import {PostThreadViewPostModel} from '../../../state/models/post-thread-view'
|
||||
import {Link} from '../util/Link'
|
||||
|
@ -18,6 +17,7 @@ import {useStores} from '../../../state'
|
|||
import {PostMeta} from '../util/PostMeta'
|
||||
import {PostEmbeds} from '../util/PostEmbeds'
|
||||
import {PostCtrls} from '../util/PostCtrls'
|
||||
import {ErrorMessage} from '../util/error/ErrorMessage'
|
||||
import {ComposePrompt} from '../composer/Prompt'
|
||||
import {usePalette} from '../../lib/hooks/usePalette'
|
||||
|
||||
|
@ -33,7 +33,7 @@ export const PostThreadItem = observer(function PostThreadItem({
|
|||
const pal = usePalette('default')
|
||||
const store = useStores()
|
||||
const [deleted, setDeleted] = useState(false)
|
||||
const record = item.post.record as unknown as AppBskyFeedPost.Record
|
||||
const record = item.postRecord
|
||||
const hasEngagement = item.post.upvoteCount || item.post.repostCount
|
||||
|
||||
const itemHref = useMemo(() => {
|
||||
|
@ -96,6 +96,10 @@ export const PostThreadItem = observer(function PostThreadItem({
|
|||
)
|
||||
}
|
||||
|
||||
if (!record) {
|
||||
return <ErrorMessage message="Invalid or unsupported post record" />
|
||||
}
|
||||
|
||||
if (deleted) {
|
||||
return (
|
||||
<View style={[styles.outer, pal.view, s.p20, s.flexRow]}>
|
||||
|
|
|
@ -9,7 +9,6 @@ import {
|
|||
import {observer} from 'mobx-react-lite'
|
||||
import Clipboard from '@react-native-clipboard/clipboard'
|
||||
import {AtUri} from '../../../third-party/uri'
|
||||
import {AppBskyFeedPost} from '@atproto/api'
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||
import {PostThreadViewModel} from '../../../state/models/post-thread-view'
|
||||
import {Link} from '../util/Link'
|
||||
|
@ -21,6 +20,7 @@ import {Text} from '../util/text/Text'
|
|||
import {RichText} from '../util/text/RichText'
|
||||
import * as Toast from '../util/Toast'
|
||||
import {UserAvatar} from '../util/UserAvatar'
|
||||
import {ErrorMessage} from '../util/error/ErrorMessage'
|
||||
import {useStores} from '../../../state'
|
||||
import {s, colors} from '../../lib/styles'
|
||||
import {usePalette} from '../../lib/hooks/usePalette'
|
||||
|
@ -68,7 +68,7 @@ export const Post = observer(function Post({
|
|||
|
||||
// error
|
||||
// =
|
||||
if (view.hasError || !view.thread) {
|
||||
if (view.hasError || !view.thread || !view.thread?.postRecord) {
|
||||
return (
|
||||
<View style={pal.view}>
|
||||
<Text>{view.error || 'Thread not found'}</Text>
|
||||
|
@ -79,7 +79,7 @@ export const Post = observer(function Post({
|
|||
// loaded
|
||||
// =
|
||||
const item = view.thread
|
||||
const record = view.thread?.post.record as unknown as AppBskyFeedPost.Record
|
||||
const record = view.thread.postRecord
|
||||
|
||||
const itemUrip = new AtUri(item.post.uri)
|
||||
const itemHref = `/profile/${item.post.author.handle}/post/${itemUrip.rkey}`
|
||||
|
|
|
@ -4,7 +4,6 @@ import {StyleSheet, View} from 'react-native'
|
|||
import Clipboard from '@react-native-clipboard/clipboard'
|
||||
import Svg, {Circle, Line} from 'react-native-svg'
|
||||
import {AtUri} from '../../../third-party/uri'
|
||||
import {AppBskyFeedPost} from '@atproto/api'
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||
import {FeedItemModel} from '../../../state/models/feed-view'
|
||||
import {Link} from '../util/Link'
|
||||
|
@ -34,7 +33,7 @@ export const FeedItem = observer(function ({
|
|||
const theme = useTheme()
|
||||
const pal = usePalette('default')
|
||||
const [deleted, setDeleted] = useState(false)
|
||||
const record = item.post.record as unknown as AppBskyFeedPost.Record
|
||||
const record = item.postRecord
|
||||
const itemHref = useMemo(() => {
|
||||
const urip = new AtUri(item.post.uri)
|
||||
return `/profile/${item.post.author.handle}/post/${urip.rkey}`
|
||||
|
@ -42,22 +41,22 @@ export const FeedItem = observer(function ({
|
|||
const itemTitle = `Post by ${item.post.author.handle}`
|
||||
const authorHref = `/profile/${item.post.author.handle}`
|
||||
const replyAuthorDid = useMemo(() => {
|
||||
if (!record.reply) return ''
|
||||
if (!record?.reply) return ''
|
||||
const urip = new AtUri(record.reply.parent?.uri || record.reply.root.uri)
|
||||
return urip.hostname
|
||||
}, [record.reply])
|
||||
}, [record?.reply])
|
||||
const replyHref = useMemo(() => {
|
||||
if (!record.reply) return ''
|
||||
const urip = new AtUri(record.reply.parent?.uri || record.reply.root.uri)
|
||||
if (!record?.reply) return ''
|
||||
const urip = new AtUri(record?.reply.parent?.uri || record?.reply.root.uri)
|
||||
return `/profile/${urip.hostname}/post/${urip.rkey}`
|
||||
}, [record.reply])
|
||||
}, [record?.reply])
|
||||
|
||||
const onPressReply = () => {
|
||||
store.shell.openComposer({
|
||||
replyTo: {
|
||||
uri: item.post.uri,
|
||||
cid: item.post.cid,
|
||||
text: record.text as string,
|
||||
text: record?.text || '',
|
||||
author: {
|
||||
handle: item.post.author.handle,
|
||||
displayName: item.post.author.displayName,
|
||||
|
@ -77,7 +76,7 @@ export const FeedItem = observer(function ({
|
|||
.catch(e => store.log.error('Failed to toggle upvote', e))
|
||||
}
|
||||
const onCopyPostText = () => {
|
||||
Clipboard.setString(record.text)
|
||||
Clipboard.setString(record?.text || '')
|
||||
Toast.show('Copied to clipboard')
|
||||
}
|
||||
const onDeletePost = () => {
|
||||
|
@ -93,7 +92,7 @@ export const FeedItem = observer(function ({
|
|||
)
|
||||
}
|
||||
|
||||
if (deleted) {
|
||||
if (!record || deleted) {
|
||||
return <View />
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue