add delete button
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, {useCallback, useImperativeHandle} from 'react'
|
import React, {useCallback} from 'react'
|
||||||
import {Pressable} from 'react-native'
|
import {Pressable} from 'react-native'
|
||||||
import Animated, {
|
import Animated, {
|
||||||
cancelAnimation,
|
cancelAnimation,
|
||||||
@@ -8,22 +8,19 @@ import Animated, {
|
|||||||
withTiming,
|
withTiming,
|
||||||
} from 'react-native-reanimated'
|
} from 'react-native-reanimated'
|
||||||
|
|
||||||
|
import {useHaptics} from 'lib/haptics'
|
||||||
|
|
||||||
const AnimatedPressable = Animated.createAnimatedComponent(Pressable)
|
const AnimatedPressable = Animated.createAnimatedComponent(Pressable)
|
||||||
|
|
||||||
export interface GrowWrapperRef {
|
export const GrowWrapper = function GrowWrapper({
|
||||||
reset: () => void
|
onOpenMenu,
|
||||||
}
|
children,
|
||||||
|
}: {
|
||||||
|
onOpenMenu: () => unknown
|
||||||
|
children: React.ReactNode
|
||||||
|
}) {
|
||||||
|
const playHaptic = useHaptics()
|
||||||
|
|
||||||
export const GrowWrapper = React.forwardRef(function GrowWrapper(
|
|
||||||
{
|
|
||||||
onOpenMenu,
|
|
||||||
children,
|
|
||||||
}: {
|
|
||||||
onOpenMenu: () => unknown
|
|
||||||
children: React.ReactNode
|
|
||||||
},
|
|
||||||
ref,
|
|
||||||
) {
|
|
||||||
const scale = useSharedValue(1)
|
const scale = useSharedValue(1)
|
||||||
const animationDidComplete = useSharedValue(false)
|
const animationDidComplete = useSharedValue(false)
|
||||||
|
|
||||||
@@ -31,31 +28,21 @@ export const GrowWrapper = React.forwardRef(function GrowWrapper(
|
|||||||
transform: [{scale: scale.value}],
|
transform: [{scale: scale.value}],
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const reset = useCallback(() => {
|
const onTouchStart = React.useCallback(() => {
|
||||||
|
scale.value = withTiming(1.05, {duration: 750}, finished => {
|
||||||
|
if (!finished) return
|
||||||
|
animationDidComplete.value = true
|
||||||
|
runOnJS(playHaptic)()
|
||||||
|
runOnJS(onOpenMenu)()
|
||||||
|
})
|
||||||
|
}, [scale, animationDidComplete, playHaptic, onOpenMenu])
|
||||||
|
|
||||||
|
const onTouchEnd = useCallback(() => {
|
||||||
cancelAnimation(scale)
|
cancelAnimation(scale)
|
||||||
animationDidComplete.value = false
|
animationDidComplete.value = false
|
||||||
scale.value = withTiming(1, {duration: 200})
|
scale.value = withTiming(1, {duration: 200})
|
||||||
}, [animationDidComplete, scale])
|
}, [animationDidComplete, scale])
|
||||||
|
|
||||||
const onTouchStart = React.useCallback(() => {
|
|
||||||
scale.value = withTiming(1.05, {duration: 750}, finished => {
|
|
||||||
if (!finished) return
|
|
||||||
|
|
||||||
animationDidComplete.value = true
|
|
||||||
runOnJS(onOpenMenu)()
|
|
||||||
})
|
|
||||||
}, [scale, animationDidComplete, onOpenMenu])
|
|
||||||
|
|
||||||
const onTouchEnd = React.useCallback(() => {
|
|
||||||
if (!animationDidComplete.value) {
|
|
||||||
reset()
|
|
||||||
}
|
|
||||||
}, [animationDidComplete, reset])
|
|
||||||
|
|
||||||
useImperativeHandle(ref, () => ({
|
|
||||||
reset,
|
|
||||||
}))
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatedPressable
|
<AnimatedPressable
|
||||||
style={animatedStyle}
|
style={animatedStyle}
|
||||||
@@ -65,4 +52,4 @@ export const GrowWrapper = React.forwardRef(function GrowWrapper(
|
|||||||
{children}
|
{children}
|
||||||
</AnimatedPressable>
|
</AnimatedPressable>
|
||||||
)
|
)
|
||||||
})
|
}
|
||||||
|
|||||||
@@ -1,32 +1,55 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {View} from 'react-native'
|
|
||||||
import {ChatBskyConvoDefs} from '@atproto-labs/api'
|
import {ChatBskyConvoDefs} from '@atproto-labs/api'
|
||||||
|
import {msg} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import {atoms as a} from '#/alf'
|
import {Trash_Stroke2_Corner0_Rounded as Trash} from '#/components/icons/Trash'
|
||||||
import * as Dialog from '#/components/Dialog'
|
import * as Menu from '#/components/Menu'
|
||||||
|
import * as Prompt from '#/components/Prompt'
|
||||||
|
import {usePromptControl} from '#/components/Prompt'
|
||||||
|
|
||||||
export let MessageMenu = ({
|
export let MessageMenu = ({
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
message,
|
message,
|
||||||
onClose,
|
|
||||||
control,
|
control,
|
||||||
}: {
|
}: {
|
||||||
message: ChatBskyConvoDefs.MessageView
|
message: ChatBskyConvoDefs.MessageView
|
||||||
onClose: () => void
|
control: Menu.MenuControlProps
|
||||||
control: Dialog.DialogControlProps
|
|
||||||
}): React.ReactNode => {
|
}): React.ReactNode => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
|
const deleteControl = usePromptControl()
|
||||||
|
|
||||||
|
const onDelete = React.useCallback(() => {
|
||||||
|
// TODO delete the message
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog.Outer control={control} onClose={onClose}>
|
<>
|
||||||
<Dialog.Handle />
|
<Menu.Root control={control}>
|
||||||
|
<Menu.Outer>
|
||||||
|
<Menu.Group>
|
||||||
|
<Menu.Item
|
||||||
|
testID="postDropdownDeleteBtn"
|
||||||
|
label={_(msg`Delete message`)}
|
||||||
|
onPress={deleteControl.open}>
|
||||||
|
<Menu.ItemText>{_(msg`Delete message`)}</Menu.ItemText>
|
||||||
|
<Menu.ItemIcon icon={Trash} position="right" />
|
||||||
|
</Menu.Item>
|
||||||
|
</Menu.Group>
|
||||||
|
</Menu.Outer>
|
||||||
|
</Menu.Root>
|
||||||
|
|
||||||
<Dialog.ScrollableInner label="Menu TODO">
|
<Prompt.Basic
|
||||||
<View style={{height: a.gap_lg.gap}} />
|
control={deleteControl}
|
||||||
</Dialog.ScrollableInner>
|
title={_(msg`Delete message`)}
|
||||||
</Dialog.Outer>
|
description={_(
|
||||||
|
msg`Are you sure you want to delete this message?? The message will be deleted for you, but not for other participants.`,
|
||||||
|
)}
|
||||||
|
confirmButtonCta={_(msg`Delete`)}
|
||||||
|
confirmButtonColor="negative"
|
||||||
|
onConfirm={onDelete}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
MessageMenu = React.memo(MessageMenu)
|
MessageMenu = React.memo(MessageMenu)
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
import React, {useMemo} from 'react'
|
import React, {useMemo} from 'react'
|
||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
import {ChatBskyConvoDefs} from '@atproto-labs/api'
|
import {ChatBskyConvoDefs} from '@atproto-labs/api'
|
||||||
import {msg} from '@lingui/macro'
|
|
||||||
import {useLingui} from '@lingui/react'
|
|
||||||
|
|
||||||
import {useSession} from '#/state/session'
|
import {useSession} from '#/state/session'
|
||||||
import {TimeElapsed} from '#/view/com/util/TimeElapsed'
|
|
||||||
import {atoms as a, useTheme} from '#/alf'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
import {useDialogControl} from '#/components/Dialog'
|
|
||||||
import {GrowWrapper} from '#/components/dms/GrowWrapper'
|
import {GrowWrapper} from '#/components/dms/GrowWrapper'
|
||||||
|
import {MessageItemMetadata} from '#/components/dms/MesageItemMetadata'
|
||||||
import {MessageMenu} from '#/components/dms/MessageMenu'
|
import {MessageMenu} from '#/components/dms/MessageMenu'
|
||||||
import * as Prompt from '#/components/Prompt'
|
import {useMenuControl} from '#/components/Menu'
|
||||||
import {usePromptControl} from '#/components/Prompt'
|
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
export function MessageItem({
|
export function MessageItem({
|
||||||
@@ -25,10 +21,9 @@ export function MessageItem({
|
|||||||
| null
|
| null
|
||||||
}) {
|
}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {_} = useLingui()
|
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
|
|
||||||
const control = useDialogControl()
|
const menuControl = useMenuControl()
|
||||||
|
|
||||||
const isFromSelf = item.sender?.did === currentAccount?.did
|
const isFromSelf = item.sender?.did === currentAccount?.did
|
||||||
|
|
||||||
@@ -57,8 +52,8 @@ export function MessageItem({
|
|||||||
}, [item, next, isFromSelf, isNextFromSelf])
|
}, [item, next, isFromSelf, isNextFromSelf])
|
||||||
|
|
||||||
const onOpenMenu = React.useCallback(() => {
|
const onOpenMenu = React.useCallback(() => {
|
||||||
control.open()
|
menuControl.open()
|
||||||
}, [control])
|
}, [menuControl])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
@@ -94,17 +89,7 @@ export function MessageItem({
|
|||||||
isLastInGroup={isLastInGroup}
|
isLastInGroup={isLastInGroup}
|
||||||
style={isFromSelf ? a.text_right : a.text_left}
|
style={isFromSelf ? a.text_right : a.text_left}
|
||||||
/>
|
/>
|
||||||
<MessageMenu message={item} control={control} />
|
<MessageMenu message={item} control={menuControl} />
|
||||||
<Prompt.Basic
|
|
||||||
control={deleteControl}
|
|
||||||
title={_(msg`Delete message`)}
|
|
||||||
description={_(
|
|
||||||
msg`Are you sure you want to delete this message?? The message will be deleted for you, but not for other participants.`,
|
|
||||||
)}
|
|
||||||
confirmButtonCta={_(msg`Leave`)}
|
|
||||||
confirmButtonColor="negative"
|
|
||||||
onConfirm={onDelete}
|
|
||||||
/>
|
|
||||||
</GrowWrapper>
|
</GrowWrapper>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user