You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

App.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { StatusBar } from 'expo-status-bar';
  2. import React, { useEffect } from 'react';
  3. import { StyleSheet, Text, View, TextInput } from 'react-native';
  4. import AddDepense from './components/add_depense';
  5. import DepensesList from './components/depenses_list';
  6. import TitleBar from './components/title_bar';
  7. import {sqlite_exec_parameterised, sqlite_exec_query} from './db/query';
  8. export default function App() {
  9. const [durationMode, onChangeDuration] = React.useState("days");
  10. const [dailyObjective, onChangeObjective] = React.useState(-1);
  11. const [fetchDepenses, onFetchDepenses] = React.useState(true)
  12. if(dailyObjective != -1)
  13. sqlite_exec_parameterised("update objective set value = ?", [dailyObjective], (res) => {});
  14. useEffect( () => {
  15. sqlite_exec_query("create table if not exists objective(value integer)", (res)=>{
  16. sqlite_exec_query("select * from objective", (res) => {
  17. if(res.rows.length == 0)
  18. {
  19. sqlite_exec_parameterised("insert into objective (value) values (?)",[dailyObjective],(res)=>{})
  20. }
  21. else
  22. {
  23. onChangeObjective(res.rows._array[0].value);
  24. }
  25. });
  26. });
  27. });
  28. return (
  29. <View style={styles.home}>
  30. <View style={styles.container, {
  31. flexDirection: "column"
  32. }}>
  33. <TitleBar
  34. onChangeDuration={onChangeDuration}
  35. durationMode={durationMode}
  36. dailyExpense={dailyObjective}
  37. onChangeObjective={onChangeObjective}/>
  38. <DepensesList
  39. depensesFetched={() => onFetchDepenses(false)}
  40. fetchDepenses={fetchDepenses}
  41. durationMode={durationMode} />
  42. <StatusBar hidden />
  43. </View>
  44. {/* Overlay for expenses */}
  45. <AddDepense fetchDepenses={() => onFetchDepenses(true)}/>
  46. </View>
  47. );
  48. }
  49. const styles = StyleSheet.create({
  50. home: {
  51. width: '100%',
  52. height: '100%',
  53. },
  54. container: {
  55. flex: 1,
  56. backgroundColor: '#00FF00',
  57. alignItems: 'center',
  58. justifyContent: 'center',
  59. }
  60. });