Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

day_list.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. var currentDay = new Date();
  11. let isCurrentday = (
  12. currentDay.getFullYear() === props.date.getFullYear() &&
  13. currentDay.getMonth() === props.date.getMonth() &&
  14. currentDay.getDate() === props.date.getDate());
  15. props.depenses.forEach( function(depense){
  16. content.push(
  17. <DepenseListEntry fetchDepenses={props.fetchDepenses} key={"depense_list_depense"+depense.id} depense={depense}/>
  18. )
  19. total += depense.value;
  20. });
  21. let result = props.dailyObjective - total
  22. let text_color = "#000000";
  23. let bg_color = "#FFFFFF";
  24. if( result > 0)
  25. text_color = "#00"+parseInt(100 + (result / props.dailyObjective) * 100).toString(16) + "00"
  26. else
  27. bg_color = "#FF"+
  28. strLPad(parseInt(255 + Math.max(-255,(result / props.dailyObjective) * 100)).toString(16), 2, '0') +
  29. strLPad(parseInt(255 + Math.max(-255, (result / props.dailyObjective) * 100)).toString(16), 2, '0')
  30. return (
  31. <View style={[day_list_styles.day_list_container, {backgroundColor: bg_color}, isCurrentday ? day_list_styles.current_day_container : null]}>
  32. <Pressable
  33. style={day_list_styles.day_list_entry}
  34. onPress={() => {onToggleDepenses(!showDepenses)}}>
  35. <Text style={day_list_styles.day_list_day}>{props.date.toDateString()}</Text>
  36. <Text style={[day_list_styles.day_list_day, {color: text_color}]}>{"Total : "+total}</Text>
  37. </Pressable>
  38. {showDepenses ? content : <View/>}
  39. </View>
  40. )
  41. }
  42. const day_list_styles = StyleSheet.create({
  43. day_list_container: {
  44. // borderWidth: 1,
  45. margin: 1,
  46. marginTop: 15,
  47. elevation: 5,
  48. },
  49. current_day_container: {
  50. shadowColor: "#0000FF",
  51. shadowOffset: {
  52. width: 0,
  53. height: 10,
  54. },
  55. shadowOpacity: 0,
  56. shadowRadius: 10,
  57. elevation: 10,
  58. },
  59. day_list_entry: {
  60. display: 'flex',
  61. flexDirection: 'row',
  62. justifyContent: 'space-between',
  63. marginBottom: 10,
  64. },
  65. day_list_day: {
  66. fontWeight: '900',
  67. margin: 4,
  68. }
  69. });