Add post deletion

This commit is contained in:
Paul Frazee 2022-11-16 16:16:43 -06:00
parent bd1a4b198e
commit 41ae87e770
8 changed files with 114 additions and 9 deletions

View file

@ -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}>

View file

@ -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>