diff options
author | Paul Frazee <pfrazee@gmail.com> | 2022-11-16 16:16:43 -0600 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2022-11-16 16:16:43 -0600 |
commit | 41ae87e770f23ebe5ad02dbc68a497e0fb2f2a3d (patch) | |
tree | 0bba2afc4eaa19abe64fafeaf2e6ac50861cae15 /src/view/com/post-thread/PostThreadItem.tsx | |
parent | bd1a4b198e3682f96354d83f1e1efccf31813f82 (diff) | |
download | voidsky-41ae87e770f23ebe5ad02dbc68a497e0fb2f2a3d.tar.zst |
Add post deletion
Diffstat (limited to 'src/view/com/post-thread/PostThreadItem.tsx')
-rw-r--r-- | src/view/com/post-thread/PostThreadItem.tsx | 22 |
1 files changed, 21 insertions, 1 deletions
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 && ( |