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.

day_list.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React from 'react';
  2. import { StyleSheet, Text, View, TextInput, Alert, Pressable } from 'react-native';
  3. import DepenseListEntry from '../depense_list_entry';
  4. export default function DayList(props)
  5. {
  6. const [ showDepenses, onToggleDepenses] = React.useState(true);
  7. let content = []
  8. let total = 0;
  9. props.depenses.forEach( function(depense){
  10. content.push(
  11. <DepenseListEntry fetchDepenses={props.fetchDepenses} key={"depense_list_depense"+depense.id} depense={depense}/>
  12. )
  13. total += depense.value;
  14. });
  15. let result = props.dailyObjective - total
  16. let text_color = "#000000";
  17. let bg_color = "#FFFFFF";
  18. console.log(" "+props.dailyObjective +" - "+total +" = " + result)
  19. if( result > 0)
  20. text_color = "#00"+parseInt(100 + (result / props.dailyObjective) * 100).toString(16) + "00"
  21. else
  22. bg_color = "#FF"+
  23. parseInt(255 + (result / props.dailyObjective) * 100).toString(16) +
  24. parseInt(255 + (result / props.dailyObjective) * 100).toString(16)
  25. console.log(text_color)
  26. return (
  27. <View style={[day_list_styles.day_list_container, {backgroundColor: bg_color}]}>
  28. <Pressable
  29. style={day_list_styles.day_list_entry}
  30. onPress={() => {onToggleDepenses(!showDepenses)}}>
  31. <Text style={day_list_styles.day_list_day}>{props.date.toDateString()}</Text>
  32. <Text style={[day_list_styles.day_list_day, {color: text_color}]}>{"Total : "+total}</Text>
  33. </Pressable>
  34. {showDepenses ? content : <View/>}
  35. </View>
  36. )
  37. }
  38. const day_list_styles = StyleSheet.create({
  39. day_list_container: {
  40. borderWidth: 1,
  41. margin: 1,
  42. },
  43. day_list_entry: {
  44. display: 'flex',
  45. flexDirection: 'row',
  46. justifyContent: 'space-between',
  47. marginTop: 5,
  48. },
  49. day_list_day: {
  50. fontWeight: '900',
  51. margin: 4,
  52. }
  53. });