Refactor post meta to return PostView (#5645)

This commit is contained in:
dan
2024-10-24 20:41:50 +01:00
committed by GitHub
parent fa4cca11fe
commit e8a53dcea8
9 changed files with 37 additions and 106 deletions
+2 -14
View File
@@ -199,27 +199,15 @@ let PostCtrls = ({
feedContext,
})
openComposer({
quote: {
uri: post.uri,
cid: post.cid,
text: record.text,
author: post.author,
indexedAt: post.indexedAt,
},
quoteCount: post.quoteCount,
quote: post,
onPost: onPostReply,
})
}, [
_,
sendInteraction,
post.uri,
post.cid,
post.author,
post.indexedAt,
post.quoteCount,
post,
feedContext,
openComposer,
record.text,
onPostReply,
isBlocked,
])
+20 -38
View File
@@ -33,7 +33,6 @@ import {useModerationOpts} from '#/state/preferences/moderation-opts'
import {precacheProfile} from '#/state/queries/profile'
import {useResolveLinkQuery} from '#/state/queries/resolve-link'
import {useSession} from '#/state/session'
import {ComposerOptsQuote} from '#/state/shell/composer'
import {atoms as a, useTheme} from '#/alf'
import {RichText} from '#/components/RichText'
import {ContentHider} from '../../../../components/moderation/ContentHider'
@@ -68,7 +67,6 @@ export function MaybeQuoteEmbed({
return (
<QuoteEmbedModerated
viewRecord={embed.record}
postRecord={embed.record.value}
onOpen={onOpen}
style={style}
allowNestedQuotes={allowNestedQuotes}
@@ -118,39 +116,31 @@ export function MaybeQuoteEmbed({
function QuoteEmbedModerated({
viewRecord,
postRecord,
onOpen,
style,
allowNestedQuotes,
viewContext,
}: {
viewRecord: AppBskyEmbedRecord.ViewRecord
postRecord: AppBskyFeedPost.Record
onOpen?: () => void
style?: StyleProp<ViewStyle>
allowNestedQuotes?: boolean
viewContext?: QuoteEmbedViewContext
}) {
const moderationOpts = useModerationOpts()
const postView = React.useMemo(
() => viewRecordToPostView(viewRecord),
[viewRecord],
)
const moderation = React.useMemo(() => {
return moderationOpts
? moderatePost_wrapped(viewRecordToPostView(viewRecord), moderationOpts)
? moderatePost_wrapped(postView, moderationOpts)
: undefined
}, [viewRecord, moderationOpts])
const quote = {
author: viewRecord.author,
cid: viewRecord.cid,
uri: viewRecord.uri,
indexedAt: viewRecord.indexedAt,
text: postRecord.text,
facets: postRecord.facets,
embeds: viewRecord.embeds,
}
}, [postView, moderationOpts])
return (
<QuoteEmbed
quote={quote}
quote={postView}
moderation={moderation}
onOpen={onOpen}
style={style}
@@ -167,7 +157,7 @@ export function QuoteEmbed({
style,
allowNestedQuotes,
}: {
quote: ComposerOptsQuote
quote: AppBskyFeedDefs.PostView
moderation?: ModerationDecision
onOpen?: () => void
style?: StyleProp<ViewStyle>
@@ -181,16 +171,18 @@ export function QuoteEmbed({
const itemHref = makeProfileLink(quote.author, 'post', itemUrip.rkey)
const itemTitle = `Post by ${quote.author.handle}`
const richText = React.useMemo(
() =>
quote.text.trim()
? new RichTextAPI({text: quote.text, facets: quote.facets})
: undefined,
[quote.text, quote.facets],
)
const richText = React.useMemo(() => {
const text = AppBskyFeedPost.isRecord(quote.record) ? quote.record.text : ''
const facets = AppBskyFeedPost.isRecord(quote.record)
? quote.record.facets
: undefined
return text.trim()
? new RichTextAPI({text: text, facets: facets})
: undefined
}, [quote.record])
const embed = React.useMemo(() => {
const e = quote.embeds?.[0]
const e = quote.embed
if (allowNestedQuotes) {
return e
@@ -210,7 +202,7 @@ export function QuoteEmbed({
return e.media
}
}
}, [quote.embeds, allowNestedQuotes])
}, [quote.embed, allowNestedQuotes])
const onBeforePress = React.useCallback(() => {
precacheProfile(queryClient, quote.author)
@@ -292,17 +284,7 @@ export function LazyQuoteEmbed({uri}: {uri: string}) {
if (!data || data.type !== 'record' || data.kind !== 'post') {
return null
}
return (
<QuoteEmbed
quote={{
cid: data.record.cid,
uri: data.record.uri,
author: data.meta.author,
indexedAt: data.meta.indexedAt,
text: data.meta.text,
}}
/>
)
return <QuoteEmbed quote={data.meta} />
}
function viewRecordToPostView(