浏览代码

delete depenses

master
DemiSel 2 年前
父节点
当前提交
a45ab22aef
共有 4 个文件被更改,包括 36 次插入4 次删除
  1. 35
    1
      components/depense_edit/depense_form.js
  2. 0
    1
      components/depense_list_entry.js
  3. 0
    1
      components/depenses_list.js
  4. 1
    1
      db/query.js

+ 35
- 1
components/depense_edit/depense_form.js 查看文件

@@ -1,5 +1,5 @@
1 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 3
 import { sqlite_exec_parameterised } from '../../db/query';
4 4
 import DateTimePicker from '@react-native-community/datetimepicker';
5 5
 
@@ -97,6 +97,34 @@ export default function DepenseForm(props){
97 97
                         }}>
98 98
                         <Text>{update_depense ? "Update" : "Add"}</Text>
99 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 128
             </View>
101 129
     );
102 130
 }
@@ -125,5 +153,11 @@ const depense_form_styles = StyleSheet.create({
125 153
     button_add: {
126 154
         borderWidth: 1,
127 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 查看文件

@@ -11,7 +11,6 @@ export default function DepenseListEntry(props){
11 11
             <Pressable 
12 12
             onPress={() => {
13 13
                 toggleEdit(!editing);
14
-                console.log(props.depense);
15 14
             }}
16 15
             style={depense_list_entry_style.pressable_depense_list_entry}>
17 16
                     <Text >{props.depense.description}</Text>

+ 0
- 1
components/depenses_list.js 查看文件

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

+ 1
- 1
db/query.js 查看文件

@@ -14,7 +14,7 @@ export function sqlite_exec_parameterised(inQuery, inParams, inCallback){
14 14
         tx.executeSql(inQuery, inParams,
15 15
         (txobj, res) => inCallback(res),
16 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
 }

正在加载...
取消
保存