Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

depenses_list.js 1.8KB

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