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 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. import { LinearGradient } from 'expo-linear-gradient';
  6. export default function DayList(props)
  7. {
  8. const [ showDepenses, onToggleDepenses] = React.useState(false);
  9. let content = []
  10. let total = 0;
  11. var currentDay = new Date();
  12. let isCurrentday = (
  13. currentDay.getFullYear() === props.date.getFullYear() &&
  14. currentDay.getMonth() === props.date.getMonth() &&
  15. currentDay.getDate() === props.date.getDate());
  16. props.depenses.forEach( function(depense){
  17. content.push(
  18. <DepenseListEntry fetchDepenses={props.fetchDepenses} key={"depense_list_depense"+depense.id} depense={depense}/>
  19. )
  20. total += depense.value;
  21. });
  22. console.log("####");
  23. console.log(props.dailyObjective);
  24. let scale = Math.min(1, total/props.dailyObjective)
  25. let result = props.dailyObjective - total
  26. let text_color = "#000000";
  27. let bg_color = "#FFFFFF";
  28. if( result > 0)
  29. text_color = "#00"+parseInt(100 + (result / props.dailyObjective) * 100).toString(16) + "00"
  30. else
  31. bg_color = "#FF"+
  32. strLPad(parseInt(255 + Math.max(-255,(result / props.dailyObjective) * 100)).toString(16), 2, '0') +
  33. strLPad(parseInt(255 + Math.max(-255, (result / props.dailyObjective) * 100)).toString(16), 2, '0')
  34. console.log(bg_color);
  35. console.log(scale);
  36. return (
  37. <View style={[day_list_styles.day_list_container, {backgroundColor: bg_color}, isCurrentday ? day_list_styles.current_day_container : null]}>
  38. <LinearGradient
  39. colors={[scale > 0 ? '#FFDDDDFF' : '#FFFFFF','#FFFFFF', '#FFFFFF']}
  40. locations={[scale, scale+0.05, 1]}
  41. end={{x:1,y:0}}
  42. style={day_list_styles.background}
  43. />
  44. <Pressable
  45. style={day_list_styles.day_list_entry}
  46. onPress={() => {onToggleDepenses(!showDepenses)}}>
  47. <Text style={day_list_styles.day_list_day}>{props.date.toDateString()}</Text>
  48. <Text style={[day_list_styles.day_list_day, {color: text_color}]}>{"Total : "+total}</Text>
  49. </Pressable>
  50. {showDepenses || isCurrentday ? content : <View/>}
  51. </View>
  52. )
  53. }
  54. const day_list_styles = StyleSheet.create({
  55. day_list_container: {
  56. // borderWidth: 1,
  57. // margin: 1,
  58. // marginTop: 5,
  59. // marginBottom: 15,
  60. // elevation: 5,
  61. },
  62. current_day_container: {
  63. shadowColor: "#0000FF",
  64. shadowOffset: {
  65. width: 0,
  66. height: 10,
  67. },
  68. shadowOpacity: 0,
  69. shadowRadius: 10,
  70. elevation: 10,
  71. },
  72. day_list_entry: {
  73. display: 'flex',
  74. flexDirection: 'row',
  75. justifyContent: 'space-between',
  76. marginBottom: 10,
  77. },
  78. day_list_day: {
  79. fontWeight: '900',
  80. margin: 4,
  81. },
  82. background: {
  83. position: 'absolute',
  84. width: '100%',
  85. height: "100%",
  86. }
  87. });