Explorar el Código

debut bouton qui veut pas se placer au bon endroit

master
DemiSel hace 3 años
padre
commit
e86f5c63ef
Se han modificado 3 ficheros con 67 adiciones y 26 borrados
  1. 29
    26
      App.js
  2. 24
    0
      components/add_depense.js
  3. 14
    0
      db/query.js

+ 29
- 26
App.js Ver fichero

@@ -1,41 +1,44 @@
1 1
 import { StatusBar } from 'expo-status-bar';
2 2
 import React, { useEffect } from 'react';
3 3
 import { StyleSheet, Text, View, TextInput } from 'react-native';
4
+import AddDepense from './components/add_depense';
4 5
 import DepensesList from './components/depenses_list';
5 6
 import TitleBar from './components/title_bar';
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");
7
+import sqlite_exec_query from './db/query';
11 8
 
12 9
 
13 10
 export default function App() {
14 11
   const [durationMode, onChangeDuration] = React.useState("days");
15
-  const [dailyObjective, onChangeObjective] = React.useState(15);
16
-
12
+  const [dailyObjective, onChangeObjective] = React.useState(1);
13
+  console.log("bah")
17 14
   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
-      }, [])
15
+    sqlite_exec_query("create table if not exists objective(value integer)", (res)=>{
16
+      sqlite_exec_query("select * from objective", (res) => {
17
+        console.log(res.rows.length);
18
+        if(res.rows.length == 0)
19
+          onChangeObjective(15);
20
+      })
21
+    })
22
+  });
27 23
 
28 24
   return (
29
-    <View style={styles.container, {
30
-      flexDirection: "column"
31
-    }}>
32
-      <TitleBar 
33
-        onChangeDuration={onChangeDuration} 
34
-        durationMode={durationMode} 
35
-        dailyExpense={dailyObjective}
36
-        onChangeObjective={onChangeObjective}/>
37
-      <DepensesList durationMode={durationMode} database={db}/>
38
-      <StatusBar hidden />
25
+    <View>
26
+      <View style={styles.container, {
27
+        flexDirection: "column"
28
+      }}>
29
+          <TitleBar 
30
+            onChangeDuration={onChangeDuration} 
31
+            durationMode={durationMode} 
32
+            dailyExpense={dailyObjective}
33
+            onChangeObjective={onChangeObjective}/>
34
+          <DepensesList durationMode={durationMode} />
35
+          <StatusBar hidden />
36
+        </View>
37
+        <View>
38
+        {/* Overlay for expenses */}
39
+        <AddDepense/>
40
+
41
+      </View>
39 42
     </View>
40 43
   );
41 44
 }

+ 24
- 0
components/add_depense.js Ver fichero

@@ -0,0 +1,24 @@
1
+import React from 'react';
2
+import { StyleSheet, Text, View, TextInput, Button } from 'react-native';
3
+
4
+
5
+export default function AddDepense(props){
6
+
7
+        return (
8
+        <View style={add_depenses_styles.buttonAdd}>
9
+            <Button  title="+"></Button>
10
+        </View>
11
+        );
12
+    }
13
+
14
+
15
+const add_depenses_styles = StyleSheet.create({
16
+    buttonAdd: {
17
+        position: 'absolute',
18
+        bottom: 0,
19
+        right: 0
20
+    },
21
+    input: {
22
+        borderWidth: 0.5
23
+    }
24
+    });

+ 14
- 0
db/query.js Ver fichero

@@ -0,0 +1,14 @@
1
+// https://github.com/expo/examples/blob/master/with-sqlite/App.js
2
+import * as SQLite from 'expo-sqlite';
3
+
4
+const db = SQLite.openDatabase("datacoucou.db");
5
+
6
+
7
+export default function sqlite_exec_query(inQuery, inCallback){
8
+
9
+    db.transaction((tx) => {
10
+        tx.executeSql(inQuery, [],
11
+        (txobj, res) => inCallback(res),
12
+        (txobj, err) => {console.log("er");console.log(err);})
13
+    })
14
+}

Loading…
Cancelar
Guardar