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.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. dailyObjective={dailyObjective}
  42. durationMode={durationMode} />
  43. <StatusBar hidden />
  44. </View>
  45. {/* Overlay for expenses */}
  46. <AddDepense fetchDepenses={() => onFetchDepenses(true)}/>
  47. </View>
  48. );
  49. }
  50. const styles = StyleSheet.create({
  51. home: {
  52. width: '100%',
  53. height: '100%',
  54. backgroundColor: '#FFFFFF',
  55. },
  56. container: {
  57. flex: 1,
  58. backgroundColor: '#00FF00',
  59. alignItems: 'center',
  60. justifyContent: 'center',
  61. }
  62. });