@hedia/recommendation-screen 2.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/App.d.ts +2 -2
  2. package/coverage/clover.xml +700 -0
  3. package/coverage/coverage-final.json +28 -0
  4. package/coverage/lcov-report/base.css +224 -0
  5. package/coverage/lcov-report/block-navigation.js +79 -0
  6. package/coverage/lcov-report/favicon.png +0 -0
  7. package/coverage/lcov-report/index.html +201 -0
  8. package/coverage/lcov-report/prettify.css +1 -0
  9. package/coverage/lcov-report/prettify.js +2 -0
  10. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  11. package/coverage/lcov-report/sorter.js +170 -0
  12. package/coverage/lcov-report/src/RecommendationScreen.tsx.html +1460 -0
  13. package/coverage/lcov-report/src/__tests__/index.html +111 -0
  14. package/coverage/lcov-report/src/__tests__/utils.tsx.html +512 -0
  15. package/coverage/lcov-report/src/components/Header.tsx.html +347 -0
  16. package/coverage/lcov-report/src/components/InfoBars.tsx.html +404 -0
  17. package/coverage/lcov-report/src/components/InvisibleNumberInput.tsx.html +374 -0
  18. package/coverage/lcov-report/src/components/LimitationMessage.tsx.html +191 -0
  19. package/coverage/lcov-report/src/components/LineSeparator.tsx.html +152 -0
  20. package/coverage/lcov-report/src/components/RecentInsulin.tsx.html +383 -0
  21. package/coverage/lcov-report/src/components/RecommendationModal.tsx.html +737 -0
  22. package/coverage/lcov-report/src/components/RecommendedCarbs.tsx.html +857 -0
  23. package/coverage/lcov-report/src/components/RecommendedInsulin.tsx.html +605 -0
  24. package/coverage/lcov-report/src/components/Remeasure.tsx.html +440 -0
  25. package/coverage/lcov-report/src/components/TransferToLogbook.tsx.html +380 -0
  26. package/coverage/lcov-report/src/components/TwoOptionModal.tsx.html +635 -0
  27. package/coverage/lcov-report/src/components/activity/Activity.tsx.html +311 -0
  28. package/coverage/lcov-report/src/components/activity/ActivityIcon.tsx.html +242 -0
  29. package/coverage/lcov-report/src/components/activity/ActivityIntensity.tsx.html +257 -0
  30. package/coverage/lcov-report/src/components/activity/index.html +141 -0
  31. package/coverage/lcov-report/src/components/index.html +276 -0
  32. package/coverage/lcov-report/src/components/mood/Emotion.tsx.html +278 -0
  33. package/coverage/lcov-report/src/components/mood/MoodIcon.tsx.html +260 -0
  34. package/coverage/lcov-report/src/components/mood/index.html +126 -0
  35. package/coverage/lcov-report/src/index.html +111 -0
  36. package/coverage/lcov-report/src/locale/i18nUtils.ts.html +161 -0
  37. package/coverage/lcov-report/src/locale/index.html +111 -0
  38. package/coverage/lcov-report/src/utils/AttentionMessages.tsx.html +326 -0
  39. package/coverage/lcov-report/src/utils/Constants.ts.html +176 -0
  40. package/coverage/lcov-report/src/utils/RecommendationError.tsx.html +500 -0
  41. package/coverage/lcov-report/src/utils/RecommendationUtils.ts.html +467 -0
  42. package/coverage/lcov-report/src/utils/Translations.ts.html +107 -0
  43. package/coverage/lcov-report/src/utils/Utils.ts.html +263 -0
  44. package/coverage/lcov-report/src/utils/Validations.ts.html +815 -0
  45. package/coverage/lcov-report/src/utils/index.html +201 -0
  46. package/coverage/lcov.info +1581 -0
  47. package/jest.config.js +2 -1
  48. package/package.json +2 -2
  49. package/src/RecommendationScreen.d.ts +2 -3
  50. package/src/__tests__/components/Emotion.test.jsx +7 -8
  51. package/src/components/Icon.d.ts +13 -0
  52. package/src/components/Icon.jsx +42 -0
  53. package/src/components/LimitationMessage.d.ts +1 -2
  54. package/src/components/RecommendationModal.d.ts +2 -3
  55. package/src/components/RecommendationModal.jsx +2 -1
  56. package/src/components/activity/ActivityIntensity.jsx +4 -3
  57. package/src/utils/AttentionMessages.d.ts +16 -10
  58. package/src/utils/AttentionMessages.jsx +15 -10
  59. package/src/utils/RecommendationUtils.d.ts +2 -3
  60. package/src/utils/RecommendationUtils.js +10 -6
  61. package/src/utils/Utils.d.ts +1 -0
  62. package/src/utils/Utils.js +4 -0
  63. package/tsconfig.json +7 -5
  64. package/App.tsx +0 -140
  65. package/index.ts +0 -6
  66. package/src/RecommendationScreen.tsx +0 -461
  67. package/src/__tests__/RecommendationScreen.test.tsx +0 -1231
  68. package/src/__tests__/RecommendationUtils.test.ts +0 -332
  69. package/src/__tests__/Translate.test.tsx +0 -31
  70. package/src/__tests__/Utils.test.ts +0 -91
  71. package/src/__tests__/Validations.test.ts +0 -648
  72. package/src/__tests__/components/Activity.test.tsx +0 -163
  73. package/src/__tests__/components/Emotion.test.tsx +0 -110
  74. package/src/__tests__/components/Header.test.tsx +0 -44
  75. package/src/__tests__/components/InfoBars.test.tsx +0 -152
  76. package/src/__tests__/components/InvisibleNumberInput.test.tsx +0 -294
  77. package/src/__tests__/components/LimitationMessage.test.tsx +0 -58
  78. package/src/__tests__/components/MoodIcon.test.tsx +0 -45
  79. package/src/__tests__/components/RecommendationModal.test.tsx +0 -169
  80. package/src/__tests__/components/RecommendedCarbs.test.tsx +0 -234
  81. package/src/__tests__/components/RecommendedInsulin.test.tsx +0 -241
  82. package/src/__tests__/components/Remeasure.test.tsx +0 -97
  83. package/src/__tests__/components/TransferToLogbook.test.tsx +0 -38
  84. package/src/__tests__/components/TwoOptionModal.test.tsx +0 -72
  85. package/src/__tests__/utils.tsx +0 -144
  86. package/src/components/Header.tsx +0 -89
  87. package/src/components/Icon.js +0 -41
  88. package/src/components/InfoBars.tsx +0 -108
  89. package/src/components/InvisibleNumberInput.tsx +0 -98
  90. package/src/components/LimitationMessage.tsx +0 -38
  91. package/src/components/LineSeparator.tsx +0 -24
  92. package/src/components/RecentInsulin.tsx +0 -101
  93. package/src/components/RecommendationModal.tsx +0 -224
  94. package/src/components/RecommendedCarbs.tsx +0 -259
  95. package/src/components/RecommendedInsulin.tsx +0 -175
  96. package/src/components/Remeasure.tsx +0 -120
  97. package/src/components/TransferToLogbook.tsx +0 -100
  98. package/src/components/TwoOptionModal.tsx +0 -185
  99. package/src/components/activity/Activity.tsx +0 -77
  100. package/src/components/activity/ActivityIcon.tsx +0 -54
  101. package/src/components/activity/ActivityIntensity.tsx +0 -58
  102. package/src/components/mood/Emotion.tsx +0 -66
  103. package/src/components/mood/MoodIcon.tsx +0 -60
  104. package/src/locale/CleanLanguage.ts +0 -13
  105. package/src/locale/i18nUtils.ts +0 -27
  106. package/src/types/enum.ts +0 -108
  107. package/src/types/types.ts +0 -16
  108. package/src/utils/AttentionMessages.tsx +0 -75
  109. package/src/utils/Constants.ts +0 -32
  110. package/src/utils/RecommendationError.tsx +0 -140
  111. package/src/utils/RecommendationUtils.ts +0 -125
  112. package/src/utils/Translations.ts +0 -9
  113. package/src/utils/Utils.ts +0 -57
  114. package/src/utils/Validations.ts +0 -245
@@ -1,224 +0,0 @@
1
- import { t } from "@lingui/macro";
2
- import * as React from "react";
3
- import { Dimensions, StyleSheet, Text, TouchableOpacity, View } from "react-native";
4
- import ReactNativeModal from "react-native-modal";
5
- import { i18n } from "../locale/i18nUtils";
6
- import { RecommendationModalTestIds } from "../types/enum";
7
- import { AttentionMessage } from "../utils/AttentionMessages";
8
- import { BORDER_COLOUR_TEAL } from "../utils/Constants";
9
- import LimitationMessage from "./LimitationMessage";
10
-
11
- interface IModalProps {
12
- isVisible: boolean;
13
- suggestedCarbohydrates: number | null;
14
- attentionMessage: AttentionMessage | null;
15
- limitationMessage: AttentionMessage | null;
16
- onClickOkButton(): void;
17
- onAcceptCarbohydrates(): void;
18
- onDeclineCarbohydrates(): void;
19
- }
20
- interface IModalState {
21
- firstPageVisible: boolean;
22
- }
23
- export default class RecommendationModal extends React.Component<IModalProps, IModalState> {
24
- constructor(props: IModalProps) {
25
- super(props);
26
- this.state = {
27
- firstPageVisible: !!this.props.limitationMessage,
28
- };
29
- }
30
-
31
- public onPressNextButton = (): void => {
32
- const { attentionMessage, suggestedCarbohydrates } = this.props;
33
- const isPageVisible = !!attentionMessage || !!suggestedCarbohydrates;
34
- return isPageVisible ? this.setState({ firstPageVisible: false }) : this.props.onClickOkButton();
35
- };
36
-
37
- public recommendationButtons = (): JSX.Element => {
38
- return (
39
- <View style={stylesModal.recommendationButtonsContainer}>
40
- <TouchableOpacity
41
- testID={RecommendationModalTestIds.AcceptCarbs}
42
- accessibilityLabel="yesButtonModal"
43
- style={stylesModal.affirmativeCarbsButton}
44
- onPress={this.props.onAcceptCarbohydrates}
45
- >
46
- <Text style={stylesModal.affirmativeCarbsText}>{i18n._(t`OK`)}</Text>
47
- </TouchableOpacity>
48
- <TouchableOpacity
49
- testID={RecommendationModalTestIds.DeclineCarbs}
50
- accessibilityLabel="noButtonModal"
51
- style={stylesModal.negativeCarbsButton}
52
- onPress={this.props.onDeclineCarbohydrates}
53
- >
54
- <Text style={stylesModal.negativeCarbsText}>{i18n._(t`NO`)}</Text>
55
- </TouchableOpacity>
56
- </View>
57
- );
58
- };
59
-
60
- public recommendCarbohydrates = (suggestedCarbohydrates: number): JSX.Element => {
61
- const displayCarbs = Math.round(suggestedCarbohydrates);
62
-
63
- return (
64
- <React.Fragment>
65
- <View style={stylesModal.innerView}>
66
- <View style={stylesModal.recommendationRow}>
67
- <Text style={stylesModal.recommendEatingText}>
68
- {i18n._(t`We recommend eating an additional:`)}
69
- </Text>
70
- </View>
71
- <View style={stylesModal.suggestedContainer}>
72
- <Text style={stylesModal.textCenter}>
73
- <Text
74
- style={stylesModal.suggestedCarbs}
75
- testID={RecommendationModalTestIds.SuggestedCarbs}
76
- >{`${displayCarbs} `}</Text>
77
- <Text style={stylesModal.carbohydrateText}>{i18n._(t`grams of carbohydrates`)}</Text>
78
- </Text>
79
- </View>
80
- <View style={stylesModal.recommendationRow}>
81
- <Text style={stylesModal.recommendEatingText}>{i18n._(t`Instead of taking insulin`)}</Text>
82
- </View>
83
- </View>
84
- <View style={stylesModal.addToCalculationContainer}>
85
- <Text style={stylesModal.addToCalculation}>
86
- {i18n._(t`Would you like to add this to your current calculation?`)}
87
- </Text>
88
- {this.recommendationButtons()}
89
- </View>
90
- </React.Fragment>
91
- );
92
- };
93
-
94
- public secondPage = (): JSX.Element => {
95
- const { attentionMessage, suggestedCarbohydrates } = this.props;
96
- const willRecommendCarbs = suggestedCarbohydrates !== null && suggestedCarbohydrates > 0;
97
-
98
- return (
99
- <React.Fragment>
100
- <View style={stylesModal.container}>
101
- <View style={stylesModal.titleContainer}>
102
- <Text style={stylesModal.textTittleMessage}>{i18n._(t`Attention`)}</Text>
103
- </View>
104
- <Text style={stylesModal.textMessage}>{attentionMessage}</Text>
105
- {willRecommendCarbs ? this.recommendCarbohydrates(suggestedCarbohydrates!) : null}
106
- </View>
107
- {willRecommendCarbs ? null : (
108
- <View style={stylesModal.containerAcceptButton}>
109
- <TouchableOpacity
110
- testID={RecommendationModalTestIds.OkButton}
111
- accessibilityLabel="okayButtonModal"
112
- style={stylesModal.okButton}
113
- onPress={this.props.onClickOkButton}
114
- >
115
- <Text style={stylesModal.buttonText}>{i18n._(t`OK`)}</Text>
116
- </TouchableOpacity>
117
- </View>
118
- )}
119
- </React.Fragment>
120
- );
121
- };
122
-
123
- public firstPage = (): JSX.Element => {
124
- return (
125
- <LimitationMessage
126
- limitationMessage={this.props.limitationMessage}
127
- onPressNextButton={this.onPressNextButton}
128
- />
129
- );
130
- };
131
-
132
- public render(): JSX.Element {
133
- const { isVisible } = this.props;
134
- const { firstPageVisible } = this.state;
135
- return (
136
- <ReactNativeModal isVisible={isVisible} style={stylesModal.modalStyle}>
137
- {firstPageVisible ? this.firstPage() : this.secondPage()}
138
- </ReactNativeModal>
139
- );
140
- }
141
- }
142
-
143
- const { height, width } = Dimensions.get(`screen`);
144
- const buttonHeight = height / 20;
145
- const buttonWidth = width / 2.5;
146
- const buttonFontSize = width / 22;
147
- const buttonBorderRadius = height / 30;
148
- const buttonBorderWidth = height / 500;
149
- const sugestionFontSize = width / 19;
150
- const recommendEatingFontSize = height / 45;
151
- const textFontSize = width / 20;
152
- const titleFontSize = width / 13;
153
-
154
- export const stylesModal = StyleSheet.create({
155
- modalStyle: { margin: 0 },
156
- container: {
157
- flex: 4,
158
- backgroundColor: `rgba(30, 35, 87, 0.9)`,
159
- justifyContent: `center`,
160
- paddingHorizontal: `4%`,
161
- },
162
- containerAcceptButton: {
163
- flex: 1,
164
- backgroundColor: `rgba(30, 35, 87, 0.9)`,
165
- justifyContent: `flex-start`,
166
- },
167
- titleContainer: { marginBottom: `5%` },
168
- recommendationRow: { justifyContent: `center`, alignContent: `center`, marginBottom: `3%` },
169
- textTittleMessage: { color: `white`, fontSize: titleFontSize, textAlign: `center` },
170
- textMessage: { color: `white`, fontSize: textFontSize, textAlign: `center` },
171
- buttonText: { color: BORDER_COLOUR_TEAL, fontSize: buttonFontSize, textAlign: `center` },
172
- addToCalculationContainer: { justifyContent: `flex-start`, marginVertical: `5%` },
173
- innerView: {
174
- alignContent: `center`,
175
- paddingVertical: `5%`,
176
- paddingHorizontal: `3%`,
177
- marginTop: `5%`,
178
- borderRadius: height / 80,
179
- borderWidth: height / 300,
180
- borderColor: BORDER_COLOUR_TEAL,
181
- },
182
-
183
- suggestedContainer: { justifyContent: `center`, flexDirection: `row`, marginBottom: `3%` },
184
- suggestedCarbs: { color: `white`, fontSize: sugestionFontSize, fontWeight: `bold` },
185
- textCenter: { textAlign: `center` },
186
- recommendEatingText: { color: `#C5D0E7`, fontSize: recommendEatingFontSize, textAlign: `center` },
187
- carbohydrateText: { color: `white`, fontSize: sugestionFontSize },
188
- addToCalculation: { color: `white`, fontSize: textFontSize, textAlign: `center` },
189
- recommendationButtonsContainer: { justifyContent: `center`, flexDirection: `row`, margin: `3%` },
190
- affirmativeCarbsText: { color: BORDER_COLOUR_TEAL, fontSize: buttonFontSize, textAlign: `center` },
191
- negativeCarbsText: { color: `white`, fontSize: buttonFontSize, textAlign: `center` },
192
- affirmativeCarbsButton: {
193
- marginTop: `2%`,
194
- borderRadius: buttonBorderRadius,
195
- borderWidth: buttonBorderWidth,
196
- borderColor: BORDER_COLOUR_TEAL,
197
- width: buttonWidth,
198
- height: buttonHeight,
199
- alignSelf: `center`,
200
- justifyContent: `center`,
201
- marginRight: `2%`,
202
- },
203
- negativeCarbsButton: {
204
- marginTop: `2%`,
205
- borderRadius: buttonBorderRadius,
206
- borderWidth: buttonBorderWidth,
207
- borderColor: `white`,
208
- width: buttonWidth,
209
- height: buttonHeight,
210
- alignSelf: `center`,
211
- justifyContent: `center`,
212
- marginLeft: `2%`,
213
- },
214
- okButton: {
215
- marginTop: `6%`,
216
- borderRadius: buttonBorderRadius,
217
- borderWidth: buttonBorderWidth,
218
- borderColor: BORDER_COLOUR_TEAL,
219
- width: buttonWidth,
220
- height: buttonHeight,
221
- alignSelf: `center`,
222
- justifyContent: `center`,
223
- },
224
- });
@@ -1,259 +0,0 @@
1
- import { t } from "@lingui/macro";
2
- import React from "react";
3
- import { Alert, Dimensions, StyleSheet, Text, TouchableOpacity, View } from "react-native";
4
- import { i18n } from "../locale/i18nUtils";
5
- import { RecommendedCarbsTestIds } from "../types/enum";
6
- import { BORDER_COLOUR_GREY, BORDER_COLOUR_TEAL } from "../utils/Constants";
7
- import { CarbohydrateLimitError } from "../utils/RecommendationError";
8
- import Icon from "./Icon";
9
- import { infoStyles } from "./InfoBars";
10
- import InvisibleNumberInput from "./InvisibleNumberInput";
11
- import LineSeparator from "./LineSeparator";
12
-
13
- interface ICalculationRow {
14
- label: string;
15
- value: string;
16
- units: string;
17
- }
18
-
19
- interface IProps {
20
- // Values
21
- recommendedCarbs?: string;
22
- enteredCarbs: string;
23
-
24
- // Callbacks
25
- removeRecommendedCarbs(): void;
26
- changedRecommendedCarbs(value: number): void;
27
- }
28
-
29
- interface IState {
30
- partialInput?: string;
31
- }
32
-
33
- export default class RecommendedCarbs extends React.Component<IProps, IState> {
34
- public state: IState = {
35
- partialInput: undefined,
36
- };
37
-
38
- public callbackInput?: () => void;
39
-
40
- public showTextInput = (): void => {
41
- this.callbackInput?.();
42
- };
43
-
44
- public handlePartialInput = (partialInput: string): void => {
45
- this.setState({
46
- partialInput,
47
- });
48
- };
49
-
50
- public handleChangedCarbs = (carbs: number): void => {
51
- if (carbs >= 0) {
52
- if (carbs > 300) {
53
- this.setState({ partialInput: this.props.recommendedCarbs });
54
- return Alert.alert(i18n._(t`Attention`), CarbohydrateLimitError().message, [
55
- {
56
- text: i18n._(t`OK`),
57
- },
58
- ]);
59
- }
60
- this.props.changedRecommendedCarbs(carbs);
61
- }
62
- };
63
-
64
- public renderRecommendedCarbs = (): JSX.Element => {
65
- const shownCarbs = this.state.partialInput ?? Math.round(Number(this.props.recommendedCarbs));
66
- const totalCarbs = Math.round(parseFloat(this.props.enteredCarbs) + Number(shownCarbs));
67
- return (
68
- <React.Fragment>
69
- <LineSeparator color={BORDER_COLOUR_GREY} />
70
- <View style={calculationStyles.borderContainer}>
71
- <View style={calculationStyles.recommendedContainer}>
72
- <TouchableOpacity
73
- testID={RecommendedCarbsTestIds.RemoveRecommendation}
74
- accessibilityLabel="removeRecommendedCarbs"
75
- style={calculationStyles.removeRecommended}
76
- onPress={this.props.removeRecommendedCarbs}
77
- >
78
- <Icon
79
- iconIdentifier={`Ionicons/ios-close-circle-outline`}
80
- style={calculationStyles.removeRecommendedIcon}
81
- />
82
- </TouchableOpacity>
83
- <Text style={calculationStyles.recommendedLabel}>{i18n._(t`Recommended`)}</Text>
84
- </View>
85
- </View>
86
- <View style={calculationStyles.borderContainer}>
87
- <View style={calculationStyles.recommendedContainer}>
88
- <Text style={calculationStyles.recommendedLabel}>{i18n._(t`Additional`)}</Text>
89
- </View>
90
- <View style={calculationStyles.valueUnitContainer}>
91
- <TouchableOpacity
92
- testID={RecommendedCarbsTestIds.EditRecommendedCarbs}
93
- accessibilityLabel="editRecommendedCarbsButton"
94
- onPress={this.showTextInput}
95
- style={[calculationStyles.valueUnitContainer]}
96
- >
97
- <View style={calculationStyles.valueContainer}>
98
- <Text
99
- testID={RecommendedCarbsTestIds.RecommendedCarbs}
100
- style={[calculationStyles.value, { color: BORDER_COLOUR_TEAL }]}
101
- >
102
- {shownCarbs}
103
- </Text>
104
- </View>
105
- <View style={[calculationStyles.unitContainer]}>
106
- <View style={calculationStyles.editIconContainer}>
107
- <Icon style={calculationStyles.editIcon} iconIdentifier={`Feather/edit`} />
108
- </View>
109
- <Text style={[calculationStyles.units, { color: BORDER_COLOUR_TEAL }]}>
110
- {i18n._(t`grams`)}
111
- </Text>
112
- </View>
113
- </TouchableOpacity>
114
- </View>
115
- </View>
116
- <LineSeparator color={BORDER_COLOUR_TEAL} />
117
- {this.renderRow(
118
- {
119
- label: i18n._(t`Total`),
120
- value: totalCarbs.toString(),
121
- units: i18n._(t`grams`),
122
- },
123
- RecommendedCarbsTestIds.TotalCarbs,
124
- )}
125
- <InvisibleNumberInput
126
- testID={RecommendedCarbsTestIds.InvisibleCarbInput}
127
- negativeAllowed={false}
128
- cleanPartialInput={true}
129
- decimalPlaces={0}
130
- visible={(callback): (() => void) => (this.callbackInput = callback)}
131
- partialInput={this.handlePartialInput}
132
- onEnd={this.handleChangedCarbs}
133
- startValue={this.props.recommendedCarbs}
134
- maxLength={3}
135
- />
136
- </React.Fragment>
137
- );
138
- };
139
-
140
- public renderRow = (row: ICalculationRow, testID: RecommendedCarbsTestIds): JSX.Element => {
141
- return (
142
- <View style={[calculationStyles.borderContainer, { paddingVertical: `1%` }]}>
143
- <View style={calculationStyles.rowContainer}>
144
- <Text style={calculationStyles.rowLabel}>{row.label}</Text>
145
- </View>
146
- <View style={calculationStyles.valueUnitContainer}>
147
- <View style={calculationStyles.valueContainer}>
148
- <Text testID={testID} style={calculationStyles.value}>
149
- {row.value}
150
- </Text>
151
- </View>
152
- <View style={calculationStyles.unitContainer}>
153
- <Text style={calculationStyles.units}>{row.units}</Text>
154
- </View>
155
- </View>
156
- </View>
157
- );
158
- };
159
-
160
- public render(): JSX.Element {
161
- const carbs = Number(this.props.recommendedCarbs);
162
- return (
163
- <React.Fragment>
164
- <View style={calculationStyles.foodTitleContainer}>
165
- <Text style={infoStyles.label}>{i18n._(t`Food`)}</Text>
166
- <Text style={calculationStyles.foodUnitsLabel}>{`(${i18n._(t`Carbohydrates`)})`}</Text>
167
- </View>
168
- {this.renderRow(
169
- {
170
- label: i18n._(t`Entered`),
171
- value: this.props.enteredCarbs,
172
- units: i18n._(t`grams`),
173
- },
174
- RecommendedCarbsTestIds.EnteredCarbs,
175
- )}
176
- {!isNaN(carbs) && carbs > 0 ? this.renderRecommendedCarbs() : null}
177
- </React.Fragment>
178
- );
179
- }
180
- }
181
-
182
- const calculationStyles = StyleSheet.create({
183
- borderContainer: {
184
- ...infoStyles.borderContainer,
185
- alignItems: `center`,
186
- },
187
- foodTitleContainer: {
188
- flex: infoStyles.borderContainer.flex,
189
- flexDirection: infoStyles.borderContainer.flexDirection,
190
- paddingHorizontal: infoStyles.borderContainer.paddingHorizontal,
191
- alignItems: `center`,
192
- paddingVertical: `2%`,
193
- },
194
- foodUnitsLabel: {
195
- ...infoStyles.units,
196
- color: `rgba(160, 180, 240, 1)`,
197
- paddingLeft: `1%`,
198
- },
199
- rowContainer: {
200
- flex: 7,
201
- },
202
- rowLabel: {
203
- color: `white`,
204
- fontSize: Dimensions.get(`screen`).width / 25,
205
- fontWeight: `bold`,
206
- },
207
- enteredContainer: {
208
- flex: 3,
209
- alignItems: `flex-end`,
210
- },
211
- entered: {
212
- color: `white`,
213
- fontSize: Dimensions.get(`screen`).width / 23,
214
- },
215
- valueUnitContainer: {
216
- ...infoStyles.valueUnitContainer,
217
- },
218
- valueContainer: {
219
- ...infoStyles.valueContainer,
220
- },
221
- value: {
222
- ...infoStyles.value,
223
- },
224
- unitContainer: {
225
- ...infoStyles.unitContainer,
226
- },
227
- units: {
228
- ...infoStyles.units,
229
- },
230
- editIconContainer: {
231
- justifyContent: `flex-end`,
232
- paddingRight: `20%`,
233
- flexDirection: `row`,
234
- },
235
- editIcon: {
236
- color: BORDER_COLOUR_TEAL,
237
- fontSize: Dimensions.get(`screen`).width / 30,
238
- },
239
- recommendedContainer: {
240
- flex: 7,
241
- flexDirection: `row`,
242
- },
243
- recommendedLabel: {
244
- color: BORDER_COLOUR_TEAL,
245
- fontSize: Dimensions.get(`screen`).width / 25,
246
- alignSelf: `center`,
247
- fontWeight: `bold`,
248
- },
249
- removeRecommended: {
250
- justifyContent: `center`,
251
- marginRight: `1%`,
252
- marginTop: `1%`,
253
- },
254
- removeRecommendedIcon: {
255
- color: BORDER_COLOUR_TEAL,
256
- fontSize: Dimensions.get(`screen`).width / 20,
257
- paddingBottom: `0.5%`,
258
- },
259
- });
@@ -1,175 +0,0 @@
1
- import { BolusCalculator, UserSettings } from "@hedia/types";
2
- import { t } from "@lingui/macro";
3
- import React from "react";
4
- import { Alert, Dimensions, Platform, StyleSheet, Text, TouchableOpacity, View } from "react-native";
5
- import LinearGradient from "react-native-linear-gradient";
6
- import { i18n } from "../locale/i18nUtils";
7
- import { RecommendedInsulinTestIds } from "../types/enum";
8
- import { Messages } from "../utils/AttentionMessages";
9
- import { Utils } from "../utils/Utils";
10
- import Icon from "./Icon";
11
- import { infoStyles } from "./InfoBars";
12
- import InvisibleNumberInput from "./InvisibleNumberInput";
13
-
14
- interface IProps {
15
- // Values
16
- insulinRecommendation: number;
17
- enteredInsulin: number | null;
18
- activityReduction: number | null;
19
- injectionMethod: UserSettings.Enums.InjectionMethod;
20
-
21
- // Callbacks
22
- updateRecommendedInsulin(value: number): void;
23
- }
24
-
25
- interface IState {
26
- partialInput?: string;
27
- }
28
-
29
- const SAFETY_INSULIN_LIMIT = BolusCalculator.Constants.SAFETY_INSULIN_LIMIT;
30
-
31
- export default class RecommendedInsulin extends React.Component<IProps, IState> {
32
- public callbackInput?: () => void;
33
-
34
- constructor(props: IProps) {
35
- super(props);
36
-
37
- this.state = {
38
- partialInput: undefined,
39
- };
40
- }
41
-
42
- public componentDidUpdate(prevProps: IProps): void {
43
- const { enteredInsulin } = this.props;
44
- if (prevProps.enteredInsulin !== enteredInsulin) {
45
- this.setState({ partialInput: enteredInsulin?.toString() });
46
- }
47
- }
48
-
49
- public handleOnPress = (): void => {
50
- this.callbackInput?.();
51
- };
52
-
53
- public updatePartially = (insulin: string): string => {
54
- const replacedZero =
55
- insulin.length > 1 && insulin.startsWith(`0`) && !insulin.startsWith(`0.`) ? insulin.substring(1) : insulin;
56
- this.setState({
57
- partialInput: replacedZero,
58
- });
59
- return replacedZero;
60
- };
61
-
62
- public handleUpdatedInsulin = (value: number): void => {
63
- const rounded = Utils.roundValue(value, this.props.injectionMethod);
64
-
65
- // https://hedia.atlassian.net/browse/HDA-795
66
- const limited = (1 - (this.props.activityReduction ?? 0)) * SAFETY_INSULIN_LIMIT;
67
-
68
- if (rounded > limited) {
69
- this.setState({ partialInput: this.props.insulinRecommendation?.toString() ?? null });
70
- this.props.updateRecommendedInsulin(this.props.insulinRecommendation);
71
- return Alert.alert(i18n._(t`Attention`), Messages.InsulinInputWasLimited(this.props.activityReduction), [
72
- {
73
- text: i18n._(t`OK`),
74
- },
75
- ]);
76
- }
77
- this.updatePartially(`${rounded}`);
78
- this.props.updateRecommendedInsulin(rounded);
79
- };
80
-
81
- public render = (): JSX.Element => {
82
- const paddingBottom = Platform.OS === `ios` ? `3%` : `1%`;
83
- const shownInsulin = this.state.partialInput ?? this.props.insulinRecommendation ?? `0`;
84
- return (
85
- <React.Fragment>
86
- <TouchableOpacity
87
- accessibilityLabel="editRecommendedInsulin"
88
- testID={RecommendedInsulinTestIds.EditRecommendedInsulin}
89
- onPress={this.handleOnPress}
90
- >
91
- <LinearGradient
92
- style={recommendedInsulinStyles.container}
93
- colors={[`#a200ff`, `#578aff`]}
94
- start={{ x: 0, y: 0 }}
95
- end={{ x: 1, y: 0 }}
96
- >
97
- <View style={recommendedInsulinStyles.recommendedTextContainer}>
98
- <Text style={recommendedInsulinStyles.recommendedText}>
99
- {i18n._(t`Recommended amount of insulin`)}
100
- </Text>
101
- </View>
102
- <View style={[recommendedInsulinStyles.recommendedContainer, { paddingBottom }]}>
103
- <View style={recommendedInsulinStyles.valueContainer}>
104
- <Text
105
- style={recommendedInsulinStyles.value}
106
- testID={RecommendedInsulinTestIds.ShownInsulinText}
107
- >
108
- {shownInsulin}
109
- </Text>
110
- <Text style={recommendedInsulinStyles.units}>{i18n._(t`Units`)}</Text>
111
- </View>
112
- <Icon style={recommendedInsulinStyles.editIcon} iconIdentifier={`Feather/edit`} />
113
- </View>
114
- </LinearGradient>
115
- </TouchableOpacity>
116
- <InvisibleNumberInput
117
- testID={RecommendedInsulinTestIds.InvisibleInsulinInput}
118
- decimalPlaces={3}
119
- negativeAllowed={false}
120
- cleanPartialInput={false}
121
- partialInput={this.updatePartially}
122
- onEnd={this.handleUpdatedInsulin}
123
- visible={(visible): (() => void) => (this.callbackInput = visible)}
124
- startValue={`${shownInsulin}`}
125
- />
126
- </React.Fragment>
127
- );
128
- };
129
- }
130
-
131
- const recommendedInsulinStyles = StyleSheet.create({
132
- container: {
133
- marginHorizontal: infoStyles.margin.margin,
134
- marginTop: infoStyles.margin.margin,
135
- borderRadius: 5,
136
- },
137
- recommendedTextContainer: {
138
- flex: 1,
139
- alignItems: `center`,
140
- marginTop: `3%`,
141
- },
142
- recommendedText: {
143
- paddingTop: `1%`,
144
- ...infoStyles.label,
145
- },
146
- recommendedContainer: {
147
- flex: 1,
148
- flexDirection: `row`,
149
- marginLeft: `10%`,
150
- },
151
- valueContainer: {
152
- flex: 1,
153
- flexDirection: `row`,
154
- justifyContent: `center`,
155
- minHeight: Dimensions.get(`screen`).width / 4,
156
- },
157
- value: {
158
- color: `white`,
159
- fontWeight: `bold`,
160
- fontSize: Dimensions.get(`screen`).width / 5,
161
- },
162
- units: {
163
- alignSelf: `flex-end`,
164
- color: `white`,
165
- fontSize: Dimensions.get(`screen`).width / 28,
166
- paddingBottom: `6%`,
167
- },
168
- editIcon: {
169
- color: `white`,
170
- fontSize: Dimensions.get(`screen`).width / 28,
171
- textAlignVertical: `center`,
172
- paddingBottom: `10%`,
173
- marginRight: `5%`,
174
- },
175
- });