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

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