diff options
Diffstat (limited to 'src/view/com/util')
-rw-r--r-- | src/view/com/util/DropdownBtn.tsx | 23 | ||||
-rw-r--r-- | src/view/com/util/PostMeta.tsx | 6 |
2 files changed, 26 insertions, 3 deletions
diff --git a/src/view/com/util/DropdownBtn.tsx b/src/view/com/util/DropdownBtn.tsx index 960293320..bef193f1d 100644 --- a/src/view/com/util/DropdownBtn.tsx +++ b/src/view/com/util/DropdownBtn.tsx @@ -13,7 +13,7 @@ import RootSiblings from 'react-native-root-siblings' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {colors} from '../../lib/styles' import {useStores} from '../../../state' -import {SharePostModel} from '../../../state/models/shell-ui' +import {SharePostModel, ConfirmModel} from '../../../state/models/shell-ui' export interface DropdownItem { icon?: IconProp @@ -69,11 +69,15 @@ export function PostDropdownBtn({ children, itemHref, itemTitle, + isAuthor, + onDeletePost, }: { style?: StyleProp<ViewStyle> children?: React.ReactNode itemHref: string itemTitle: string + isAuthor: boolean + onDeletePost: () => void }) { const store = useStores() @@ -92,7 +96,22 @@ export function PostDropdownBtn({ store.shell.openModal(new SharePostModel(itemHref)) }, }, - ] + isAuthor + ? { + icon: ['far', 'trash-can'], + label: 'Delete post', + onPress() { + store.shell.openModal( + new ConfirmModel( + 'Delete this post?', + 'Are you sure? This can not be undone.', + onDeletePost, + ), + ) + }, + } + : undefined, + ].filter(Boolean) as DropdownItem[] return ( <DropdownBtn style={style} items={dropdownItems} menuWidth={200}> diff --git a/src/view/com/util/PostMeta.tsx b/src/view/com/util/PostMeta.tsx index 95dfcbd64..840de8709 100644 --- a/src/view/com/util/PostMeta.tsx +++ b/src/view/com/util/PostMeta.tsx @@ -13,6 +13,8 @@ interface PostMetaOpts { authorHandle: string authorDisplayName: string | undefined timestamp: string + isAuthor: boolean + onDeletePost: () => void } export function PostMeta(opts: PostMetaOpts) { @@ -48,7 +50,9 @@ export function PostMeta(opts: PostMetaOpts) { <PostDropdownBtn style={styles.metaItem} itemHref={opts.itemHref} - itemTitle={opts.itemTitle}> + itemTitle={opts.itemTitle} + isAuthor={opts.isAuthor} + onDeletePost={opts.onDeletePost}> <FontAwesomeIcon icon="ellipsis-h" size={14} style={[s.mt2, s.mr5]} /> </PostDropdownBtn> </View> |