about summary refs log tree commit diff
path: root/src/view/com/posts/FeedItem.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/view/com/posts/FeedItem.tsx')
-rw-r--r--src/view/com/posts/FeedItem.tsx123
1 files changed, 73 insertions, 50 deletions
diff --git a/src/view/com/posts/FeedItem.tsx b/src/view/com/posts/FeedItem.tsx
index f054a40f2..20d199745 100644
--- a/src/view/com/posts/FeedItem.tsx
+++ b/src/view/com/posts/FeedItem.tsx
@@ -102,10 +102,6 @@ let FeedItemInner = ({
 }): React.ReactNode => {
   const {openComposer} = useComposerControls()
   const pal = usePalette('default')
-  const [limitLines, setLimitLines] = useState(
-    () => countLines(richText.text) >= MAX_POST_LINES,
-  )
-
   const href = useMemo(() => {
     const urip = new AtUri(post.uri)
     return makeProfileLink(post.author, 'post', urip.rkey)
@@ -134,10 +130,6 @@ let FeedItemInner = ({
     })
   }, [post, record, openComposer])
 
-  const onPressShowMore = React.useCallback(() => {
-    setLimitLines(false)
-  }, [setLimitLines])
-
   const outerStyles = [
     styles.outer,
     pal.view,
@@ -286,48 +278,12 @@ let FeedItemInner = ({
               </Text>
             </View>
           )}
-          <ContentHider
-            testID="contentHider-post"
-            moderation={moderation.content}
-            ignoreMute
-            childContainerStyle={styles.contentHiderChild}>
-            <PostAlerts moderation={moderation.content} style={styles.alert} />
-            {richText.text ? (
-              <View style={styles.postTextContainer}>
-                <RichText
-                  testID="postText"
-                  type="post-text"
-                  richText={richText}
-                  lineHeight={1.3}
-                  numberOfLines={limitLines ? MAX_POST_LINES : undefined}
-                  style={s.flex1}
-                />
-              </View>
-            ) : undefined}
-            {limitLines ? (
-              <TextLink
-                text="Show More"
-                style={pal.link}
-                onPress={onPressShowMore}
-                href="#"
-              />
-            ) : undefined}
-            {post.embed ? (
-              <ContentHider
-                testID="contentHider-embed"
-                moderation={moderation.embed}
-                moderationDecisions={moderation.decisions}
-                ignoreMute={isEmbedByEmbedder(post.embed, post.author.did)}
-                ignoreQuoteDecisions
-                style={styles.embed}>
-                <PostEmbeds
-                  embed={post.embed}
-                  moderation={moderation.embed}
-                  moderationDecisions={moderation.decisions}
-                />
-              </ContentHider>
-            ) : null}
-          </ContentHider>
+          <PostContent
+            moderation={moderation}
+            richText={richText}
+            postEmbed={post.embed}
+            postAuthor={post.author}
+          />
           <PostCtrls post={post} record={record} onPressReply={onPressReply} />
         </View>
       </View>
@@ -336,6 +292,73 @@ let FeedItemInner = ({
 }
 FeedItemInner = memo(FeedItemInner)
 
+let PostContent = ({
+  moderation,
+  richText,
+  postEmbed,
+  postAuthor,
+}: {
+  moderation: PostModeration
+  richText: RichTextAPI
+  postEmbed: AppBskyFeedDefs.PostView['embed']
+  postAuthor: AppBskyFeedDefs.PostView['author']
+}): React.ReactNode => {
+  const pal = usePalette('default')
+  const [limitLines, setLimitLines] = useState(
+    () => countLines(richText.text) >= MAX_POST_LINES,
+  )
+
+  const onPressShowMore = React.useCallback(() => {
+    setLimitLines(false)
+  }, [setLimitLines])
+
+  return (
+    <ContentHider
+      testID="contentHider-post"
+      moderation={moderation.content}
+      ignoreMute
+      childContainerStyle={styles.contentHiderChild}>
+      <PostAlerts moderation={moderation.content} style={styles.alert} />
+      {richText.text ? (
+        <View style={styles.postTextContainer}>
+          <RichText
+            testID="postText"
+            type="post-text"
+            richText={richText}
+            lineHeight={1.3}
+            numberOfLines={limitLines ? MAX_POST_LINES : undefined}
+            style={s.flex1}
+          />
+        </View>
+      ) : undefined}
+      {limitLines ? (
+        <TextLink
+          text="Show More"
+          style={pal.link}
+          onPress={onPressShowMore}
+          href="#"
+        />
+      ) : undefined}
+      {postEmbed ? (
+        <ContentHider
+          testID="contentHider-embed"
+          moderation={moderation.embed}
+          moderationDecisions={moderation.decisions}
+          ignoreMute={isEmbedByEmbedder(postEmbed, postAuthor.did)}
+          ignoreQuoteDecisions
+          style={styles.embed}>
+          <PostEmbeds
+            embed={postEmbed}
+            moderation={moderation.embed}
+            moderationDecisions={moderation.decisions}
+          />
+        </ContentHider>
+      ) : null}
+    </ContentHider>
+  )
+}
+PostContent = memo(PostContent)
+
 const styles = StyleSheet.create({
   outer: {
     borderTopWidth: 1,