Skip to content

Commit

Permalink
3. After a long press - delete an entry
Browse files Browse the repository at this point in the history
  • Loading branch information
ramirobg94 committed Oct 18, 2024
1 parent ecf09ba commit 8281d5f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/arena-mobile-ui/components/Pressable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ const Pressable = ({
onLongPress = EMPTY_FN,
accessibilityState = EMPTY_OBJECT,
children,
pressedColor,
}) => {
const customStyle = useCallback(
({pressed}) => {
return StyleSheet.compose(style || {}, {opacity: pressed ? 0.5 : 1});
return StyleSheet.compose(style || {}, {
opacity: pressed ? 0.5 : 1,
backgroundColor: pressedColor && pressed ? pressedColor : 'transparent',
});
},
[style],
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import React, {useCallback, useMemo} from 'react';
import React, {useCallback, useMemo, useState} from 'react';
import {useTranslation} from 'react-i18next';
import {useDispatch, useSelector} from 'react-redux';

import Pressable from 'arena-mobile-ui/components/Pressable';
import useNodeDefNameOrLabel from 'arena-mobile-ui/hooks/useNodeDefNameOrLabel';
import {alert} from 'arena-mobile-ui/utils';
import {selectors as formSelectors, actions as formActions} from 'state/form';

import Pressable from 'arena-mobile-ui/components/Pressable';
import * as colors from 'arena-mobile-ui/colors';
import Cell from '../Cell';

import styles from './styles';

const Row = ({item: parentNode, headers, getWidth, onPress}) => {
const {t} = useTranslation();
const dispatch = useDispatch();
const parentEntityNodeDef = useSelector(formSelectors.getParentEntityNodeDef);
const parentLabel = useNodeDefNameOrLabel({nodeDef: parentEntityNodeDef});
const isRecordLocked = useSelector(formSelectors.isRecordLocked);
const parentEntityKeyString = useSelector(state =>
formSelectors.getEntityKey(state, parentNode),
);

const renderCells = useMemo(() => {
return headers.map(nodeDef => (
<Cell
Expand All @@ -23,8 +38,28 @@ const Row = ({item: parentNode, headers, getWidth, onPress}) => {
[onPress, parentNode],
);

const handleDeleteEntityNode = useCallback(() => {
if (isRecordLocked) return;
alert({
title: t('Form:deleteNode.alert.title'),
message: t('Form:deleteNode.alert.message', {
name: `${parentLabel} [${parentEntityKeyString}]`,
}),
acceptText: t('Form:deleteNode.alert.accept'),
dismissText: t('Form:deleteNode.alert.dismiss'),
onAccept: () => {
dispatch(formActions.deleteNodeEntity({node: parentNode}));
},
onDismiss: () => null,
});
}, [dispatch, parentEntityKeyString, parentLabel, parentNode, t]);

return (
<Pressable onPress={handlePress} style={styles.container}>
<Pressable
onPress={handlePress}
style={styles.container}
onLongPress={handleDeleteEntityNode}
pressedColor={colors.alert}>
{renderCells}
</Pressable>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {StyleSheet} from 'react-native';

import * as colors from 'arena-mobile-ui/colors';

const styles = StyleSheet.create({
container: {
flexDirection: 'row',
backgroundColor: colors.backgroundLight,
},
});

Expand Down

0 comments on commit 8281d5f

Please sign in to comment.