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/Post.tsx | |
parent | bd1a4b198e3682f96354d83f1e1efccf31813f82 (diff) | |
download | voidsky-41ae87e770f23ebe5ad02dbc68a497e0fb2f2a3d.tar.zst |
Add post deletion
Diffstat (limited to 'src/view/com/post/Post.tsx')
-rw-r--r-- | src/view/com/post/Post.tsx | 27 |
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'}]}> |