From 41ae87e770f23ebe5ad02dbc68a497e0fb2f2a3d Mon Sep 17 00:00:00 2001
From: Paul Frazee <pfrazee@gmail.com>
Date: Wed, 16 Nov 2022 16:16:43 -0600
Subject: Add post deletion

---
 src/view/com/post-thread/PostThreadItem.tsx | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

(limited to 'src/view/com/post-thread/PostThreadItem.tsx')

diff --git a/src/view/com/post-thread/PostThreadItem.tsx b/src/view/com/post-thread/PostThreadItem.tsx
index c63364ecb..0ee52660b 100644
--- a/src/view/com/post-thread/PostThreadItem.tsx
+++ b/src/view/com/post-thread/PostThreadItem.tsx
@@ -1,4 +1,4 @@
-import React, {useMemo} from 'react'
+import React, {useMemo, useState} from 'react'
 import {observer} from 'mobx-react-lite'
 import {StyleSheet, Text, View} from 'react-native'
 import Svg, {Line} from 'react-native-svg'
@@ -9,6 +9,7 @@ import {PostThreadViewPostModel} from '../../../state/models/post-thread-view'
 import {Link} from '../util/Link'
 import {RichText} from '../util/RichText'
 import {PostDropdownBtn} from '../util/DropdownBtn'
+import Toast from '../util/Toast'
 import {UserAvatar} from '../util/UserAvatar'
 import {s, colors} from '../../lib/styles'
 import {ago, pluralize} from '../../lib/strings'
@@ -28,6 +29,7 @@ export const PostThreadItem = observer(function PostThreadItem({
   onPostReply: () => void
 }) {
   const store = useStores()
+  const [deleted, setDeleted] = useState(false)
   const record = item.record as unknown as PostType.Record
   const hasEngagement =
     item.upvoteCount || item.downvoteCount || item.repostCount
@@ -76,6 +78,22 @@ export const PostThreadItem = observer(function PostThreadItem({
       .toggleDownvote()
       .catch(e => console.error('Failed to toggle downvote', record, e))
   }
+  const onDeletePost = () => {
+    item.delete().then(
+      () => {
+        setDeleted(true)
+        Toast.show('Post deleted', {
+          position: Toast.positions.TOP,
+        })
+      },
+      e => {
+        console.error(e)
+        Toast.show('Failed to delete post, please try again', {
+          position: Toast.positions.TOP,
+        })
+      },
+    )
+  }
 
   if (item._isHighlightedPost) {
     return (
@@ -250,6 +268,8 @@ export const PostThreadItem = observer(function PostThreadItem({
               authorHandle={item.author.handle}
               authorDisplayName={item.author.displayName}
               timestamp={item.indexedAt}
+              isAuthor={item.author.did === store.me.did}
+              onDeletePost={onDeletePost}
             />
             {item.replyingToAuthor &&
               item.replyingToAuthor !== item.author.handle && (
-- 
cgit 1.4.1

