Browse Source

delete depenses

master
DemiSel 2 years ago
parent
commit
a45ab22aef

+ 35
- 1
components/depense_edit/depense_form.js View File

1
 import React from 'react';
1
 import React from 'react';
2
-import { StyleSheet, Text, View, TextInput, Button, Pressable } from 'react-native';
2
+import { StyleSheet, Text, View, TextInput, Alert, Pressable } from 'react-native';
3
 import { sqlite_exec_parameterised } from '../../db/query';
3
 import { sqlite_exec_parameterised } from '../../db/query';
4
 import DateTimePicker from '@react-native-community/datetimepicker';
4
 import DateTimePicker from '@react-native-community/datetimepicker';
5
 
5
 
97
                         }}>
97
                         }}>
98
                         <Text>{update_depense ? "Update" : "Add"}</Text>
98
                         <Text>{update_depense ? "Update" : "Add"}</Text>
99
                     </Pressable>
99
                     </Pressable>
100
+                    {
101
+                        update_depense ? 
102
+                        <Pressable
103
+                            style={ [depense_form_styles.button_add, depense_form_styles.button_delete]}
104
+                            onPress={ () => {
105
+                                console.log("delete");
106
+                                Alert.alert(
107
+                                    "Delete ?",
108
+                                    "Ciao bye bye ?",
109
+                                    [
110
+                                        {text: "Oopsie", style: "cancel"},
111
+                                        {text: "Oui oui", style: "destructive", onPress: () => {
112
+                                            sqlite_exec_parameterised(
113
+                                                "DELETE FROM expense WHERE id = ?",
114
+                                                [props.depense.id],(res) =>
115
+                                                {
116
+                                                    props.fetchDepenses();
117
+                                                }
118
+                                            )
119
+                                        }}
120
+                                    ])
121
+                            }}
122
+                            >
123
+                                <Text>💣</Text>
124
+                        </Pressable> :
125
+                        <View/>
126
+                    }
127
+                    
100
             </View>
128
             </View>
101
     );
129
     );
102
 }
130
 }
125
     button_add: {
153
     button_add: {
126
         borderWidth: 1,
154
         borderWidth: 1,
127
         padding: 10,
155
         padding: 10,
156
+        margin: 1,
128
     },
157
     },
158
+    button_delete: {
159
+        position: 'absolute',
160
+        right: 1,
161
+        borderColor: "#CC5555",
162
+    }
129
 })
163
 })

+ 0
- 1
components/depense_list_entry.js View File

11
             <Pressable 
11
             <Pressable 
12
             onPress={() => {
12
             onPress={() => {
13
                 toggleEdit(!editing);
13
                 toggleEdit(!editing);
14
-                console.log(props.depense);
15
             }}
14
             }}
16
             style={depense_list_entry_style.pressable_depense_list_entry}>
15
             style={depense_list_entry_style.pressable_depense_list_entry}>
17
                     <Text >{props.depense.description}</Text>
16
                     <Text >{props.depense.description}</Text>

+ 0
- 1
components/depenses_list.js View File

34
     }
34
     }
35
         depenses
35
         depenses
36
             .forEach( function(depense){
36
             .forEach( function(depense){
37
-            // console.log(depense.date)
38
             content.push(
37
             content.push(
39
                 <DepenseListEntry fetchDepenses={() => preventFetchDepenses(false)} key={"depense_list_depense"+depense.id} depense={depense}/>
38
                 <DepenseListEntry fetchDepenses={() => preventFetchDepenses(false)} key={"depense_list_depense"+depense.id} depense={depense}/>
40
             )
39
             )

+ 1
- 1
db/query.js View File

14
         tx.executeSql(inQuery, inParams,
14
         tx.executeSql(inQuery, inParams,
15
         (txobj, res) => inCallback(res),
15
         (txobj, res) => inCallback(res),
16
         (txobj, err) => {
16
         (txobj, err) => {
17
-            console.log("query.js error |");console.log(err);
17
+            console.error("query.js error |");console.log(err);
18
         })
18
         })
19
     })
19
     })
20
 }
20
 }

Loading…
Cancel
Save