Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

depenses_list.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. content.push(
  33. <DepenseListEntry fetchDepenses={() => preventFetchDepenses(false)} key={"depense_list_depense"+depense.id} depense={depense}/>
  34. )
  35. });
  36. return(
  37. <SafeAreaView>
  38. <ScrollView>
  39. {content}
  40. </ScrollView>
  41. </SafeAreaView >
  42. )
  43. }
  44. const depense_list_style = StyleSheet.create({
  45. list_container: {
  46. flex: 1
  47. }
  48. });
  49. export default DepensesList