Skip to content

Commit

Permalink
reset positions on map change alert
Browse files Browse the repository at this point in the history
  • Loading branch information
sknr15 committed Oct 26, 2022
1 parent 5b2c2b0 commit be99c47
Showing 1 changed file with 68 additions and 8 deletions.
76 changes: 68 additions & 8 deletions src/Map/MapPicker/MapPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,47 @@ export const MapPicker = ({ map, onChange, testId }: Props) => {
};
}

let _positions = tempMap.positions;

if (tempMap.positions && tempMap.positions.length > 0) {
if (Platform.OS === 'web') {
const result = window?.confirm(`Do you want to reset the positions?`);

if (result) {
_positions = [];
}
} else {
Alert.alert('Reset?', `Do you want to reset the positions?`, [
{
text: 'No',
style: 'cancel'
},
{
text: 'Yes',
onPress: () => {
setTempMap({ ...tempMap, imageSource: _src, positions: [] });
if (onChange) {
onChange({ ...tempMap, imageSource: _src, positions: [] });
}
return;
},
style: 'destructive'
}
]);
}
}

setTempMap({
...tempMap,
imageSource: _src
//positions: []
imageSource: _src,
positions: _positions
});

if (onChange) {
onChange({
...tempMap,
imageSource: _src
// positions: []
imageSource: _src,
positions: _positions
});
}
}
Expand Down Expand Up @@ -106,17 +136,47 @@ export const MapPicker = ({ map, onChange, testId }: Props) => {
}

if (tempMap) {
let _positions = tempMap.positions;

if (tempMap.positions && tempMap.positions.length > 0) {
if (Platform.OS === 'web') {
const result = window?.confirm(`Do you want to reset the positions?`);

if (result) {
_positions = [];
}
} else {
Alert.alert('Reset?', `Do you want to reset the positions?`, [
{
text: 'No',
style: 'cancel'
},
{
text: 'Yes',
onPress: () => {
setTempMap({ ...tempMap, imageSource: { uri }, positions: [] });
if (onChange) {
onChange({ ...tempMap, imageSource: { uri }, positions: [] });
}
return;
},
style: 'destructive'
}
]);
}
}

setTempMap({
...tempMap,
imageSource: { uri }
//positions: []
imageSource: { uri },
positions: _positions
});

if (onChange)
onChange({
...tempMap,
imageSource: { uri }
//positions: []
imageSource: { uri },
positions: _positions
});
}
}
Expand Down

0 comments on commit be99c47

Please sign in to comment.