import React, { useEffect } from 'react'; import { StyleSheet, Text, View, TextInput, FlatList, SafeAreaView } from 'react-native'; import { ScrollView } from 'react-native-gesture-handler'; import { sqlite_exec_query } from '../db/query'; import DepenseListEntry from './depense_list_entry'; function DepensesList(props) { const [depenses, onGetDepenses] = React.useState([]); const [depensesFetched, preventFetchDepenses] = React.useState(false) let fetchDepenses = props.fetchDepenses || !depensesFetched useEffect( () => { sqlite_exec_query(`create table if not exists expense (id integer primary key not null, value real, description text, date integer);`,(res)=>{ if(fetchDepenses) sqlite_exec_query("select * from expense order by date desc", (res) => { onGetDepenses(res.rows._array); preventFetchDepenses(true); props.depensesFetched(); }); }); }); let content = [] if(depenses.length > 0) { // get latest and oldest depense let latest_depense = depenses[0]; let oldest_depense = depenses[depenses.length - 1] let curDate = new Date(latest_depense.date); let oldestDate = new Date(oldest_depense.date); } depenses .forEach( function(depense){ // console.log(depense.date) content.push( preventFetchDepenses(false)} key={"depense_list_depense"+depense.id} depense={depense}/> ) }); return( {content} ) } const depense_list_style = StyleSheet.create({ list_container: { flex: 1 } }); export default DepensesList