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.

depenses_list.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import React, { useEffect } from 'react';
  2. import { StyleSheet, Text, View, TextInput } from 'react-native';
  3. import { sqlite_exec_query } from '../db/query';
  4. import DepenseListEntry from './depense_list_entry';
  5. function DepensesList(props)
  6. {
  7. const [depenses, onGetDepenses] = React.useState([]);
  8. const [depensesFetched, preventFetchDepenses] = React.useState(false)
  9. let fetchDepenses = props.fetchDepenses || !depensesFetched
  10. useEffect( () => {
  11. sqlite_exec_query(`create table if not exists expense (id integer primary key not null, value real, description text, date integer);`,(res)=>{
  12. if(fetchDepenses)
  13. sqlite_exec_query("select * from expense order by date desc", (res) => {
  14. onGetDepenses(res.rows._array);
  15. preventFetchDepenses(true);
  16. props.depensesFetched();
  17. });
  18. });
  19. });
  20. let content = []
  21. if(depenses.length > 0)
  22. {
  23. // get latest and oldest depense
  24. let latest_depense = depenses[0];
  25. let oldest_depense = depenses[depenses.length - 1]
  26. let curDate = new Date(latest_depense.date);
  27. let oldestDate = new Date(oldest_depense.date);
  28. console.log(curDate);
  29. console.log(oldestDate);
  30. // while(curDate > oldestDate)
  31. // {
  32. // console.log(curDate);
  33. // curDate.setDate( curDate.getDate() - 1);
  34. // }
  35. }
  36. depenses
  37. .forEach( function(depense){
  38. console.log(depense.date)
  39. content.push(
  40. <DepenseListEntry key={"depense_list_depense"+depense.id} depense={depense}/>
  41. )
  42. });
  43. return(
  44. <View>
  45. {content}
  46. </View>
  47. )
  48. }
  49. const depense_list_style = StyleSheet.create({
  50. depense_list_entry: {
  51. display: "flex",
  52. flexDirection: "row",
  53. justifyContent: "space-between",
  54. // flex: 1,
  55. // backgroundColor: '#00FF00',
  56. // alignItems: 'center',
  57. // justifyContent: 'center',
  58. }
  59. });
  60. export default DepensesList