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

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