Quellcode durchsuchen

database created, now use it

master
DemiSel vor 3 Jahren
Ursprung
Commit
8cce729a14
7 geänderte Dateien mit 232 neuen und 33 gelöschten Zeilen
  1. 29
    9
      App.js
  2. 13
    0
      components/depenses_list.js
  3. 48
    12
      components/title_bar.js
  4. 0
    6
      db/database-connect.js
  5. 130
    3
      package-lock.json
  6. 8
    3
      package.json
  7. 4
    0
      tsconfig.json

+ 29
- 9
App.js Datei anzeigen

@@ -1,16 +1,41 @@
1 1
 import { StatusBar } from 'expo-status-bar';
2
-import React from 'react';
2
+import React, { useEffect } from 'react';
3 3
 import { StyleSheet, Text, View, TextInput } from 'react-native';
4
+import DepensesList from './components/depenses_list';
4 5
 import TitleBar from './components/title_bar';
5 6
 
7
+// https://github.com/expo/examples/blob/master/with-sqlite/App.js
8
+import * as SQLite from 'expo-sqlite';
9
+
10
+const db = SQLite.openDatabase("datacoucou.db");
11
+
12
+
6 13
 export default function App() {
14
+  const [durationMode, onChangeDuration] = React.useState("days");
15
+  const [dailyObjective, onChangeObjective] = React.useState(15);
16
+
17
+  useEffect( () => {
18
+    db.transaction((tx) => {
19
+      tx.executeSql(
20
+        `
21
+        create table if not exists expense (id integer primary key not null, value real, description text, date integer);
22
+        create table if not exists objective(value integer);
23
+        `
24
+      );
25
+    });
26
+      }, [])
27
+
7 28
   return (
8 29
     <View style={styles.container, {
9 30
       flexDirection: "column"
10 31
     }}>
11
-      <TitleBar/>
12
-      <Text>Open up App.js to start working on your app!</Text>
13
-      <StatusBar style="auto" />
32
+      <TitleBar 
33
+        onChangeDuration={onChangeDuration} 
34
+        durationMode={durationMode} 
35
+        dailyExpense={dailyObjective}
36
+        onChangeObjective={onChangeObjective}/>
37
+      <DepensesList durationMode={durationMode} database={db}/>
38
+      <StatusBar hidden />
14 39
     </View>
15 40
   );
16 41
 }
@@ -21,10 +46,5 @@ const styles = StyleSheet.create({
21 46
     backgroundColor: '#fff',
22 47
     alignItems: 'center',
23 48
     justifyContent: 'center',
24
-  },
25
-  controlBar: {
26
-    flex: 1,
27
-    flexDirection: "row",
28
-    justifyContent: 'space-between'
29 49
   }
30 50
 });

+ 13
- 0
components/depenses_list.js Datei anzeigen

@@ -0,0 +1,13 @@
1
+import React from 'react';
2
+import { StyleSheet, Text, View, TextInput } from 'react-native';
3
+
4
+
5
+function DepensesList(props)
6
+{
7
+
8
+    return(
9
+        <Text>{props.durationMode}</Text>
10
+    )
11
+}
12
+
13
+export default DepensesList

+ 48
- 12
components/title_bar.js Datei anzeigen

@@ -3,6 +3,17 @@ import { StyleSheet, Text, View, TextInput, Button } from 'react-native';
3 3
 
4 4
 
5 5
 function TitleBar(props){
6
+    let expenseMultiplicator = 1;
7
+    if (props.durationMode === "year")
8
+        expenseMultiplicator = 365
9
+        if (props.durationMode === "weeks")
10
+        expenseMultiplicator = 7
11
+    if(props.durationMode === "months")
12
+        expenseMultiplicator = 30
13
+    const [currentEditValue, onDurationEdit] = React.useState(null);
14
+    let displayValue = currentEditValue
15
+    if(null == displayValue)
16
+        displayValue = expenseMultiplicator*props.dailyExpense
6 17
 
7 18
     return (
8 19
         <View style={styles.controlBar}>
@@ -10,31 +21,56 @@ function TitleBar(props){
10 21
             flexDirection: 'row'
11 22
             }}>
12 23
             <Text>Objectif</Text>
13
-            <TextInput/>
24
+            <TextInput
25
+                keyboardType="numeric"
26
+                value={(displayValue).toString()}
27
+                style={styles.input}
28
+                onChangeText={(value) => onDurationEdit(value)}
29
+                onEndEditing={() => {
30
+                    props.onChangeObjective(parseInt(parseInt( currentEditValue ) / expenseMultiplicator));
31
+                    onDurationEdit(null);
32
+                    }}
33
+                />
34
+            <Text>(/{props.durationMode})</Text>
14 35
             </View>
15 36
             <View style={{
16 37
             alignItems: 'flex-end',
17 38
             flexDirection: 'row'
18 39
             }}>
19
-            <Button title={"Jour"}></Button>
20
-            <Button title={"Mois"}></Button>
21
-            <Button title={"YTD"}></Button>
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>
22 61
             </View>
23 62
         </View>
24 63
     );
25 64
 }
26 65
 
27 66
 const styles = StyleSheet.create({
28
-    container: {
29
-      flex: 1,
30
-      backgroundColor: '#fff',
31
-      alignItems: 'center',
32
-      justifyContent: 'center',
33
-    },
34 67
     controlBar: {
35
-      flex: 1,
36 68
       flexDirection: "row",
37
-      justifyContent: 'space-between'
69
+      justifyContent: 'space-between',
70
+      alignItems: 'center'
71
+    },
72
+    input: {
73
+        borderWidth: 0.5
38 74
     }
39 75
   });
40 76
 

+ 0
- 6
db/database-connect.js Datei anzeigen

@@ -1,6 +0,0 @@
1
-import {openDatabase} from 'react-native-sqlite-storage';
2
-
3
-// TODO reprends ici https://blog.logrocket.com/using-sqlite-with-react-native/
4
-export const getDBConnection = async () => {
5
-    return openDatabase({name: 'todo-data.db', location: 'default'});
6
-  };

+ 130
- 3
package-lock.json Datei anzeigen

@@ -1229,6 +1229,42 @@
1229 1229
         "minimist": "^1.2.0"
1230 1230
       }
1231 1231
     },
1232
+    "@databases/escape-identifier": {
1233
+      "version": "1.0.2",
1234
+      "resolved": "https://registry.npmjs.org/@databases/escape-identifier/-/escape-identifier-1.0.2.tgz",
1235
+      "integrity": "sha512-O3ZrXE01nonp3XjFJ3Z4S/yZjuc4NEhCfmGIn0cHgif0yrZmgZuuMvUkYaCv77UQQN1v5zGdV1IEUECrhu0GeA==",
1236
+      "requires": {
1237
+        "@databases/validate-unicode": "^1.0.0"
1238
+      }
1239
+    },
1240
+    "@databases/expo": {
1241
+      "version": "5.0.0",
1242
+      "resolved": "https://registry.npmjs.org/@databases/expo/-/expo-5.0.0.tgz",
1243
+      "integrity": "sha512-VV4ATcsyRqo1+EwbUqOn22EQ3YBCM0WU1KhyadnDIvKsKqLQC/PfhtEeHfnxR2+/RDANfIsX5ofbVwjM66TcsA==",
1244
+      "requires": {
1245
+        "@databases/websql-core": "^4.0.0"
1246
+      }
1247
+    },
1248
+    "@databases/sql": {
1249
+      "version": "3.2.0",
1250
+      "resolved": "https://registry.npmjs.org/@databases/sql/-/sql-3.2.0.tgz",
1251
+      "integrity": "sha512-xQZzKIa0lvcdo0MYxnyFMVS1TRla9lpDSCYkobJl19vQEOJ9TqE4o8QBGRJNUfhSkbQIWyvMeBl3KBBbqyUVQQ=="
1252
+    },
1253
+    "@databases/validate-unicode": {
1254
+      "version": "1.0.0",
1255
+      "resolved": "https://registry.npmjs.org/@databases/validate-unicode/-/validate-unicode-1.0.0.tgz",
1256
+      "integrity": "sha512-dLKqxGcymeVwEb/6c44KjOnzaAafFf0Wxa8xcfEjx/qOl3rdijsKYBAtIGhtVtOlpPf/PFKfgTuFurSPn/3B/g=="
1257
+    },
1258
+    "@databases/websql-core": {
1259
+      "version": "4.0.0",
1260
+      "resolved": "https://registry.npmjs.org/@databases/websql-core/-/websql-core-4.0.0.tgz",
1261
+      "integrity": "sha512-4PtvllVaQdTxY+vmM6CHEUVjlepAhMmKXsLbElrXjdpV3NKJfeuMMAQXqj+e+YOxBpxSxi4iOmJy1s07tMQkTQ==",
1262
+      "requires": {
1263
+        "@babel/code-frame": "^7.0.0",
1264
+        "@databases/escape-identifier": "^1.0.0",
1265
+        "@databases/sql": "^3.0.0"
1266
+      }
1267
+    },
1232 1268
     "@egjs/hammerjs": {
1233 1269
       "version": "2.0.17",
1234 1270
       "resolved": "https://registry.npmjs.org/@egjs/hammerjs/-/hammerjs-2.0.17.tgz",
@@ -1476,6 +1512,18 @@
1476 1512
         "lodash.template": "^4.5.0"
1477 1513
       }
1478 1514
     },
1515
+    "@expo/websql": {
1516
+      "version": "1.0.1",
1517
+      "resolved": "https://registry.npmjs.org/@expo/websql/-/websql-1.0.1.tgz",
1518
+      "integrity": "sha1-//DPnBuqH3D54dZYt8OaQg2bEKk=",
1519
+      "requires": {
1520
+        "argsarray": "^0.0.1",
1521
+        "immediate": "^3.2.2",
1522
+        "noop-fn": "^1.0.0",
1523
+        "pouchdb-collections": "^1.0.1",
1524
+        "tiny-queue": "^0.2.1"
1525
+      }
1526
+    },
1479 1527
     "@hapi/hoek": {
1480 1528
       "version": "9.2.1",
1481 1529
       "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.2.1.tgz",
@@ -1923,6 +1971,38 @@
1923 1971
       "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.9.tgz",
1924 1972
       "integrity": "sha512-MKmdASMf3LtPzwLyRrFjtFFZ48cMf8jmX5VRYrDQiJa8Ybu5VAmkqBWqKU8fdCwD8ysw4mQ9nrEHvzg6gunR7A=="
1925 1973
     },
1974
+    "@types/prop-types": {
1975
+      "version": "15.7.4",
1976
+      "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.4.tgz",
1977
+      "integrity": "sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ==",
1978
+      "dev": true
1979
+    },
1980
+    "@types/react": {
1981
+      "version": "17.0.35",
1982
+      "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.35.tgz",
1983
+      "integrity": "sha512-r3C8/TJuri/SLZiiwwxQoLAoavaczARfT9up9b4Jr65+ErAUX3MIkU0oMOQnrpfgHme8zIqZLX7O5nnjm5Wayw==",
1984
+      "dev": true,
1985
+      "requires": {
1986
+        "@types/prop-types": "*",
1987
+        "@types/scheduler": "*",
1988
+        "csstype": "^3.0.2"
1989
+      }
1990
+    },
1991
+    "@types/react-native": {
1992
+      "version": "0.64.19",
1993
+      "resolved": "https://registry.npmjs.org/@types/react-native/-/react-native-0.64.19.tgz",
1994
+      "integrity": "sha512-bT62QhaPvOKFGmlfURIC98ILjUDoIFrc2Bn5EzL3qciZrT91vHwkxFOkuEyQJy+DWaHCa2z3IrtIEJywkGu/Bg==",
1995
+      "dev": true,
1996
+      "requires": {
1997
+        "@types/react": "*"
1998
+      }
1999
+    },
2000
+    "@types/scheduler": {
2001
+      "version": "0.16.2",
2002
+      "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz",
2003
+      "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==",
2004
+      "dev": true
2005
+    },
1926 2006
     "@types/yargs": {
1927 2007
       "version": "15.0.14",
1928 2008
       "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.14.tgz",
@@ -2018,6 +2098,11 @@
2018 2098
         "sprintf-js": "~1.0.2"
2019 2099
       }
2020 2100
     },
2101
+    "argsarray": {
2102
+      "version": "0.0.1",
2103
+      "resolved": "https://registry.npmjs.org/argsarray/-/argsarray-0.0.1.tgz",
2104
+      "integrity": "sha1-bnIHtOzbObCviDA/pa4ivajfYcs="
2105
+    },
2021 2106
     "arr-diff": {
2022 2107
       "version": "4.0.0",
2023 2108
       "resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-4.0.0.tgz",
@@ -2844,6 +2929,12 @@
2844 2929
         "isobject": "^3.0.1"
2845 2930
       }
2846 2931
     },
2932
+    "csstype": {
2933
+      "version": "3.0.10",
2934
+      "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.10.tgz",
2935
+      "integrity": "sha512-2u44ZG2OcNUO9HDp/Jl8C07x6pU/eTR3ncV91SiK3dhG9TWvRVsCoJw14Ckx5DgWkzGA3waZWO3d7pgqpUI/XA==",
2936
+      "dev": true
2937
+    },
2847 2938
     "dayjs": {
2848 2939
       "version": "1.10.7",
2849 2940
       "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.7.tgz",
@@ -2946,9 +3037,9 @@
2946 3037
       "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
2947 3038
     },
2948 3039
     "electron-to-chromium": {
2949
-      "version": "1.3.903",
2950
-      "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.903.tgz",
2951
-      "integrity": "sha512-+PnYAyniRRTkNq56cqYDLq9LyklZYk0hqoDy9GpcU11H5QjRmFZVDbxtgHUMK/YzdNTcn1XWP5gb+hFlSCr20g=="
3040
+      "version": "1.3.904",
3041
+      "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.904.tgz",
3042
+      "integrity": "sha512-x5uZWXcVNYkTh4JubD7KSC1VMKz0vZwJUqVwY3ihsW0bst1BXDe494Uqbg3Y0fDGVjJqA8vEeGuvO5foyH2+qw=="
2952 3043
     },
2953 3044
     "emoji-regex": {
2954 3045
       "version": "8.0.0",
@@ -3312,6 +3403,16 @@
3312 3403
         "expo-modules-core": "~0.4.7"
3313 3404
       }
3314 3405
     },
3406
+    "expo-sqlite": {
3407
+      "version": "10.0.3",
3408
+      "resolved": "https://registry.npmjs.org/expo-sqlite/-/expo-sqlite-10.0.3.tgz",
3409
+      "integrity": "sha512-uQEb98iW7POCul3rrpamc8qZNvhoPwfqa457loSSt2HHJXCU7cnc5Ll7Xxdi+Yy1X5GGxmVlgss+DBT6A/K06g==",
3410
+      "requires": {
3411
+        "@expo/websql": "^1.0.1",
3412
+        "expo-modules-core": "~0.4.4",
3413
+        "lodash": "^4.17.15"
3414
+      }
3415
+    },
3315 3416
     "expo-status-bar": {
3316 3417
       "version": "1.1.0",
3317 3418
       "resolved": "https://registry.npmjs.org/expo-status-bar/-/expo-status-bar-1.1.0.tgz",
@@ -3855,6 +3956,11 @@
3855 3956
       "resolved": "https://registry.npmjs.org/image-size/-/image-size-0.6.3.tgz",
3856 3957
       "integrity": "sha512-47xSUiQioGaB96nqtp5/q55m0aBQSQdyIloMOc/x+QVTDZLNmXE892IIDrJ0hM1A5vcNUDD5tDffkSP5lCaIIA=="
3857 3958
     },
3959
+    "immediate": {
3960
+      "version": "3.3.0",
3961
+      "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.3.0.tgz",
3962
+      "integrity": "sha512-HR7EVodfFUdQCTIeySw+WDRFJlPcLOJbXfwwZ7Oom6tjsvZ3bOkCDJHehQC3nxJrv7+f9XecwazynjU8e4Vw3Q=="
3963
+    },
3858 3964
     "import-fresh": {
3859 3965
       "version": "2.0.0",
3860 3966
       "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-2.0.0.tgz",
@@ -5230,6 +5336,11 @@
5230 5336
       "resolved": "https://registry.npmjs.org/node-stream-zip/-/node-stream-zip-1.15.0.tgz",
5231 5337
       "integrity": "sha512-LN4fydt9TqhZhThkZIVQnF9cwjU3qmUH9h78Mx/K7d3VvfRqqwthLwJEUOEL0QPZ0XQmNN7be5Ggit5+4dq3Bw=="
5232 5338
     },
5339
+    "noop-fn": {
5340
+      "version": "1.0.0",
5341
+      "resolved": "https://registry.npmjs.org/noop-fn/-/noop-fn-1.0.0.tgz",
5342
+      "integrity": "sha1-XzPUfxPSFQ35PgywNmmemC94/78="
5343
+    },
5233 5344
     "normalize-css-color": {
5234 5345
       "version": "1.0.2",
5235 5346
       "resolved": "https://registry.npmjs.org/normalize-css-color/-/normalize-css-color-1.0.2.tgz",
@@ -5625,6 +5736,11 @@
5625 5736
       "resolved": "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz",
5626 5737
       "integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs="
5627 5738
     },
5739
+    "pouchdb-collections": {
5740
+      "version": "1.0.1",
5741
+      "resolved": "https://registry.npmjs.org/pouchdb-collections/-/pouchdb-collections-1.0.1.tgz",
5742
+      "integrity": "sha1-/mOhfal3YRq+98uAJssalVP9g1k="
5743
+    },
5628 5744
     "pretty-format": {
5629 5745
       "version": "26.6.2",
5630 5746
       "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz",
@@ -7107,6 +7223,11 @@
7107 7223
         "xtend": "~4.0.1"
7108 7224
       }
7109 7225
     },
7226
+    "tiny-queue": {
7227
+      "version": "0.2.1",
7228
+      "resolved": "https://registry.npmjs.org/tiny-queue/-/tiny-queue-0.2.1.tgz",
7229
+      "integrity": "sha1-JaZ/LG4lOyypQZd7XvdELvl6YEY="
7230
+    },
7110 7231
     "tmpl": {
7111 7232
       "version": "1.0.5",
7112 7233
       "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz",
@@ -7179,6 +7300,12 @@
7179 7300
       "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.3.1.tgz",
7180 7301
       "integrity": "sha512-cUGJnCdr4STbePCgqNFbpVNCepa+kAVohJs1sLhxzdH+gnEoOd8VhbYa7pD3zZYGiURWM2xzEII3fQcRizDkYQ=="
7181 7302
     },
7303
+    "typescript": {
7304
+      "version": "4.3.5",
7305
+      "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz",
7306
+      "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==",
7307
+      "dev": true
7308
+    },
7182 7309
     "ua-parser-js": {
7183 7310
       "version": "0.7.31",
7184 7311
       "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.31.tgz",

+ 8
- 3
package.json Datei anzeigen

@@ -7,10 +7,11 @@
7 7
     "start": "react-native start"
8 8
   },
9 9
   "dependencies": {
10
+    "@databases/expo": "^5.0.0",
10 11
     "expo": "~43.0.2",
11 12
     "expo-splash-screen": "~0.13.5",
12 13
     "expo-status-bar": "~1.1.0",
13
-    "expo-updates": "~0.10.13",
14
+    "expo-updates": "~0.10.15",
14 15
     "react": "17.0.1",
15 16
     "react-dom": "17.0.1",
16 17
     "react-native": "0.64.3",
@@ -19,10 +20,14 @@
19 20
     "react-native-safe-area-context": "3.3.2",
20 21
     "react-native-screens": "~3.8.0",
21 22
     "react-native-sqlite-storage": "^6.0.1",
22
-    "react-native-web": "0.17.1"
23
+    "react-native-web": "0.17.1",
24
+    "expo-sqlite": "~10.0.3"
23 25
   },
24 26
   "devDependencies": {
25
-    "@babel/core": "^7.12.9"
27
+    "@babel/core": "^7.12.9",
28
+    "typescript": "~4.3.5",
29
+    "@types/react": "~17.0.21",
30
+    "@types/react-native": "~0.64.12"
26 31
   },
27 32
   "private": true
28 33
 }

+ 4
- 0
tsconfig.json Datei anzeigen

@@ -0,0 +1,4 @@
1
+{
2
+  "compilerOptions": {},
3
+  "extends": "expo/tsconfig.base"
4
+}

Laden…
Abbrechen
Speichern