12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import React, { useEffect } from 'react';
- import { StyleSheet, Text, View, TextInput } from 'react-native';
- 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);
- console.log(curDate);
- console.log(oldestDate);
- // while(curDate > oldestDate)
- // {
- // console.log(curDate);
- // curDate.setDate( curDate.getDate() - 1);
- // }
-
- }
- depenses
- .forEach( function(depense){
- console.log(depense.date)
- content.push(
- <DepenseListEntry key={"depense_list_depense"+depense.id} depense={depense}/>
- )
- });
-
-
- return(
- <View>
- {content}
- </View>
- )
- }
-
- const depense_list_style = StyleSheet.create({
- depense_list_entry: {
- display: "flex",
- flexDirection: "row",
- justifyContent: "space-between",
- // flex: 1,
- // backgroundColor: '#00FF00',
- // alignItems: 'center',
- // justifyContent: 'center',
- }
- });
-
- export default DepensesList
|