about summary refs log tree commit diff
path: root/src/view/com/post/Post.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/view/com/post/Post.tsx')
-rw-r--r--src/view/com/post/Post.tsx27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/view/com/post/Post.tsx b/src/view/com/post/Post.tsx
index 83bf8bed8..7d2edff4c 100644
--- a/src/view/com/post/Post.tsx
+++ b/src/view/com/post/Post.tsx
@@ -10,14 +10,15 @@ import {UserInfoText} from '../util/UserInfoText'
 import {PostMeta} from '../util/PostMeta'
 import {PostCtrls} from '../util/PostCtrls'
 import {RichText} from '../util/RichText'
+import Toast from '../util/Toast'
 import {UserAvatar} from '../util/UserAvatar'
 import {useStores} from '../../../state'
 import {s, colors} from '../../lib/styles'
-import {ago} from '../../lib/strings'
 
 export const Post = observer(function Post({uri}: {uri: string}) {
   const store = useStores()
   const [view, setView] = useState<PostThreadViewModel | undefined>()
+  const [deleted, setDeleted] = useState(false)
 
   useEffect(() => {
     if (view?.params.uri === uri) {
@@ -28,6 +29,12 @@ export const Post = observer(function Post({uri}: {uri: string}) {
     newView.setup().catch(err => console.error('Failed to fetch post', err))
   }, [uri, view?.params.uri, store])
 
+  // deleted
+  // =
+  if (deleted) {
+    return <View />
+  }
+
   // loading
   // =
   if (!view || view.isLoading || view.params.uri !== uri) {
@@ -83,6 +90,22 @@ export const Post = observer(function Post({uri}: {uri: string}) {
       .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,
+        })
+      },
+    )
+  }
 
   return (
     <Link style={styles.outer} href={itemHref} title={itemTitle}>
@@ -102,6 +125,8 @@ export const Post = observer(function Post({uri}: {uri: string}) {
             authorHandle={item.author.handle}
             authorDisplayName={item.author.displayName}
             timestamp={item.indexedAt}
+            isAuthor={item.author.did === store.me.did}
+            onDeletePost={onDeletePost}
           />
           {replyHref !== '' && (
             <View style={[s.flexRow, s.mb2, {alignItems: 'center'}]}>