Browse Source

petits ajustements

master
DemiBSel 2 years ago
parent
commit
1346ae5bfa

+ 13
- 8
App.js View File

@@ -4,23 +4,28 @@ import { StyleSheet, Text, View, TextInput } from 'react-native';
4 4
 import AddDepense from './components/add_depense';
5 5
 import DepensesList from './components/depenses_list';
6 6
 import TitleBar from './components/title_bar';
7
-import {sqlite_exec_query} from './db/query';
7
+import {sqlite_exec_parameterised, sqlite_exec_query} from './db/query';
8 8
 
9 9
 
10 10
 export default function App() {
11 11
   const [durationMode, onChangeDuration] = React.useState("days");
12
-  const [dailyObjective, onChangeObjective] = React.useState(1);
13
-  console.log("bah")
14
-  useEffect( () => {
12
+  const [dailyObjective, onChangeObjective] = React.useState(-1);
13
+  if(dailyObjective != -1)
14
+    sqlite_exec_parameterised("update objective set value = ?", [dailyObjective], (res) => {});
15
+
16
+    useEffect( () => {
15 17
     sqlite_exec_query("create table if not exists objective(value integer)", (res)=>{
16 18
       sqlite_exec_query("select * from objective", (res) => {
17
-        console.log(res.rows.length);
18 19
         if(res.rows.length == 0)
19
-          onChangeObjective(15);
20
+          {
21
+            sqlite_exec_parameterised("insert into objective (value) values (?)",[dailyObjective],(res)=>{})
22
+          }
23
+        else
24
+          {
25
+            onChangeObjective(res.rows._array[0].value);
26
+          } 
20 27
       });
21 28
     });
22
-    sqlite_exec_query(`
23
-      create table if not exists expense (id integer primary key not null, value real, description text, date integer);`,(res)=>{});
24 29
   });
25 30
 
26 31
   return (

+ 23
- 0
components/depense_list_entry.js View File

@@ -0,0 +1,23 @@
1
+import React, { useEffect } from 'react';
2
+import { StyleSheet, Text, View, TextInput } from 'react-native';
3
+
4
+
5
+export default function DepenseListEntry(props){
6
+
7
+    return(
8
+        <View style={depense_list_entry_style.depense_list_entry}>
9
+                <Text >{props.depense.description}</Text>
10
+                <Text >{props.depense.value}</Text>
11
+            </View>
12
+    )
13
+}
14
+
15
+const depense_list_entry_style = StyleSheet.create({
16
+    depense_list_entry: {
17
+        display: "flex",
18
+        flexDirection: "row",
19
+        justifyContent: "space-between",
20
+        margin: 2,
21
+        borderBottomWidth: 0.5
22
+    }
23
+  });

+ 9
- 7
components/depenses_list.js View File

@@ -1,15 +1,19 @@
1 1
 import React, { useEffect } from 'react';
2 2
 import { StyleSheet, Text, View, TextInput } from 'react-native';
3 3
 import { sqlite_exec_query } from '../db/query';
4
+import DepenseListEntry from './depense_list_entry';
4 5
 
5 6
 
6 7
 function DepensesList(props)
7 8
 {
8 9
     const [depenses, onGetDepenses] = React.useState([]);
9 10
     useEffect( () => {
10
-        sqlite_exec_query("select * from expense", (res) => {
11
-            onGetDepenses(res.rows._array);
12
-        })
11
+        sqlite_exec_query(`create table if not exists expense (id integer primary key not null, value real, description text, date integer);`,(res)=>{
12
+            sqlite_exec_query("select * from expense", (res) => {
13
+                onGetDepenses(res.rows._array);
14
+            });
15
+        });
16
+        
13 17
     });
14 18
     let content = []
15 19
 
@@ -17,10 +21,8 @@ function DepensesList(props)
17 21
         .sort((a,b) => (a.date > b.date) ? -1 : (b.date > a.date) ? 1 : 0)
18 22
         .forEach( function(depense){
19 23
         content.push(
20
-            <View key={"depense_list_depense"+depense.id} style={depense_list_style.depense_list_entry}>
21
-                <Text >{depense.description}</Text>
22
-                <Text >{depense.value}</Text>
23
-            </View>
24
+            <DepenseListEntry key={"depense_list_depense"+depense.id} depense={depense}/>
25
+            
24 26
         )
25 27
     });
26 28
 

+ 33
- 26
components/title_bar.js View File

@@ -1,5 +1,6 @@
1 1
 import React from 'react';
2 2
 import { StyleSheet, Text, View, TextInput, Button } from 'react-native';
3
+import TitleBarButton from './title_bar/title_bar_button';
3 4
 
4 5
 
5 6
 function TitleBar(props){
@@ -16,7 +17,7 @@ function TitleBar(props){
16 17
         displayValue = expenseMultiplicator*props.dailyExpense
17 18
 
18 19
     return (
19
-        <View style={styles.controlBar}>
20
+        <View style={title_bar_styles.controlBar}>
20 21
             <View style={{
21 22
             flexDirection: 'row'
22 23
             }}>
@@ -24,7 +25,7 @@ function TitleBar(props){
24 25
             <TextInput
25 26
                 keyboardType="numeric"
26 27
                 value={(displayValue).toString()}
27
-                style={styles.input}
28
+                style={title_bar_styles.input}
28 29
                 onChangeText={(value) => onDurationEdit(value)}
29 30
                 onEndEditing={() => {
30 31
                     props.onChangeObjective(parseInt(parseInt( currentEditValue ) / expenseMultiplicator));
@@ -37,40 +38,46 @@ function TitleBar(props){
37 38
             alignItems: 'flex-end',
38 39
             flexDirection: 'row'
39 40
             }}>
40
-            <Button 
41
-                onPress={() => props.onChangeDuration("days")}
42
-                title={"Jour"}></Button>
43
-            <Button 
44
-                onPress={() => {
45
-                    props.onChangeDuration("weeks");
46
-                    onDurationEdit(null);
47
-                }}
48
-                title={"Semaine"}></Button>
49
-            <Button 
50
-                title={"Mois"}
51
-                onPress={() => {
52
-                    props.onChangeDuration("months");
53
-                    onDurationEdit(null);
54
-                    }}></Button>
55
-            <Button 
56
-                title={"Année"}
57
-                onPress={() => {
58
-                    props.onChangeDuration("year")
59
-                    onDurationEdit(null);
60
-                    }}></Button>
61
-            </View>
41
+            <TitleBarButton 
42
+                currentDurationMode={props.durationMode}
43
+                onChangeDuration={props.onChangeDuration} 
44
+                onDurationEdit={onDurationEdit} 
45
+                durationMode="days"/>
46
+            <TitleBarButton 
47
+                currentDurationMode={props.durationMode}
48
+                onChangeDuration={props.onChangeDuration} 
49
+                onDurationEdit={onDurationEdit} 
50
+                durationMode="weeks"/>
51
+            <TitleBarButton 
52
+                currentDurationMode={props.durationMode}
53
+                onChangeDuration={props.onChangeDuration} 
54
+                onDurationEdit={onDurationEdit} 
55
+                durationMode="months"/>
56
+            <TitleBarButton 
57
+                currentDurationMode={props.durationMode}
58
+                onChangeDuration={props.onChangeDuration} 
59
+                onDurationEdit={onDurationEdit} 
60
+                durationMode="year"/>
62 61
         </View>
62
+    </View>
63
+
63 64
     );
64 65
 }
65 66
 
66
-const styles = StyleSheet.create({
67
+const title_bar_styles = StyleSheet.create({
67 68
     controlBar: {
68 69
       flexDirection: "row",
69 70
       justifyContent: 'space-between',
70
-      alignItems: 'center'
71
+      alignItems: 'center',
72
+      borderBottomWidth: 0.5,
73
+      paddingBottom: 5,
71 74
     },
72 75
     input: {
73 76
         borderWidth: 0.5
77
+    },
78
+    highlighted: {
79
+        backgroundColor: "#ff8899",
80
+        borderWidth: 3
74 81
     }
75 82
   });
76 83
 

+ 33
- 0
components/title_bar/title_bar_button.js View File

@@ -0,0 +1,33 @@
1
+import React from 'react';
2
+import { StyleSheet, Text, Pressable, View, TextInput, Button } from 'react-native';
3
+
4
+
5
+export default function TitleBarButton(props){
6
+
7
+    return(
8
+        <Pressable 
9
+        style={[styles.button, (props.currentDurationMode == props.durationMode ? styles.highlighted : null)]} 
10
+        onPress={() => {
11
+            props.onChangeDuration(props.durationMode)
12
+            props.onDurationEdit(null);
13
+            }}>
14
+        <Text>{props.durationMode}</Text>
15
+        </Pressable>
16
+    )
17
+}
18
+
19
+
20
+const styles = StyleSheet.create({
21
+    button: {
22
+      padding: 1,
23
+      margin:1,
24
+      borderWidth: 1,
25
+    },
26
+    input: {
27
+        borderWidth: 0.5
28
+    },
29
+    highlighted: {
30
+        backgroundColor: "#ECECEC",
31
+        borderWidth: 1.5,
32
+    }
33
+  });

+ 21
- 11
package-lock.json View File

@@ -3276,13 +3276,13 @@
3276 3276
       },
3277 3277
       "dependencies": {
3278 3278
         "@expo/config-plugins": {
3279
-          "version": "4.0.7",
3280
-          "resolved": "https://registry.npmjs.org/@expo/config-plugins/-/config-plugins-4.0.7.tgz",
3281
-          "integrity": "sha512-m160Y039LJcI8Q4arzA9edWNRPPnLnTe5tB41812Mn1BAmtoZy9OMs4Rj78OKFkMx6A9JJKUTWMnP/FVAbeMiw==",
3279
+          "version": "4.0.9",
3280
+          "resolved": "https://registry.npmjs.org/@expo/config-plugins/-/config-plugins-4.0.9.tgz",
3281
+          "integrity": "sha512-3wv0uhG5U5O4BGX2qm4gjFK3jvYVTy0raFsR6B/2zoBNgD3lXF8Ae5osVN118aKNZb2B7SMx3V7McunZhf7RXg==",
3282 3282
           "requires": {
3283 3283
             "@expo/config-types": "^43.0.1",
3284
-            "@expo/json-file": "8.2.33",
3285
-            "@expo/plist": "0.0.15",
3284
+            "@expo/json-file": "8.2.34",
3285
+            "@expo/plist": "0.0.16",
3286 3286
             "@react-native/normalize-color": "^2.0.0",
3287 3287
             "chalk": "^4.1.2",
3288 3288
             "debug": "^4.3.1",
@@ -3302,10 +3302,20 @@
3302 3302
           "resolved": "https://registry.npmjs.org/@expo/config-types/-/config-types-43.0.1.tgz",
3303 3303
           "integrity": "sha512-EtllpCGDdB/UdwAIs5YXJwBLpbFQNdlLLrxIvoILA9cXrpQMWkeDCT9lQPJzFRMFcLUaMuGvkzX2tR4tx5EQFQ=="
3304 3304
         },
3305
+        "@expo/json-file": {
3306
+          "version": "8.2.34",
3307
+          "resolved": "https://registry.npmjs.org/@expo/json-file/-/json-file-8.2.34.tgz",
3308
+          "integrity": "sha512-ZxtBodAZGxdLtgKzmsC+8ViUxt1mhFW642Clu2OuG3f6PAyAFsU/SqEGag9wKFaD3x3Wt8VhL+3y5fMJmUFgPw==",
3309
+          "requires": {
3310
+            "@babel/code-frame": "~7.10.4",
3311
+            "json5": "^1.0.1",
3312
+            "write-file-atomic": "^2.3.0"
3313
+          }
3314
+        },
3305 3315
         "@expo/plist": {
3306
-          "version": "0.0.15",
3307
-          "resolved": "https://registry.npmjs.org/@expo/plist/-/plist-0.0.15.tgz",
3308
-          "integrity": "sha512-LDxiS0KNZAGJu4fIJhbEKczmb+zeftl1NU0LE0tj0mozoMI5HSKdMUchgvnBm35bwBl8ekKkAfJJ0ONxljWQjQ==",
3316
+          "version": "0.0.16",
3317
+          "resolved": "https://registry.npmjs.org/@expo/plist/-/plist-0.0.16.tgz",
3318
+          "integrity": "sha512-yQMt2CTm2VNLiHv2/EqHYrHvfflI2mFJd+DZIQQy569hvpZle0CxMPGH1p2KatbrO8htxJNvwrlR/4TIwhQJ5w==",
3309 3319
           "requires": {
3310 3320
             "@xmldom/xmldom": "~0.7.0",
3311 3321
             "base64-js": "^1.2.3",
@@ -6449,9 +6459,9 @@
6449 6459
       "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8="
6450 6460
     },
6451 6461
     "reselect": {
6452
-      "version": "4.1.4",
6453
-      "resolved": "https://registry.npmjs.org/reselect/-/reselect-4.1.4.tgz",
6454
-      "integrity": "sha512-i1LgXw8DKSU5qz1EV0ZIKz4yIUHJ7L3bODh+Da6HmVSm9vdL/hG7IpbgzQ3k2XSirzf8/eI7OMEs81gb1VV2fQ=="
6462
+      "version": "4.1.5",
6463
+      "resolved": "https://registry.npmjs.org/reselect/-/reselect-4.1.5.tgz",
6464
+      "integrity": "sha512-uVdlz8J7OO+ASpBYoz1Zypgx0KasCY20H+N8JD13oUMtPvSHQuscrHop4KbXrbsBcdB9Ds7lVK7eRkBIfO43vQ=="
6455 6465
     },
6456 6466
     "resolve": {
6457 6467
       "version": "1.20.0",

+ 3
- 3
package.json View File

@@ -8,8 +8,9 @@
8 8
   },
9 9
   "dependencies": {
10 10
     "@databases/expo": "^5.0.0",
11
-    "expo": "~43.0.2",
11
+    "expo": "^43.0.3",
12 12
     "expo-splash-screen": "~0.13.5",
13
+    "expo-sqlite": "~10.0.3",
13 14
     "expo-status-bar": "~1.1.0",
14 15
     "expo-updates": "~0.10.15",
15 16
     "react": "17.0.1",
@@ -20,8 +21,7 @@
20 21
     "react-native-safe-area-context": "3.3.2",
21 22
     "react-native-screens": "~3.8.0",
22 23
     "react-native-sqlite-storage": "^6.0.1",
23
-    "react-native-web": "0.17.1",
24
-    "expo-sqlite": "~10.0.3"
24
+    "react-native-web": "0.17.1"
25 25
   },
26 26
   "devDependencies": {
27 27
     "@babel/core": "^7.12.9",

Loading…
Cancel
Save