Compare commits
297 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fd818404d4 | |||
| a26080ad2a | |||
| bef7b6ae54 | |||
| 70c13387a9 | |||
| ef9e7c535b | |||
| 1d449252c0 | |||
| 71247e1c7d | |||
| 8469edc573 | |||
| a7aae0673e | |||
| 9d137dfd3a | |||
| 930ed3fdc5 | |||
| 240c61e46e | |||
| 0e1b95d313 | |||
| 880dd8b843 | |||
| 54b30ec229 | |||
| dc1164ef03 | |||
| be4f50c962 | |||
| 91bf76621a | |||
| 37c5821411 | |||
| 4442c229f7 | |||
| c0c025cd69 | |||
| 41e2406727 | |||
| e11915460c | |||
| 1413525e91 | |||
| 1291fe70bc | |||
| 908ae9a305 | |||
| 7d46706cf2 | |||
| f987628ced | |||
| 052b9bd2aa | |||
| c7740c7c57 | |||
| 5ec5d02b8d | |||
| 075813c314 | |||
| 098c0e69a5 | |||
| 02db9c1722 | |||
| 297c1cf3d5 | |||
| ee0b83d1ca | |||
| 620f5e77da | |||
| 268ec56c88 | |||
| 9235a57fd7 | |||
| c1959962d0 | |||
| 06edde5340 | |||
| 5b2dc82218 | |||
| 9b4da9bd19 | |||
| 64a4c8c455 | |||
| 95068e92c4 | |||
| 47379d7a1e | |||
| 3dbcb41d67 | |||
| 8444d466db | |||
| f9d2838008 | |||
| 9e34c1b8b4 | |||
| e901cae0f5 | |||
| 21c5ac72a6 | |||
| 0e0e00948f | |||
| 407bc2e524 | |||
| aab64a433f | |||
| 346d7e6dad | |||
| 12b8e5c213 | |||
| 9ce7dbf6b6 | |||
| a9333bd848 | |||
| ec907ab23c | |||
| d5b1944988 | |||
| 0a86f38472 | |||
| 49fedcc634 | |||
| af562e329c | |||
| 6badd97f2c | |||
| 1c0c2276de | |||
| f789a7990f | |||
| aa2165590b | |||
| 17815fcefe | |||
| b42cbc8826 | |||
| 76101eec74 | |||
| 9fbc3e7e2a | |||
| e88f26dc16 | |||
| d054187485 | |||
| 856f6216ee | |||
| c7f0c1cb6f | |||
| c7882eb619 | |||
| 28356d6664 | |||
| 882f183c8e | |||
| 7b69719e22 | |||
| 62df30de8a | |||
| 8cad357e60 | |||
| 026a9c17c3 | |||
| e66ca3f8db | |||
| e479b93638 | |||
| f444de0b87 | |||
| ae0d909407 | |||
| 963e0ffea0 | |||
| 009c8fa0f2 | |||
| 7b8292ab6a | |||
| 446c5d4600 | |||
| 1c7856081e | |||
| cb13222780 | |||
| e52736f8a1 | |||
| 580f1e79ba | |||
| 45ee67e4d8 | |||
| 51c96b5b37 | |||
| 2ecb2e7647 | |||
| c24284a57d | |||
| 36ae949f31 | |||
| 796d995aad | |||
| 767a2c9709 | |||
| fe1ec38b68 | |||
| 71e4c6d11e | |||
| 765916e7fe | |||
| 03a235d8cb | |||
| 0adbf3436b | |||
| 09129adba3 | |||
| ed66395318 | |||
| bc04f6a24b | |||
| 3598dd5b80 | |||
| 270b823c20 | |||
| 34a0e15e66 | |||
| 02ca733147 | |||
| f00010e1ca | |||
| 1d8350c468 | |||
| e14bd690dc | |||
| 7514b01cf4 | |||
| f376602843 | |||
| 889e0e36d7 | |||
| 5d3950ca5c | |||
| 3d53af8012 | |||
| 6175738fec | |||
| 71c5a0b51b | |||
| 23ba5115d2 | |||
| 3dd235f8d9 | |||
| 1c25ad3046 | |||
| 48d519d557 | |||
| e0091497e4 | |||
| 5d436630d3 | |||
| 20595c6c3a | |||
| 8ce840306a | |||
| c74c5d372c | |||
| c0235d148b | |||
| 85b5b4d387 | |||
| 2f25c5cffe | |||
| 3f7b58b04c | |||
| e9fd961913 | |||
| c3a2eea3a5 | |||
| 525defa1c9 | |||
| 16cc2cef5c | |||
| 29a076e5a2 | |||
| c226923759 | |||
| 216a9044cd | |||
| 2d1ab273a0 | |||
| a7d6cdc8cc | |||
| e2270ea1e2 | |||
| d2d5d2f41f | |||
| 8a528d5529 | |||
| 82cf26334f | |||
| 917bd8f7c4 | |||
| 48778c1959 | |||
| 7e807dba7f | |||
| 888be9531d | |||
| 2539918d0c | |||
| a9e84b9255 | |||
| 5b2cd1c8f4 | |||
| 6628543141 | |||
| 6065470b2f | |||
| e4209e28b7 | |||
| fa20e84bfe | |||
| a152b497fb | |||
| c11b80d7fa | |||
| b21938fdd8 | |||
| c7f1a029a3 | |||
| e8b0d60fdd | |||
| 5e32f4d7dc | |||
| 8008c8e2cc | |||
| 2cc5ffb50f | |||
| e7949377a2 | |||
| 592f2b3e16 | |||
| 7506e911f7 | |||
| 09bbfe8a7d | |||
| bb1bd949c3 | |||
| 406b71250e | |||
| 6228cd8953 | |||
| 2623fedec9 | |||
| bfdad895ce | |||
| dce8138e12 | |||
| 7864ebfc41 | |||
| 442bcc5cee | |||
| e8aac6d41e | |||
| 2bbe737101 | |||
| 8856b3f1bc | |||
| aadc36f45c | |||
| 6c56b6f83c | |||
| 018ec3bcda | |||
| bc358bd9ed | |||
| f8eef66810 | |||
| ac2bad1de0 | |||
| 6cbfcb9d64 | |||
| 39df9c2ec0 | |||
| 138f1d28b3 | |||
| e2abc4dbeb | |||
| 0cfc85933c | |||
| c6fd5e6db2 | |||
| 8e57febf9e | |||
| ed38a5b450 | |||
| 16b3199892 | |||
| d13a776970 | |||
| 418b9c0f5d | |||
| c35f333daa | |||
| 668acb4afe | |||
| ac0690ec9f | |||
| cef2e850d7 | |||
| 4b469f2f49 | |||
| b0b2e8ceb5 | |||
| 82a9bf0a0f | |||
| 417083b0c1 | |||
| 25ed0d168e | |||
| d7b599d03b | |||
| 3f52cae04b | |||
| 59c3636139 | |||
| 472d793627 | |||
| 43b98ed9a5 | |||
| 69d2517dd2 | |||
| 0f6567e66b | |||
| c81f7d6291 | |||
| e9c18add5e | |||
| 4071c30b8b | |||
| ff1afcb8dc | |||
| d2c0891a68 | |||
| a557733d30 | |||
| 0f7ab6c803 | |||
| b7088c44f2 | |||
| 00294ff6f6 | |||
| 1d61675ef7 | |||
| 6a8d22f9f0 | |||
| 6811b5a692 | |||
| 9ff37e2874 | |||
| f022fb6b8a | |||
| 37564621e0 | |||
| 5057e1a38e | |||
| e781919434 | |||
| 3715e0c4d2 | |||
| 3ff996e946 | |||
| 6011bd9208 | |||
| d1e16abe34 | |||
| bc13f5c1e6 | |||
| ecf3ebf16d | |||
| 08fd3afc34 | |||
| 2528c03315 | |||
| d322e557a3 | |||
| 9fd17d769e | |||
| ca68186351 | |||
| 8d6f5d637b | |||
| c6790fe271 | |||
| 6402370eaf | |||
| f1ca709f25 | |||
| 51160b033b | |||
| c4884f8f8f | |||
| 647567abd2 | |||
| f123dbf730 | |||
| bc0d36ed54 | |||
| 745f874ccf | |||
| ea36d4ec7a | |||
| bb5623a621 | |||
| cf6c601c47 | |||
| 8efe906e87 | |||
| 3924c04e56 | |||
| a9401d4a0f | |||
| 53ec882e53 | |||
| 7387db4a69 | |||
| 9ef84f9b31 | |||
| f9c928d45c | |||
| 70860860d5 | |||
| 6a98b28427 | |||
| 9ee7819462 | |||
| 5a320e148c | |||
| 767aa23841 | |||
| 227aa69677 | |||
| 722c372f2d | |||
| 92e02c48dc | |||
| 3449746ead | |||
| ee52f75927 | |||
| 9c8cc8de2e | |||
| ea279338e0 | |||
| f15dc75908 | |||
| c00684ebbb | |||
| d0f4ae5109 | |||
| 187fbef207 | |||
| 4c655b13c3 | |||
| 2276b37741 | |||
| 7c5d0b9ae2 | |||
| b8b2d3d2bf | |||
| 3ec4d2218e | |||
| dc5b34546a | |||
| 6577038f22 | |||
| 93abaf99be | |||
| dd24e6058f | |||
| ded3a79bbc | |||
| ab0970e33f | |||
| 49d5d77a82 | |||
| 0cf8820e94 | |||
| 1ef3585cdc | |||
| 25ff6ca01f | |||
| c22bff5948 |
@@ -19,25 +19,21 @@
|
|||||||
"plugins": [
|
"plugins": [
|
||||||
"react"
|
"react"
|
||||||
],
|
],
|
||||||
|
"settings": {
|
||||||
|
"react": {
|
||||||
|
"version": require('./package.json').dependencies.react,
|
||||||
|
},
|
||||||
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"quotemark": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"no-var-requires": false,
|
|
||||||
"indent": [
|
"indent": [
|
||||||
"error",
|
"error",
|
||||||
2
|
2
|
||||||
],
|
],
|
||||||
"no-console": 0,
|
"no-console": [
|
||||||
"eofline": false,
|
"error",
|
||||||
"no-unused-variable": true,
|
{ allow: ["warn", "error"] }
|
||||||
"no-unused-expression": true,
|
|
||||||
"only-arrow-functions": false,
|
|
||||||
"space-before-function-paren": 0,
|
|
||||||
"trailing-comma": [
|
|
||||||
true,
|
|
||||||
"never"
|
|
||||||
],
|
],
|
||||||
"object-literal-sort-keys": false,
|
"space-before-function-paren": 0,
|
||||||
"semi": [
|
"semi": [
|
||||||
"warn",
|
"warn",
|
||||||
"never"
|
"never"
|
||||||
@@ -48,7 +44,7 @@
|
|||||||
"no-var": "error",
|
"no-var": "error",
|
||||||
"prefer-const": "error",
|
"prefer-const": "error",
|
||||||
"no-trailing-spaces": "error",
|
"no-trailing-spaces": "error",
|
||||||
"react/prop-types": 0,
|
"react/prop-types": 2,
|
||||||
"max-len": [
|
"max-len": [
|
||||||
1,
|
1,
|
||||||
{
|
{
|
||||||
@@ -56,6 +52,7 @@
|
|||||||
"ignoreComments": true,
|
"ignoreComments": true,
|
||||||
"ignoreTemplateLiterals": true
|
"ignoreTemplateLiterals": true
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"no-multi-spaces": 2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -21,6 +21,7 @@ DerivedData
|
|||||||
*.ipa
|
*.ipa
|
||||||
*.xcuserstate
|
*.xcuserstate
|
||||||
project.xcworkspace
|
project.xcworkspace
|
||||||
|
ios/Index/DataStore
|
||||||
|
|
||||||
# Android/IntelliJ
|
# Android/IntelliJ
|
||||||
#
|
#
|
||||||
@@ -55,13 +56,16 @@ buck-out/
|
|||||||
# Bundle artifact
|
# Bundle artifact
|
||||||
*.jsbundle
|
*.jsbundle
|
||||||
|
|
||||||
# RN android release
|
# RN android release
|
||||||
android/app/bin/
|
android/app/bin/
|
||||||
android/app/release/
|
android/app/release/
|
||||||
android/app/src/main/assets/index.android.bundle
|
android/app/src/main/assets/index.android.bundle
|
||||||
android/.project
|
android/.project
|
||||||
android/app/.project
|
android/app/.project
|
||||||
|
|
||||||
|
ios/Podfile.lock
|
||||||
|
android/app/src/main/res/drawable-*
|
||||||
|
|
||||||
# nodejs-mobile creates these with every npm install
|
# nodejs-mobile creates these with every npm install
|
||||||
nodejs-assets/nodejs-project/sample-*
|
nodejs-assets/nodejs-project/sample-*
|
||||||
nodejs-assets/build-native-modules-MacOS-helper-script-node.sh
|
nodejs-assets/build-native-modules-MacOS-helper-script-node.sh
|
||||||
|
|||||||
+71
-6
@@ -1,24 +1,89 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
## v0.20-05-2.beta
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
||||||
|
### Adds
|
||||||
|
* Feature allowing app chart not to show temperature part, when temperature is not tracked and corresponding refactoring
|
||||||
|
* Detox support for e2e testing and addition of the e2e tests
|
||||||
|
* Introduction of Redux global state (date and navigation are stored locally now)
|
||||||
|
* Introduction of clear.sh script to the project automising clearing project caches and packages reinstallation
|
||||||
|
|
||||||
## [0.0.2] - 2019-04-16
|
|
||||||
## Second updated beta release version
|
|
||||||
### Changes
|
### Changes
|
||||||
|
* Update of chart shades for bleeding
|
||||||
|
* Eslint rule cleanup and addition of new rules (checks for PropTypes definition for React components, multi spaces)
|
||||||
|
* sympto library upgrade to version 2.2.0
|
||||||
|
* Preparation for support of drip on iOS devices
|
||||||
|
* Updates representation of the incomplete mucus and cervix values on chart
|
||||||
|
* React Native update to 0.59.10
|
||||||
|
* Refactoring of header, cycle day overview, temperature edit view pages
|
||||||
|
* Setting minimum SDK version to 23 to allow using drip on earlier versions of Android
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
* Fixes adding notes to the future dates
|
||||||
|
* Fixes app exiting with error when hitting back button on device
|
||||||
|
* Fixes Sex symptom showing on y axis of chart even though the contraception method was deleted
|
||||||
|
* Fix of the clear.sh file name in package.json
|
||||||
|
* Fix of navigation from chart to the cycle day overview
|
||||||
|
* Bug fix for maximum value of mucus not showing on chart
|
||||||
|
* Fixes delete button bug on symptom edit page
|
||||||
|
* Fix of home screen centering
|
||||||
|
|
||||||
|
### Security
|
||||||
|
* Update of node.js to fix security issue
|
||||||
|
|
||||||
|
## v0.1905.29-beta
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
* Auto save functionality for all symptoms
|
||||||
|
* Add donation section to about
|
||||||
|
* Clearer labels on cycle day overview
|
||||||
|
* Rename mucus to cervical mucus
|
||||||
|
* Set show more on homescreen to default and get rid of more/less switch
|
||||||
|
* Add loading screen to data import
|
||||||
|
* Removes logo and adds header on the main login screen
|
||||||
|
* Nicer formatting for past bleeding prediction
|
||||||
|
* Removes permissions not required for debug or production
|
||||||
|
* Temperature screen styling update
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
* Styling
|
||||||
|
* Line width in chart
|
||||||
|
* Prediction range in drop on homescreen
|
||||||
|
|
||||||
|
## v0.0.3 - 2019-04-17
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
- Removes Google services from notification library and use fork of react-native-push-notification: <https://github.com/github:jfr3000/react-native-push-notification>
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Button functionality in settings for password
|
||||||
|
|
||||||
|
## v0.0.2 - 2019-04-09
|
||||||
|
|
||||||
|
## Second updated beta release version
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
- First day of the week in calendar is now Monday instead of Sunday
|
- First day of the week in calendar is now Monday instead of Sunday
|
||||||
- Minor styling consistency
|
- Minor styling consistency
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Typos
|
- Typos
|
||||||
- Bleeding value is visible in shortcut from Homescreen
|
- Bleeding value is visible in shortcut from Homescreen
|
||||||
- Delete button for sex, pain and mood
|
- Delete button for sex, pain and mood
|
||||||
- Dates on chart
|
- Dates on chart
|
||||||
|
|
||||||
## [0.0.1] - 2019-02-15
|
## v0.0.1 - 2019-02-15
|
||||||
|
|
||||||
## First beta release version
|
## First beta release version
|
||||||
|
|
||||||
### Added (list of core functionality)
|
### Added (list of core functionality)
|
||||||
|
|
||||||
- you can track your menstrual bleeding
|
- you can track your menstrual bleeding
|
||||||
- you can track symptoms related to natural family planning (nfp), i.e. basal temperature and mucus or cervix
|
- you can track symptoms related to natural family planning (nfp), i.e. basal temperature and mucus or cervix
|
||||||
- you can use nfp symptoms for fertility awareness (drip implements the sympto-thermal method)
|
- you can use nfp symptoms for fertility awareness (drip implements the sympto-thermal method)
|
||||||
@@ -28,4 +93,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- you can see basic stats about your cycle lengths
|
- you can see basic stats about your cycle lengths
|
||||||
- you can encrypt your data and protect it with a password
|
- you can encrypt your data and protect it with a password
|
||||||
- you can import and export your data in a nice format (csv)
|
- you can import and export your data in a nice format (csv)
|
||||||
- you can set reminders (daily reminder for taking your temperature or once per cycle for your next period
|
- you can set reminders (daily reminder for taking your temperature or once per cycle for your next period
|
||||||
|
|||||||
+2
-2
@@ -14,12 +14,12 @@ So good to see you here, hello :wave\_tone1: :wave\_tone2: :wave\_tone3: :wave\_
|
|||||||
|
|
||||||
## TL;DR
|
## TL;DR
|
||||||
|
|
||||||
You just want to say hello? Send us a [nice email](mailto:bl00dyhealth@mailbox.org?Subject=Nice%20incoming%20mail) :postbox: or tweet :bird: at us [@bl00dyhealth](https://twitter.com/bl00dyhealth).
|
You just want to say hello? Send us a [nice email](mailto:drip@mailbox.org?Subject=Nice%20incoming%20mail) :postbox: or tweet :bird: at us [@bl00dyhealth](https://twitter.com/bl00dyhealth).
|
||||||
|
|
||||||
## What should I know before I get started?
|
## What should I know before I get started?
|
||||||
|
|
||||||
We have prepared something for **you**: check out our [README](https://gitlab.com/bloodyhealth/drip/blob/master/README.md) for more information on how to set up and install everything you'll need.
|
We have prepared something for **you**: check out our [README](https://gitlab.com/bloodyhealth/drip/blob/master/README.md) for more information on how to set up and install everything you'll need.
|
||||||
[Ping us](mailto:bl00dyhealth@mailbox.org) if you could need some help :helmet\_with\_cross: !
|
[Ping us](mailto:drip@mailbox.org) if you could need some help :helmet\_with\_cross: !
|
||||||
|
|
||||||
Let us know if you want to suggest improvements for the README and open a merge request (which is just like Github's pull request)
|
Let us know if you want to suggest improvements for the README and open a merge request (which is just like Github's pull request)
|
||||||
|
|
||||||
|
|||||||
@@ -3,35 +3,54 @@
|
|||||||
A menstrual cycle tracking app that's open-source and leaves your data on your phone. Use it to track your menstrual cycle and/or for fertility awareness!
|
A menstrual cycle tracking app that's open-source and leaves your data on your phone. Use it to track your menstrual cycle and/or for fertility awareness!
|
||||||
Find more information on [our website](https://bloodyhealth.gitlab.io/).
|
Find more information on [our website](https://bloodyhealth.gitlab.io/).
|
||||||
|
|
||||||
The app is build in React Native and currently developed for Android.
|
[<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png"
|
||||||
|
alt="Get it on F-Droid"
|
||||||
|
height="80">](https://f-droid.org/packages/com.drip/)
|
||||||
|
[<img src="https://play.google.com/intl/en_us/badges/images/generic/en-play-badge.png"
|
||||||
|
alt="Get it on Google Play"
|
||||||
|
height="80">](https://play.google.com/store/apps/details?id=com.drip)
|
||||||
|
|
||||||
|
The app is built in React Native and currently developed for Android.
|
||||||
|
|
||||||
Here --> you will find our [contributing guide](https://gitlab.com/bloodyhealth/drip/blob/master/CONTRIBUTING.md).
|
Here --> you will find our [contributing guide](https://gitlab.com/bloodyhealth/drip/blob/master/CONTRIBUTING.md).
|
||||||
|
|
||||||
## Development setup
|
## Development setup
|
||||||
|
|
||||||
1. Install [Android Studio](https://developer.android.com/studio/) - you'll need it to install some dependencies.
|
#### 1. Android Studio
|
||||||
|
|
||||||
|
Install [Android Studio](https://developer.android.com/studio/) - you'll need it to install some dependencies.
|
||||||
|
|
||||||
|
#### 2. Node version
|
||||||
|
|
||||||
|
Make sure you are running Node 10 (newer versions won’t work). It's easiest to switch Node versions using `nvm`, here’s how to do it:
|
||||||
|
|
||||||
1. Make sure you are running Node 8 (newer versions won’t work). It's easiest to switch Node versions using `nvm`, here’s how to do it:
|
|
||||||
|
|
||||||
```
|
|
||||||
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
|
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
|
||||||
$ nvm install v8
|
$ nvm install v10
|
||||||
```
|
|
||||||
|
|
||||||
1. Clone this repository:
|
|
||||||
|
|
||||||
```
|
#### 3. Get this repository
|
||||||
|
|
||||||
|
Clone it with SSH
|
||||||
|
|
||||||
$ git clone git@gitlab.com:bloodyhealth/drip.git
|
$ git clone git@gitlab.com:bloodyhealth/drip.git
|
||||||
|
|
||||||
|
or clone it with HTTPS
|
||||||
|
|
||||||
|
$ git clone https://gitlab.com/bloodyhealth/drip.git
|
||||||
|
|
||||||
|
and run
|
||||||
|
|
||||||
$ cd drip
|
$ cd drip
|
||||||
```
|
|
||||||
and run
|
|
||||||
```
|
|
||||||
$ npm install
|
$ npm install
|
||||||
```
|
|
||||||
|
|
||||||
1. Open Android Studio and click on "Open an existing Android Studio project". Navigate to the drip repository you cloned and double click the android folder. It detects, downloads and cofigures requirements that might be missing, like the NDK and CMake to build the native code part of the project. Also see the [nodejs-mobile repository](https://github.com/janeasystems/nodejs-mobile) for the necessary prerequisites for your system.
|
#### 4. More requirements from Android Studio
|
||||||
|
|
||||||
1. Either start a [virtual device in Android Studio](https://developer.android.com/studio/run/emulator) or [set your physical device like your Android phone up](https://developer.android.com/training/basics/firstapp/running-app) to run the app.
|
Open Android Studio and click on "Open an existing Android Studio project". Navigate to the drip repository you cloned and double click the android folder. It detects, downloads and cofigures requirements that might be missing, like the NDK and CMake to build the native code part of the project. Also see the [nodejs-mobile repository](https://github.com/janeasystems/nodejs-mobile) for the necessary prerequisites for your system.
|
||||||
|
|
||||||
|
#### 5. Run the app
|
||||||
|
|
||||||
|
Either start a [virtual device in Android Studio](https://developer.android.com/studio/run/emulator) or [set your physical device like your Android phone up](https://developer.android.com/training/basics/firstapp/running-app) to run the app.
|
||||||
|
|
||||||
1. Open a terminal and run
|
1. Open a terminal and run
|
||||||
```
|
```
|
||||||
@@ -57,9 +76,9 @@ Make sure that you have Java 1.8 by running `java -version`.
|
|||||||
|
|
||||||
If you don't have Java installed, or your Java version is different, the app may not work. You can try just using Android Studio's Java by prepending it to your `$PATH` in your shell profile:
|
If you don't have Java installed, or your Java version is different, the app may not work. You can try just using Android Studio's Java by prepending it to your `$PATH` in your shell profile:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ export PATH="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin:${PATH}"
|
$ export PATH="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin:${PATH}"
|
||||||
```
|
```
|
||||||
|
|
||||||
Now, `which java` should output `/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java`, and the correct Java version should be used.
|
Now, `which java` should output `/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java`, and the correct Java version should be used.
|
||||||
|
|
||||||
@@ -75,15 +94,41 @@ If you get error messages about `adb` not being found on your path:
|
|||||||
$ ln -s ~/Library/Android/sdk/platform-tools/adb /usr/local/bin/adb
|
$ ln -s ~/Library/Android/sdk/platform-tools/adb /usr/local/bin/adb
|
||||||
```
|
```
|
||||||
|
|
||||||
### [Windows 10] react native problems
|
|
||||||
|
|
||||||
Unfortunately, the react native version we use doesn't work on Windows 10 it seems, find [more info here](https://github.com/facebook/react-native/issues/20015).
|
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
|
||||||
|
### Unit tests
|
||||||
You can run the tests with:
|
You can run the tests with:
|
||||||
```
|
```
|
||||||
$ npm test
|
$ npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### End to end tests
|
||||||
|
1. Check what testing device is specified in [package.json](https://gitlab.com/bloodyhealth/drip/blob/master/package.json) under:
|
||||||
|
```
|
||||||
|
{"detox":
|
||||||
|
{"configurations":
|
||||||
|
{"name": "NEXUS_DEVICE_OR_WHATEVER_SPECIFIED_DEVICE"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
2. Check if the current device is already installed on your machine. Go to `cd ~/Android/sdk/emulator/` or wherever you have Android installed on your machine. Here you can run `./emulator -list-avds` and compare the devices with the one you found in step 1.
|
||||||
|
3. Open Android Studio and go to -> Tools -> AVD manager -> `+Create virtual device` and select the device checked in the previous step
|
||||||
|
4. Use the emulator on your machine to run it without heavy Android Studio, e.g. in `~/Android/Sdk/emulator` OR chose to run the emulator within Android Studio
|
||||||
|
4.1 Here run: `$ ./emulator -avd NEXUS_DEVICE_OR_WHATEVER_SPECIFIED_DEVICE`
|
||||||
|
4.2 You might need to specify the following environment variables in your zsh or bash file according to where you have it installed. You can find exact path in Android Studio (Android Studio Preferences → Appearance and Behavior → System Settings → Android SDK). After adding environment variables, you might need to restart your terminal or source the modified bash profile (i.e. "source ~/.bash_profile").
|
||||||
|
```
|
||||||
|
export ANDROID_HOME="/home/myname/Android/Sdk"
|
||||||
|
export ANDROID_SDK_ROOT="/home/myname/Android/Sdk"
|
||||||
|
export ANDROID_AVD_HOME="/home/myname/.android/avd"
|
||||||
|
```
|
||||||
|
5. For the first time you need to get the app on the phone or if you run into this error:
|
||||||
|
`'app-debug-androidTest.apk' could not be found`
|
||||||
|
--> open a new 2nd tab and run (in your drip folder): `cd android and ./gradlew assembleAndroidTest`
|
||||||
|
Otherwise just open a new 2nd tab to run (in your drip folder) `npm run android`
|
||||||
|
6. Open a new 3rd tab to run `./node_modules/.bin/detox test -c android.emu.debug`
|
||||||
|
|
||||||
|
Hopefully you see the magic happening clicking through the app and happy test results on your console :sun_with_face: !
|
||||||
|
|
||||||
## Debugging
|
## Debugging
|
||||||
In order to see logging output from the app, run `npm run log` in a separate terminal. You can output specific code you want to see, with:
|
In order to see logging output from the app, run `npm run log` in a separate terminal. You can output specific code you want to see, with:
|
||||||
@@ -96,7 +141,7 @@ More information about how the app calculates fertility status and bleeding pred
|
|||||||
|
|
||||||
## Adding a new tracking icon
|
## Adding a new tracking icon
|
||||||
|
|
||||||
1. We use [fontello](http://fontello.com/) to create icon fonts for us. You need to upload the complete set of tracking icons (bleeding, mucus, ...) including the new icon you wish to add, all in SVG.
|
1. We use [fontello](http://fontello.com/) to create icon fonts for us. You need to upload the complete set of tracking icons (bleeding, cervical mucus, ...) including the new icon you wish to add, all in SVG.
|
||||||
2. Download webfont from fontello
|
2. Download webfont from fontello
|
||||||
3. Copy both the content of `config.json` and `font.tff` into `assets/fonts`, replacing it with the current content of `config-drip-icon-font.json` and `drip-icon-font.tff`.
|
3. Copy both the content of `config.json` and `font.tff` into `assets/fonts`, replacing it with the current content of `config-drip-icon-font.json` and `drip-icon-font.tff`.
|
||||||
4. Now run the following command in your console:
|
4. Now run the following command in your console:
|
||||||
|
|||||||
+25
-16
@@ -98,15 +98,22 @@ android {
|
|||||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.drip"
|
applicationId "com.drip"
|
||||||
minSdkVersion rootProject.ext.minSdkVersion
|
minSdkVersion rootProject.ext.minSdkVersion
|
||||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||||
versionCode 1
|
versionCode 3
|
||||||
versionName "1.0"
|
versionName "0.1905.29-beta"
|
||||||
ndk {
|
ndk {
|
||||||
abiFilters "armeabi-v7a", "x86"
|
abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
|
||||||
}
|
}
|
||||||
|
testBuildType System.getProperty('testBuildType', 'debug') // This will later be used to control the test apk build type
|
||||||
|
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
|
||||||
}
|
}
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
release {
|
release {
|
||||||
@@ -123,7 +130,7 @@ android {
|
|||||||
reset()
|
reset()
|
||||||
enable enableSeparateBuildPerCPUArchitecture
|
enable enableSeparateBuildPerCPUArchitecture
|
||||||
universalApk false // If true, also generate a universal APK
|
universalApk false // If true, also generate a universal APK
|
||||||
include "armeabi-v7a", "x86"
|
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
@@ -138,7 +145,7 @@ android {
|
|||||||
variant.outputs.each { output ->
|
variant.outputs.each { output ->
|
||||||
// For each separate APK per architecture, set a unique version code as described here:
|
// For each separate APK per architecture, set a unique version code as described here:
|
||||||
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
|
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
|
||||||
def versionCodes = ["armeabi-v7a":1, "x86":2]
|
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a":3, "x86_64":4]
|
||||||
def abi = output.getFilter(OutputFile.ABI)
|
def abi = output.getFilter(OutputFile.ABI)
|
||||||
if (abi != null) { // null for the universal-debug, universal-release variants
|
if (abi != null) { // null for the universal-debug, universal-release variants
|
||||||
output.versionCodeOverride =
|
output.versionCodeOverride =
|
||||||
@@ -149,17 +156,19 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':nodejs-mobile-react-native')
|
implementation project(':realm')
|
||||||
compile project(':react-native-restart')
|
implementation project(':react-native-vector-icons')
|
||||||
compile project(':react-native-push-notification')
|
implementation project(':react-native-share')
|
||||||
compile project(':react-native-vector-icons')
|
implementation project(':react-native-restart')
|
||||||
compile project(':react-native-fs')
|
implementation project(':react-native-push-notification')
|
||||||
compile project(':react-native-document-picker')
|
implementation project(':react-native-fs')
|
||||||
compile project(':react-native-share')
|
implementation project(':react-native-document-picker')
|
||||||
compile project(':realm')
|
implementation project(':nodejs-mobile-react-native')
|
||||||
compile fileTree(dir: "libs", include: ["*.jar"])
|
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||||
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
|
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
|
||||||
compile "com.facebook.react:react-native:+" // From node_modules
|
implementation "com.facebook.react:react-native:+" // From node_modules
|
||||||
|
androidTestImplementation('com.wix:detox:+') { transitive = true }
|
||||||
|
androidTestImplementation 'junit:junit:4.12'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run this once to be able to run the application with BUCK
|
// Run this once to be able to run the application with BUCK
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.drip;
|
||||||
|
|
||||||
|
import com.wix.detox.Detox;
|
||||||
|
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
import androidx.test.filters.LargeTest;
|
||||||
|
import androidx.test.rule.ActivityTestRule;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
@LargeTest
|
||||||
|
public class DetoxTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void runDetoxTests() {
|
||||||
|
Detox.runTests(mActivityRule);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||||
|
|
||||||
|
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
|
||||||
|
</manifest>
|
||||||
@@ -7,6 +7,9 @@
|
|||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
|
<uses-permission tools:node="remove" android:name="android.permission.READ_PHONE_STATE" />
|
||||||
|
<uses-permission tools:node="remove" android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission tools:node="remove" android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
<permission
|
<permission
|
||||||
android:name="${applicationId}.permission.C2D_MESSAGE"
|
android:name="${applicationId}.permission.C2D_MESSAGE"
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -10,6 +10,6 @@ public class MainActivity extends ReactActivity {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected String getMainComponentName() {
|
protected String getMainComponentName() {
|
||||||
return "home";
|
return "drip";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.drip"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<uses-permission tools:node="remove" android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||||
|
<uses-permission tools:node="remove" android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
|
</manifest>
|
||||||
+21
-20
@@ -5,11 +5,13 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
google()
|
google()
|
||||||
}
|
}
|
||||||
|
ext.kotlinVersion = '1.3.10'
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.1.0'
|
classpath 'com.android.tools.build:gradle:3.4.0'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,30 +27,29 @@ allprojects {
|
|||||||
url 'https://maven.google.com/'
|
url 'https://maven.google.com/'
|
||||||
name 'Google'
|
name 'Google'
|
||||||
}
|
}
|
||||||
|
google()
|
||||||
|
maven {
|
||||||
|
// All of Detox' artifacts are provided via the npm module
|
||||||
|
url "$rootDir/../node_modules/detox/Detox-android"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
buildToolsVersion = "26.0.3"
|
buildToolsVersion = "28.0.3"
|
||||||
minSdkVersion = 16
|
minSdkVersion = 23
|
||||||
compileSdkVersion = 26
|
compileSdkVersion = 28
|
||||||
targetSdkVersion = 26
|
targetSdkVersion = 28
|
||||||
supportLibVersion = "26.1.0"
|
supportLibVersion = "28.0.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
subprojects {project ->
|
subprojects {
|
||||||
buildscript {
|
afterEvaluate {project ->
|
||||||
repositories {
|
if (project.hasProperty("android")) {
|
||||||
maven { url = 'https://dl.bintray.com/android/android-tools/' }
|
android {
|
||||||
|
compileSdkVersion 28
|
||||||
|
buildToolsVersion '28.0.3'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// https://stackoverflow.com/questions/52613089/getting-verifyreleaseresources-error-after-upgrading-react-native
|
|
||||||
afterEvaluate {
|
|
||||||
if (project.hasProperty("android")) {
|
|
||||||
android {
|
|
||||||
compileSdkVersion 27
|
|
||||||
buildToolsVersion "27.0.3"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,4 @@
|
|||||||
# When configured, Gradle will run in incubating parallel mode.
|
# When configured, Gradle will run in incubating parallel mode.
|
||||||
# This option should only be used with decoupled projects. More details, visit
|
# This option should only be used with decoupled projects. More details, visit
|
||||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||||
# org.gradle.parallel=true
|
# org.gradle.parallel=true
|
||||||
|
|
||||||
android.useDeprecatedNdk=true
|
|
||||||
BIN
Binary file not shown.
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
|
|
||||||
|
|||||||
Vendored
+17
-1
@@ -1,5 +1,21 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright 2015 the original author or authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
##
|
##
|
||||||
## Gradle start up script for UN*X
|
## Gradle start up script for UN*X
|
||||||
@@ -7,7 +23,7 @@
|
|||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
DEFAULT_JVM_OPTS=""
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
APP_NAME="Gradle"
|
||||||
APP_BASE_NAME=`basename "$0"`
|
APP_BASE_NAME=`basename "$0"`
|
||||||
|
|||||||
Vendored
+17
-1
@@ -1,3 +1,19 @@
|
|||||||
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%" == "" @echo off
|
@if "%DEBUG%" == "" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@rem
|
@rem
|
||||||
@@ -9,7 +25,7 @@
|
|||||||
if "%OS%"=="Windows_NT" setlocal
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
set DEFAULT_JVM_OPTS=
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,18 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import { View } from 'react-native'
|
||||||
|
|
||||||
|
import AppText from './app-text'
|
||||||
|
import { shared } from '../i18n/en/labels'
|
||||||
|
|
||||||
|
const AppLoadingView = () => {
|
||||||
|
return (
|
||||||
|
<View flex={1}>
|
||||||
|
<View style={{flex:1, justifyContent: 'center'}}>
|
||||||
|
<AppText style={{alignSelf: 'center'}}>{shared.loading}</AppText>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AppLoadingView
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { TextInput } from 'react-native'
|
||||||
|
import styles from '../styles'
|
||||||
|
|
||||||
|
export default function AppTextInput({ style, ...props }) {
|
||||||
|
if (!Array.isArray(style)) style = [style]
|
||||||
|
return (
|
||||||
|
<TextInput
|
||||||
|
style={[styles.textInputField, ...style]}
|
||||||
|
autoFocus={props.autoFocus}
|
||||||
|
onChangeText={props.onChangeText}
|
||||||
|
value={props.value}
|
||||||
|
placeholder={props.placeholder}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
AppTextInput.propTypes = {
|
||||||
|
autoFocus: PropTypes.bool,
|
||||||
|
onChangeText: PropTypes.func,
|
||||||
|
placeholder: PropTypes.string,
|
||||||
|
style: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
||||||
|
value: PropTypes.string,
|
||||||
|
}
|
||||||
|
|
||||||
|
AppTextInput.defaultProps = {
|
||||||
|
style: []
|
||||||
|
}
|
||||||
+11
-25
@@ -1,40 +1,26 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
import { Text } from 'react-native'
|
import { Text } from 'react-native'
|
||||||
import styles from "../styles"
|
import styles from "../styles"
|
||||||
import Link from './link'
|
import Link from './link'
|
||||||
|
|
||||||
export default function AppText(props) {
|
export default function AppText({ children, onPress, numberOfLines, style}) {
|
||||||
// we parse for links in case the text contains any
|
// we parse for links in case the text contains any
|
||||||
return (
|
return (
|
||||||
<Link>
|
<Link>
|
||||||
<Text
|
<Text style={[styles.appText, style]}
|
||||||
style={[styles.appText, props.style]}
|
onPress={onPress}
|
||||||
onPress={props.onPress}
|
numberOfLines={numberOfLines}
|
||||||
numberOfLines={props.numberOfLines}
|
|
||||||
>
|
>
|
||||||
{props.children}
|
{children}
|
||||||
</Text>
|
</Text>
|
||||||
</Link>
|
</Link>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ActionHint(props) {
|
AppText.propTypes = {
|
||||||
if(props.isVisible) {
|
children: PropTypes.node,
|
||||||
return (
|
onPress: PropTypes.func,
|
||||||
<AppText
|
numberOfLines: PropTypes.number,
|
||||||
style={[styles.actionHint, props.style]}>
|
style: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
||||||
{props.children}
|
|
||||||
</AppText>
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SymptomSectionHeader(props) {
|
|
||||||
return (
|
|
||||||
<AppText style={styles.symptomViewHeading}>
|
|
||||||
{props.children}
|
|
||||||
</AppText>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
+67
-21
@@ -1,44 +1,90 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { View } from 'react-native'
|
|
||||||
import nodejs from 'nodejs-mobile-react-native'
|
import nodejs from 'nodejs-mobile-react-native'
|
||||||
|
|
||||||
|
import { getLicenseFlag, saveEncryptionFlag } from '../local-storage'
|
||||||
|
import { openDb } from '../db'
|
||||||
|
|
||||||
import App from './app'
|
import App from './app'
|
||||||
import PasswordPrompt from './password-prompt'
|
import PasswordPrompt from './password-prompt'
|
||||||
import License from './license'
|
import License from './license'
|
||||||
import { getLicenseFlag } from '../local-storage'
|
import AppLoadingView from './app-loading'
|
||||||
|
|
||||||
|
import store from "../store"
|
||||||
|
import { Provider } from 'react-redux'
|
||||||
|
|
||||||
export default class AppWrapper extends Component {
|
export default class AppWrapper extends Component {
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
this.state = {
|
this.state = {
|
||||||
retrievingLicenseSetting: true
|
isCheckingLicenseAgreement: true,
|
||||||
|
shouldShowLicenseAgreement: false,
|
||||||
|
shouldShowPasswordPrompt: false,
|
||||||
|
shouldShowApp: false,
|
||||||
}
|
}
|
||||||
nodejs.start('main.js')
|
nodejs.start('main.js')
|
||||||
this.checkLicenseAgreement()
|
this.checkLicenseAgreement()
|
||||||
|
this.checkDbPasswordSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkLicenseAgreement() {
|
async checkLicenseAgreement() {
|
||||||
const agreed = await getLicenseFlag()
|
const isLicenseFlagSet = await getLicenseFlag()
|
||||||
this.setState({retrievingLicenseSetting: false})
|
if (!isLicenseFlagSet) {
|
||||||
if (!agreed) this.setState({showLicense: true})
|
this.enableShowLicenseAgreement()
|
||||||
|
} else {
|
||||||
|
this.setState({ isCheckingLicenseAgreement: false })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async checkDbPasswordSet() {
|
||||||
|
const canConnectToDb = await openDb()
|
||||||
|
if (canConnectToDb) {
|
||||||
|
this.enableShowApp()
|
||||||
|
await saveEncryptionFlag(false)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
this.setState({ shouldShowPasswordPrompt: true })
|
||||||
|
await saveEncryptionFlag(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
enableShowLicenseAgreement = () => {
|
||||||
|
this.setState({
|
||||||
|
shouldShowLicenseAgreement: true,
|
||||||
|
isCheckingLicenseAgreement: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
disableShowLicenseAgreement = () => {
|
||||||
|
this.setState({ shouldShowLicenseAgreement: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
enableShowApp = () => {
|
||||||
|
this.setState({
|
||||||
|
shouldShowApp: true,
|
||||||
|
shouldShowPasswordPrompt: false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const whiteScreen = <View style={{ flex: 1 }}></View>
|
const {
|
||||||
const licenseScreen = <License setLicense={() => {
|
isCheckingLicenseAgreement,
|
||||||
this.setState({showLicense: false})
|
shouldShowLicenseAgreement,
|
||||||
}}/>
|
shouldShowPasswordPrompt,
|
||||||
const passwordPrompt = <PasswordPrompt showApp={() => {
|
shouldShowApp,
|
||||||
this.setState({showApp: true})
|
} = this.state
|
||||||
}}/>
|
|
||||||
|
|
||||||
if (this.state.retrievingLicenseSetting) {
|
let initialView = null
|
||||||
return whiteScreen
|
|
||||||
} else if (this.state.showLicense) {
|
if (isCheckingLicenseAgreement) {
|
||||||
return licenseScreen
|
initialView = <AppLoadingView />
|
||||||
} else if (!this.state.showApp) {
|
} else if (shouldShowLicenseAgreement) {
|
||||||
return passwordPrompt
|
initialView = <License setLicense={this.disableShowLicenseAgreement}/>
|
||||||
} else {
|
} else if (shouldShowPasswordPrompt) {
|
||||||
return <App/>
|
initialView = <PasswordPrompt enableShowApp={this.enableShowApp} />
|
||||||
|
} else if (shouldShowApp) {
|
||||||
|
initialView = <App />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return <Provider store={store}>{initialView}</Provider>
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+87
-123
@@ -1,150 +1,114 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { View, BackHandler } from 'react-native'
|
import { View, BackHandler } from 'react-native'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
import { connect } from 'react-redux'
|
||||||
|
|
||||||
|
import { getDate } from '../slices/date'
|
||||||
|
import { getNavigation, navigate, goBack } from '../slices/navigation'
|
||||||
|
|
||||||
import Header from './header'
|
import Header from './header'
|
||||||
import Menu from './menu'
|
import Menu from './menu'
|
||||||
import Home from './home'
|
import { viewsList } from './views'
|
||||||
import Calendar from './calendar'
|
import { isSymptomView, isSettingsView } from './pages'
|
||||||
import CycleDay from './cycle-day/cycle-day-overview'
|
|
||||||
import symptomViews from './cycle-day/symptoms'
|
import { headerTitles } from '../i18n/en/labels'
|
||||||
import Chart from './chart/chart'
|
|
||||||
import SettingsMenu from './settings/settings-menu'
|
|
||||||
import settingsViews from './settings'
|
|
||||||
import Stats from './stats'
|
|
||||||
import {headerTitles, menuTitles} from '../i18n/en/labels'
|
|
||||||
import InfoSymptom from './cycle-day/symptoms/info-symptom'
|
|
||||||
import setupNotifications from '../lib/notifications'
|
import setupNotifications from '../lib/notifications'
|
||||||
|
import { getCycleDay, closeDb } from '../db'
|
||||||
|
|
||||||
// design wants everyhting lowercased, but we don't
|
class App extends Component {
|
||||||
// have CSS pseudo properties
|
|
||||||
const headerTitlesLowerCase = Object.keys(headerTitles).reduce((acc, curr) => {
|
|
||||||
acc[curr] = headerTitles[curr].toLowerCase()
|
|
||||||
return acc
|
|
||||||
}, {})
|
|
||||||
|
|
||||||
const HOME_PAGE = 'Home'
|
static propTypes = {
|
||||||
const INFO_SYMPTOM_PAGE = 'InfoSymptom'
|
date: PropTypes.string,
|
||||||
const CYCLE_DAY_PAGE = 'CycleDay'
|
navigation: PropTypes.object.isRequired,
|
||||||
const SETTINGS_MENU_PAGE = 'SettingsMenu'
|
navigate: PropTypes.func,
|
||||||
|
goBack: PropTypes.func,
|
||||||
|
}
|
||||||
|
|
||||||
export default class App extends Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
|
||||||
currentPage: HOME_PAGE
|
this.backHandler = BackHandler.addEventListener(
|
||||||
|
'hardwareBackPress',
|
||||||
|
this.goBack
|
||||||
|
)
|
||||||
|
|
||||||
|
setupNotifications(this.props.navigate)
|
||||||
|
}
|
||||||
|
|
||||||
|
goBack = () => {
|
||||||
|
const { currentPage } = this.props.navigation
|
||||||
|
|
||||||
|
if (currentPage === 'Home') {
|
||||||
|
closeDb()
|
||||||
|
BackHandler.exitApp()
|
||||||
|
} else {
|
||||||
|
this.props.goBack()
|
||||||
}
|
}
|
||||||
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonPress)
|
|
||||||
setupNotifications(this.navigate)
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.backHandler.remove()
|
this.backHandler.remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
navigate = (pageName, props) => {
|
|
||||||
const { currentPage } = this.state
|
|
||||||
// for the back button to work properly, we want to
|
|
||||||
// remember two origins: which menu item we came from
|
|
||||||
// and from where we navigated to the symptom view (day
|
|
||||||
// view or home page)
|
|
||||||
if (this.isMenuItem()) {
|
|
||||||
this.menuOrigin = currentPage
|
|
||||||
}
|
|
||||||
if (!this.isSymptomView() && !this.isInfoSymptomView()) {
|
|
||||||
this.originForSymptomView = currentPage
|
|
||||||
}
|
|
||||||
this.setState({ currentPage: pageName, currentProps: props })
|
|
||||||
}
|
|
||||||
|
|
||||||
handleBackButtonPress = () => {
|
|
||||||
const { currentPage, currentProps } = this.state
|
|
||||||
if (currentPage === HOME_PAGE) return false
|
|
||||||
if (this.isSymptomView()) {
|
|
||||||
this.navigate(
|
|
||||||
this.originForSymptomView, { date: currentProps.date }
|
|
||||||
)
|
|
||||||
} else if (this.isSettingsView()) {
|
|
||||||
this.navigate(SETTINGS_MENU_PAGE)
|
|
||||||
} else if (currentPage === CYCLE_DAY_PAGE) {
|
|
||||||
this.navigate(this.menuOrigin)
|
|
||||||
} else if (this.isInfoSymptomView()) {
|
|
||||||
const { date, cycleDay, symptomView } = currentProps
|
|
||||||
this.navigate(
|
|
||||||
symptomView, { date, cycleDay })
|
|
||||||
} else {
|
|
||||||
this.navigate(HOME_PAGE)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
isMenuItem() {
|
|
||||||
return Object.keys(menuTitles).includes(this.state.currentPage)
|
|
||||||
}
|
|
||||||
|
|
||||||
isSymptomView() {
|
|
||||||
return Object.keys(symptomViews).includes(this.state.currentPage)
|
|
||||||
}
|
|
||||||
|
|
||||||
isInfoSymptomView() {
|
|
||||||
return this.state.currentPage === INFO_SYMPTOM_PAGE
|
|
||||||
}
|
|
||||||
|
|
||||||
isSettingsView() {
|
|
||||||
return Object.keys(settingsViews).includes(this.state.currentPage)
|
|
||||||
}
|
|
||||||
|
|
||||||
isDefaultView() {
|
|
||||||
const { currentPage } = this.state
|
|
||||||
return this.isMenuItem(currentPage) || currentPage === SETTINGS_MENU_PAGE
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { currentPage, currentProps } = this.state
|
const { date, navigation, goBack } = this.props
|
||||||
const pages = {
|
const { currentPage } = navigation
|
||||||
Home,
|
|
||||||
Calendar,
|
if (!currentPage) {
|
||||||
CycleDay,
|
return false
|
||||||
Chart,
|
|
||||||
InfoSymptom,
|
|
||||||
SettingsMenu,
|
|
||||||
...settingsViews,
|
|
||||||
Stats,
|
|
||||||
...symptomViews
|
|
||||||
}
|
}
|
||||||
const page = pages[currentPage]
|
|
||||||
const title = headerTitlesLowerCase[currentPage]
|
const Page = viewsList[currentPage]
|
||||||
|
const title = headerTitles[currentPage]
|
||||||
|
|
||||||
|
const isSymptomEditView = isSymptomView(currentPage)
|
||||||
|
const isSettingsSubView = isSettingsView(currentPage)
|
||||||
|
const isCycleDayView = currentPage === 'CycleDay'
|
||||||
|
|
||||||
|
const headerProps = {
|
||||||
|
title,
|
||||||
|
handleBack: isSettingsSubView ? goBack : null,
|
||||||
|
}
|
||||||
|
|
||||||
|
const pageProps = {
|
||||||
|
cycleDay: date && getCycleDay(date),
|
||||||
|
date,
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={{flex: 1}}>
|
<View style={{ flex: 1 }}>
|
||||||
{this.isDefaultView() &&
|
{
|
||||||
<Header title={title} />
|
!isSymptomEditView &&
|
||||||
|
!isCycleDayView &&
|
||||||
|
<Header { ...headerProps } />
|
||||||
}
|
}
|
||||||
{(this.isInfoSymptomView() || this.isSettingsView()) &&
|
|
||||||
<Header
|
|
||||||
title={title}
|
|
||||||
showBackButton={true}
|
|
||||||
goBack={this.handleBackButtonPress}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
{this.isSymptomView() &&
|
|
||||||
<Header
|
|
||||||
title={title}
|
|
||||||
isSymptomView={true}
|
|
||||||
goBack={this.handleBackButtonPress}
|
|
||||||
date={currentProps.date}
|
|
||||||
goToSymptomInfo={() => this.navigate(INFO_SYMPTOM_PAGE, {
|
|
||||||
symptomView: currentPage,
|
|
||||||
...currentProps
|
|
||||||
})}
|
|
||||||
/>}
|
|
||||||
|
|
||||||
{React.createElement(page, {
|
<Page { ...pageProps } />
|
||||||
navigate: this.navigate,
|
|
||||||
...currentProps
|
|
||||||
})}
|
|
||||||
|
|
||||||
{!this.isSymptomView() &&
|
{ !isSymptomEditView && <Menu /> }
|
||||||
<Menu navigate={this.navigate} currentPage={currentPage} />
|
|
||||||
}
|
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => {
|
||||||
|
return({
|
||||||
|
date: getDate(state),
|
||||||
|
navigation: getNavigation(state)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => {
|
||||||
|
return({
|
||||||
|
navigate: (page) => dispatch(navigate(page)),
|
||||||
|
goBack: () => dispatch(goBack()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(
|
||||||
|
mapStateToProps,
|
||||||
|
mapDispatchToProps
|
||||||
|
)(App)
|
||||||
|
|||||||
+22
-11
@@ -1,20 +1,31 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
import { TouchableOpacity } from 'react-native'
|
import { TouchableOpacity } from 'react-native'
|
||||||
import AppText from './app-text'
|
import AppText from './app-text'
|
||||||
import styles from '../styles'
|
import styles from '../styles'
|
||||||
|
|
||||||
export default function Button(props) {
|
export default function Button({
|
||||||
|
backgroundColor,
|
||||||
|
children,
|
||||||
|
onPress,
|
||||||
|
style,
|
||||||
|
testID
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={props.onPress}
|
onPress={onPress}
|
||||||
style={[
|
style={[styles.button, style, { backgroundColor }]}
|
||||||
styles.button,
|
testID={testID}
|
||||||
props.style,
|
>
|
||||||
{backgroundColor: props.backgroundColor}
|
<AppText style={styles.homeButtonText}>{children}</AppText>
|
||||||
]}>
|
|
||||||
<AppText style={styles.homeButtonText}>
|
|
||||||
{props.children}
|
|
||||||
</AppText>
|
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Button.propTypes = {
|
||||||
|
backgroundColor: PropTypes.string,
|
||||||
|
children: PropTypes.node,
|
||||||
|
onPress: PropTypes.func,
|
||||||
|
style: PropTypes.object,
|
||||||
|
testID: PropTypes.string
|
||||||
|
}
|
||||||
|
|||||||
+28
-3
@@ -1,5 +1,11 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
import { CalendarList } from 'react-native-calendars'
|
import { CalendarList } from 'react-native-calendars'
|
||||||
|
import { connect } from 'react-redux'
|
||||||
|
|
||||||
|
import { setDate } from '../slices/date'
|
||||||
|
import { navigate } from '../slices/navigation'
|
||||||
|
|
||||||
import { LocalDate } from 'js-joda'
|
import { LocalDate } from 'js-joda'
|
||||||
import { getBleedingDaysSortedByDate } from '../db'
|
import { getBleedingDaysSortedByDate } from '../db'
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
@@ -7,7 +13,12 @@ import { shadesOfRed, calendarTheme } from '../styles/index'
|
|||||||
import styles from '../styles/index'
|
import styles from '../styles/index'
|
||||||
import nothingChanged from '../db/db-unchanged'
|
import nothingChanged from '../db/db-unchanged'
|
||||||
|
|
||||||
export default class CalendarView extends Component {
|
class CalendarView extends Component {
|
||||||
|
static propTypes = {
|
||||||
|
setDate: PropTypes.func.isRequired,
|
||||||
|
navigate: PropTypes.func.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.bleedingDays = getBleedingDaysSortedByDate()
|
this.bleedingDays = getBleedingDaysSortedByDate()
|
||||||
@@ -36,9 +47,10 @@ export default class CalendarView extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
passDateToDayView = (result) => {
|
passDateToDayView = (result) => {
|
||||||
const navigate = this.props.navigate
|
this.props.setDate(result.dateString)
|
||||||
navigate('CycleDay', { date: result.dateString })
|
this.props.navigate('CycleDay')
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<CalendarList
|
<CalendarList
|
||||||
@@ -60,6 +72,19 @@ export default class CalendarView extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => {
|
||||||
|
return({
|
||||||
|
setDate: (date) => dispatch(setDate(date)),
|
||||||
|
navigate: (page) => dispatch(navigate(page)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(
|
||||||
|
null,
|
||||||
|
mapDispatchToProps,
|
||||||
|
)(CalendarView)
|
||||||
|
|
||||||
|
|
||||||
function toCalFormat(bleedingDaysSortedByDate) {
|
function toCalFormat(bleedingDaysSortedByDate) {
|
||||||
const todayDateString = LocalDate.now().toString()
|
const todayDateString = LocalDate.now().toString()
|
||||||
return bleedingDaysSortedByDate.reduce((acc, day) => {
|
return bleedingDaysSortedByDate.reduce((acc, day) => {
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { View } from 'react-native'
|
||||||
|
|
||||||
|
import AppText from '../app-text'
|
||||||
|
import DripHomeIcon from '../../assets/drip-home-icons'
|
||||||
|
|
||||||
|
import styles from './styles'
|
||||||
|
import { cycleDayColor } from '../../styles'
|
||||||
|
|
||||||
|
import { shared as labels } from '../../i18n/en/labels'
|
||||||
|
|
||||||
|
const ChartLegend = ({ xAxisHeight }) => {
|
||||||
|
return (
|
||||||
|
<View style={[styles.yAxis, styles.chartLegend, {height: xAxisHeight}]}>
|
||||||
|
<DripHomeIcon
|
||||||
|
name="circle"
|
||||||
|
size={styles.yAxis.width - 7}
|
||||||
|
color={cycleDayColor}
|
||||||
|
/>
|
||||||
|
<AppText style={styles.yAxisLabels.dateLabel}>
|
||||||
|
{labels.date.toLowerCase()}
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
ChartLegend.propTypes = {
|
||||||
|
xAxisHeight: PropTypes.number.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ChartLegend
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
import { Shape } from 'react-native/Libraries/ART/ReactNativeART'
|
||||||
|
|
||||||
|
import styles from './styles'
|
||||||
|
|
||||||
|
const ChartLine = ({ path, isNfpLine = false }) => {
|
||||||
|
const strokeStyle =
|
||||||
|
isNfpLine ? styles.nfpLine.stroke : styles.column.stroke.color
|
||||||
|
const strokeWidth =
|
||||||
|
isNfpLine ? styles.nfpLine.strokeWidth : styles.column.stroke.width
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Shape
|
||||||
|
stroke={strokeStyle}
|
||||||
|
strokeWidth={strokeWidth}
|
||||||
|
d={path}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
ChartLine.propTypes = {
|
||||||
|
path: PropTypes.object,
|
||||||
|
isNfpLine: PropTypes.bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ChartLine
|
||||||
+130
-150
@@ -1,37 +1,55 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
import { View, FlatList, ActivityIndicator } from 'react-native'
|
import { View, FlatList, ActivityIndicator } from 'react-native'
|
||||||
import { LocalDate } from 'js-joda'
|
|
||||||
import { makeYAxisLabels, makeHorizontalGrid } from './y-axis'
|
import NoData from './no-data'
|
||||||
|
import AppLoadingView from '../app-loading'
|
||||||
|
import YAxis from './y-axis'
|
||||||
import nfpLines from './nfp-lines'
|
import nfpLines from './nfp-lines'
|
||||||
import DayColumn from './day-column'
|
import DayColumn from './day-column'
|
||||||
import { getCycleDaysSortedByDate, getAmountOfCycleDays } from '../../db'
|
import HorizontalGrid from './horizontal-grid'
|
||||||
import styles from './styles'
|
|
||||||
import { cycleDayColor } from '../../styles'
|
|
||||||
import { scaleObservable } from '../../local-storage'
|
|
||||||
import config from '../../config'
|
|
||||||
import AppText from '../app-text'
|
import AppText from '../app-text'
|
||||||
import { shared as labels } from '../../i18n/en/labels'
|
|
||||||
import DripIcon from '../../assets/drip-icons'
|
import { connect } from 'react-redux'
|
||||||
import DripHomeIcon from '../../assets/drip-home-icons'
|
import { navigate } from '../../slices/navigation'
|
||||||
|
|
||||||
|
import { getCycleDaysSortedByDate } from '../../db'
|
||||||
import nothingChanged from '../../db/db-unchanged'
|
import nothingChanged from '../../db/db-unchanged'
|
||||||
|
import { scaleObservable } from '../../local-storage'
|
||||||
|
import { makeColumnInfo } from '../helpers/chart'
|
||||||
|
|
||||||
const symptomIcons = {
|
import config from '../../config'
|
||||||
bleeding: <DripIcon size={16} name='drip-icon-bleeding' color={styles.iconShades.bleeding[3]}/>,
|
import { shared } from '../../i18n/en/labels'
|
||||||
mucus: <DripIcon size={16} name='drip-icon-mucus' color={styles.iconShades.mucus[4]}/>,
|
import styles from './styles'
|
||||||
cervix: <DripIcon size={16} name='drip-icon-cervix' color={styles.iconShades.cervix[3]}/>,
|
|
||||||
desire: <DripIcon size={16} name='drip-icon-desire' color={styles.iconShades.desire[2]}/>,
|
class CycleChart extends Component {
|
||||||
sex: <DripIcon size={16} name='drip-icon-sex' color={styles.iconShades.sex[2]}/>,
|
static propTypes = {
|
||||||
pain: <DripIcon size={16} name='drip-icon-pain' color={styles.iconShades.pain[0]}/>,
|
navigate: PropTypes.func,
|
||||||
mood: <DripIcon size={16} name='drip-icon-mood' color={styles.iconShades.mood[0]}/>,
|
end: PropTypes.bool
|
||||||
note: <DripIcon size={16} name='drip-icon-note' color={styles.iconShades.note[0]}/>
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export default class CycleChart extends Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.state = {}
|
this.state = {}
|
||||||
this.cycleDaysSortedByDate = getCycleDaysSortedByDate()
|
this.cycleDaysSortedByDate = getCycleDaysSortedByDate()
|
||||||
this.getFhmAndLtlInfo = nfpLines()
|
this.getFhmAndLtlInfo = nfpLines()
|
||||||
|
this.shouldShowTemperatureColumn = false
|
||||||
|
|
||||||
|
this.prepareSymptomData()
|
||||||
|
}
|
||||||
|
|
||||||
|
prepareSymptomData = () => {
|
||||||
|
this.symptomRowSymptoms = config.symptoms.filter((symptomName) => {
|
||||||
|
return this.cycleDaysSortedByDate.some(cycleDay => {
|
||||||
|
return cycleDay[symptomName]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
this.chartSymptoms = [...this.symptomRowSymptoms]
|
||||||
|
if (this.cycleDaysSortedByDate.some(day => day.temperature)) {
|
||||||
|
this.chartSymptoms.push('temperature')
|
||||||
|
this.shouldShowTemperatureColumn = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderColumn = ({ item, index }) => {
|
renderColumn = ({ item, index }) => {
|
||||||
@@ -42,55 +60,42 @@ export default class CycleChart extends Component {
|
|||||||
navigate={this.props.navigate}
|
navigate={this.props.navigate}
|
||||||
symptomHeight={this.symptomHeight}
|
symptomHeight={this.symptomHeight}
|
||||||
columnHeight={this.columnHeight}
|
columnHeight={this.columnHeight}
|
||||||
chartHeight={this.state.chartHeight}
|
|
||||||
symptomRowSymptoms={this.symptomRowSymptoms}
|
symptomRowSymptoms={this.symptomRowSymptoms}
|
||||||
chartSymptoms={this.chartSymptoms}
|
chartSymptoms={this.chartSymptoms}
|
||||||
|
shouldShowTemperatureColumn={this.shouldShowTemperatureColumn}
|
||||||
getFhmAndLtlInfo={this.getFhmAndLtlInfo}
|
getFhmAndLtlInfo={this.getFhmAndLtlInfo}
|
||||||
|
xAxisHeight={this.xAxisHeight}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reCalculateChartInfo = (nativeEvent) => {
|
||||||
|
const { height, width } = nativeEvent.layout
|
||||||
|
const xAxisCoefficient = this.shouldShowTemperatureColumn ?
|
||||||
|
config.xAxisHeightPercentage : config.xAxisHeightPercentageLarge
|
||||||
|
const symptomCoefficient = this.shouldShowTemperatureColumn ?
|
||||||
|
config.symptomHeightPercentage : config.symptomHeightPercentageLarge
|
||||||
|
|
||||||
|
this.xAxisHeight = height * xAxisCoefficient
|
||||||
|
const remainingHeight = height - this.xAxisHeight
|
||||||
|
this.symptomHeight = remainingHeight * symptomCoefficient
|
||||||
|
this.symptomRowHeight = this.symptomRowSymptoms.length *
|
||||||
|
this.symptomHeight
|
||||||
|
this.columnHeight = remainingHeight - this.symptomRowHeight
|
||||||
|
const chartHeight = this.shouldShowTemperatureColumn ?
|
||||||
|
height : (this.symptomRowHeight + this.xAxisHeight)
|
||||||
|
|
||||||
|
const numberOfColumnsToRender = Math.round(width / config.columnWidth)
|
||||||
|
const columns = makeColumnInfo()
|
||||||
|
|
||||||
|
this.setState({ columns, chartHeight, numberOfColumnsToRender })
|
||||||
|
}
|
||||||
|
|
||||||
onLayout = ({ nativeEvent }) => {
|
onLayout = ({ nativeEvent }) => {
|
||||||
if (this.state.chartHeight) return
|
if (this.state.chartHeight) return
|
||||||
const height = nativeEvent.layout.height
|
|
||||||
const reCalculateChartInfo = () => {
|
|
||||||
// how many symptoms need to be displayed on the chart's upper symptom row?
|
|
||||||
this.symptomRowSymptoms = [
|
|
||||||
'bleeding',
|
|
||||||
'mucus',
|
|
||||||
'cervix',
|
|
||||||
'sex',
|
|
||||||
'desire',
|
|
||||||
'pain',
|
|
||||||
'mood',
|
|
||||||
'note'
|
|
||||||
].filter((symptomName) => {
|
|
||||||
return this.cycleDaysSortedByDate.some(cycleDay => {
|
|
||||||
return cycleDay[symptomName]
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
this.xAxisHeight = height * config.xAxisHeightPercentage
|
this.reCalculateChartInfo(nativeEvent)
|
||||||
const remainingHeight = height - this.xAxisHeight
|
this.updateListeners(this.reCalculateChartInfo)
|
||||||
this.symptomHeight = config.symptomHeightPercentage * remainingHeight
|
|
||||||
this.symptomRowHeight = this.symptomRowSymptoms.length *
|
|
||||||
this.symptomHeight
|
|
||||||
this.columnHeight = remainingHeight - this.symptomRowHeight
|
|
||||||
|
|
||||||
this.chartSymptoms = [...this.symptomRowSymptoms]
|
|
||||||
if (this.cycleDaysSortedByDate.some(day => day.temperature)) {
|
|
||||||
this.chartSymptoms.push('temperature')
|
|
||||||
}
|
|
||||||
|
|
||||||
const columnData = this.makeColumnInfo()
|
|
||||||
this.setState({
|
|
||||||
columns: columnData,
|
|
||||||
chartHeight: height
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
reCalculateChartInfo()
|
|
||||||
this.updateListeners(reCalculateChartInfo)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateListeners(dataUpdateHandler) {
|
updateListeners(dataUpdateHandler) {
|
||||||
@@ -114,110 +119,85 @@ export default class CycleChart extends Component {
|
|||||||
this.removeObvListener()
|
this.removeObvListener()
|
||||||
}
|
}
|
||||||
|
|
||||||
makeColumnInfo() {
|
|
||||||
let amountOfCycleDays = getAmountOfCycleDays()
|
|
||||||
// if there's not much data yet, we want to show at least 30 days on the chart
|
|
||||||
if (amountOfCycleDays < 30) {
|
|
||||||
amountOfCycleDays = 30
|
|
||||||
} else {
|
|
||||||
// we don't want the chart to end abruptly before the first data day
|
|
||||||
amountOfCycleDays += 5
|
|
||||||
}
|
|
||||||
const localDates = getTodayAndPreviousDays(amountOfCycleDays)
|
|
||||||
return localDates.map(localDate => localDate.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { chartHeight, chartLoaded, numberOfColumnsToRender } = this.state
|
||||||
|
const shouldShowChart = this.chartSymptoms.length > 0 ? true : false
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View
|
<View onLayout={this.onLayout} style={styles.container}>
|
||||||
onLayout={this.onLayout}
|
{!shouldShowChart && <NoData navigate={this.props.navigate}/>}
|
||||||
style={{ flexDirection: 'row', flex: 1 }}
|
{shouldShowChart && !chartHeight && !chartLoaded && <AppLoadingView />}
|
||||||
>
|
<View style={styles.chartContainer}>
|
||||||
{!this.state.chartLoaded &&
|
{shouldShowChart && (
|
||||||
<View style={{width: '100%', justifyContent: 'center', alignItems: 'center'}}>
|
<View style={styles.chartArea}>
|
||||||
<AppText>{labels.loading}</AppText>
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
|
|
||||||
{this.state.chartHeight && this.state.chartLoaded &&
|
{chartHeight && chartLoaded && (
|
||||||
<View>
|
<React.Fragment>
|
||||||
<View style={[styles.yAxis, {height: this.symptomRowHeight}]}>
|
<YAxis
|
||||||
{this.symptomRowSymptoms.map(symptomName => {
|
height={this.columnHeight}
|
||||||
return <View
|
symptomsToDisplay={this.symptomRowSymptoms}
|
||||||
style={{ alignItems: 'center', justifyContent: 'center' }}
|
symptomsSectionHeight={this.symptomRowHeight}
|
||||||
key={symptomName}
|
shouldShowTemperatureColumn=
|
||||||
width={styles.yAxis.width}
|
{this.shouldShowTemperatureColumn}
|
||||||
height={this.symptomRowHeight /
|
xAxisHeight={this.xAxisHeight}
|
||||||
this.symptomRowSymptoms.length}
|
/>
|
||||||
>
|
{this.shouldShowTemperatureColumn && (<HorizontalGrid
|
||||||
{symptomIcons[symptomName]}
|
height={this.columnHeight}
|
||||||
</View>
|
startPosition={this.symptomRowHeight}
|
||||||
})}
|
/>)}
|
||||||
|
</React.Fragment>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{chartHeight &&
|
||||||
|
<FlatList
|
||||||
|
horizontal={true}
|
||||||
|
inverted={true}
|
||||||
|
showsHorizontalScrollIndicator={false}
|
||||||
|
data={this.state.columns}
|
||||||
|
renderItem={this.renderColumn}
|
||||||
|
keyExtractor={item => item}
|
||||||
|
initialNumToRender={numberOfColumnsToRender}
|
||||||
|
windowSize={30}
|
||||||
|
onLayout={() => this.setState({chartLoaded: true})}
|
||||||
|
onEndReached={() => this.setState({end: true})}
|
||||||
|
ListFooterComponent={<LoadingMoreView end={this.state.end}/>}
|
||||||
|
updateCellsBatchingPeriod={800}
|
||||||
|
contentContainerStyle={{height: chartHeight}}
|
||||||
|
/>
|
||||||
|
}
|
||||||
</View>
|
</View>
|
||||||
<View style={[styles.yAxis, {height: this.columnHeight}]}>
|
)}
|
||||||
{makeYAxisLabels(this.columnHeight)}
|
</View>
|
||||||
|
{shouldShowChart && chartLoaded && !this.shouldShowTemperatureColumn
|
||||||
|
&& (
|
||||||
|
<View style={styles.centerItem}>
|
||||||
|
<AppText style={{textAlign: 'center'}}>{shared.noTemperatureWarning}</AppText>
|
||||||
</View>
|
</View>
|
||||||
<View style={[styles.yAxis, { alignItems: 'center', justifyContent: 'center' }]}>
|
)}
|
||||||
<DripHomeIcon
|
|
||||||
name="circle"
|
|
||||||
size={styles.yAxis.width - 7}
|
|
||||||
color={cycleDayColor}
|
|
||||||
/>
|
|
||||||
<AppText style={[styles.yAxisLabels.dateLabel]}>
|
|
||||||
{labels.date.toLowerCase()}
|
|
||||||
</AppText>
|
|
||||||
</View>
|
|
||||||
</View>}
|
|
||||||
|
|
||||||
|
|
||||||
{this.state.chartHeight && this.state.chartLoaded &&
|
|
||||||
makeHorizontalGrid(this.columnHeight, this.symptomRowHeight)
|
|
||||||
}
|
|
||||||
|
|
||||||
{this.state.chartHeight &&
|
|
||||||
<FlatList
|
|
||||||
horizontal={true}
|
|
||||||
inverted={true}
|
|
||||||
showsHorizontalScrollIndicator={false}
|
|
||||||
data={this.state.columns}
|
|
||||||
renderItem={this.renderColumn}
|
|
||||||
keyExtractor={item => item}
|
|
||||||
initialNumToRender={15}
|
|
||||||
windowSize={30}
|
|
||||||
onLayout={() => this.setState({chartLoaded: true})}
|
|
||||||
onEndReached={() => this.setState({end: true})}
|
|
||||||
ListFooterComponent={<LoadingMoreView end={this.state.end}/>}
|
|
||||||
updateCellsBatchingPeriod={800}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function LoadingMoreView(props) {
|
function LoadingMoreView({ end }) {
|
||||||
return (
|
return (
|
||||||
<View style={styles.loadingMore}>
|
<View style={styles.loadingMore}>
|
||||||
{!props.end &&
|
{!end && <ActivityIndicator size={'large'} color={'white'}/>}
|
||||||
<ActivityIndicator size={'large'} color={'white'}/>
|
|
||||||
}
|
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTodayAndPreviousDays(n) {
|
LoadingMoreView.propTypes = {
|
||||||
const today = LocalDate.now()
|
end: PropTypes.bool
|
||||||
const targetDate = today.minusDays(n)
|
|
||||||
|
|
||||||
function getDaysInRange(currDate, range) {
|
|
||||||
if (currDate.isBefore(targetDate)) {
|
|
||||||
return range
|
|
||||||
} else {
|
|
||||||
range.push(currDate)
|
|
||||||
const next = currDate.minusDays(1)
|
|
||||||
return getDaysInRange(next, range)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return getDaysInRange(today, [])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => {
|
||||||
|
return({
|
||||||
|
navigate: (page) => dispatch(navigate(page)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(
|
||||||
|
null,
|
||||||
|
mapDispatchToProps,
|
||||||
|
)(CycleChart)
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
import { Text, View } from 'react-native'
|
||||||
|
|
||||||
|
import moment from 'moment'
|
||||||
|
import { LocalDate } from 'js-joda'
|
||||||
|
|
||||||
|
import styles from './styles'
|
||||||
|
import cycleModule from '../../lib/cycle'
|
||||||
|
|
||||||
|
const CycleDayLabel = ({ height, date }) => {
|
||||||
|
const { label } = styles.column
|
||||||
|
const dayDate = LocalDate.parse(date)
|
||||||
|
const cycleDayNumber = cycleModule().getCycleDayNumber(date)
|
||||||
|
|
||||||
|
const isFirstDayOfMonth = dayDate.dayOfMonth() === 1
|
||||||
|
const dateFormatting = isFirstDayOfMonth ? 'MMM' : 'Do'
|
||||||
|
const shortDate = moment(date, "YYYY-MM-DD").format(dateFormatting)
|
||||||
|
const boldDateLabel = isFirstDayOfMonth ? {fontWeight: 'bold'} : {}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={[styles.chartLegend, { height }]}>
|
||||||
|
<Text style={label.number}>
|
||||||
|
{cycleDayNumber ? cycleDayNumber : ' '}
|
||||||
|
</Text>
|
||||||
|
<Text style={[label.date, boldDateLabel]}>
|
||||||
|
{shortDate}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
CycleDayLabel.propTypes = {
|
||||||
|
height: PropTypes.number,
|
||||||
|
date: PropTypes.string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CycleDayLabel
|
||||||
+100
-268
@@ -1,305 +1,137 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import {
|
import PropTypes from 'prop-types'
|
||||||
Text, View, TouchableOpacity
|
import { TouchableOpacity } from 'react-native'
|
||||||
} from 'react-native'
|
import { connect } from 'react-redux'
|
||||||
import { Surface, Group as G, Path, Shape } from 'react-native/Libraries/ART/ReactNativeART'
|
|
||||||
import { LocalDate } from 'js-joda'
|
import { setDate } from '../../slices/date'
|
||||||
import moment from 'moment'
|
import { navigate } from '../../slices/navigation'
|
||||||
import styles from './styles'
|
|
||||||
import config from '../../config'
|
|
||||||
import cycleModule from '../../lib/cycle'
|
|
||||||
import { getCycleDay } from '../../db'
|
import { getCycleDay } from '../../db'
|
||||||
import DotAndLine from './dot-and-line'
|
|
||||||
import { normalizeToScale } from './y-axis'
|
|
||||||
|
|
||||||
const label = styles.column.label
|
import SymptomCell from './symptom-cell'
|
||||||
|
import TemperatureColumn from './temperature-column'
|
||||||
|
import CycleDayLabel from './cycle-day-label'
|
||||||
|
|
||||||
|
import {
|
||||||
|
symptomColorMethods,
|
||||||
|
getTemperatureProps,
|
||||||
|
isSymptomDataComplete
|
||||||
|
} from '../helpers/chart'
|
||||||
|
|
||||||
|
class DayColumn extends Component {
|
||||||
|
static propTypes = {
|
||||||
|
dateString: PropTypes.string.isRequired,
|
||||||
|
chartSymptoms: PropTypes.array,
|
||||||
|
columnHeight: PropTypes.number.isRequired,
|
||||||
|
getFhmAndLtlInfo: PropTypes.func.isRequired,
|
||||||
|
navigate: PropTypes.func.isRequired,
|
||||||
|
setDate: PropTypes.func.isRequired,
|
||||||
|
shouldShowTemperatureColumn: PropTypes.bool,
|
||||||
|
symptomHeight: PropTypes.number.isRequired,
|
||||||
|
symptomRowSymptoms: PropTypes.array,
|
||||||
|
xAxisHeight: PropTypes.number,
|
||||||
|
}
|
||||||
|
|
||||||
export default class DayColumn extends Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super()
|
super()
|
||||||
const dateString = props.dateString
|
|
||||||
const columnHeight = props.columnHeight
|
const { dateString, chartSymptoms, columnHeight } = props
|
||||||
this.getCycleDayNumber = cycleModule().getCycleDayNumber
|
const cycleDayData = getCycleDay(dateString)
|
||||||
const cycleDay = getCycleDay(dateString)
|
|
||||||
this.data = {}
|
this.data = {}
|
||||||
if (cycleDay) {
|
|
||||||
this.data = props.chartSymptoms.reduce((acc, symptom) => {
|
if (cycleDayData) {
|
||||||
if (['bleeding', 'temperature', 'mucus', 'desire', 'note'].includes(symptom)) {
|
this.data = chartSymptoms.reduce((symptomDataToDisplay, symptom, ) => {
|
||||||
acc[symptom] = cycleDay[symptom] && cycleDay[symptom].value
|
const symptomData = cycleDayData[symptom]
|
||||||
if (symptom === 'temperature' && acc.temperature) {
|
|
||||||
acc.y = normalizeToScale(acc.temperature, columnHeight)
|
if (symptomData && symptom === 'temperature') {
|
||||||
const neighbor = getInfoForNeighborColumns(dateString, columnHeight)
|
symptomDataToDisplay[symptom] =
|
||||||
for (const key in neighbor) {
|
getTemperatureProps(symptomData, columnHeight, dateString)
|
||||||
acc[key] = neighbor[key]
|
} else {
|
||||||
}
|
if (symptomData && ! symptomData.exclude) {
|
||||||
|
// if symptomColorMethods entry doesn't exist for given symptom,
|
||||||
|
// use 'default'
|
||||||
|
const getSymptomColorIndex =
|
||||||
|
symptomColorMethods[symptom] || symptomColorMethods['default']
|
||||||
|
|
||||||
|
symptomDataToDisplay[symptom] = getSymptomColorIndex(symptomData)
|
||||||
}
|
}
|
||||||
} else if (symptom === 'cervix') {
|
|
||||||
acc.cervix = cycleDay.cervix &&
|
|
||||||
(cycleDay.cervix.opening + cycleDay.cervix.firmness)
|
|
||||||
} else if (symptom === 'sex') {
|
|
||||||
// solo = 1 + partner = 2
|
|
||||||
acc.sex = cycleDay.sex &&
|
|
||||||
(cycleDay.sex.solo + 2 * cycleDay.sex.partner)
|
|
||||||
} else if (symptom === 'pain') {
|
|
||||||
// is any pain documented?
|
|
||||||
acc.pain = cycleDay.pain &&
|
|
||||||
Object.values({...cycleDay.pain}).some(x => x === true)
|
|
||||||
} else if (symptom === 'mood') {
|
|
||||||
// is mood documented?
|
|
||||||
acc.mood = cycleDay.mood &&
|
|
||||||
Object.values({...cycleDay.mood}).some(x => x === true)
|
|
||||||
}
|
}
|
||||||
acc[`${symptom}Exclude`] = cycleDay[symptom] && cycleDay[symptom].exclude
|
|
||||||
return acc
|
return symptomDataToDisplay
|
||||||
}, this.data)
|
}, this.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fhmAndLtl = props.getFhmAndLtlInfo(
|
this.fhmAndLtl = props.getFhmAndLtlInfo(
|
||||||
props.dateString,
|
props.dateString,
|
||||||
this.data.temperature,
|
this.data.temperature ? this.data.temperature.value : null,
|
||||||
props.columnHeight
|
props.columnHeight
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDaySelect = (date) => {
|
||||||
|
this.props.setDate(date)
|
||||||
|
this.props.navigate('CycleDay')
|
||||||
|
}
|
||||||
|
|
||||||
shouldComponentUpdate() {
|
shouldComponentUpdate() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const columnElements = []
|
const { columnHeight,
|
||||||
const dateString = this.props.dateString
|
dateString,
|
||||||
const symptomHeight = this.props.symptomHeight
|
shouldShowTemperatureColumn,
|
||||||
|
symptomHeight,
|
||||||
if(this.fhmAndLtl.drawLtlAt) {
|
symptomRowSymptoms,
|
||||||
const ltlLine = (<Shape
|
xAxisHeight
|
||||||
stroke={styles.nfpLine.stroke}
|
} = this.props
|
||||||
strokeWidth={styles.nfpLine.strokeWidth}
|
|
||||||
d={new Path()
|
|
||||||
.moveTo(0, this.fhmAndLtl.drawLtlAt)
|
|
||||||
.lineTo(config.columnWidth, this.fhmAndLtl.drawLtlAt)
|
|
||||||
}
|
|
||||||
key='ltl'
|
|
||||||
/>)
|
|
||||||
columnElements.push(ltlLine)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.fhmAndLtl.drawFhmLine) {
|
|
||||||
const x = styles.nfpLine.strokeWidth / 2
|
|
||||||
const fhmLine = (<Shape
|
|
||||||
fill="red"
|
|
||||||
stroke={styles.nfpLine.stroke}
|
|
||||||
strokeWidth={styles.nfpLine.strokeWidth}
|
|
||||||
d={new Path()
|
|
||||||
.moveTo(x, x)
|
|
||||||
.lineTo(x, this.props.columnHeight)
|
|
||||||
}
|
|
||||||
key='fhm'
|
|
||||||
/>)
|
|
||||||
columnElements.push(fhmLine)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (this.data.y) {
|
|
||||||
columnElements.push(
|
|
||||||
<DotAndLine
|
|
||||||
y={this.data.y}
|
|
||||||
exclude={this.data.temperatureExclude}
|
|
||||||
rightY={this.data.rightY}
|
|
||||||
rightTemperatureExclude={this.data.rightTemperatureExclude}
|
|
||||||
leftY={this.data.leftY}
|
|
||||||
leftTemperatureExclude={this.data.leftTemperatureExclude}
|
|
||||||
key='dotandline'
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const cycleDayNumber = this.getCycleDayNumber(dateString)
|
|
||||||
const dayDate = LocalDate.parse(dateString)
|
|
||||||
const shortDate = dayDate.dayOfMonth() === 1 ?
|
|
||||||
moment(dateString, "YYYY-MM-DD").format('MMM')
|
|
||||||
:
|
|
||||||
moment(dateString, "YYYY-MM-DD").format('Do')
|
|
||||||
const boldDateLabel = dayDate.dayOfMonth() === 1 ? {fontWeight: 'bold'} : {}
|
|
||||||
const cycleDayLabel = (
|
|
||||||
<Text style = {label.number}>
|
|
||||||
{cycleDayNumber ? cycleDayNumber : ' '}
|
|
||||||
</Text>)
|
|
||||||
const dateLabel = (
|
|
||||||
<Text style = {[label.date, boldDateLabel]}>
|
|
||||||
{shortDate}
|
|
||||||
</Text>
|
|
||||||
)
|
|
||||||
|
|
||||||
const column = (
|
|
||||||
<G>
|
|
||||||
<Shape
|
|
||||||
stroke={styles.column.stroke.color}
|
|
||||||
strokeWidth={styles.column.stroke.width}
|
|
||||||
d={new Path().lineTo(0, this.props.chartHeight)}
|
|
||||||
/>
|
|
||||||
{ columnElements }
|
|
||||||
</G>
|
|
||||||
)
|
|
||||||
|
|
||||||
const symptomIconViews = {
|
|
||||||
bleeding: (
|
|
||||||
<SymptomIconView
|
|
||||||
value={this.data.bleeding}
|
|
||||||
symptomHeight={symptomHeight}
|
|
||||||
key='bleeding'
|
|
||||||
>
|
|
||||||
<View
|
|
||||||
{...styles.symptomIcon}
|
|
||||||
backgroundColor={styles.iconShades.bleeding[this.data.bleeding]}
|
|
||||||
/>
|
|
||||||
</SymptomIconView>
|
|
||||||
),
|
|
||||||
mucus: (
|
|
||||||
<SymptomIconView
|
|
||||||
value={this.data.mucus}
|
|
||||||
symptomHeight={symptomHeight}
|
|
||||||
key='mucus'
|
|
||||||
>
|
|
||||||
<View
|
|
||||||
{...styles.symptomIcon}
|
|
||||||
backgroundColor={styles.iconShades.mucus[this.data.mucus]}
|
|
||||||
/>
|
|
||||||
</SymptomIconView>
|
|
||||||
),
|
|
||||||
cervix: (
|
|
||||||
<SymptomIconView
|
|
||||||
value={this.data.cervix}
|
|
||||||
symptomHeight={symptomHeight}
|
|
||||||
key='cervix'
|
|
||||||
>
|
|
||||||
<View
|
|
||||||
{...styles.symptomIcon}
|
|
||||||
// cervix is sum of openess and firmness - fertile only when closed and hard (=0)
|
|
||||||
backgroundColor={this.data.cervix > 0 ?
|
|
||||||
styles.iconShades.cervix[2] :
|
|
||||||
styles.iconShades.cervix[0]
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</SymptomIconView>
|
|
||||||
),
|
|
||||||
sex: (
|
|
||||||
<SymptomIconView
|
|
||||||
value={this.data.sex}
|
|
||||||
symptomHeight={symptomHeight}
|
|
||||||
key='sex'
|
|
||||||
>
|
|
||||||
<View
|
|
||||||
{...styles.symptomIcon}
|
|
||||||
backgroundColor={styles.iconShades.sex[this.data.sex - 1]}
|
|
||||||
/>
|
|
||||||
</SymptomIconView>
|
|
||||||
),
|
|
||||||
desire: (
|
|
||||||
<SymptomIconView
|
|
||||||
value={this.data.desire}
|
|
||||||
symptomHeight={symptomHeight}
|
|
||||||
key='desire'
|
|
||||||
>
|
|
||||||
<View
|
|
||||||
{...styles.symptomIcon}
|
|
||||||
backgroundColor={styles.iconShades.desire[this.data.desire]}
|
|
||||||
/>
|
|
||||||
</SymptomIconView>
|
|
||||||
),
|
|
||||||
pain: (
|
|
||||||
<SymptomIconView
|
|
||||||
value={this.data.pain}
|
|
||||||
symptomHeight={symptomHeight}
|
|
||||||
key='pain'
|
|
||||||
>
|
|
||||||
<View
|
|
||||||
{...styles.symptomIcon}
|
|
||||||
backgroundColor={styles.iconShades.pain}
|
|
||||||
/>
|
|
||||||
</SymptomIconView>
|
|
||||||
),
|
|
||||||
mood: (
|
|
||||||
<SymptomIconView
|
|
||||||
value={this.data.mood}
|
|
||||||
symptomHeight={symptomHeight}
|
|
||||||
key='mood'
|
|
||||||
>
|
|
||||||
<View
|
|
||||||
{...styles.symptomIcon}
|
|
||||||
backgroundColor={styles.iconShades.mood}
|
|
||||||
/>
|
|
||||||
</SymptomIconView>
|
|
||||||
),
|
|
||||||
note: (
|
|
||||||
<SymptomIconView
|
|
||||||
value={this.data.note}
|
|
||||||
symptomHeight={symptomHeight}
|
|
||||||
key='note'
|
|
||||||
>
|
|
||||||
<View
|
|
||||||
{...styles.symptomIcon}
|
|
||||||
backgroundColor={styles.iconShades.note}
|
|
||||||
/>
|
|
||||||
</SymptomIconView>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={() => this.props.navigate('CycleDay', { date: dateString })}
|
onPress={() => this.onDaySelect(dateString)}
|
||||||
activeOpacity={1}
|
activeOpacity={1}
|
||||||
>
|
>
|
||||||
<View>
|
|
||||||
{this.props.symptomRowSymptoms.map(symptomName => {
|
|
||||||
return symptomIconViews[symptomName]
|
|
||||||
})}
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<Surface width={config.columnWidth} height={this.props.columnHeight}>
|
{ symptomRowSymptoms.map(symptom => {
|
||||||
{column}
|
const hasSymptomData = this.data.hasOwnProperty(symptom)
|
||||||
</Surface>
|
return (
|
||||||
|
<SymptomCell
|
||||||
|
key={symptom}
|
||||||
|
symptom={symptom}
|
||||||
|
symptomValue={hasSymptomData && this.data[symptom]}
|
||||||
|
isSymptomDataComplete={
|
||||||
|
hasSymptomData && isSymptomDataComplete(symptom, dateString)
|
||||||
|
}
|
||||||
|
height={symptomHeight}
|
||||||
|
/>)
|
||||||
|
}
|
||||||
|
)}
|
||||||
|
|
||||||
|
{shouldShowTemperatureColumn && <TemperatureColumn
|
||||||
|
horizontalLinePosition={this.fhmAndLtl.drawLtlAt}
|
||||||
|
isVerticalLine={this.fhmAndLtl.drawFhmLine}
|
||||||
|
data={this.data && this.data.temperature}
|
||||||
|
columnHeight={columnHeight}
|
||||||
|
/>}
|
||||||
|
|
||||||
|
<CycleDayLabel
|
||||||
|
height={xAxisHeight}
|
||||||
|
date={dateString}
|
||||||
|
/>
|
||||||
|
|
||||||
<View style={{height: this.props.xAxisHeight}}>
|
|
||||||
{cycleDayLabel}
|
|
||||||
{dateLabel}
|
|
||||||
</View>
|
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => {
|
||||||
function SymptomIconView(props) {
|
return({
|
||||||
const style = [styles.symptomRow, {height: props.symptomHeight}]
|
setDate: (date) => dispatch(setDate(date)),
|
||||||
return (
|
navigate: (page) => dispatch(navigate(page)),
|
||||||
<View style={style}>
|
})
|
||||||
{(typeof props.value === 'number' || props.value === true || typeof props.value === 'string') &&
|
|
||||||
props.children
|
|
||||||
}
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInfoForNeighborColumns(dateString, columnHeight) {
|
export default connect(
|
||||||
const ret = {
|
null,
|
||||||
rightY: null,
|
mapDispatchToProps,
|
||||||
rightTemperatureExclude: null,
|
)(DayColumn)
|
||||||
leftY: null,
|
|
||||||
leftTemperatureExclude: null
|
|
||||||
}
|
|
||||||
const target = LocalDate.parse(dateString)
|
|
||||||
const dayBefore = target.minusDays(1).toString()
|
|
||||||
const dayAfter = target.plusDays(1).toString()
|
|
||||||
const cycleDayBefore = getCycleDay(dayBefore)
|
|
||||||
const cycleDayAfter = getCycleDay(dayAfter)
|
|
||||||
if (cycleDayAfter && cycleDayAfter.temperature) {
|
|
||||||
ret.rightY = normalizeToScale(cycleDayAfter.temperature.value, columnHeight)
|
|
||||||
ret.rightTemperatureExclude = cycleDayAfter.temperature.exclude
|
|
||||||
}
|
|
||||||
if (cycleDayBefore && cycleDayBefore.temperature) {
|
|
||||||
ret.leftY = normalizeToScale(cycleDayBefore.temperature.value, columnHeight)
|
|
||||||
ret.leftTemperatureExclude = cycleDayBefore.temperature.exclude
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
import { Path, Shape } from 'react-native/Libraries/ART/ReactNativeART'
|
import { Path, Shape } from 'react-native/Libraries/ART/ReactNativeART'
|
||||||
|
|
||||||
import styles from './styles'
|
import styles from './styles'
|
||||||
import config from '../../config'
|
import config from '../../config'
|
||||||
|
|
||||||
export default class DotAndLine extends Component {
|
export default class DotAndLine extends Component {
|
||||||
|
static propTypes = {
|
||||||
|
exclude: PropTypes.bool,
|
||||||
|
leftY: PropTypes.number,
|
||||||
|
leftTemperatureExclude: PropTypes.bool,
|
||||||
|
rightY: PropTypes.number,
|
||||||
|
rightTemperatureExclude: PropTypes.bool,
|
||||||
|
y: PropTypes.number.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(newProps) {
|
shouldComponentUpdate(newProps) {
|
||||||
return Object.keys(newProps).some(key => newProps[key] != this.props[key])
|
return Object.keys(newProps).some(key => newProps[key] != this.props[key])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { View } from 'react-native'
|
||||||
|
|
||||||
|
import { getTickPositions } from '../helpers/chart'
|
||||||
|
|
||||||
|
import styles from './styles'
|
||||||
|
|
||||||
|
const HorizontalGrid = ({ height, startPosition }) => {
|
||||||
|
return getTickPositions(height).map(tick => {
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
top={startPosition + tick}
|
||||||
|
{...styles.horizontalGrid}
|
||||||
|
key={tick}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
HorizontalGrid.propTypes = {
|
||||||
|
height: PropTypes.number,
|
||||||
|
startPosition: PropTypes.number,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default HorizontalGrid
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { getCycleStatusForDay } from '../../lib/sympto-adapter'
|
import { getCycleStatusForDay } from '../../lib/sympto-adapter'
|
||||||
import { normalizeToScale } from './y-axis'
|
import { normalizeToScale } from '../helpers/chart'
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
const cycle = {
|
const cycle = {
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { View } from 'react-native'
|
||||||
|
|
||||||
|
import AppText from '../app-text'
|
||||||
|
import SettingsButton from '../settings/shared/settings-button'
|
||||||
|
|
||||||
|
import { shared } from '../../i18n/en/labels'
|
||||||
|
import styles from './styles'
|
||||||
|
|
||||||
|
const NoData = ({ navigate }) => {
|
||||||
|
return (
|
||||||
|
<View flex={1}>
|
||||||
|
<View style={styles.centerItem}>
|
||||||
|
<AppText>{shared.noDataWarning}</AppText>
|
||||||
|
<SettingsButton
|
||||||
|
onPress={() => {navigate('CycleDay')}}
|
||||||
|
style={{marginHorizontal: 40}}
|
||||||
|
>
|
||||||
|
{shared.noDataButtonText}
|
||||||
|
</SettingsButton>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
NoData.propTypes = {
|
||||||
|
navigate: PropTypes.func,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default NoData
|
||||||
+74
-34
@@ -7,10 +7,33 @@ export const dotRadius = 5
|
|||||||
const lineWidth = 1.5
|
const lineWidth = 1.5
|
||||||
const colorLtl = '#feb47b'
|
const colorLtl = '#feb47b'
|
||||||
const gridColor = '#d3d3d3'
|
const gridColor = '#d3d3d3'
|
||||||
const gridLineWidth = 0.5
|
const gridLineWidthVertical = 0.6
|
||||||
|
const gridLineWidthHorizontal = 0.3
|
||||||
const numberLabelFontSize = 13
|
const numberLabelFontSize = 13
|
||||||
|
|
||||||
|
const redColor = '#c3000d'
|
||||||
|
const violetColor = '#6a7b98'
|
||||||
|
const shadesOfViolet = ['#e3e7ed', '#c8cfdc', '#acb8cb', '#91a0ba', '#7689a9', violetColor] // light to dark
|
||||||
|
const yellowColor = '#dbb40c'
|
||||||
|
const shadesOfYellow = ['#f0e19d', '#e9d26d', '#e2c33c', yellowColor] // light to dark
|
||||||
|
const magentaColor = '#6f2565'
|
||||||
|
const shadesOfMagenta = ['#a87ca2', '#8b5083', magentaColor] // light to dark
|
||||||
|
const pinkColor = '#9e346c'
|
||||||
|
const shadesOfPink = ['#c485a6', '#b15c89', pinkColor] // light to dark
|
||||||
|
const lightGreenColor = '#bccd67'
|
||||||
|
const orangeColor = '#bc6642'
|
||||||
|
const mintColor = '#6ca299'
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
|
container: { flex: 1 },
|
||||||
|
chartContainer: { flexDirection: 'column' },
|
||||||
|
chartArea: { flexDirection: 'row' },
|
||||||
|
centerItem: {
|
||||||
|
flex:1,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
marginHorizontal: 25,
|
||||||
|
},
|
||||||
curve: {
|
curve: {
|
||||||
stroke: colorTemperature,
|
stroke: colorTemperature,
|
||||||
strokeWidth: lineWidth,
|
strokeWidth: lineWidth,
|
||||||
@@ -44,42 +67,47 @@ const styles = {
|
|||||||
},
|
},
|
||||||
stroke: {
|
stroke: {
|
||||||
color: gridColor,
|
color: gridColor,
|
||||||
width: gridLineWidth,
|
width: gridLineWidthVertical,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
symptomIcon: {
|
symptomDot: {
|
||||||
width: 12,
|
width: 12,
|
||||||
height: 12,
|
height: 12,
|
||||||
borderRadius: 50,
|
borderRadius: 50,
|
||||||
},
|
},
|
||||||
iconShades: {
|
iconColors: {
|
||||||
'bleeding': shadesOfRed,
|
'bleeding': {
|
||||||
'mucus': [
|
color: redColor,
|
||||||
'#e3e7ed',
|
shades: shadesOfRed,
|
||||||
'#c8cfdc',
|
},
|
||||||
'#acb8cb',
|
'mucus': {
|
||||||
'#91a0ba',
|
color: violetColor,
|
||||||
'#7689a9'
|
shades: shadesOfViolet,
|
||||||
],
|
},
|
||||||
'cervix': [
|
'cervix': {
|
||||||
'#f0e19d',
|
color: yellowColor,
|
||||||
'#e9d26d',
|
shades: shadesOfYellow,
|
||||||
'#e2c33c',
|
},
|
||||||
'#dbb40c',
|
'sex': {
|
||||||
],
|
color: magentaColor,
|
||||||
'sex': [
|
shades: shadesOfMagenta,
|
||||||
'#a87ca2',
|
},
|
||||||
'#8b5083',
|
'desire': {
|
||||||
'#6f2565',
|
color: pinkColor,
|
||||||
],
|
shades: shadesOfPink,
|
||||||
'desire': [
|
},
|
||||||
'#c485a6',
|
'pain': {
|
||||||
'#b15c89',
|
color: lightGreenColor,
|
||||||
'#9e346c',
|
shades: [lightGreenColor],
|
||||||
],
|
},
|
||||||
'pain': ['#bccd67'],
|
'mood': {
|
||||||
'mood': ['#bc6642'],
|
color: orangeColor,
|
||||||
'note': ['#6ca299']
|
shades: [orangeColor],
|
||||||
|
},
|
||||||
|
'note': {
|
||||||
|
color: mintColor,
|
||||||
|
shades: [mintColor],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
yAxis: {
|
yAxis: {
|
||||||
width: 27,
|
width: 27,
|
||||||
@@ -108,12 +136,24 @@ const styles = {
|
|||||||
fontWeight: '100',
|
fontWeight: '100',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
symptomIcon: {
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
chartLegend: {
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'flex-end',
|
||||||
|
},
|
||||||
|
boldTick: {
|
||||||
|
fontWeight: 'bold',
|
||||||
|
fontSize: 11,
|
||||||
|
},
|
||||||
horizontalGrid: {
|
horizontalGrid: {
|
||||||
position:'absolute',
|
position:'absolute',
|
||||||
borderColor: gridColor,
|
|
||||||
borderWidth: gridLineWidth,
|
|
||||||
width: '100%',
|
|
||||||
borderStyle: 'solid',
|
borderStyle: 'solid',
|
||||||
|
borderBottomColor: gridColor,
|
||||||
|
borderBottomWidth: gridLineWidthHorizontal,
|
||||||
|
width: '100%',
|
||||||
left: config.columnWidth
|
left: config.columnWidth
|
||||||
},
|
},
|
||||||
nfpLine: {
|
nfpLine: {
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { View } from 'react-native'
|
||||||
|
|
||||||
|
import styles from './styles'
|
||||||
|
import config from '../../config'
|
||||||
|
|
||||||
|
const SymptomCell = ({
|
||||||
|
height,
|
||||||
|
symptom,
|
||||||
|
symptomValue,
|
||||||
|
isSymptomDataComplete
|
||||||
|
}) => {
|
||||||
|
|
||||||
|
const shouldDrawDot = symptomValue !== false
|
||||||
|
const styleParent = [styles.symptomRow, { height, width: config.columnWidth }]
|
||||||
|
let styleChild
|
||||||
|
|
||||||
|
if (shouldDrawDot) {
|
||||||
|
const styleSymptom = styles.iconColors[symptom]
|
||||||
|
const symptomColor = styleSymptom.shades[symptomValue]
|
||||||
|
|
||||||
|
const isMucusOrCervix = (symptom === 'mucus') || (symptom === 'cervix')
|
||||||
|
|
||||||
|
const backgroundColor = (isMucusOrCervix && !isSymptomDataComplete) ?
|
||||||
|
'white' : symptomColor
|
||||||
|
const borderWidth = (isMucusOrCervix && !isSymptomDataComplete) ? 2 : 0
|
||||||
|
const borderColor = symptomColor
|
||||||
|
styleChild = [styles.symptomDot, {
|
||||||
|
backgroundColor,
|
||||||
|
borderColor,
|
||||||
|
borderWidth
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styleParent} key={symptom}>
|
||||||
|
{shouldDrawDot && <View style={styleChild} />}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
SymptomCell.propTypes = {
|
||||||
|
height: PropTypes.number,
|
||||||
|
symptom: PropTypes.string,
|
||||||
|
symptomValue: PropTypes.oneOfType([
|
||||||
|
PropTypes.bool,
|
||||||
|
PropTypes.number,
|
||||||
|
]),
|
||||||
|
isSymptomDataComplete: PropTypes.bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SymptomCell
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { View } from 'react-native'
|
||||||
|
|
||||||
|
import DripIcon from '../../assets/drip-icons'
|
||||||
|
|
||||||
|
import styles from './styles'
|
||||||
|
|
||||||
|
const SymptomIcon = ({ symptom, height }) => {
|
||||||
|
return (
|
||||||
|
<View style={styles.symptomIcon} width={styles.yAxis.width} height={height}>
|
||||||
|
<DripIcon
|
||||||
|
size={16}
|
||||||
|
name={`drip-icon-${symptom}`}
|
||||||
|
color={styles.iconColors[symptom].color}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
SymptomIcon.propTypes = {
|
||||||
|
height: PropTypes.number,
|
||||||
|
symptom: PropTypes.string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default SymptomIcon
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
import { Surface , Path } from 'react-native/Libraries/ART/ReactNativeART'
|
||||||
|
|
||||||
|
import ChartLine from './chart-line'
|
||||||
|
import DotAndLine from './dot-and-line'
|
||||||
|
|
||||||
|
import styles from './styles'
|
||||||
|
import config from '../../config'
|
||||||
|
|
||||||
|
const TemperatureColumn = ({
|
||||||
|
horizontalLinePosition,
|
||||||
|
isVerticalLine,
|
||||||
|
data,
|
||||||
|
columnHeight
|
||||||
|
}) => {
|
||||||
|
|
||||||
|
const x = styles.nfpLine.strokeWidth / 2
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Surface width={config.columnWidth} height={columnHeight}>
|
||||||
|
|
||||||
|
<ChartLine
|
||||||
|
path={new Path().lineTo(0, columnHeight)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{horizontalLinePosition && <ChartLine
|
||||||
|
path={new Path()
|
||||||
|
.moveTo(0, horizontalLinePosition)
|
||||||
|
.lineTo(config.columnWidth, horizontalLinePosition)
|
||||||
|
}
|
||||||
|
isNfpLine={true}
|
||||||
|
key='ltl'
|
||||||
|
/>}
|
||||||
|
|
||||||
|
{isVerticalLine && <ChartLine
|
||||||
|
path={new Path().moveTo(x, x).lineTo(x, columnHeight)}
|
||||||
|
isNfpLine={true}
|
||||||
|
key='fhm'
|
||||||
|
/>}
|
||||||
|
|
||||||
|
{data && data.y && <DotAndLine
|
||||||
|
y={data.y}
|
||||||
|
exclude={data.temperatureExclude}
|
||||||
|
rightY={data.rightY}
|
||||||
|
rightTemperatureExclude={data.rightTemperatureExclude}
|
||||||
|
leftY={data.leftY}
|
||||||
|
leftTemperatureExclude={data.leftTemperatureExclude}
|
||||||
|
key='dotandline'
|
||||||
|
/>}
|
||||||
|
|
||||||
|
</Surface>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
TemperatureColumn.propTypes = {
|
||||||
|
horizontalLinePosition: PropTypes.number,
|
||||||
|
isVerticalLine: PropTypes.bool,
|
||||||
|
data: PropTypes.object,
|
||||||
|
columnHeight: PropTypes.number,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TemperatureColumn
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { View } from 'react-native'
|
||||||
|
|
||||||
|
import Tick from './tick'
|
||||||
|
|
||||||
|
import { getTickList } from '../helpers/chart'
|
||||||
|
|
||||||
|
import styles from './styles'
|
||||||
|
|
||||||
|
const TickList = ({ height }) => {
|
||||||
|
return (
|
||||||
|
<View style={[styles.yAxis, { height }]}>{
|
||||||
|
getTickList(height)
|
||||||
|
.map(({ label, position, isBold, shouldShowLabel}) => {
|
||||||
|
return (
|
||||||
|
<Tick
|
||||||
|
key={label}
|
||||||
|
yPosition={position}
|
||||||
|
isBold={isBold}
|
||||||
|
shouldShowLabel={shouldShowLabel}
|
||||||
|
label={label}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
TickList.propTypes = {
|
||||||
|
height: PropTypes.number,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TickList
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
import AppText from '../app-text'
|
||||||
|
|
||||||
|
import styles from './styles'
|
||||||
|
|
||||||
|
const Tick = ({ yPosition, isBold, shouldShowLabel, label }) => {
|
||||||
|
// this eyeballing is sadly necessary because RN does not
|
||||||
|
// support percentage values for transforms, which we'd need
|
||||||
|
// to reliably place the label vertically centered to the grid
|
||||||
|
const topPosition = yPosition - 8
|
||||||
|
const style = [
|
||||||
|
styles.yAxisLabels.tempScale,
|
||||||
|
{top: topPosition},
|
||||||
|
isBold && styles.boldTick
|
||||||
|
]
|
||||||
|
|
||||||
|
return <AppText style={style}>{shouldShowLabel && label}</AppText>
|
||||||
|
}
|
||||||
|
|
||||||
|
Tick.propTypes = {
|
||||||
|
yPosition: PropTypes.number,
|
||||||
|
isBold: PropTypes.bool,
|
||||||
|
shouldShowLabel: PropTypes.bool,
|
||||||
|
label: PropTypes.string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Tick
|
||||||
+37
-66
@@ -1,75 +1,46 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
import { View } from 'react-native'
|
import { View } from 'react-native'
|
||||||
import config from '../../config'
|
|
||||||
|
import SymptomIcon from './symptom-icon'
|
||||||
|
import TickList from './tick-list'
|
||||||
|
import ChartLegend from './chart-legend'
|
||||||
|
|
||||||
import styles from './styles'
|
import styles from './styles'
|
||||||
import { scaleObservable, unitObservable } from '../../local-storage'
|
|
||||||
import AppText from '../app-text'
|
|
||||||
|
|
||||||
export function makeYAxisLabels(columnHeight) {
|
const YAxis = ({
|
||||||
const units = unitObservable.value
|
height,
|
||||||
const scaleMax = scaleObservable.value.max
|
symptomsToDisplay,
|
||||||
const style = styles.yAxisLabels.tempScale
|
symptomsSectionHeight,
|
||||||
|
shouldShowTemperatureColumn,
|
||||||
|
xAxisHeight
|
||||||
|
}) => {
|
||||||
|
const symptomIconHeight = symptomsSectionHeight / symptomsToDisplay.length
|
||||||
|
|
||||||
return getTickPositions(columnHeight).map((y, i) => {
|
return (
|
||||||
const tick = scaleMax - i * units
|
<View>
|
||||||
const tickLabel = tick * 10 % 10 ? tick.toString() : tick.toString() + '.0'
|
<View style={[styles.yAxis, {height: symptomsSectionHeight}]}>
|
||||||
let showTick
|
{symptomsToDisplay.map(symptom => (
|
||||||
let tickBold
|
<SymptomIcon
|
||||||
if (units === 0.1) {
|
key={symptom}
|
||||||
showTick = (tick * 10 % 2) ? false : true
|
symptom={symptom}
|
||||||
tickBold = tick * 10 % 5 ? {} : {fontWeight: 'bold', fontSize: 11}
|
height={symptomIconHeight}
|
||||||
} else {
|
/>
|
||||||
showTick = (tick * 10 % 5) ? false : true
|
)
|
||||||
tickBold = tick * 10 % 10 ? {} : {fontWeight: 'bold', fontSize: 11}
|
)}
|
||||||
}
|
</View>
|
||||||
// this eyeballing is sadly necessary because RN does not
|
{shouldShowTemperatureColumn && <TickList height={height} />}
|
||||||
// support percentage values for transforms, which we'd need
|
<ChartLegend xAxisHeight={xAxisHeight} />
|
||||||
// to reliably place the label vertically centered to the grid
|
</View>
|
||||||
return (
|
)
|
||||||
<AppText
|
|
||||||
style={[style, {top: y - 8}, tickBold]}
|
|
||||||
key={i}>
|
|
||||||
{showTick && tickLabel}
|
|
||||||
</AppText>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function makeHorizontalGrid(columnHeight, symptomRowHeight) {
|
YAxis.propTypes = {
|
||||||
return getTickPositions(columnHeight).map(tick => {
|
height: PropTypes.number,
|
||||||
return (
|
symptomsToDisplay: PropTypes.array,
|
||||||
<View
|
symptomsSectionHeight: PropTypes.number,
|
||||||
top={tick + symptomRowHeight}
|
shouldShowTemperatureColumn: PropTypes.bool,
|
||||||
{...styles.horizontalGrid}
|
xAxisHeight: PropTypes.number.isRequired
|
||||||
key={tick}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTickPositions(columnHeight) {
|
export default YAxis
|
||||||
const units = unitObservable.value
|
|
||||||
const scaleMin = scaleObservable.value.min
|
|
||||||
const scaleMax = scaleObservable.value.max
|
|
||||||
const numberOfTicks = (scaleMax - scaleMin) * (1 / units) + 1
|
|
||||||
const tickDistance = 1 / (numberOfTicks - 1)
|
|
||||||
const tickPositions = []
|
|
||||||
for (let i = 0; i < numberOfTicks; i++) {
|
|
||||||
const position = getAbsoluteValue(tickDistance * i, columnHeight)
|
|
||||||
tickPositions.push(position)
|
|
||||||
}
|
|
||||||
return tickPositions
|
|
||||||
}
|
|
||||||
|
|
||||||
export function normalizeToScale(temp, columnHeight) {
|
|
||||||
const scale = scaleObservable.value
|
|
||||||
const valueRelativeToScale = (scale.max - temp) / (scale.max - scale.min)
|
|
||||||
return getAbsoluteValue(valueRelativeToScale, columnHeight)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAbsoluteValue(relative, columnHeight) {
|
|
||||||
// we add some height to have some breathing room
|
|
||||||
const verticalPadding = columnHeight * config.temperatureScale.verticalPadding
|
|
||||||
const scaleHeight = columnHeight - 2 * verticalPadding
|
|
||||||
return scaleHeight * relative + verticalPadding
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import React, { Component } from 'react'
|
||||||
|
import { View, Dimensions } from 'react-native'
|
||||||
|
import styles from '../../styles'
|
||||||
|
|
||||||
|
export default class FillerBoxes extends Component {
|
||||||
|
render() {
|
||||||
|
const n = Dimensions.get('window').width / styles.symptomBox.width
|
||||||
|
const fillerBoxes = []
|
||||||
|
for (let i = 0; i < Math.ceil(n); i++) {
|
||||||
|
fillerBoxes.push(
|
||||||
|
<View
|
||||||
|
width={styles.symptomBox.width}
|
||||||
|
height={0}
|
||||||
|
key={i.toString()}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return fillerBoxes
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,174 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { View, TouchableOpacity } from 'react-native'
|
||||||
|
|
||||||
|
import AppText from '../app-text'
|
||||||
|
import DripIcon from '../../assets/drip-icons'
|
||||||
|
|
||||||
|
import styles from '../../styles'
|
||||||
|
|
||||||
|
import { headerTitles as symptomTitles } from '../../i18n/en/labels'
|
||||||
|
import * as labels from '../../i18n/en/cycle-day'
|
||||||
|
const bleedingLabels = labels.bleeding.labels
|
||||||
|
const intensityLabels = labels.intensity
|
||||||
|
const sexLabels = labels.sex.categories
|
||||||
|
const contraceptiveLabels = labels.contraceptives.categories
|
||||||
|
const painLabels = labels.pain.categories
|
||||||
|
const moodLabels = labels.mood.categories
|
||||||
|
|
||||||
|
function isNumber(val) {
|
||||||
|
return typeof val === 'number'
|
||||||
|
}
|
||||||
|
|
||||||
|
const l = {
|
||||||
|
bleeding: ({ value, exclude }) => {
|
||||||
|
if (isNumber(value)) {
|
||||||
|
const bleedingLabel = bleedingLabels[value]
|
||||||
|
return exclude ? `(${bleedingLabel})` : bleedingLabel
|
||||||
|
}
|
||||||
|
},
|
||||||
|
temperature: ({ value, time, exclude }) => {
|
||||||
|
if (isNumber(value)) {
|
||||||
|
let temperatureLabel = `${value} °C`
|
||||||
|
if (time) {
|
||||||
|
temperatureLabel += ` - ${time}`
|
||||||
|
}
|
||||||
|
if (exclude) {
|
||||||
|
temperatureLabel = `(${temperatureLabel})`
|
||||||
|
}
|
||||||
|
return temperatureLabel
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mucus: mucus => {
|
||||||
|
const filledCategories = ['feeling', 'texture'].filter(c => isNumber(mucus[c]))
|
||||||
|
let label = filledCategories.map(category => {
|
||||||
|
return labels.mucus.subcategories[category] + ': ' + labels.mucus[category].categories[mucus[category]]
|
||||||
|
}).join(', ')
|
||||||
|
|
||||||
|
if (isNumber(mucus.value)) label += `\n => ${labels.mucusNFP[mucus.value]}`
|
||||||
|
if (mucus.exclude) label = `(${label})`
|
||||||
|
|
||||||
|
return label
|
||||||
|
},
|
||||||
|
cervix: cervix => {
|
||||||
|
const filledCategories = ['opening', 'firmness', 'position'].filter(c => isNumber(cervix[c]))
|
||||||
|
let label = filledCategories.map(category => {
|
||||||
|
return labels.cervix.subcategories[category] + ': ' + labels.cervix[category].categories[cervix[category]]
|
||||||
|
}).join(', ')
|
||||||
|
|
||||||
|
if (cervix.exclude) label = `(${label})`
|
||||||
|
|
||||||
|
return label
|
||||||
|
},
|
||||||
|
note: note => note.value,
|
||||||
|
desire: ({ value }) => {
|
||||||
|
if (isNumber(value)) {
|
||||||
|
return intensityLabels[value]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
sex: sex => {
|
||||||
|
const sexLabel = []
|
||||||
|
if (sex && Object.values({...sex}).some(val => val)){
|
||||||
|
Object.keys(sex).forEach(key => {
|
||||||
|
if(sex[key] && key !== 'other' && key !== 'note') {
|
||||||
|
sexLabel.push(
|
||||||
|
sexLabels[key] ||
|
||||||
|
contraceptiveLabels[key]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if(key === 'other' && sex.other) {
|
||||||
|
let label = contraceptiveLabels[key]
|
||||||
|
if(sex.note) {
|
||||||
|
label = `${label} (${sex.note})`
|
||||||
|
}
|
||||||
|
sexLabel.push(label)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return sexLabel.join(', ')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
pain: pain => {
|
||||||
|
const painLabel = []
|
||||||
|
if (pain && Object.values({...pain}).some(val => val)){
|
||||||
|
Object.keys(pain).forEach(key => {
|
||||||
|
if(pain[key] && key !== 'other' && key !== 'note') {
|
||||||
|
painLabel.push(painLabels[key])
|
||||||
|
}
|
||||||
|
if(key === 'other' && pain.other) {
|
||||||
|
let label = painLabels[key]
|
||||||
|
if(pain.note) {
|
||||||
|
label = `${label} (${pain.note})`
|
||||||
|
}
|
||||||
|
painLabel.push(label)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return painLabel.join(', ')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mood: mood => {
|
||||||
|
const moodLabel = []
|
||||||
|
if (mood && Object.values({...mood}).some(val => val)){
|
||||||
|
Object.keys(mood).forEach(key => {
|
||||||
|
if(mood[key] && key !== 'other' && key !== 'note') {
|
||||||
|
moodLabel.push(moodLabels[key])
|
||||||
|
}
|
||||||
|
if(key === 'other' && mood.other) {
|
||||||
|
let label = moodLabels[key]
|
||||||
|
if(mood.note) {
|
||||||
|
label = `${label} (${mood.note})`
|
||||||
|
}
|
||||||
|
moodLabel.push(label)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return moodLabel.join(', ')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getLabel = (symptom, symptomData) => {
|
||||||
|
return symptomData && l[symptom](symptomData)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function SymptomBox(
|
||||||
|
{ disabled, onPress, symptom, symptomData }) {
|
||||||
|
|
||||||
|
const data = getLabel(symptom, symptomData)
|
||||||
|
const iconName = `drip-icon-${symptom}`
|
||||||
|
|
||||||
|
const disabledStyle = disabled ? styles.symptomInFuture : null
|
||||||
|
const containerStyle = [
|
||||||
|
styles.symptomBox,
|
||||||
|
data && styles.symptomBoxActive,
|
||||||
|
disabledStyle
|
||||||
|
]
|
||||||
|
const titleStyle = [
|
||||||
|
data && styles.symptomTextActive,
|
||||||
|
disabledStyle,
|
||||||
|
{fontSize: 15}
|
||||||
|
]
|
||||||
|
const dataBoxStyle = [styles.symptomDataBox, disabledStyle]
|
||||||
|
const iconColor = data ? 'white' : 'black'
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TouchableOpacity onPress={onPress} disabled={disabled} testID={iconName}>
|
||||||
|
<View style={containerStyle}>
|
||||||
|
<DripIcon name={iconName} size={50} color={iconColor} />
|
||||||
|
<AppText style={titleStyle} numberOfLines={1}>
|
||||||
|
{symptomTitles[symptom].toLowerCase()}
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
<View style={dataBoxStyle}>
|
||||||
|
<AppText style={styles.symptomDataText} numberOfLines={3}>
|
||||||
|
{data}
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
</TouchableOpacity>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
SymptomBox.propTypes = {
|
||||||
|
disabled: PropTypes.bool.isRequired,
|
||||||
|
onPress: PropTypes.func.isRequired,
|
||||||
|
symptom: PropTypes.string.isRequired,
|
||||||
|
symptomData: PropTypes.object
|
||||||
|
}
|
||||||
@@ -1,265 +1,110 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import {
|
import { ScrollView, View } from 'react-native'
|
||||||
ScrollView,
|
import PropTypes from 'prop-types'
|
||||||
View,
|
|
||||||
TouchableOpacity,
|
import { connect } from 'react-redux'
|
||||||
Dimensions
|
import { getDate, setDate } from '../../slices/date'
|
||||||
} from 'react-native'
|
import { navigate } from '../../slices/navigation'
|
||||||
|
|
||||||
import { LocalDate } from 'js-joda'
|
import { LocalDate } from 'js-joda'
|
||||||
import Header from '../header'
|
import Header from '../header'
|
||||||
import { getCycleDay } from '../../db'
|
import FillerBoxes from './FillerBoxes'
|
||||||
|
import SymptomBox from './SymptomBox'
|
||||||
|
|
||||||
import cycleModule from '../../lib/cycle'
|
import cycleModule from '../../lib/cycle'
|
||||||
|
import formatDate from '../helpers/format-date'
|
||||||
|
import { getCycleDay } from '../../db'
|
||||||
import styles from '../../styles'
|
import styles from '../../styles'
|
||||||
import * as labels from '../../i18n/en/cycle-day'
|
|
||||||
import AppText from '../app-text'
|
|
||||||
import DripIcon from '../../assets/drip-icons'
|
|
||||||
|
|
||||||
const bleedingLabels = labels.bleeding.labels
|
class CycleDayOverView extends Component {
|
||||||
const feelingLabels = labels.mucus.feeling.categories
|
|
||||||
const textureLabels = labels.mucus.texture.categories
|
static propTypes = {
|
||||||
const openingLabels = labels.cervix.opening.categories
|
navigate: PropTypes.func,
|
||||||
const firmnessLabels = labels.cervix.firmness.categories
|
setDate: PropTypes.func,
|
||||||
const positionLabels = labels.cervix.position.categories
|
// The following are not being used,
|
||||||
const intensityLabels = labels.intensity
|
// we could see if it's possible to not pass them from the <App />
|
||||||
const sexLabels = labels.sex.categories
|
cycleDay: PropTypes.object,
|
||||||
const contraceptiveLabels = labels.contraceptives.categories
|
date: PropTypes.string,
|
||||||
const painLabels = labels.pain.categories
|
}
|
||||||
const moodLabels = labels.mood.categories
|
|
||||||
|
|
||||||
export default class CycleDayOverView extends Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
date: this.props.date,
|
cycleDay: getCycleDay(props.date)
|
||||||
cycleDay: getCycleDay(this.props.date)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
goToCycleDay = (target) => {
|
updateCycleDay = (date) => {
|
||||||
const localDate = LocalDate.parse(this.state.date)
|
this.props.setDate(date)
|
||||||
const targetDate = target === 'before' ?
|
|
||||||
localDate.minusDays(1).toString() :
|
|
||||||
localDate.plusDays(1).toString()
|
|
||||||
this.setState({
|
this.setState({
|
||||||
date: targetDate,
|
cycleDay: getCycleDay(date)
|
||||||
cycleDay: getCycleDay(targetDate)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
navigate(symptom) {
|
goToPrevDay = () => {
|
||||||
this.props.navigate(symptom, this.state)
|
const { date } = this.props
|
||||||
|
const prevDate = LocalDate.parse(date).minusDays(1).toString()
|
||||||
|
this.updateCycleDay(prevDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
getLabel(symptomName) {
|
goToNextDay = () => {
|
||||||
const cycleDay = this.state.cycleDay
|
const { date } = this.props
|
||||||
if (!cycleDay || !cycleDay[symptomName]) return
|
const nextDate = LocalDate.parse(date).plusDays(1).toString()
|
||||||
|
this.updateCycleDay(nextDate)
|
||||||
const l = {
|
|
||||||
bleeding: bleeding => {
|
|
||||||
if (isNumber(bleeding.value)) {
|
|
||||||
let bleedingLabel = bleedingLabels[bleeding.value]
|
|
||||||
if (bleeding.exclude) bleedingLabel = "( " + bleedingLabel + " )"
|
|
||||||
return bleedingLabel
|
|
||||||
}
|
|
||||||
},
|
|
||||||
temperature: temperature => {
|
|
||||||
if (isNumber(temperature.value)) {
|
|
||||||
let temperatureLabel = `${temperature.value} °C - ${temperature.time}`
|
|
||||||
if (temperature.exclude) {
|
|
||||||
temperatureLabel = "( " + temperatureLabel + " )"
|
|
||||||
}
|
|
||||||
return temperatureLabel
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mucus: mucus => {
|
|
||||||
const categories = ['feeling', 'texture', 'value']
|
|
||||||
if (categories.every(c => isNumber(mucus[c]))) {
|
|
||||||
let mucusLabel = [feelingLabels[mucus.feeling], textureLabels[mucus.texture]].join(', ')
|
|
||||||
mucusLabel += `\n${labels.mucusNFP[mucus.value]}`
|
|
||||||
if (mucus.exclude) mucusLabel = `(${mucusLabel})`
|
|
||||||
return mucusLabel
|
|
||||||
}
|
|
||||||
},
|
|
||||||
cervix: cervix => {
|
|
||||||
let cervixLabel = []
|
|
||||||
if (isNumber(cervix.opening) && isNumber(cervix.firmness)) {
|
|
||||||
cervixLabel.push(
|
|
||||||
openingLabels[cervix.opening],
|
|
||||||
firmnessLabels[cervix.firmness]
|
|
||||||
)
|
|
||||||
if (isNumber(cervix.position)) {
|
|
||||||
cervixLabel.push(positionLabels[cervix.position])
|
|
||||||
}
|
|
||||||
cervixLabel = cervixLabel.join(', ')
|
|
||||||
if (cervix.exclude) cervixLabel = `(${cervixLabel})`
|
|
||||||
return cervixLabel
|
|
||||||
}
|
|
||||||
},
|
|
||||||
note: note => {
|
|
||||||
return note.value
|
|
||||||
},
|
|
||||||
desire: desire => {
|
|
||||||
if (isNumber(desire.value)) {
|
|
||||||
const desireLabel = `${intensityLabels[desire.value]}`
|
|
||||||
return desireLabel
|
|
||||||
}
|
|
||||||
},
|
|
||||||
sex: sex => {
|
|
||||||
let sexLabel = []
|
|
||||||
if (sex && Object.values({...sex}).some(val => val)){
|
|
||||||
Object.keys(sex).forEach(key => {
|
|
||||||
if(sex[key] && key !== 'other' && key !== 'note') {
|
|
||||||
sexLabel.push(
|
|
||||||
sexLabels[key] ||
|
|
||||||
contraceptiveLabels[key]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if(key === 'other' && sex.other) {
|
|
||||||
let label = contraceptiveLabels[key]
|
|
||||||
if(sex.note) {
|
|
||||||
label = `${label} (${sex.note})`
|
|
||||||
}
|
|
||||||
sexLabel.push(label)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
sexLabel = sexLabel.join(', ')
|
|
||||||
return sexLabel
|
|
||||||
}
|
|
||||||
},
|
|
||||||
pain: pain => {
|
|
||||||
let painLabel = []
|
|
||||||
if (pain && Object.values({...pain}).some(val => val)){
|
|
||||||
Object.keys(pain).forEach(key => {
|
|
||||||
if(pain[key] && key !== 'other' && key !== 'note') {
|
|
||||||
painLabel.push(painLabels[key])
|
|
||||||
}
|
|
||||||
if(key === 'other' && pain.other) {
|
|
||||||
let label = painLabels[key]
|
|
||||||
if(pain.note) {
|
|
||||||
label = `${label} (${pain.note})`
|
|
||||||
}
|
|
||||||
painLabel.push(label)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
painLabel = painLabel.join(', ')
|
|
||||||
return painLabel
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mood: mood => {
|
|
||||||
let moodLabel = []
|
|
||||||
if (mood && Object.values({...mood}).some(val => val)){
|
|
||||||
Object.keys(mood).forEach(key => {
|
|
||||||
if(mood[key] && key !== 'other' && key !== 'note') {
|
|
||||||
moodLabel.push(moodLabels[key])
|
|
||||||
}
|
|
||||||
if(key === 'other' && mood.other) {
|
|
||||||
let label = moodLabels[key]
|
|
||||||
if(mood.note) {
|
|
||||||
label = `${label} (${mood.note})`
|
|
||||||
}
|
|
||||||
moodLabel.push(label)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
moodLabel = moodLabel.join(', ')
|
|
||||||
return moodLabel
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const symptomValue = cycleDay[symptomName]
|
|
||||||
return l[symptomName](symptomValue)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const getCycleDayNumber = cycleModule().getCycleDayNumber
|
const { cycleDay } = this.state
|
||||||
const cycleDayNumber = getCycleDayNumber(this.state.date)
|
const { date } = this.props
|
||||||
const dateInFuture = LocalDate
|
|
||||||
.now()
|
const dateInFuture = LocalDate.now().isBefore(LocalDate.parse(date))
|
||||||
.isBefore(LocalDate.parse(this.state.date))
|
|
||||||
|
const symptomBoxesList = [
|
||||||
|
'bleeding',
|
||||||
|
'temperature',
|
||||||
|
'mucus',
|
||||||
|
'cervix',
|
||||||
|
'desire',
|
||||||
|
'sex',
|
||||||
|
'pain',
|
||||||
|
'mood',
|
||||||
|
'note',
|
||||||
|
]
|
||||||
|
|
||||||
|
const { getCycleDayNumber } = cycleModule()
|
||||||
|
const cycleDayNumber = getCycleDayNumber(date)
|
||||||
|
const headerSubtitle = cycleDayNumber && `Cycle day ${cycleDayNumber}`
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 1 }}>
|
<View style={{ flex: 1 }}>
|
||||||
<Header
|
<Header
|
||||||
isCycleDayOverView={true}
|
handleBack={this.goToPrevDay}
|
||||||
cycleDayNumber={cycleDayNumber}
|
handleNext={this.goToNextDay}
|
||||||
date={this.state.date}
|
title={formatDate(date)}
|
||||||
goToCycleDay={this.goToCycleDay}
|
subtitle={headerSubtitle}
|
||||||
/>
|
/>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<View style={styles.symptomBoxesView}>
|
<View style={styles.symptomBoxesView}>
|
||||||
<SymptomBox
|
{
|
||||||
title='Bleeding'
|
symptomBoxesList.map(symptom => {
|
||||||
onPress={() => this.navigate('BleedingEditView')}
|
const symptomEditView =
|
||||||
data={this.getLabel('bleeding')}
|
`${symptom[0].toUpperCase() + symptom.substring(1)}EditView`
|
||||||
disabled={dateInFuture}
|
const symptomData =
|
||||||
iconName='drip-icon-bleeding'
|
cycleDay && cycleDay[symptom] ? cycleDay[symptom] : null
|
||||||
>
|
return(
|
||||||
</SymptomBox>
|
<SymptomBox
|
||||||
<SymptomBox
|
key={symptom}
|
||||||
title='Temperature'
|
symptom={symptom}
|
||||||
onPress={() => this.navigate('TemperatureEditView')}
|
symptomData={symptomData}
|
||||||
data={this.getLabel('temperature')}
|
onPress={() => this.props.navigate(symptomEditView)}
|
||||||
disabled={dateInFuture}
|
disabled={dateInFuture && symptom !== 'note'}
|
||||||
iconName='drip-icon-temperature'
|
/>)
|
||||||
>
|
})
|
||||||
</SymptomBox>
|
}
|
||||||
<SymptomBox
|
{
|
||||||
title='Mucus'
|
// this is just to make the last row adhere to the grid
|
||||||
onPress={() => this.navigate('MucusEditView')}
|
// (and) because there are no pseudo properties in RN
|
||||||
data={this.getLabel('mucus')}
|
}
|
||||||
disabled={dateInFuture}
|
|
||||||
iconName='drip-icon-mucus'
|
|
||||||
>
|
|
||||||
</SymptomBox>
|
|
||||||
<SymptomBox
|
|
||||||
title='Cervix'
|
|
||||||
onPress={() => this.navigate('CervixEditView')}
|
|
||||||
data={this.getLabel('cervix')}
|
|
||||||
disabled={dateInFuture}
|
|
||||||
iconName='drip-icon-cervix'
|
|
||||||
>
|
|
||||||
</SymptomBox>
|
|
||||||
<SymptomBox
|
|
||||||
title='Desire'
|
|
||||||
onPress={() => this.navigate('DesireEditView')}
|
|
||||||
data={this.getLabel('desire')}
|
|
||||||
disabled={dateInFuture}
|
|
||||||
iconName='drip-icon-desire'
|
|
||||||
>
|
|
||||||
</SymptomBox>
|
|
||||||
<SymptomBox
|
|
||||||
title='Sex'
|
|
||||||
onPress={() => this.navigate('SexEditView')}
|
|
||||||
data={this.getLabel('sex')}
|
|
||||||
disabled={dateInFuture}
|
|
||||||
iconName='drip-icon-sex'
|
|
||||||
>
|
|
||||||
</SymptomBox>
|
|
||||||
<SymptomBox
|
|
||||||
title='Pain'
|
|
||||||
onPress={() => this.navigate('PainEditView')}
|
|
||||||
data={this.getLabel('pain')}
|
|
||||||
disabled={dateInFuture}
|
|
||||||
iconName='drip-icon-pain'
|
|
||||||
>
|
|
||||||
</SymptomBox>
|
|
||||||
<SymptomBox
|
|
||||||
title='Mood'
|
|
||||||
onPress={() => this.navigate('MoodEditView')}
|
|
||||||
data={this.getLabel('mood')}
|
|
||||||
disabled={dateInFuture}
|
|
||||||
iconName='drip-icon-mood'
|
|
||||||
>
|
|
||||||
</SymptomBox>
|
|
||||||
<SymptomBox
|
|
||||||
title='Note'
|
|
||||||
onPress={() => this.navigate('NoteEditView')}
|
|
||||||
data={this.getLabel('note')}
|
|
||||||
iconName='drip-icon-note'
|
|
||||||
>
|
|
||||||
</SymptomBox>
|
|
||||||
{/* this is just to make the last row adhere to the grid
|
|
||||||
(and) because there are no pseudo properties in RN */}
|
|
||||||
<FillerBoxes />
|
<FillerBoxes />
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
@@ -268,55 +113,20 @@ export default class CycleDayOverView extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => {
|
||||||
|
return({
|
||||||
|
date: getDate(state),
|
||||||
class SymptomBox extends Component {
|
})
|
||||||
render() {
|
|
||||||
const hasData = this.props.data
|
|
||||||
const boxActive = hasData ? styles.symptomBoxActive : {}
|
|
||||||
const textActive = hasData ? styles.symptomTextActive : {}
|
|
||||||
const disabledStyle = this.props.disabled ? styles.symptomInFuture : {}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<TouchableOpacity
|
|
||||||
onPress={this.props.onPress}
|
|
||||||
disabled={this.props.disabled}
|
|
||||||
>
|
|
||||||
<View style={[styles.symptomBox, boxActive, disabledStyle]}>
|
|
||||||
<DripIcon name={this.props.iconName} size={50} color={hasData ? 'white' : 'black'}/>
|
|
||||||
<AppText style={[textActive, disabledStyle]}>
|
|
||||||
{this.props.title.toLowerCase()}
|
|
||||||
</AppText>
|
|
||||||
</View>
|
|
||||||
<View style={[styles.symptomDataBox, disabledStyle]}>
|
|
||||||
<AppText
|
|
||||||
style={styles.symptomDataText}
|
|
||||||
numberOfLines={3}
|
|
||||||
>{this.props.data}</AppText>
|
|
||||||
</View>
|
|
||||||
</TouchableOpacity>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FillerBoxes extends Component {
|
const mapDispatchToProps = (dispatch) => {
|
||||||
render() {
|
return({
|
||||||
const n = Dimensions.get('window').width / styles.symptomBox.width
|
setDate: (date) => dispatch(setDate(date)),
|
||||||
const fillerBoxes = []
|
navigate: (page) => dispatch(navigate(page)),
|
||||||
for (let i = 0; i < Math.ceil(n); i++) {
|
})
|
||||||
fillerBoxes.push(
|
|
||||||
<View
|
|
||||||
width={styles.symptomBox.width}
|
|
||||||
height={0}
|
|
||||||
key={i.toString()}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return fillerBoxes
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNumber(val) {
|
export default connect(
|
||||||
return typeof val === 'number'
|
mapStateToProps,
|
||||||
}
|
mapDispatchToProps,
|
||||||
|
)(CycleDayOverView)
|
||||||
|
|||||||
@@ -1,34 +1,38 @@
|
|||||||
import React, { Component } from 'react'
|
import React from 'react'
|
||||||
import {
|
import PropTypes from 'prop-types'
|
||||||
View,
|
import { View, TouchableOpacity } from 'react-native'
|
||||||
TouchableOpacity,
|
|
||||||
} from 'react-native'
|
|
||||||
import styles from '../../styles'
|
|
||||||
import AppText from '../app-text'
|
import AppText from '../app-text'
|
||||||
|
|
||||||
export default class SelectBoxGroup extends Component {
|
import styles from '../../styles'
|
||||||
render() {
|
|
||||||
return (
|
export default function SelectBoxGroup({ labels, onSelect, optionsState }) {
|
||||||
<View style={styles.selectBoxSection}>
|
return (
|
||||||
{Object.keys(this.props.labels).map(key => {
|
<View style={styles.selectBoxSection}>
|
||||||
const style = [styles.selectBox]
|
{Object.keys(labels).map(key => {
|
||||||
const textStyle = []
|
const style = [styles.selectBox]
|
||||||
if (this.props.optionsState[key]) {
|
const textStyle = []
|
||||||
style.push(styles.selectBoxActive)
|
if (optionsState[key]) {
|
||||||
textStyle.push(styles.selectBoxTextActive)
|
style.push(styles.selectBoxActive)
|
||||||
}
|
textStyle.push(styles.selectBoxTextActive)
|
||||||
return (
|
}
|
||||||
<TouchableOpacity
|
return (
|
||||||
onPress={() => this.props.onSelect(key)}
|
<TouchableOpacity
|
||||||
key={key}
|
onPress={() => onSelect(key)}
|
||||||
>
|
key={key}
|
||||||
<View style={style}>
|
>
|
||||||
<AppText style={textStyle}>{this.props.labels[key]}</AppText>
|
<View style={style}>
|
||||||
</View>
|
<AppText style={textStyle}>{labels[key]}</AppText>
|
||||||
</TouchableOpacity>
|
</View>
|
||||||
)
|
</TouchableOpacity>
|
||||||
})}
|
)
|
||||||
</View>
|
})}
|
||||||
)
|
</View>
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SelectBoxGroup.propTypes = {
|
||||||
|
labels: PropTypes.object.isRequired,
|
||||||
|
onSelect: PropTypes.func.isRequired,
|
||||||
|
optionsState: PropTypes.object.isRequired
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,46 +1,50 @@
|
|||||||
import React, { Component } from 'react'
|
import React from 'react'
|
||||||
import {
|
import PropTypes from 'prop-types'
|
||||||
View,
|
import { View, TouchableOpacity } from 'react-native'
|
||||||
TouchableOpacity,
|
|
||||||
} from 'react-native'
|
|
||||||
import styles from '../../styles'
|
|
||||||
import AppText from '../app-text'
|
import AppText from '../app-text'
|
||||||
|
|
||||||
export default class SelectTabGroup extends Component {
|
import styles from '../../styles'
|
||||||
render() {
|
|
||||||
return (
|
export default function SelectTabGroup({ active, buttons, onSelect }) {
|
||||||
<View style={styles.selectTabGroup}>
|
return (
|
||||||
{
|
<View style={styles.selectTabGroup}>
|
||||||
this.props.buttons.map(({ label, value }, i) => {
|
{
|
||||||
let firstOrLastStyle
|
buttons.map(({ label, value }, i) => {
|
||||||
if (i === this.props.buttons.length - 1) {
|
let firstOrLastStyle
|
||||||
firstOrLastStyle = styles.selectTabLast
|
if (i === buttons.length - 1) {
|
||||||
} else if (i === 0) {
|
firstOrLastStyle = styles.selectTabLast
|
||||||
firstOrLastStyle = styles.selectTabFirst
|
} else if (i === 0) {
|
||||||
}
|
firstOrLastStyle = styles.selectTabFirst
|
||||||
let activeStyle
|
}
|
||||||
const isActive = value === this.props.active
|
let activeStyle
|
||||||
if (isActive) activeStyle = styles.selectTabActive
|
const isActive = value === active
|
||||||
return (
|
if (isActive) activeStyle = styles.selectTabActive
|
||||||
<TouchableOpacity
|
return (
|
||||||
onPress={() => isActive ? this.props.onSelect(null) : this.props.onSelect(value)}
|
<TouchableOpacity
|
||||||
key={i}
|
onPress={() => onSelect(isActive ? null : value)}
|
||||||
activeOpacity={1}
|
key={i}
|
||||||
>
|
activeOpacity={1}
|
||||||
<View>
|
>
|
||||||
<View style={[
|
<View>
|
||||||
styles.selectTab,
|
<View style={[
|
||||||
firstOrLastStyle,
|
styles.selectTab,
|
||||||
activeStyle
|
firstOrLastStyle,
|
||||||
]}>
|
activeStyle
|
||||||
<AppText style={activeStyle}>{label}</AppText>
|
]}>
|
||||||
</View>
|
<AppText style={activeStyle}>{label}</AppText>
|
||||||
</View>
|
</View>
|
||||||
</TouchableOpacity>
|
</View>
|
||||||
)
|
</TouchableOpacity>
|
||||||
})
|
)
|
||||||
}
|
})
|
||||||
</View>
|
}
|
||||||
)
|
</View>
|
||||||
}
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
SelectTabGroup.propTypes = {
|
||||||
|
active: PropTypes.number,
|
||||||
|
buttons: PropTypes.array.isRequired,
|
||||||
|
onSelect: PropTypes.func.isRequired
|
||||||
}
|
}
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
import React, { Component } from 'react'
|
|
||||||
import {
|
|
||||||
View, TouchableOpacity, Text, Alert, ToastAndroid
|
|
||||||
} from 'react-native'
|
|
||||||
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
|
|
||||||
import { saveSymptom } from '../../../db'
|
|
||||||
import styles, {iconStyles} from '../../../styles'
|
|
||||||
import {sharedDialogs as labels} from '../../../i18n/en/cycle-day'
|
|
||||||
|
|
||||||
|
|
||||||
export default class ActionButtonFooter extends Component {
|
|
||||||
render() {
|
|
||||||
const {
|
|
||||||
symptom,
|
|
||||||
currentSymptomValue,
|
|
||||||
date,
|
|
||||||
saveAction,
|
|
||||||
saveDisabled,
|
|
||||||
navigate,
|
|
||||||
autoShowDayView = true}
|
|
||||||
= this.props
|
|
||||||
const navigateToOverView = () => navigate('CycleDay', {date})
|
|
||||||
const buttons = [
|
|
||||||
{
|
|
||||||
title: labels.delete,
|
|
||||||
action: () => {
|
|
||||||
Alert.alert(
|
|
||||||
labels.areYouSureTitle,
|
|
||||||
labels.areYouSureToDelete,
|
|
||||||
[{
|
|
||||||
text: labels.cancel,
|
|
||||||
style: 'cancel'
|
|
||||||
}, {
|
|
||||||
text: labels.reallyDeleteData,
|
|
||||||
onPress: () => {
|
|
||||||
saveSymptom(symptom, date)
|
|
||||||
navigateToOverView()
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
)
|
|
||||||
},
|
|
||||||
disabledCondition: (!currentSymptomValue ||
|
|
||||||
(Object.keys(currentSymptomValue).length === 0 && currentSymptomValue.constructor === Object) ||
|
|
||||||
(Object.values(currentSymptomValue).every(x => !x) && currentSymptomValue.constructor === Object)
|
|
||||||
),
|
|
||||||
icon: 'delete-outline'
|
|
||||||
}, {
|
|
||||||
title: labels.save,
|
|
||||||
action: () => {
|
|
||||||
if(saveDisabled) {
|
|
||||||
ToastAndroid.show(labels.disabledInfo, ToastAndroid.LONG)
|
|
||||||
} else {
|
|
||||||
saveAction()
|
|
||||||
if (autoShowDayView) navigateToOverView()
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
disabledCondition: saveDisabled,
|
|
||||||
icon: 'content-save-outline'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
return (
|
|
||||||
<View style={styles.menu}>
|
|
||||||
{buttons.map(({ title, action, disabledCondition, icon }, i) => {
|
|
||||||
const textStyle = [styles.menuText]
|
|
||||||
if (disabledCondition) {
|
|
||||||
textStyle.push(styles.menuTextInActive)
|
|
||||||
}
|
|
||||||
const iconStyle = disabledCondition ?
|
|
||||||
Object.assign(
|
|
||||||
{},
|
|
||||||
iconStyles.menuIcon,
|
|
||||||
iconStyles.menuIconInactive
|
|
||||||
)
|
|
||||||
:
|
|
||||||
iconStyles.menuIcon
|
|
||||||
return (
|
|
||||||
<TouchableOpacity
|
|
||||||
onPress={action}
|
|
||||||
style={styles.menuItem}
|
|
||||||
key={i.toString()}
|
|
||||||
>
|
|
||||||
<Icon name={icon} {...iconStyle} />
|
|
||||||
<Text style={textStyle}>
|
|
||||||
{title.toLowerCase()}
|
|
||||||
</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,75 +1,85 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import {
|
import { Switch } from 'react-native'
|
||||||
View,
|
import PropTypes from 'prop-types'
|
||||||
Switch,
|
|
||||||
ScrollView
|
|
||||||
} from 'react-native'
|
|
||||||
import styles from '../../../styles'
|
|
||||||
import { saveSymptom } from '../../../db'
|
|
||||||
import { bleeding } from '../../../i18n/en/cycle-day'
|
import { bleeding } from '../../../i18n/en/cycle-day'
|
||||||
import ActionButtonFooter from './action-button-footer'
|
|
||||||
import SelectTabGroup from '../select-tab-group'
|
import SelectTabGroup from '../select-tab-group'
|
||||||
import SymptomSection from './symptom-section'
|
import SymptomSection from './symptom-section'
|
||||||
|
import SymptomView from './symptom-view'
|
||||||
|
|
||||||
|
import { getLabelsList } from '../../helpers/labels'
|
||||||
|
import { saveSymptom } from '../../../db'
|
||||||
|
|
||||||
|
class Bleeding extends Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
cycleDay: PropTypes.object,
|
||||||
|
date: PropTypes.string.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
export default class Bleeding extends Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
const cycleDay = props.cycleDay
|
const symptom = 'bleeding'
|
||||||
this.bleeding = cycleDay && cycleDay.bleeding
|
const { cycleDay } = props
|
||||||
this.makeActionButtons = props.makeActionButtons
|
|
||||||
this.state = {
|
const defaultSymptomData = {
|
||||||
currentValue: this.bleeding && this.bleeding.value,
|
value: null,
|
||||||
exclude: this.bleeding ? this.bleeding.exclude : false
|
exclude: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const symptomData =
|
||||||
|
cycleDay && cycleDay[symptom] ? cycleDay[symptom] : defaultSymptomData
|
||||||
|
|
||||||
|
this.state = { ...symptomData }
|
||||||
|
|
||||||
|
this.bleedingRadioProps = getLabelsList(bleeding.labels)
|
||||||
|
|
||||||
|
this.symptom = symptom
|
||||||
|
}
|
||||||
|
|
||||||
|
autoSave = () => {
|
||||||
|
const { date } = this.props
|
||||||
|
const valuesToSave = { ...this.state }
|
||||||
|
const hasValueToSave = typeof this.state.value === 'number'
|
||||||
|
saveSymptom(this.symptom, date, hasValueToSave ? valuesToSave : null)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
this.autoSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const bleedingRadioProps = [
|
|
||||||
{ label: bleeding.labels[0], value: 0 },
|
|
||||||
{ label: bleeding.labels[1], value: 1 },
|
|
||||||
{ label: bleeding.labels[2], value: 2 },
|
|
||||||
{ label: bleeding.labels[3], value: 3 },
|
|
||||||
]
|
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 1 }}>
|
<SymptomView
|
||||||
<ScrollView style={styles.page}>
|
symptom={this.symptom}
|
||||||
<SymptomSection
|
values={this.state}
|
||||||
header={bleeding.heaviness.header}
|
date={this.props.date}
|
||||||
explainer={bleeding.heaviness.explainer}
|
>
|
||||||
>
|
<SymptomSection
|
||||||
<SelectTabGroup
|
header={bleeding.heaviness.header}
|
||||||
buttons={bleedingRadioProps}
|
explainer={bleeding.heaviness.explainer}
|
||||||
active={this.state.currentValue}
|
>
|
||||||
onSelect={val => this.setState({ currentValue: val })}
|
<SelectTabGroup
|
||||||
/>
|
buttons={this.bleedingRadioProps}
|
||||||
</SymptomSection>
|
active={this.state.value}
|
||||||
<SymptomSection
|
onSelect={val => this.setState({ value: val })}
|
||||||
header={bleeding.exclude.header}
|
/>
|
||||||
explainer={bleeding.exclude.explainer}
|
</SymptomSection>
|
||||||
inline={true}
|
<SymptomSection
|
||||||
>
|
header={bleeding.exclude.header}
|
||||||
<Switch
|
explainer={bleeding.exclude.explainer}
|
||||||
onValueChange={(val) => {
|
inline={true}
|
||||||
this.setState({ exclude: val })
|
>
|
||||||
}}
|
<Switch
|
||||||
value={this.state.exclude}
|
onValueChange={(val) => {
|
||||||
/>
|
this.setState({ exclude: val })
|
||||||
</SymptomSection>
|
}}
|
||||||
</ScrollView>
|
value={this.state.exclude}
|
||||||
<ActionButtonFooter
|
/>
|
||||||
symptom='bleeding'
|
</SymptomSection>
|
||||||
date={this.props.date}
|
</SymptomView>
|
||||||
currentSymptomValue={this.bleeding}
|
|
||||||
saveAction={() => {
|
|
||||||
saveSymptom('bleeding', this.props.date, {
|
|
||||||
value: this.state.currentValue,
|
|
||||||
exclude: this.state.exclude
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
saveDisabled={typeof this.state.currentValue != 'number'}
|
|
||||||
navigate={this.props.navigate}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Bleeding
|
||||||
|
|||||||
@@ -1,105 +1,113 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import {
|
import { Switch } from 'react-native'
|
||||||
View,
|
import PropTypes from 'prop-types'
|
||||||
Switch,
|
|
||||||
ScrollView
|
|
||||||
} from 'react-native'
|
|
||||||
import styles from '../../../styles'
|
|
||||||
import { saveSymptom } from '../../../db'
|
|
||||||
import { cervix as labels } from '../../../i18n/en/cycle-day'
|
import { cervix as labels } from '../../../i18n/en/cycle-day'
|
||||||
import ActionButtonFooter from './action-button-footer'
|
|
||||||
import SelectTabGroup from '../select-tab-group'
|
import SelectTabGroup from '../select-tab-group'
|
||||||
import SymptomSection from './symptom-section'
|
import SymptomSection from './symptom-section'
|
||||||
import { ActionHint } from '../../app-text'
|
import SymptomView from './symptom-view'
|
||||||
|
|
||||||
|
import { getLabelsList } from '../../helpers/labels'
|
||||||
|
import { saveSymptom } from '../../../db'
|
||||||
|
|
||||||
|
class Cervix extends Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
cycleDay: PropTypes.object,
|
||||||
|
date: PropTypes.string.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
export default class Cervix extends Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
const cycleDay = props.cycleDay
|
const symptom = 'cervix'
|
||||||
this.cervix = cycleDay && cycleDay.cervix
|
const { cycleDay } = props
|
||||||
this.makeActionButtons = props.makeActionButtons
|
|
||||||
this.state = this.cervix ? this.cervix : {}
|
const defaultSymptomData = {}
|
||||||
|
|
||||||
|
const symptomData =
|
||||||
|
cycleDay && cycleDay[symptom] ? cycleDay[symptom] : defaultSymptomData
|
||||||
|
|
||||||
|
this.state = { ...symptomData }
|
||||||
|
|
||||||
|
this.cervixOpeningRadioProps = getLabelsList(labels.opening.categories)
|
||||||
|
this.cervixFirmnessRadioProps = getLabelsList(labels.firmness.categories)
|
||||||
|
this.cervixPositionRadioProps = getLabelsList(labels.position.categories)
|
||||||
|
|
||||||
|
this.symptom = symptom
|
||||||
|
}
|
||||||
|
|
||||||
|
autoSave = () => {
|
||||||
|
const { date } = this.props
|
||||||
|
const { opening, firmness, position, exclude } = this.state
|
||||||
|
const valuesToSave = {
|
||||||
|
opening,
|
||||||
|
firmness,
|
||||||
|
position,
|
||||||
|
exclude: Boolean(exclude)
|
||||||
|
}
|
||||||
|
const nothingEntered = ['opening', 'firmness', 'position'].every(
|
||||||
|
val => typeof this.state[val] !== 'number')
|
||||||
|
saveSymptom(this.symptom, date, nothingEntered ? null : valuesToSave)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
this.autoSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const cervixOpeningRadioProps = [
|
// TODO saving this info for notice when leaving incomplete data
|
||||||
{ label: labels.opening.categories[0], value: 0 },
|
// const mandatoryNotCompleted = typeof this.state.opening != 'number' || typeof this.state.firmness != 'number'
|
||||||
{ label: labels.opening.categories[1], value: 1 },
|
|
||||||
{ label: labels.opening.categories[2], value: 2 }
|
|
||||||
]
|
|
||||||
const cervixFirmnessRadioProps = [
|
|
||||||
{ label: labels.firmness.categories[0], value: 0 },
|
|
||||||
{ label: labels.firmness.categories[1], value: 1 }
|
|
||||||
]
|
|
||||||
const cervixPositionRadioProps = [
|
|
||||||
{ label: labels.position.categories[0], value: 0 },
|
|
||||||
{ label: labels.position.categories[1], value: 1 },
|
|
||||||
{ label: labels.position.categories[2], value: 2 }
|
|
||||||
]
|
|
||||||
const mandatoryNotCompletedYet = typeof this.state.opening != 'number' || typeof this.state.firmness != 'number'
|
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 1 }}>
|
<SymptomView
|
||||||
<ScrollView style={styles.page}>
|
symptom={this.symptom}
|
||||||
<SymptomSection
|
values={this.state}
|
||||||
header="Opening"
|
date={this.props.date}
|
||||||
explainer={labels.opening.explainer}
|
>
|
||||||
>
|
<SymptomSection
|
||||||
<SelectTabGroup
|
header="Opening"
|
||||||
buttons={cervixOpeningRadioProps}
|
explainer={labels.opening.explainer}
|
||||||
active={this.state.opening}
|
>
|
||||||
onSelect={val => this.setState({ opening: val })}
|
<SelectTabGroup
|
||||||
/>
|
buttons={this.cervixOpeningRadioProps}
|
||||||
</SymptomSection>
|
active={this.state.opening}
|
||||||
<SymptomSection
|
onSelect={val => this.setState({ opening: val })}
|
||||||
header="Firmness"
|
/>
|
||||||
explainer={labels.firmness.explainer}
|
</SymptomSection>
|
||||||
>
|
<SymptomSection
|
||||||
<SelectTabGroup
|
header="Firmness"
|
||||||
buttons={cervixFirmnessRadioProps}
|
explainer={labels.firmness.explainer}
|
||||||
active={this.state.firmness}
|
>
|
||||||
onSelect={val => this.setState({ firmness: val })}
|
<SelectTabGroup
|
||||||
/>
|
buttons={this.cervixFirmnessRadioProps}
|
||||||
</SymptomSection>
|
active={this.state.firmness}
|
||||||
<SymptomSection
|
onSelect={val => this.setState({ firmness: val })}
|
||||||
header="Position"
|
/>
|
||||||
explainer={labels.position.explainer}
|
</SymptomSection>
|
||||||
>
|
<SymptomSection
|
||||||
<SelectTabGroup
|
header="Position"
|
||||||
buttons={cervixPositionRadioProps}
|
explainer={labels.position.explainer}
|
||||||
active={this.state.position}
|
>
|
||||||
onSelect={val => this.setState({ position: val })}
|
<SelectTabGroup
|
||||||
/>
|
buttons={this.cervixPositionRadioProps}
|
||||||
</SymptomSection>
|
active={this.state.position}
|
||||||
<SymptomSection
|
onSelect={val => this.setState({ position: val })}
|
||||||
header="Exclude"
|
/>
|
||||||
explainer="You can exclude this value if you don't want to use it for fertility detection"
|
</SymptomSection>
|
||||||
inline={true}
|
<SymptomSection
|
||||||
>
|
header="Exclude"
|
||||||
<Switch
|
explainer="You can exclude this value if you don't want to use it for fertility detection"
|
||||||
onValueChange={(val) => {
|
inline={true}
|
||||||
this.setState({ exclude: val })
|
>
|
||||||
}}
|
<Switch
|
||||||
value={this.state.exclude}
|
onValueChange={(val) => {
|
||||||
/>
|
this.setState({ exclude: val })
|
||||||
</SymptomSection>
|
}}
|
||||||
</ScrollView>
|
value={this.state.exclude}
|
||||||
<ActionHint isVisible={mandatoryNotCompletedYet}>{labels.actionHint}</ActionHint>
|
/>
|
||||||
<ActionButtonFooter
|
</SymptomSection>
|
||||||
symptom='cervix'
|
</SymptomView>
|
||||||
date={this.props.date}
|
|
||||||
currentSymptomValue={this.cervix}
|
|
||||||
saveAction={() => {
|
|
||||||
saveSymptom('cervix', this.props.date, {
|
|
||||||
opening: this.state.opening,
|
|
||||||
firmness: this.state.firmness,
|
|
||||||
position: this.state.position,
|
|
||||||
exclude: Boolean(this.state.exclude)
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
saveDisabled={mandatoryNotCompletedYet}
|
|
||||||
navigate={this.props.navigate}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Cervix
|
||||||
|
|||||||
@@ -1,56 +1,69 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import {
|
import PropTypes from 'prop-types'
|
||||||
View,
|
|
||||||
ScrollView
|
|
||||||
} from 'react-native'
|
|
||||||
import styles from '../../../styles'
|
|
||||||
import { saveSymptom } from '../../../db'
|
|
||||||
import { intensity, desire } from '../../../i18n/en/cycle-day'
|
import { intensity, desire } from '../../../i18n/en/cycle-day'
|
||||||
import ActionButtonFooter from './action-button-footer'
|
|
||||||
import SelectTabGroup from '../select-tab-group'
|
import SelectTabGroup from '../select-tab-group'
|
||||||
import SymptomSection from './symptom-section'
|
import SymptomSection from './symptom-section'
|
||||||
|
import SymptomView from './symptom-view'
|
||||||
|
|
||||||
|
import { getLabelsList } from '../../helpers/labels'
|
||||||
|
import { saveSymptom } from '../../../db'
|
||||||
|
|
||||||
|
class Desire extends Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
cycleDay: PropTypes.object,
|
||||||
|
date: PropTypes.string.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
export default class Desire extends Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
const cycleDay = props.cycleDay
|
const symptom = 'desire'
|
||||||
this.desire = cycleDay && cycleDay.desire
|
const { cycleDay } = props
|
||||||
this.makeActionButtons = props.makeActionButtons
|
|
||||||
const desireValue = this.desire && this.desire.value
|
const defaultSymptomData = { value: null }
|
||||||
this.state = { currentValue: desireValue }
|
|
||||||
|
const symptomData =
|
||||||
|
cycleDay && cycleDay[symptom] ? cycleDay[symptom] : defaultSymptomData
|
||||||
|
|
||||||
|
this.state = { ...symptomData }
|
||||||
|
|
||||||
|
this.symptom = symptom
|
||||||
|
|
||||||
|
this.desireRadioProps = getLabelsList(intensity)
|
||||||
|
}
|
||||||
|
|
||||||
|
autoSave = () => {
|
||||||
|
const { date } = this.props
|
||||||
|
const valuesToSave = { ...this.state }
|
||||||
|
const hasValueToSave = typeof this.state.value === 'number'
|
||||||
|
saveSymptom(this.symptom, date, hasValueToSave ? valuesToSave : null)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
this.autoSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const desireRadioProps = [
|
|
||||||
{ label: intensity[0], value: 0 },
|
|
||||||
{ label: intensity[1], value: 1 },
|
|
||||||
{ label: intensity[2], value: 2 }
|
|
||||||
]
|
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 1 }}>
|
<SymptomView
|
||||||
<ScrollView style={styles.page}>
|
symptom={this.symptom}
|
||||||
<SymptomSection
|
values={this.state}
|
||||||
header={desire.header}
|
date={this.props.date}
|
||||||
explainer={desire.explainer}
|
>
|
||||||
>
|
<SymptomSection
|
||||||
<SelectTabGroup
|
header={desire.header}
|
||||||
buttons={desireRadioProps}
|
explainer={desire.explainer}
|
||||||
active={this.state.currentValue}
|
>
|
||||||
onSelect={val => this.setState({ currentValue: val })}
|
<SelectTabGroup
|
||||||
/>
|
buttons={this.desireRadioProps}
|
||||||
</SymptomSection>
|
active={this.state.value}
|
||||||
</ScrollView>
|
onSelect={val => this.setState({ value: val })}
|
||||||
<ActionButtonFooter
|
/>
|
||||||
symptom='desire'
|
</SymptomSection>
|
||||||
date={this.props.date}
|
</SymptomView>
|
||||||
currentSymptomValue={this.desire}
|
|
||||||
saveAction={() => {
|
|
||||||
saveSymptom('desire', this.props.date, { value: this.state.currentValue })
|
|
||||||
}}
|
|
||||||
saveDisabled={typeof this.state.currentValue != 'number'}
|
|
||||||
navigate={this.props.navigate}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Desire
|
||||||
|
|||||||
@@ -1,35 +1,28 @@
|
|||||||
import React, { Component } from 'react'
|
import React from 'react'
|
||||||
import { ScrollView } from 'react-native'
|
import PropTypes from 'prop-types'
|
||||||
|
import { ScrollView, View, TouchableOpacity } from 'react-native'
|
||||||
|
import Icon from 'react-native-vector-icons/SimpleLineIcons'
|
||||||
import AppText from '../../app-text'
|
import AppText from '../../app-text'
|
||||||
import labels from '../../../i18n/en/symptom-info.js'
|
import labels from '../../../i18n/en/symptom-info.js'
|
||||||
import FramedSegment from '../../framed-segment'
|
import styles, {iconStyles} from '../../../styles/index'
|
||||||
import styles from '../../../styles/index'
|
|
||||||
|
|
||||||
export default class InfoSymptom extends Component {
|
export default function InfoSymptom({ close, symptom }) {
|
||||||
render() {
|
return (
|
||||||
const symptomView = this.props.symptomView
|
<View style={styles.infoPopUpWrapper}>
|
||||||
const symptomMapping = {
|
<View style={styles.dimmed}></View>
|
||||||
BleedingEditView: 'bleeding',
|
<View style={styles.infoPopUp} testID="symptomInfoPopup">
|
||||||
CervixEditView: 'cervix',
|
<TouchableOpacity onPress={close} style={styles.infoSymptomClose}>
|
||||||
DesireEditView: 'desire',
|
<Icon name='close' {...iconStyles.infoPopUpClose}/>
|
||||||
MoodEditView: 'mood',
|
</TouchableOpacity>
|
||||||
MucusEditView: 'mucus',
|
<ScrollView style={styles.infoSymptomText}>
|
||||||
NoteEditView: 'note',
|
<AppText>{labels[symptom].text}</AppText>
|
||||||
PainEditView: 'pain',
|
</ScrollView>
|
||||||
SexEditView: 'sex',
|
</View>
|
||||||
TemperatureEditView: 'temperature'
|
</View>
|
||||||
}
|
)
|
||||||
const currentSymptom = symptomMapping[symptomView]
|
}
|
||||||
|
|
||||||
return (
|
InfoSymptom.propTypes = {
|
||||||
<ScrollView>
|
close: PropTypes.func.isRequired,
|
||||||
<FramedSegment
|
symptom: PropTypes.string.isRequired
|
||||||
style={styles.framedSegmentLast}
|
|
||||||
title={labels[currentSymptom].title}
|
|
||||||
>
|
|
||||||
<AppText>{labels[currentSymptom].text}</AppText>
|
|
||||||
</FramedSegment>
|
|
||||||
</ScrollView>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,53 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import {
|
import { TextInput } from 'react-native'
|
||||||
ScrollView,
|
import PropTypes from 'prop-types'
|
||||||
TextInput,
|
|
||||||
View
|
|
||||||
} from 'react-native'
|
|
||||||
import { saveSymptom } from '../../../db'
|
|
||||||
import { mood as labels } from '../../../i18n/en/cycle-day'
|
import { mood as labels } from '../../../i18n/en/cycle-day'
|
||||||
import ActionButtonFooter from './action-button-footer'
|
|
||||||
import SelectBoxGroup from '../select-box-group'
|
import SelectBoxGroup from '../select-box-group'
|
||||||
import SymptomSection from './symptom-section'
|
import SymptomSection from './symptom-section'
|
||||||
import styles from '../../../styles'
|
import SymptomView from './symptom-view'
|
||||||
|
|
||||||
|
import { saveSymptom } from '../../../db'
|
||||||
|
|
||||||
|
class Mood extends Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
cycleDay: PropTypes.object,
|
||||||
|
date: PropTypes.string.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
export default class Mood extends Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
const cycleDay = props.cycleDay
|
const symptom = 'mood'
|
||||||
if (cycleDay && cycleDay.mood) {
|
const { cycleDay } = props
|
||||||
this.state = Object.assign({}, cycleDay.mood)
|
|
||||||
} else {
|
const defaultSymptomData = {}
|
||||||
this.state = {}
|
|
||||||
}
|
const symptomData =
|
||||||
if (this.state.note) {
|
cycleDay && cycleDay[symptom] ? cycleDay[symptom] : defaultSymptomData
|
||||||
this.state.other = true
|
|
||||||
|
this.state = { ...symptomData }
|
||||||
|
|
||||||
|
// We make sure other is always true when there is a note,
|
||||||
|
// e.g. when import is messed up.
|
||||||
|
if (this.state.note) this.state.other = true
|
||||||
|
|
||||||
|
this.symptom = symptom
|
||||||
|
}
|
||||||
|
|
||||||
|
autoSave = () => {
|
||||||
|
const { date } = this.props
|
||||||
|
const valuesToSave = Object.assign({}, this.state)
|
||||||
|
if (!valuesToSave.other) {
|
||||||
|
valuesToSave.note = null
|
||||||
}
|
}
|
||||||
|
const nothingEntered = Object.values(this.state).every(val => !val)
|
||||||
|
|
||||||
|
saveSymptom(this.symptom, date, nothingEntered ? null : valuesToSave)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
this.autoSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleState = (key) => {
|
toggleState = (key) => {
|
||||||
@@ -35,17 +60,20 @@ export default class Mood extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 1 }}>
|
<SymptomView
|
||||||
<ScrollView style={styles.page}>
|
symptom={this.symptom}
|
||||||
<SymptomSection
|
values={this.state}
|
||||||
explainer={labels.explainer}
|
date={this.props.date}
|
||||||
>
|
>
|
||||||
<SelectBoxGroup
|
<SymptomSection
|
||||||
labels={labels.categories}
|
explainer={labels.explainer}
|
||||||
onSelect={this.toggleState}
|
>
|
||||||
optionsState={this.state}
|
<SelectBoxGroup
|
||||||
/>
|
labels={labels.categories}
|
||||||
{ this.state.other &&
|
onSelect={this.toggleState}
|
||||||
|
optionsState={this.state}
|
||||||
|
/>
|
||||||
|
{ this.state.other &&
|
||||||
<TextInput
|
<TextInput
|
||||||
autoFocus={this.state.focusTextArea}
|
autoFocus={this.state.focusTextArea}
|
||||||
multiline={true}
|
multiline={true}
|
||||||
@@ -55,24 +83,11 @@ export default class Mood extends Component {
|
|||||||
this.setState({note: val})
|
this.setState({note: val})
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
</SymptomSection>
|
</SymptomSection>
|
||||||
</ScrollView>
|
</SymptomView>
|
||||||
<ActionButtonFooter
|
|
||||||
symptom='mood'
|
|
||||||
date={this.props.date}
|
|
||||||
currentSymptomValue={this.state}
|
|
||||||
saveAction={() => {
|
|
||||||
const copyOfState = Object.assign({}, this.state)
|
|
||||||
if (!copyOfState.other) {
|
|
||||||
copyOfState.note = null
|
|
||||||
}
|
|
||||||
saveSymptom('mood', this.props.date, copyOfState)
|
|
||||||
}}
|
|
||||||
saveDisabled={Object.values(this.state).every(value => !value)}
|
|
||||||
navigate={this.props.navigate}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Mood
|
||||||
|
|||||||
@@ -1,95 +1,104 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import {
|
import { Switch } from 'react-native'
|
||||||
View,
|
import PropTypes from 'prop-types'
|
||||||
Switch,
|
|
||||||
ScrollView
|
|
||||||
} from 'react-native'
|
|
||||||
import styles from '../../../styles'
|
|
||||||
import { saveSymptom } from '../../../db'
|
|
||||||
import { mucus as labels } from '../../../i18n/en/cycle-day'
|
import { mucus as labels } from '../../../i18n/en/cycle-day'
|
||||||
import computeNfpValue from '../../../lib/nfp-mucus'
|
import computeNfpValue from '../../../lib/nfp-mucus'
|
||||||
import ActionButtonFooter from './action-button-footer'
|
|
||||||
import SelectTabGroup from '../select-tab-group'
|
import SelectTabGroup from '../select-tab-group'
|
||||||
import SymptomSection from './symptom-section'
|
import SymptomSection from './symptom-section'
|
||||||
import { ActionHint } from '../../app-text'
|
import SymptomView from './symptom-view'
|
||||||
|
|
||||||
|
import { getLabelsList } from '../../helpers/labels'
|
||||||
|
import { saveSymptom } from '../../../db'
|
||||||
|
|
||||||
|
class Mucus extends Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
cycleDay: PropTypes.object,
|
||||||
|
date: PropTypes.string.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
export default class Mucus extends Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
const cycleDay = props.cycleDay
|
const symptom = 'mucus'
|
||||||
this.mucus = cycleDay && cycleDay.mucus
|
const { cycleDay } = props
|
||||||
this.makeActionButtons = props.makeActionButtons
|
|
||||||
this.state = this.mucus ? this.mucus : {}
|
const defaultSymptomData = {}
|
||||||
|
|
||||||
|
const symptomData =
|
||||||
|
cycleDay && cycleDay[symptom] ? cycleDay[symptom] : defaultSymptomData
|
||||||
|
|
||||||
|
this.state = { ...symptomData }
|
||||||
|
|
||||||
|
this.mucusFeeling = getLabelsList(labels.feeling.categories)
|
||||||
|
this.mucusTexture = getLabelsList(labels.texture.categories)
|
||||||
|
|
||||||
|
this.symptom = symptom
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldAutoSave = () => {
|
||||||
|
const { date } = this.props
|
||||||
|
const nothingEntered = ['feeling', 'texture'].every(
|
||||||
|
val => typeof this.state[val] !== 'number'
|
||||||
|
)
|
||||||
|
const { feeling, texture, exclude} = this.state
|
||||||
|
const valuesToSave = {
|
||||||
|
feeling,
|
||||||
|
texture,
|
||||||
|
value: computeNfpValue(feeling, texture),
|
||||||
|
exclude: Boolean(exclude)
|
||||||
|
}
|
||||||
|
saveSymptom(this.symptom, date, nothingEntered ? null : valuesToSave)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
this.shouldAutoSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const mucusFeeling = [
|
// TODO leaving this info for notice when leaving incomplete data
|
||||||
{ label: labels.feeling.categories[0], value: 0 },
|
// const mandatoryNotCompletedYet = typeof this.state.feeling != 'number' || typeof this.state.texture != 'number'
|
||||||
{ label: labels.feeling.categories[1], value: 1 },
|
|
||||||
{ label: labels.feeling.categories[2], value: 2 },
|
|
||||||
{ label: labels.feeling.categories[3], value: 3 }
|
|
||||||
]
|
|
||||||
const mucusTexture = [
|
|
||||||
{ label: labels.texture.categories[0], value: 0 },
|
|
||||||
{ label: labels.texture.categories[1], value: 1 },
|
|
||||||
{ label: labels.texture.categories[2], value: 2 }
|
|
||||||
]
|
|
||||||
const mandatoryNotCompletedYet = typeof this.state.feeling != 'number' || typeof this.state.texture != 'number'
|
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 1 }}>
|
<SymptomView
|
||||||
<ScrollView style={styles.page}>
|
symptom={this.symptom}
|
||||||
<SymptomSection
|
values={this.state}
|
||||||
header='Feeling'
|
date={this.props.date}
|
||||||
explainer={labels.feeling.explainer}
|
>
|
||||||
>
|
<SymptomSection
|
||||||
<SelectTabGroup
|
header='Feeling'
|
||||||
buttons={mucusFeeling}
|
explainer={labels.feeling.explainer}
|
||||||
onSelect={val => this.setState({ feeling: val })}
|
>
|
||||||
active={this.state.feeling}
|
<SelectTabGroup
|
||||||
/>
|
buttons={this.mucusFeeling}
|
||||||
</SymptomSection>
|
onSelect={val => this.setState({ feeling: val })}
|
||||||
<SymptomSection
|
active={this.state.feeling}
|
||||||
header='Texture'
|
/>
|
||||||
explainer={labels.texture.explainer}
|
</SymptomSection>
|
||||||
>
|
<SymptomSection
|
||||||
<SelectTabGroup
|
header='Texture'
|
||||||
buttons={mucusTexture}
|
explainer={labels.texture.explainer}
|
||||||
onSelect={val => this.setState({ texture: val })}
|
>
|
||||||
active={this.state.texture}
|
<SelectTabGroup
|
||||||
/>
|
buttons={this.mucusTexture}
|
||||||
</SymptomSection>
|
onSelect={val => this.setState({ texture: val })}
|
||||||
<SymptomSection
|
active={this.state.texture}
|
||||||
header="Exclude"
|
/>
|
||||||
explainer={labels.excludeExplainer}
|
</SymptomSection>
|
||||||
inline={true}
|
<SymptomSection
|
||||||
>
|
header="Exclude"
|
||||||
<Switch
|
explainer={labels.excludeExplainer}
|
||||||
onValueChange={(val) => {
|
inline={true}
|
||||||
this.setState({ exclude: val })
|
>
|
||||||
}}
|
<Switch
|
||||||
value={this.state.exclude}
|
onValueChange={(val) => {
|
||||||
/>
|
this.setState({ exclude: val })
|
||||||
</SymptomSection>
|
}}
|
||||||
</ScrollView>
|
value={this.state.exclude}
|
||||||
<ActionHint isVisible={mandatoryNotCompletedYet}>{labels.actionHint}</ActionHint>
|
/>
|
||||||
<ActionButtonFooter
|
</SymptomSection>
|
||||||
symptom='mucus'
|
</SymptomView>
|
||||||
date={this.props.date}
|
|
||||||
currentSymptomValue={this.mucus}
|
|
||||||
saveAction={() => {
|
|
||||||
const feeling = this.state.feeling
|
|
||||||
const texture = this.state.texture
|
|
||||||
saveSymptom('mucus', this.props.date, {
|
|
||||||
feeling,
|
|
||||||
texture,
|
|
||||||
value: computeNfpValue(feeling, texture),
|
|
||||||
exclude: Boolean(this.state.exclude)
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
saveDisabled={mandatoryNotCompletedYet}
|
|
||||||
navigate={this.props.navigate}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Mucus
|
||||||
|
|||||||
@@ -1,60 +1,65 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import {
|
import PropTypes from 'prop-types'
|
||||||
View,
|
import { TextInput } from 'react-native'
|
||||||
ScrollView,
|
|
||||||
TextInput,
|
|
||||||
} from 'react-native'
|
|
||||||
|
|
||||||
import styles from '../../../styles'
|
|
||||||
import { saveSymptom } from '../../../db'
|
|
||||||
import ActionButtonFooter from './action-button-footer'
|
|
||||||
import SymptomSection from './symptom-section'
|
import SymptomSection from './symptom-section'
|
||||||
import { noteExplainer } from '../../../i18n/en/cycle-day'
|
import { noteExplainer } from '../../../i18n/en/cycle-day'
|
||||||
import { shared as sharedLabels } from '../../../i18n/en/labels'
|
import { shared as sharedLabels } from '../../../i18n/en/labels'
|
||||||
|
import SymptomView from './symptom-view'
|
||||||
|
|
||||||
|
import { saveSymptom } from '../../../db'
|
||||||
|
|
||||||
|
class Note extends Component {
|
||||||
|
static propTypes = {
|
||||||
|
cycleDay: PropTypes.object,
|
||||||
|
date: PropTypes.string.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
export default class Note extends Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
const cycleDay = props.cycleDay
|
const symptom = 'note'
|
||||||
this.note = cycleDay && cycleDay.note
|
const { cycleDay } = props
|
||||||
this.makeActionButtons = props.makeActionButtons
|
|
||||||
|
|
||||||
this.state = {
|
const defaultSymptomData = { value: '' }
|
||||||
currentValue: this.note && this.note.value || ''
|
|
||||||
}
|
const symptomData =
|
||||||
|
cycleDay && cycleDay[symptom] ? cycleDay[symptom] : defaultSymptomData
|
||||||
|
|
||||||
|
this.state = { ...symptomData }
|
||||||
|
|
||||||
|
this.symptom = symptom
|
||||||
|
}
|
||||||
|
|
||||||
|
autoSave = () => {
|
||||||
|
const { date } = this.props
|
||||||
|
const valuesToSave = { ...this.state }
|
||||||
|
saveSymptom(this.symptom, date, this.state.value ? valuesToSave : null)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
this.autoSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 1 }}>
|
<SymptomView
|
||||||
<ScrollView style={styles.page}>
|
symptom={this.symptom}
|
||||||
<SymptomSection
|
values={this.state}
|
||||||
explainer={noteExplainer}
|
date={this.props.date}
|
||||||
>
|
>
|
||||||
<TextInput
|
<SymptomSection explainer={noteExplainer} >
|
||||||
autoFocus={!this.state.currentValue}
|
<TextInput
|
||||||
multiline={true}
|
autoFocus={true}
|
||||||
placeholder={sharedLabels.enter}
|
multiline={true}
|
||||||
onChangeText={(val) => {
|
placeholder={sharedLabels.enter}
|
||||||
this.setState({ currentValue: val })
|
onChangeText={(val) => { this.setState({ value: val })}}
|
||||||
}}
|
value={this.state.value}
|
||||||
value={this.state.currentValue}
|
testID='noteInput'
|
||||||
/>
|
/>
|
||||||
</SymptomSection>
|
</SymptomSection>
|
||||||
</ScrollView>
|
</SymptomView>
|
||||||
<ActionButtonFooter
|
|
||||||
symptom='note'
|
|
||||||
date={this.props.date}
|
|
||||||
currentSymptomValue={this.note}
|
|
||||||
saveAction={() => {
|
|
||||||
saveSymptom('note', this.props.date, {
|
|
||||||
value: this.state.currentValue
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
saveDisabled={!this.state.currentValue}
|
|
||||||
navigate={this.props.navigate}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Note
|
||||||
|
|||||||
@@ -1,29 +1,54 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import {
|
import { TextInput } from 'react-native'
|
||||||
ScrollView,
|
import PropTypes from 'prop-types'
|
||||||
TextInput,
|
|
||||||
View
|
|
||||||
} from 'react-native'
|
|
||||||
import { saveSymptom } from '../../../db'
|
|
||||||
import { pain as labels } from '../../../i18n/en/cycle-day'
|
import { pain as labels } from '../../../i18n/en/cycle-day'
|
||||||
import { shared as sharedLabels } from '../../../i18n/en/labels'
|
import { shared as sharedLabels } from '../../../i18n/en/labels'
|
||||||
import ActionButtonFooter from './action-button-footer'
|
|
||||||
import SelectBoxGroup from '../select-box-group'
|
import SelectBoxGroup from '../select-box-group'
|
||||||
import SymptomSection from './symptom-section'
|
import SymptomSection from './symptom-section'
|
||||||
import styles from '../../../styles'
|
import SymptomView from './symptom-view'
|
||||||
|
|
||||||
|
import { saveSymptom } from '../../../db'
|
||||||
|
|
||||||
|
class Pain extends Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
cycleDay: PropTypes.object,
|
||||||
|
date: PropTypes.string.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
export default class Pain extends Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
const cycleDay = props.cycleDay
|
const symptom = 'pain'
|
||||||
if (cycleDay && cycleDay.pain) {
|
const { cycleDay } = props
|
||||||
this.state = Object.assign({}, cycleDay.pain)
|
|
||||||
} else {
|
const defaultSymptomData = {}
|
||||||
this.state = {}
|
|
||||||
}
|
const symptomData =
|
||||||
if (this.state.note) {
|
cycleDay && cycleDay[symptom] ? cycleDay[symptom] : defaultSymptomData
|
||||||
this.state.other = true
|
|
||||||
|
this.state = { ...symptomData }
|
||||||
|
|
||||||
|
// We make sure other is always true when there is a note,
|
||||||
|
// e.g. when import is messed up.
|
||||||
|
if (this.state.note) this.state.other = true
|
||||||
|
|
||||||
|
this.symptom = symptom
|
||||||
|
}
|
||||||
|
|
||||||
|
autoSave = () => {
|
||||||
|
const { date } = this.props
|
||||||
|
const valuesToSave = Object.assign({}, this.state)
|
||||||
|
if (!valuesToSave.other) {
|
||||||
|
valuesToSave.note = null
|
||||||
}
|
}
|
||||||
|
const nothingEntered = Object.values(this.state).every(val => !val)
|
||||||
|
|
||||||
|
saveSymptom(this.symptom, date, nothingEntered ? null : valuesToSave)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
this.autoSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleState = (key) => {
|
toggleState = (key) => {
|
||||||
@@ -36,17 +61,20 @@ export default class Pain extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 1 }}>
|
<SymptomView
|
||||||
<ScrollView style={styles.page}>
|
symptom={this.symptom}
|
||||||
<SymptomSection
|
values={this.state}
|
||||||
explainer={labels.explainer}
|
date={this.props.date}
|
||||||
>
|
>
|
||||||
<SelectBoxGroup
|
<SymptomSection
|
||||||
labels={labels.categories}
|
explainer={labels.explainer}
|
||||||
onSelect={this.toggleState}
|
>
|
||||||
optionsState={this.state}
|
<SelectBoxGroup
|
||||||
/>
|
labels={labels.categories}
|
||||||
{ this.state.other &&
|
onSelect={this.toggleState}
|
||||||
|
optionsState={this.state}
|
||||||
|
/>
|
||||||
|
{ this.state.other &&
|
||||||
<TextInput
|
<TextInput
|
||||||
autoFocus={this.state.focusTextArea}
|
autoFocus={this.state.focusTextArea}
|
||||||
multiline={true}
|
multiline={true}
|
||||||
@@ -56,24 +84,11 @@ export default class Pain extends Component {
|
|||||||
this.setState({note: val})
|
this.setState({note: val})
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
</SymptomSection>
|
</SymptomSection>
|
||||||
</ScrollView>
|
</SymptomView>
|
||||||
<ActionButtonFooter
|
|
||||||
symptom='pain'
|
|
||||||
date={this.props.date}
|
|
||||||
currentSymptomValue={this.state}
|
|
||||||
saveAction={() => {
|
|
||||||
const copyOfState = Object.assign({}, this.state)
|
|
||||||
if (!copyOfState.other) {
|
|
||||||
copyOfState.note = null
|
|
||||||
}
|
|
||||||
saveSymptom('pain', this.props.date, copyOfState)
|
|
||||||
}}
|
|
||||||
saveDisabled={Object.values(this.state).every(value => !value)}
|
|
||||||
navigate={this.props.navigate}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Pain
|
||||||
|
|||||||
@@ -1,65 +1,97 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import {
|
import { TextInput } from 'react-native'
|
||||||
TextInput,
|
import PropTypes from 'prop-types'
|
||||||
View,
|
|
||||||
ScrollView
|
|
||||||
} from 'react-native'
|
|
||||||
import styles from '../../../styles'
|
|
||||||
import { saveSymptom } from '../../../db'
|
|
||||||
import { sex as sexLabels, contraceptives as contraceptivesLabels } from '../../../i18n/en/cycle-day'
|
import { sex as sexLabels, contraceptives as contraceptivesLabels } from '../../../i18n/en/cycle-day'
|
||||||
import { shared as sharedLabels } from '../../../i18n/en/labels'
|
import { shared as sharedLabels } from '../../../i18n/en/labels'
|
||||||
import ActionButtonFooter from './action-button-footer'
|
|
||||||
import SelectBoxGroup from '../select-box-group'
|
import SelectBoxGroup from '../select-box-group'
|
||||||
import SymptomSection from './symptom-section'
|
import SymptomSection from './symptom-section'
|
||||||
|
import SymptomView from './symptom-view'
|
||||||
|
|
||||||
|
import { saveSymptom } from '../../../db'
|
||||||
|
|
||||||
|
class Sex extends Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
cycleDay: PropTypes.object,
|
||||||
|
date: PropTypes.string.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
export default class Sex extends Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
const cycleDay = props.cycleDay
|
const symptom = 'sex'
|
||||||
if (cycleDay && cycleDay.sex) {
|
const { cycleDay } = props
|
||||||
this.state = Object.assign({}, cycleDay.sex)
|
|
||||||
} else {
|
const defaultSymptomData = {}
|
||||||
this.state = {}
|
|
||||||
}
|
const symptomData =
|
||||||
|
cycleDay && cycleDay[symptom] ? cycleDay[symptom] : defaultSymptomData
|
||||||
|
|
||||||
|
this.state = { ...symptomData }
|
||||||
|
|
||||||
// We make sure other is always true when there is a note,
|
// We make sure other is always true when there is a note,
|
||||||
// e.g. when import is messed up.
|
// e.g. when import is messed up.
|
||||||
if (this.state.note) this.state.other = true
|
if (this.state.note) this.state.other = true
|
||||||
|
|
||||||
|
this.symptom = symptom
|
||||||
|
}
|
||||||
|
|
||||||
|
autoSave = () => {
|
||||||
|
const { date } = this.props
|
||||||
|
const valuesToSave = Object.assign({}, this.state)
|
||||||
|
if (!valuesToSave.other) {
|
||||||
|
valuesToSave.note = null
|
||||||
|
}
|
||||||
|
const nothingEntered = Object.values(this.state).every(val => !val)
|
||||||
|
|
||||||
|
saveSymptom(this.symptom, date, nothingEntered ? null : valuesToSave)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
this.autoSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleState = (key) => {
|
toggleState = (key) => {
|
||||||
const curr = this.state[key]
|
const curr = this.state[key]
|
||||||
this.setState({[key]: !curr})
|
this.setState({[key]: !curr})
|
||||||
if (key === 'other' && !curr) {
|
if (key === 'other'){
|
||||||
this.setState({focusTextArea: true})
|
if (curr){
|
||||||
|
this.setState({note: ""})
|
||||||
|
} else {
|
||||||
|
this.setState({focusTextArea: true})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 1 }}>
|
<SymptomView
|
||||||
<ScrollView style={styles.page}>
|
symptom={this.symptom}
|
||||||
<SymptomSection
|
values={this.state}
|
||||||
header={sexLabels.header}
|
date={this.props.date}
|
||||||
explainer={sexLabels.explainer}
|
>
|
||||||
>
|
<SymptomSection
|
||||||
<SelectBoxGroup
|
header={sexLabels.header}
|
||||||
labels={sexLabels.categories}
|
explainer={sexLabels.explainer}
|
||||||
onSelect={this.toggleState}
|
>
|
||||||
optionsState={this.state}
|
<SelectBoxGroup
|
||||||
/>
|
labels={sexLabels.categories}
|
||||||
</SymptomSection>
|
onSelect={this.toggleState}
|
||||||
<SymptomSection
|
optionsState={this.state}
|
||||||
header={contraceptivesLabels.header}
|
/>
|
||||||
explainer={contraceptivesLabels.explainer}
|
</SymptomSection>
|
||||||
>
|
<SymptomSection
|
||||||
<SelectBoxGroup
|
header={contraceptivesLabels.header}
|
||||||
labels={contraceptivesLabels.categories}
|
explainer={contraceptivesLabels.explainer}
|
||||||
onSelect={this.toggleState}
|
>
|
||||||
optionsState={this.state}
|
<SelectBoxGroup
|
||||||
/>
|
labels={contraceptivesLabels.categories}
|
||||||
</SymptomSection>
|
onSelect={this.toggleState}
|
||||||
|
optionsState={this.state}
|
||||||
|
/>
|
||||||
|
</SymptomSection>
|
||||||
|
|
||||||
{this.state.other &&
|
{this.state.other &&
|
||||||
<TextInput
|
<TextInput
|
||||||
autoFocus={this.state.focusTextArea}
|
autoFocus={this.state.focusTextArea}
|
||||||
multiline={true}
|
multiline={true}
|
||||||
@@ -69,23 +101,10 @@ export default class Sex extends Component {
|
|||||||
this.setState({ note: val })
|
this.setState({ note: val })
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
</ScrollView>
|
</SymptomView>
|
||||||
<ActionButtonFooter
|
|
||||||
symptom='sex'
|
|
||||||
date={this.props.date}
|
|
||||||
currentSymptomValue={this.state}
|
|
||||||
saveAction={() => {
|
|
||||||
const copyOfState = Object.assign({}, this.state)
|
|
||||||
if (!copyOfState.other) {
|
|
||||||
copyOfState.note = null
|
|
||||||
}
|
|
||||||
saveSymptom('sex', this.props.date, copyOfState)
|
|
||||||
}}
|
|
||||||
saveDisabled={Object.values(this.state).every(value => !value)}
|
|
||||||
navigate={this.props.navigate}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Sex
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import React, { Component } from 'react'
|
||||||
|
import { TouchableOpacity } from 'react-native'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import Icon from 'react-native-vector-icons/Entypo'
|
||||||
|
|
||||||
|
import InfoPopUp from './info-symptom'
|
||||||
|
|
||||||
|
import styles, { iconStyles } from '../../../styles'
|
||||||
|
|
||||||
|
export default class SymptomInfo extends Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
symptom: PropTypes.string
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
this.state = { showInfo: false }
|
||||||
|
}
|
||||||
|
|
||||||
|
showInfo = () => this.setState({ showInfo: true })
|
||||||
|
|
||||||
|
hideInfo = () => this.setState({ showInfo: false })
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={this.showInfo}
|
||||||
|
style={styles.infoButtonSymptomView}
|
||||||
|
testID="symptomInfoButton"
|
||||||
|
>
|
||||||
|
<Icon name="info-with-circle" style={iconStyles.info} />
|
||||||
|
</TouchableOpacity>
|
||||||
|
{ this.state.showInfo &&
|
||||||
|
<InfoPopUp symptom={this.props.symptom} close={this.hideInfo} />
|
||||||
|
}
|
||||||
|
</React.Fragment>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { View } from 'react-native'
|
import { View } from 'react-native'
|
||||||
import AppText, { SymptomSectionHeader } from '../../app-text'
|
import AppText from '../../app-text'
|
||||||
|
import styles from '../../../styles'
|
||||||
|
|
||||||
export default class SymptomSection extends Component {
|
export default class SymptomSection extends Component {
|
||||||
render() {
|
render() {
|
||||||
@@ -13,16 +14,20 @@ export default class SymptomSection extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<View style={placeHeadingInline}>
|
<View style={[placeHeadingInline, styles.symptomSection]}>
|
||||||
<SymptomSectionHeader flex={1}>{p.header}</SymptomSectionHeader>
|
{ p.header &&
|
||||||
|
<AppText style={styles.symptomViewHeading}>{p.header}</AppText>
|
||||||
|
}
|
||||||
<View
|
<View
|
||||||
flexDirection={p.inline ? 'row' : null}
|
flexDirection={p.inline ? 'row' : null}
|
||||||
flex={1}
|
flex={1}
|
||||||
alignItems={p.inline ? 'center' : null}
|
alignItems={p.inline ? 'center' : null}
|
||||||
>
|
>
|
||||||
<View flex={1}>
|
{ p.explainer && (
|
||||||
<AppText>{p.explainer}</AppText>
|
<View flex={1}>
|
||||||
</View>
|
<AppText>{p.explainer}</AppText>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
{p.children}
|
{p.children}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -0,0 +1,117 @@
|
|||||||
|
import React, { Component } from 'react'
|
||||||
|
import { ScrollView, View, Alert } from 'react-native'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
import { connect } from 'react-redux'
|
||||||
|
import { getDate } from '../../../slices/date'
|
||||||
|
import { goBack } from '../../../slices/navigation'
|
||||||
|
|
||||||
|
import { saveSymptom } from '../../../db'
|
||||||
|
import formatDate from '../../helpers/format-date'
|
||||||
|
|
||||||
|
import Header from '../../header'
|
||||||
|
import SymptomInfo from './symptom-info'
|
||||||
|
|
||||||
|
import { headerTitles } from '../../../i18n/en/labels'
|
||||||
|
import { sharedDialogs } from '../../../i18n/en/cycle-day'
|
||||||
|
|
||||||
|
import styles from '../../../styles'
|
||||||
|
|
||||||
|
const checkIfHasValues = data => {
|
||||||
|
const isMeaningfulValue = value => value || value === 0
|
||||||
|
return Object.values(data).some(isMeaningfulValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
class SymptomView extends Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
symptom: PropTypes.string.isRequired,
|
||||||
|
values: PropTypes.object,
|
||||||
|
date: PropTypes.string,
|
||||||
|
children: PropTypes.node,
|
||||||
|
goBack: PropTypes.func,
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super()
|
||||||
|
this.state = {
|
||||||
|
shouldShowDelete: checkIfHasValues(props.values)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
const shouldShowDelete = checkIfHasValues(this.props.values)
|
||||||
|
if (shouldShowDelete !== this.state.shouldShowDelete) {
|
||||||
|
this.setState({ shouldShowDelete })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteSymptomEntry() {
|
||||||
|
const { symptom, date } = this.props
|
||||||
|
saveSymptom(symptom, date, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
onDeleteConfirmation = () => {
|
||||||
|
this.deleteSymptomEntry()
|
||||||
|
this.props.goBack()
|
||||||
|
}
|
||||||
|
|
||||||
|
showConfirmationAlert = () => {
|
||||||
|
|
||||||
|
const cancelButton = {
|
||||||
|
text: sharedDialogs.cancel,
|
||||||
|
style: 'cancel'
|
||||||
|
}
|
||||||
|
|
||||||
|
const confirmationButton = {
|
||||||
|
text: sharedDialogs.reallyDeleteData,
|
||||||
|
onPress: this.onDeleteConfirmation
|
||||||
|
}
|
||||||
|
|
||||||
|
return Alert.alert(
|
||||||
|
sharedDialogs.areYouSureTitle,
|
||||||
|
sharedDialogs.areYouSureToDelete,
|
||||||
|
[cancelButton, confirmationButton]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { symptom, date, goBack } = this.props
|
||||||
|
const { shouldShowDelete } = this.state
|
||||||
|
const handleDelete = shouldShowDelete ? this.showConfirmationAlert : null
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={{flex: 1}}>
|
||||||
|
<Header
|
||||||
|
title={headerTitles[symptom]}
|
||||||
|
subtitle={formatDate(date)}
|
||||||
|
handleBack={goBack}
|
||||||
|
handleDelete={handleDelete}
|
||||||
|
/>
|
||||||
|
<View flex={1}>
|
||||||
|
<ScrollView style={styles.page}>
|
||||||
|
{this.props.children}
|
||||||
|
</ScrollView>
|
||||||
|
<SymptomInfo symptom={symptom} />
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => {
|
||||||
|
return({
|
||||||
|
date: getDate(state),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => {
|
||||||
|
return({
|
||||||
|
goBack: () => dispatch(goBack()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(
|
||||||
|
mapStateToProps,
|
||||||
|
mapDispatchToProps,
|
||||||
|
)(SymptomView)
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
import React, { Component } from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
import { View } from 'react-native'
|
||||||
|
import AppText from '../../app-text'
|
||||||
|
import AppTextInput from '../../app-text-input'
|
||||||
|
|
||||||
|
import { temperature as labels } from '../../../i18n/en/cycle-day'
|
||||||
|
|
||||||
|
import styles from '../../../styles'
|
||||||
|
|
||||||
|
import { getPreviousTemperature } from '../../../db'
|
||||||
|
import { scaleObservable } from '../../../local-storage'
|
||||||
|
import config from '../../../config'
|
||||||
|
|
||||||
|
export default class TemperatureInput extends Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
temperature: PropTypes.string,
|
||||||
|
handleTemperatureChange: PropTypes.func,
|
||||||
|
date: PropTypes.string,
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props)
|
||||||
|
|
||||||
|
let shouldShowSuggestion = false
|
||||||
|
let suggestedTemperature = null
|
||||||
|
|
||||||
|
if (!props.temperature) {
|
||||||
|
const prevTemp = getPreviousTemperature(props.date)
|
||||||
|
if (prevTemp) {
|
||||||
|
shouldShowSuggestion = true
|
||||||
|
suggestedTemperature = prevTemp.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
temperature: props.temperature,
|
||||||
|
shouldShowSuggestion,
|
||||||
|
suggestedTemperature
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setTemperature = (temperature) => {
|
||||||
|
this.setState({
|
||||||
|
shouldShowSuggestion: false,
|
||||||
|
temperature
|
||||||
|
})
|
||||||
|
this.props.handleTemperatureChange(Number(temperature))
|
||||||
|
}
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const {
|
||||||
|
shouldShowSuggestion,
|
||||||
|
suggestedTemperature,
|
||||||
|
temperature
|
||||||
|
} = this.state
|
||||||
|
const inputStyle = [
|
||||||
|
styles.temperatureTextInput,
|
||||||
|
shouldShowSuggestion ? styles.temperatureTextInputSuggestion : null
|
||||||
|
]
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<View style={styles.framedSegmentInlineChildren}>
|
||||||
|
<AppTextInput
|
||||||
|
style={inputStyle}
|
||||||
|
autoFocus={true}
|
||||||
|
value={shouldShowSuggestion ? suggestedTemperature : temperature}
|
||||||
|
onChangeText={this.setTemperature}
|
||||||
|
keyboardType='numeric'
|
||||||
|
maxLength={5}
|
||||||
|
testID='temperatureInput'
|
||||||
|
/>
|
||||||
|
<AppText style={{ marginLeft: 5 }}>°C</AppText>
|
||||||
|
</View>
|
||||||
|
<OutOfRangeWarning temperature={this.props.temperature} />
|
||||||
|
</React.Fragment>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const OutOfRangeWarning = ({ temperature }) => {
|
||||||
|
if (temperature === '') {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = Number(temperature)
|
||||||
|
const { min, max } = config.temperatureScale
|
||||||
|
const range = { min, max }
|
||||||
|
const scale = scaleObservable.value
|
||||||
|
|
||||||
|
let warningMsg
|
||||||
|
|
||||||
|
if (value < range.min || value > range.max) {
|
||||||
|
warningMsg = labels.outOfAbsoluteRangeWarning
|
||||||
|
} else if (value < scale.min || value > scale.max) {
|
||||||
|
warningMsg = labels.outOfRangeWarning
|
||||||
|
} else {
|
||||||
|
warningMsg = null
|
||||||
|
}
|
||||||
|
|
||||||
|
return <AppText style={styles.hint}>{warningMsg}</AppText>
|
||||||
|
}
|
||||||
|
|
||||||
|
OutOfRangeWarning.propTypes = {
|
||||||
|
temperature: PropTypes.string.isRequired
|
||||||
|
}
|
||||||
@@ -1,213 +1,139 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import {
|
import { Switch } from 'react-native'
|
||||||
View,
|
import PropTypes from 'prop-types'
|
||||||
TextInput,
|
|
||||||
Switch,
|
|
||||||
Keyboard,
|
|
||||||
Alert,
|
|
||||||
ScrollView
|
|
||||||
} from 'react-native'
|
|
||||||
import DateTimePicker from 'react-native-modal-datetime-picker-nevo'
|
|
||||||
import padWithZeros from '../../helpers/pad-time-with-zeros'
|
|
||||||
|
|
||||||
import { getPreviousTemperature, saveSymptom } from '../../../db'
|
|
||||||
import styles from '../../../styles'
|
|
||||||
import { LocalTime, ChronoUnit } from 'js-joda'
|
import { LocalTime, ChronoUnit } from 'js-joda'
|
||||||
import { temperature as labels } from '../../../i18n/en/cycle-day'
|
import { temperature as labels } from '../../../i18n/en/cycle-day'
|
||||||
import { scaleObservable } from '../../../local-storage'
|
|
||||||
import { shared as sharedLabels } from '../../../i18n/en/labels'
|
import { shared as sharedLabels } from '../../../i18n/en/labels'
|
||||||
import ActionButtonFooter from './action-button-footer'
|
|
||||||
import config from '../../../config'
|
import AppTextInput from '../../app-text-input'
|
||||||
import SymptomSection from './symptom-section'
|
import SymptomSection from './symptom-section'
|
||||||
|
import SymptomView from './symptom-view'
|
||||||
|
import TimeInput from './time-input'
|
||||||
|
import TemperatureInput from './temperature-input'
|
||||||
|
|
||||||
|
import { saveSymptom } from '../../../db'
|
||||||
|
|
||||||
const minutes = ChronoUnit.MINUTES
|
const minutes = ChronoUnit.MINUTES
|
||||||
|
|
||||||
export default class Temp extends Component {
|
class Temperature extends Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
cycleDay: PropTypes.object,
|
||||||
|
date: PropTypes.string.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
const cycleDay = props.cycleDay
|
const symptom = 'temperature'
|
||||||
this.temperature = cycleDay && cycleDay.temperature
|
const { cycleDay } = props
|
||||||
this.makeActionButtons = props.makeActionButtons
|
|
||||||
|
|
||||||
const temp = this.temperature
|
const defaultSymptomData = {
|
||||||
|
time: LocalTime.now().truncatedTo(minutes).toString(),
|
||||||
this.state = {
|
temperature: null,
|
||||||
exclude: temp ? temp.exclude : false,
|
note: '',
|
||||||
time: temp ? temp.time : LocalTime.now().truncatedTo(minutes).toString(),
|
exclude: false
|
||||||
isTimePickerVisible: false,
|
|
||||||
outOfRange: null,
|
|
||||||
note: temp ? temp.note : null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (temp) {
|
const symptomData =
|
||||||
this.state.temperature = temp.value.toString()
|
cycleDay && cycleDay[symptom] ? cycleDay[symptom] : defaultSymptomData
|
||||||
if (temp.value === Math.floor(temp.value)) {
|
|
||||||
this.state.temperature = `${this.state.temperature}.0`
|
const { value, ...restSymptomData } = symptomData
|
||||||
}
|
this.state = { temperature: value, ...restSymptomData }
|
||||||
} else {
|
|
||||||
const prevTemp = getPreviousTemperature(this.props.date)
|
this.symptom = symptom
|
||||||
if (prevTemp) {
|
|
||||||
this.state.temperature = prevTemp.toString()
|
|
||||||
this.state.isSuggestion = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
saveTemperature = () => {
|
isDeleteIconActive() {
|
||||||
const dataToSave = {
|
return ['temperature', 'note', 'exclude'].some(key => {
|
||||||
value: Number(this.state.temperature),
|
// the time is always and the suggested temp sometimes prefilled, so they're not relevant for setting
|
||||||
exclude: this.state.exclude,
|
// the delete button active.
|
||||||
time: this.state.time,
|
return this.state[key] || this.state[key] === 0
|
||||||
note: this.state.note
|
})
|
||||||
}
|
|
||||||
saveSymptom('temperature', this.props.date, dataToSave)
|
|
||||||
this.props.navigate('CycleDay', {date: this.props.date})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkRangeAndSave = () => {
|
autoSave = () => {
|
||||||
const value = Number(this.state.temperature)
|
const { date } = this.props
|
||||||
|
const { temperature, exclude, time, note } = this.state
|
||||||
|
|
||||||
const absolute = {
|
const valuesToSave = {
|
||||||
min: config.temperatureScale.min,
|
value: temperature,
|
||||||
max: config.temperatureScale.max
|
exclude,
|
||||||
}
|
time,
|
||||||
const scale = scaleObservable.value
|
note
|
||||||
let warningMsg
|
|
||||||
if (value < absolute.min || value > absolute.max) {
|
|
||||||
warningMsg = labels.outOfAbsoluteRangeWarning
|
|
||||||
} else if (value < scale.min || value > scale.max) {
|
|
||||||
warningMsg = labels.outOfRangeWarning
|
|
||||||
}
|
|
||||||
|
|
||||||
if (warningMsg) {
|
|
||||||
Alert.alert(
|
|
||||||
sharedLabels.warning,
|
|
||||||
warningMsg,
|
|
||||||
[
|
|
||||||
{ text: sharedLabels.cancel },
|
|
||||||
{ text: sharedLabels.save, onPress: this.saveTemperature}
|
|
||||||
]
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
this.saveTemperature()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveSymptom(this.symptom, date, temperature ? valuesToSave : null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTime = (time) => {
|
||||||
|
this.setState({ time })
|
||||||
|
}
|
||||||
|
|
||||||
|
setTemperature = (temperature) => {
|
||||||
|
this.setState({ temperature })
|
||||||
|
}
|
||||||
|
|
||||||
|
setNote = (note) => {
|
||||||
|
this.setState({ note })
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
this.autoSave()
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { temperature } = this.state
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 1 }}>
|
<SymptomView
|
||||||
<ScrollView style={styles.page}>
|
symptom={'temperature'}
|
||||||
<View>
|
values={this.state}
|
||||||
<SymptomSection
|
date={this.props.date}
|
||||||
header={labels.temperature.header}
|
>
|
||||||
explainer={labels.temperature.explainer}
|
<SymptomSection
|
||||||
inline={true}
|
header={labels.temperature.header}
|
||||||
>
|
explainer={labels.temperature.explainer}
|
||||||
<TempInput
|
>
|
||||||
value={this.state.temperature}
|
<TemperatureInput
|
||||||
setState={(val) => this.setState(val)}
|
temperature={temperature ? temperature.toFixed(2) : ''}
|
||||||
isSuggestion={this.state.isSuggestion}
|
date={this.props.date}
|
||||||
/>
|
handleTemperatureChange={this.setTemperature}
|
||||||
</SymptomSection>
|
/>
|
||||||
<SymptomSection
|
</SymptomSection>
|
||||||
header={labels.time}
|
<SymptomSection header={labels.time}>
|
||||||
inline={true}
|
<TimeInput
|
||||||
>
|
time={this.state.time}
|
||||||
<TextInput
|
handleTimeChange={this.setTime}
|
||||||
style={styles.temperatureTextInput}
|
/>
|
||||||
onFocus={() => {
|
</SymptomSection>
|
||||||
Keyboard.dismiss()
|
<SymptomSection
|
||||||
this.setState({ isTimePickerVisible: true })
|
header={labels.note.header}
|
||||||
}}
|
explainer={labels.note.explainer}
|
||||||
value={this.state.time}
|
>
|
||||||
/>
|
<AppTextInput
|
||||||
<DateTimePicker
|
multiline={true}
|
||||||
mode="time"
|
placeholder={sharedLabels.enter}
|
||||||
isVisible={this.state.isTimePickerVisible}
|
value={this.state.note}
|
||||||
onConfirm={jsDate => {
|
onChangeText={this.setNote}
|
||||||
this.setState({
|
testID='noteInput'
|
||||||
time: padWithZeros(jsDate),
|
/>
|
||||||
isTimePickerVisible: false
|
</SymptomSection>
|
||||||
})
|
<SymptomSection
|
||||||
}}
|
header={labels.exclude.header}
|
||||||
onCancel={() => this.setState({ isTimePickerVisible: false })}
|
explainer={labels.exclude.explainer}
|
||||||
/>
|
inline={true}
|
||||||
</SymptomSection>
|
>
|
||||||
<SymptomSection
|
<Switch
|
||||||
header={labels.note.header}
|
onValueChange={(val) => {
|
||||||
explainer={labels.note.explainer}
|
this.setState({ exclude: val })
|
||||||
>
|
}}
|
||||||
<TextInput
|
value={this.state.exclude}
|
||||||
multiline={true}
|
/>
|
||||||
autoFocus={this.state.focusTextArea}
|
</SymptomSection>
|
||||||
placeholder={sharedLabels.enter}
|
</SymptomView>
|
||||||
value={this.state.note}
|
|
||||||
onChangeText={(val) => {
|
|
||||||
this.setState({ note: val })
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</SymptomSection>
|
|
||||||
<SymptomSection
|
|
||||||
header={labels.exclude.header}
|
|
||||||
explainer={labels.exclude.explainer}
|
|
||||||
inline={true}
|
|
||||||
>
|
|
||||||
<Switch
|
|
||||||
onValueChange={(val) => {
|
|
||||||
this.setState({ exclude: val })
|
|
||||||
}}
|
|
||||||
value={this.state.exclude}
|
|
||||||
/>
|
|
||||||
</SymptomSection>
|
|
||||||
</View>
|
|
||||||
</ScrollView>
|
|
||||||
<ActionButtonFooter
|
|
||||||
symptom='temperature'
|
|
||||||
date={this.props.date}
|
|
||||||
currentSymptomValue={this.temperature}
|
|
||||||
saveAction={() => this.checkRangeAndSave()}
|
|
||||||
saveDisabled={
|
|
||||||
this.state.temperature === '' ||
|
|
||||||
isNaN(Number(this.state.temperature)) ||
|
|
||||||
isInvalidTime(this.state.time)
|
|
||||||
}
|
|
||||||
navigate={this.props.navigate}
|
|
||||||
autoShowDayView={false}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TempInput extends Component {
|
export default Temperature
|
||||||
render() {
|
|
||||||
const style = [styles.temperatureTextInput]
|
|
||||||
if (this.props.isSuggestion) {
|
|
||||||
style.push(styles.temperatureTextInputSuggestion)
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<TextInput
|
|
||||||
style={style}
|
|
||||||
onChangeText={(val) => {
|
|
||||||
if (isNaN(Number(val))) return
|
|
||||||
this.props.setState({ temperature: val, isSuggestion: false })
|
|
||||||
}}
|
|
||||||
keyboardType='numeric'
|
|
||||||
value={this.props.value}
|
|
||||||
onBlur={this.checkRange}
|
|
||||||
autoFocus={true}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function isInvalidTime(timeString) {
|
|
||||||
try {
|
|
||||||
LocalTime.parse(timeString)
|
|
||||||
} catch (err) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import React, { Component } from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { Keyboard } from 'react-native'
|
||||||
|
|
||||||
|
import AppTextInput from '../../app-text-input'
|
||||||
|
import styles from '../../../styles'
|
||||||
|
|
||||||
|
import DateTimePicker from 'react-native-modal-datetime-picker-nevo'
|
||||||
|
import moment from 'moment'
|
||||||
|
|
||||||
|
export default class TimeInput extends Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
time: PropTypes.string,
|
||||||
|
handleTimeChange: PropTypes.func,
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props)
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
isTimePickerVisible: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
showTimePicker = () => {
|
||||||
|
Keyboard.dismiss()
|
||||||
|
this.setState({ isTimePickerVisible: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
hideTimePicker = () => {
|
||||||
|
this.setState({ isTimePickerVisible: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
handleConfirm = (jsDate) => {
|
||||||
|
// DateTimePicker also when in mode="time" returns full date (with time)
|
||||||
|
const time = moment(jsDate).format('HH:mm')
|
||||||
|
this.props.handleTimeChange(time)
|
||||||
|
this.setState({
|
||||||
|
isTimePickerVisible: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
render () {
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<AppTextInput
|
||||||
|
style={styles.temperatureTextInput}
|
||||||
|
onFocus={this.showTimePicker}
|
||||||
|
value={this.props.time}
|
||||||
|
testID='timeInput'
|
||||||
|
/>
|
||||||
|
<DateTimePicker
|
||||||
|
mode="time"
|
||||||
|
isVisible={this.state.isTimePickerVisible}
|
||||||
|
onConfirm={this.handleConfirm}
|
||||||
|
onCancel={this.hideTimePicker}
|
||||||
|
/>
|
||||||
|
</React.Fragment>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,21 +5,24 @@ import { View } from 'react-native'
|
|||||||
import AppText from './app-text'
|
import AppText from './app-text'
|
||||||
import styles from '../styles'
|
import styles from '../styles'
|
||||||
|
|
||||||
const FramedSegment = ({ children, ...props }) => {
|
const FramedSegment = ({ children, last, style, title }) => {
|
||||||
const style = [styles.framedSegment, props.style]
|
const viewStyle = [styles.framedSegment, style]
|
||||||
if (props.last) style.push(styles.framedSegmentLast)
|
if (last) viewStyle.push(styles.framedSegmentLast)
|
||||||
return (
|
return (
|
||||||
<View style={[style]}>
|
<View style={[viewStyle]}>
|
||||||
{
|
{title && <AppText style={styles.framedSegmentTitle}>{title}</AppText>}
|
||||||
props.title
|
|
||||||
&& <AppText style={styles.framedSegmentTitle}>{props.title}</AppText>
|
|
||||||
}
|
|
||||||
{children}
|
{children}
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
FramedSegment.propTypes = {
|
FramedSegment.propTypes = {
|
||||||
|
children: PropTypes.oneOfType([
|
||||||
|
PropTypes.arrayOf(PropTypes.node),
|
||||||
|
PropTypes.node
|
||||||
|
]),
|
||||||
|
last: PropTypes.bool,
|
||||||
|
style: PropTypes.object,
|
||||||
title: PropTypes.string
|
title: PropTypes.string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import {
|
|
||||||
Text,
|
|
||||||
TouchableOpacity,
|
|
||||||
View
|
|
||||||
} from 'react-native'
|
|
||||||
import styles, { iconStyles } from '../../styles'
|
|
||||||
import NavigationArrow from './navigation-arrow'
|
|
||||||
import Icon from 'react-native-vector-icons/Entypo'
|
|
||||||
|
|
||||||
export default function BackButtonHeader(props) {
|
|
||||||
return (
|
|
||||||
<View style={[styles.header, styles.headerCycleDay, styles.headerSymptom]}>
|
|
||||||
<View
|
|
||||||
style={styles.accentCircle}
|
|
||||||
left={props.middle - styles.accentCircle.width / 2}
|
|
||||||
/>
|
|
||||||
<NavigationArrow direction='left' {...props}/>
|
|
||||||
<View>
|
|
||||||
<Text style={styles.headerText}>
|
|
||||||
{props.title}
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
<TouchableOpacity style={styles.hiddenIcon}>
|
|
||||||
<Icon
|
|
||||||
name={'chevron-thin-right'}
|
|
||||||
{...iconStyles.hiddenIcon}
|
|
||||||
/>
|
|
||||||
</TouchableOpacity>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import {
|
|
||||||
View,
|
|
||||||
Text} from 'react-native'
|
|
||||||
import styles from '../../styles'
|
|
||||||
import NavigationArrow from './navigation-arrow'
|
|
||||||
import formatDate from '../helpers/format-date'
|
|
||||||
|
|
||||||
export default function CycleDayHeader({ date, ...props }) {
|
|
||||||
return (<View style={[styles.header, styles.headerCycleDay]}>
|
|
||||||
<View
|
|
||||||
style={styles.accentCircle}
|
|
||||||
left={props.middle - styles.accentCircle.width / 2}
|
|
||||||
/>
|
|
||||||
<NavigationArrow direction='left' {...props}/>
|
|
||||||
<View>
|
|
||||||
<Text style={styles.dateHeader}>
|
|
||||||
{formatDate(date)}
|
|
||||||
</Text>
|
|
||||||
{props.cycleDayNumber &&
|
|
||||||
<Text style={styles.cycleDayNumber}>
|
|
||||||
{`Cycle day ${props.cycleDayNumber}`.toLowerCase()}
|
|
||||||
</Text>}
|
|
||||||
</View>
|
|
||||||
<NavigationArrow direction='right' {...props}/>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import {
|
|
||||||
View,
|
|
||||||
Text} from 'react-native'
|
|
||||||
import styles from '../../styles'
|
|
||||||
|
|
||||||
export default function DefaultHeader(props) {
|
|
||||||
return (
|
|
||||||
<View style={styles.header}>
|
|
||||||
<View style={styles.accentCircle} />
|
|
||||||
<Text style={styles.headerText}>
|
|
||||||
{props.title}
|
|
||||||
</Text>
|
|
||||||
</View >
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { TouchableOpacity } from 'react-native'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
import Icon from 'react-native-vector-icons/AntDesign'
|
||||||
|
|
||||||
|
import styles, { iconStyles } from '../../styles'
|
||||||
|
|
||||||
|
export default function DeleteIcon({ handleDelete }) {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={handleDelete}
|
||||||
|
style={styles.headerDeleteButton}
|
||||||
|
testID="deleteIcon"
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name="delete"
|
||||||
|
{...iconStyles.symptomHeaderIcons}
|
||||||
|
/>
|
||||||
|
</TouchableOpacity>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
DeleteIcon.propTypes = {
|
||||||
|
handleDelete: PropTypes.func,
|
||||||
|
}
|
||||||
+32
-20
@@ -1,24 +1,36 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { Dimensions } from 'react-native'
|
import { View } from 'react-native'
|
||||||
import CycleDayHeader from './cycle-day'
|
import PropTypes from 'prop-types'
|
||||||
import DefaultHeader from './default'
|
|
||||||
import BackButtonHeader from './back-button'
|
|
||||||
import SymptomViewHeader from './symptom-view'
|
|
||||||
|
|
||||||
export default function Header(p) {
|
import Title from './title'
|
||||||
const middle = Dimensions.get('window').width / 2
|
import NavigationArrow from './navigation-arrow'
|
||||||
const props = Object.assign({}, p, {middle})
|
import DeleteIcon from './delete-icon'
|
||||||
|
|
||||||
if (props.isCycleDayOverView) {
|
import styles from '../../styles'
|
||||||
return (<CycleDayHeader {...props} />)
|
|
||||||
}
|
export default function Header({
|
||||||
else if (props.isSymptomView) {
|
handleBack,
|
||||||
return (<SymptomViewHeader {...props} />)
|
handleNext,
|
||||||
}
|
handleDelete,
|
||||||
else if (props.showBackButton) {
|
title,
|
||||||
return (<BackButtonHeader {...props} />)
|
subtitle,
|
||||||
}
|
}) {
|
||||||
else {
|
|
||||||
return (<DefaultHeader {...props} />)
|
return (
|
||||||
}
|
<View style={styles.header}>
|
||||||
|
<View style={styles.accentCircle} />
|
||||||
|
{ handleBack && <NavigationArrow handleBack={handleBack} /> }
|
||||||
|
<Title title={title} subtitle={subtitle} />
|
||||||
|
{ handleNext && <NavigationArrow handleNext={handleNext} /> }
|
||||||
|
{ handleDelete && <DeleteIcon handleDelete={handleDelete} /> }
|
||||||
|
</View >
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Header.propTypes = {
|
||||||
|
handleBack: PropTypes.func,
|
||||||
|
handleDelete: PropTypes.func,
|
||||||
|
handleNext: PropTypes.func,
|
||||||
|
subtitle: PropTypes.string,
|
||||||
|
title: PropTypes.string.isRequired
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,30 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { TouchableOpacity } from 'react-native'
|
import { TouchableOpacity } from 'react-native'
|
||||||
import styles, { iconStyles } from '../../styles'
|
import PropTypes from 'prop-types'
|
||||||
import Icon from 'react-native-vector-icons/Entypo'
|
import Icon from 'react-native-vector-icons/Entypo'
|
||||||
|
|
||||||
export default function NavigationArrow(props) {
|
import styles, { iconStyles } from '../../styles'
|
||||||
const iconName = {
|
|
||||||
left: 'chevron-thin-left',
|
export default function NavigationArrow({ handleBack, handleNext }) {
|
||||||
right: 'chevron-thin-right'
|
const navigationDirection = handleBack ? 'Left' : 'Right'
|
||||||
}[props.direction]
|
|
||||||
let pressHandler
|
|
||||||
if (props.goBack) {
|
|
||||||
pressHandler = () => props.goBack()
|
|
||||||
} else {
|
|
||||||
pressHandler = () => {
|
|
||||||
const target = props.direction === 'left' ? 'before' : 'after'
|
|
||||||
props.goToCycleDay(target)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
style={styles.navigationArrow}
|
style={[
|
||||||
onPress={pressHandler}
|
styles.navigationArrow,
|
||||||
|
styles[`navigationArrow${navigationDirection}`]
|
||||||
|
]}
|
||||||
|
onPress={ handleBack || handleNext }
|
||||||
|
testID={ handleBack ? 'backButton' : 'nextButton'}
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
name={iconName}
|
name={`chevron-thin-${navigationDirection.toLowerCase()}`}
|
||||||
{...iconStyles.navigationArrow}
|
{...iconStyles.navigationArrow}
|
||||||
/>
|
/>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
NavigationArrow.propTypes = {
|
||||||
|
handleBack: PropTypes.func,
|
||||||
|
handleNext: PropTypes.func,
|
||||||
}
|
}
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import {
|
|
||||||
View,
|
|
||||||
Text,
|
|
||||||
TouchableOpacity
|
|
||||||
} from 'react-native'
|
|
||||||
import styles, { iconStyles } from '../../styles'
|
|
||||||
import FeatherIcon from 'react-native-vector-icons/Feather'
|
|
||||||
import NavigationArrow from './navigation-arrow'
|
|
||||||
import formatDate from '../helpers/format-date'
|
|
||||||
|
|
||||||
export default function SymptomViewHeader(props) {
|
|
||||||
return (
|
|
||||||
<View style={[styles.header, styles.headerCycleDay, styles.headerSymptom]}>
|
|
||||||
<View
|
|
||||||
style={styles.accentCircle}
|
|
||||||
left={props.middle - styles.accentCircle.width / 2}
|
|
||||||
/>
|
|
||||||
<NavigationArrow
|
|
||||||
direction='left'
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
<View>
|
|
||||||
<Text style={styles.dateHeader}>
|
|
||||||
{props.title}
|
|
||||||
</Text>
|
|
||||||
<Text style={styles.cycleDayNumber}>
|
|
||||||
{formatDate(props.date)}
|
|
||||||
</Text>
|
|
||||||
</View >
|
|
||||||
<TouchableOpacity
|
|
||||||
onPress={() => props.goToSymptomInfo()}
|
|
||||||
style={styles.infoButton}
|
|
||||||
>
|
|
||||||
<FeatherIcon
|
|
||||||
name="info"
|
|
||||||
style={styles.symptomInfoIcon}
|
|
||||||
{...iconStyles.symptomHeaderIcons}
|
|
||||||
/>
|
|
||||||
</TouchableOpacity>
|
|
||||||
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { View, Text} from 'react-native'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
import styles from '../../styles'
|
||||||
|
|
||||||
|
export default function Title({ title, subtitle }) {
|
||||||
|
|
||||||
|
if (subtitle !== undefined) {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Text style={styles.dateHeader} testID='headerTitle'>
|
||||||
|
{ // design wants everyhting lowercased, but we don't
|
||||||
|
// have CSS pseudo properties
|
||||||
|
title.toLowerCase()}
|
||||||
|
</Text>
|
||||||
|
{ subtitle &&
|
||||||
|
<Text style={styles.cycleDayNumber} testID='headerSubtitle'>
|
||||||
|
{subtitle.toLowerCase()}
|
||||||
|
</Text>
|
||||||
|
}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Text testID='headerTitle' style={styles.headerText}>
|
||||||
|
{title.toLowerCase()}
|
||||||
|
</Text>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Title.propTypes = {
|
||||||
|
title: PropTypes.string,
|
||||||
|
subtitle: PropTypes.string,
|
||||||
|
}
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
import { LocalDate } from 'js-joda'
|
||||||
|
|
||||||
|
import { scaleObservable, unitObservable } from '../../local-storage'
|
||||||
|
import { getCycleDay, getAmountOfCycleDays } from '../../db'
|
||||||
|
|
||||||
|
import config from '../../config'
|
||||||
|
|
||||||
|
//YAxis helpers
|
||||||
|
|
||||||
|
export function normalizeToScale(temp, columnHeight) {
|
||||||
|
const scale = scaleObservable.value
|
||||||
|
const valueRelativeToScale = (scale.max - temp) / (scale.max - scale.min)
|
||||||
|
return getAbsoluteValue(valueRelativeToScale, columnHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAbsoluteValue(relative, columnHeight) {
|
||||||
|
// we add some height to have some breathing room
|
||||||
|
const verticalPadding = columnHeight * config.temperatureScale.verticalPadding
|
||||||
|
const scaleHeight = columnHeight - 2 * verticalPadding
|
||||||
|
return scaleHeight * relative + verticalPadding
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTickPositions(columnHeight) {
|
||||||
|
const units = unitObservable.value
|
||||||
|
const scaleMin = scaleObservable.value.min
|
||||||
|
const scaleMax = scaleObservable.value.max
|
||||||
|
const numberOfTicks = (scaleMax - scaleMin) * (1 / units) + 1
|
||||||
|
const tickDistance = 1 / (numberOfTicks - 1)
|
||||||
|
const tickPositions = []
|
||||||
|
for (let i = 0; i < numberOfTicks; i++) {
|
||||||
|
const position = getAbsoluteValue(tickDistance * i, columnHeight)
|
||||||
|
tickPositions.push(position)
|
||||||
|
}
|
||||||
|
return tickPositions
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTickList(columnHeight) {
|
||||||
|
|
||||||
|
const units = unitObservable.value
|
||||||
|
const scaleMax = scaleObservable.value.max
|
||||||
|
|
||||||
|
return getTickPositions(columnHeight).map((tickPosition, i) => {
|
||||||
|
|
||||||
|
const tick = scaleMax - i * units
|
||||||
|
let isBold, label, shouldShowLabel
|
||||||
|
|
||||||
|
if (Number.isInteger(tick)) {
|
||||||
|
isBold = true
|
||||||
|
label = tick.toString() + '.0'
|
||||||
|
} else {
|
||||||
|
isBold = false
|
||||||
|
label = tick.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
// when temp range <= 3, units === 0.1 we show temp values with step 0.2
|
||||||
|
// when temp range > 3, units === 0.5 we show temp values with step 0.5
|
||||||
|
|
||||||
|
if (units === 0.1) {
|
||||||
|
// show label with step 0.2
|
||||||
|
shouldShowLabel = !(tick * 10 % 2)
|
||||||
|
} else {
|
||||||
|
// show label with step 0.5
|
||||||
|
shouldShowLabel = !(tick * 10 % 5)
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
position: tickPosition,
|
||||||
|
label,
|
||||||
|
isBold,
|
||||||
|
shouldShowLabel,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
//DayColumn helpers
|
||||||
|
|
||||||
|
export function isSymptomDataComplete(symptom, dateString) {
|
||||||
|
const cycleDayData = getCycleDay(dateString)
|
||||||
|
const symptomData = cycleDayData[symptom]
|
||||||
|
|
||||||
|
const dataCompletenessCheck = {
|
||||||
|
'cervix': () => {
|
||||||
|
const { opening, firmness } = symptomData
|
||||||
|
return (opening !== null) && (firmness !== null)
|
||||||
|
},
|
||||||
|
'mucus': () => {
|
||||||
|
const { feeling, texture } = symptomData
|
||||||
|
return (feeling !== null) && (texture !== null)
|
||||||
|
},
|
||||||
|
'default': () => {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (dataCompletenessCheck[symptom] || dataCompletenessCheck['default'])()
|
||||||
|
}
|
||||||
|
|
||||||
|
function getInfoForNeighborColumns(dateString, columnHeight) {
|
||||||
|
const ret = {
|
||||||
|
rightY: null,
|
||||||
|
rightTemperatureExclude: null,
|
||||||
|
leftY: null,
|
||||||
|
leftTemperatureExclude: null
|
||||||
|
}
|
||||||
|
const target = LocalDate.parse(dateString)
|
||||||
|
const dayBefore = target.minusDays(1).toString()
|
||||||
|
const dayAfter = target.plusDays(1).toString()
|
||||||
|
const cycleDayBefore = getCycleDay(dayBefore)
|
||||||
|
const cycleDayAfter = getCycleDay(dayAfter)
|
||||||
|
|
||||||
|
if (cycleDayAfter && cycleDayAfter.temperature) {
|
||||||
|
ret.rightY = normalizeToScale(cycleDayAfter.temperature.value, columnHeight)
|
||||||
|
ret.rightTemperatureExclude = cycleDayAfter.temperature.exclude
|
||||||
|
}
|
||||||
|
if (cycleDayBefore && cycleDayBefore.temperature) {
|
||||||
|
ret.leftY = normalizeToScale(cycleDayBefore.temperature.value, columnHeight)
|
||||||
|
ret.leftTemperatureExclude = cycleDayBefore.temperature.exclude
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTemperatureProps(symptomData, columnHeight, dateString) {
|
||||||
|
const extractedData = {}
|
||||||
|
const { value, exclude } = symptomData
|
||||||
|
const neighborTemperatureGraphPoints =
|
||||||
|
getInfoForNeighborColumns(dateString, columnHeight)
|
||||||
|
|
||||||
|
for (const key in neighborTemperatureGraphPoints) {
|
||||||
|
extractedData[key] = neighborTemperatureGraphPoints[key]
|
||||||
|
}
|
||||||
|
return Object.assign({
|
||||||
|
value,
|
||||||
|
y: normalizeToScale(value, columnHeight),
|
||||||
|
temperatureExclude: exclude,
|
||||||
|
}, extractedData)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const symptomColorMethods = {
|
||||||
|
'mucus': (symptomData) => {
|
||||||
|
const { feeling, texture } = symptomData
|
||||||
|
const colorIndex = feeling + texture
|
||||||
|
return colorIndex
|
||||||
|
},
|
||||||
|
'cervix': (symptomData) => {
|
||||||
|
const { opening, firmness } = symptomData
|
||||||
|
const isDataComplete = opening !== null && firmness !== null
|
||||||
|
const isClosedAndHard =
|
||||||
|
isDataComplete &&
|
||||||
|
(opening === 0 && firmness === 0)
|
||||||
|
const colorIndex = isClosedAndHard ? 0 : 2
|
||||||
|
return colorIndex
|
||||||
|
},
|
||||||
|
'sex': (symptomData) => {
|
||||||
|
const { solo, partner } = symptomData
|
||||||
|
const colorIndex = (solo !== null && partner !== null) ?
|
||||||
|
(solo + 2 * partner - 1) : 0
|
||||||
|
return colorIndex
|
||||||
|
},
|
||||||
|
'bleeding': (symptomData) => {
|
||||||
|
const { value } = symptomData
|
||||||
|
const colorIndex = value
|
||||||
|
return colorIndex
|
||||||
|
},
|
||||||
|
'desire': (symptomData) => {
|
||||||
|
const { value } = symptomData
|
||||||
|
const colorIndex = value
|
||||||
|
return colorIndex
|
||||||
|
},
|
||||||
|
'default': () => { //pain, mood, note
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chart helpers
|
||||||
|
|
||||||
|
export function makeColumnInfo() {
|
||||||
|
let amountOfCycleDays = getAmountOfCycleDays()
|
||||||
|
// if there's not much data yet, we want to show at least 30 days on the chart
|
||||||
|
if (amountOfCycleDays < 30) {
|
||||||
|
amountOfCycleDays = 30
|
||||||
|
} else {
|
||||||
|
// we don't want the chart to end abruptly before the first data day
|
||||||
|
amountOfCycleDays += 5
|
||||||
|
}
|
||||||
|
const localDates = getTodayAndPreviousDays(amountOfCycleDays)
|
||||||
|
return localDates.map(localDate => localDate.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTodayAndPreviousDays(n) {
|
||||||
|
const today = LocalDate.now()
|
||||||
|
const targetDate = today.minusDays(n)
|
||||||
|
|
||||||
|
function getDaysInRange(currDate, range) {
|
||||||
|
if (currDate.isBefore(targetDate)) {
|
||||||
|
return range
|
||||||
|
} else {
|
||||||
|
range.push(currDate)
|
||||||
|
const next = currDate.minusDays(1)
|
||||||
|
return getDaysInRange(next, range)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return getDaysInRange(today, [])
|
||||||
|
}
|
||||||
@@ -4,6 +4,11 @@ import moment from 'moment'
|
|||||||
export default function (date) {
|
export default function (date) {
|
||||||
const today = LocalDate.now()
|
const today = LocalDate.now()
|
||||||
const dateToDisplay = LocalDate.parse(date)
|
const dateToDisplay = LocalDate.parse(date)
|
||||||
const formattedDate = today.equals(dateToDisplay) ? 'today' : moment(date).format('MMMM Do YYYY')
|
return today.equals(dateToDisplay) ?
|
||||||
return formattedDate.toLowerCase()
|
'today' :
|
||||||
|
moment(date).format('MMMM Do YYYY')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatDateForShortText (date) {
|
||||||
|
return moment(date.toString()).format('dddd, MMMM Do')
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import { ChronoUnit, LocalDate } from 'js-joda'
|
||||||
|
|
||||||
|
import { formatDateForShortText } from './format-date'
|
||||||
|
|
||||||
|
import {
|
||||||
|
home as labels,
|
||||||
|
bleedingPrediction as predictLabels,
|
||||||
|
} from '../../i18n/en/labels'
|
||||||
|
|
||||||
|
function getTimes(prediction) {
|
||||||
|
const todayDate = LocalDate.now()
|
||||||
|
const predictedBleedingStart = LocalDate.parse(prediction[0][0])
|
||||||
|
/* the range of predicted bleeding days can be either 3 or 5 */
|
||||||
|
const predictedBleedingEnd =
|
||||||
|
LocalDate.parse(prediction[0][ prediction[0].length - 1 ])
|
||||||
|
const daysToEnd = todayDate.until(predictedBleedingEnd, ChronoUnit.DAYS)
|
||||||
|
return { todayDate, predictedBleedingStart, predictedBleedingEnd, daysToEnd }
|
||||||
|
}
|
||||||
|
|
||||||
|
export function determinePredictionText(bleedingPrediction) {
|
||||||
|
if (!bleedingPrediction.length) return predictLabels.noPrediction
|
||||||
|
const {
|
||||||
|
todayDate,
|
||||||
|
predictedBleedingStart,
|
||||||
|
predictedBleedingEnd,
|
||||||
|
daysToEnd
|
||||||
|
} = getTimes(bleedingPrediction)
|
||||||
|
if (todayDate.isBefore(predictedBleedingStart)) {
|
||||||
|
return predictLabels.predictionInFuture(
|
||||||
|
todayDate.until(predictedBleedingStart, ChronoUnit.DAYS),
|
||||||
|
todayDate.until(predictedBleedingEnd, ChronoUnit.DAYS)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (todayDate.isAfter(predictedBleedingEnd)) {
|
||||||
|
return predictLabels.predictionInPast(
|
||||||
|
formatDateForShortText(predictedBleedingStart),
|
||||||
|
formatDateForShortText(predictedBleedingEnd)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (daysToEnd === 0) {
|
||||||
|
return predictLabels.predictionStartedNoDaysLeft
|
||||||
|
} else if (daysToEnd === 1) {
|
||||||
|
return predictLabels.predictionStarted1DayLeft
|
||||||
|
} else {
|
||||||
|
return predictLabels.predictionStartedXDaysLeft(daysToEnd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getBleedingPredictionRange(prediction) {
|
||||||
|
if (!prediction.length) return labels.unknown
|
||||||
|
const {
|
||||||
|
todayDate,
|
||||||
|
predictedBleedingStart,
|
||||||
|
predictedBleedingEnd,
|
||||||
|
daysToEnd
|
||||||
|
} = getTimes(prediction)
|
||||||
|
if (todayDate.isBefore(predictedBleedingStart)) {
|
||||||
|
return `${todayDate.until(predictedBleedingStart, ChronoUnit.DAYS)}-${todayDate.until(predictedBleedingEnd, ChronoUnit.DAYS)}`
|
||||||
|
}
|
||||||
|
if (todayDate.isAfter(predictedBleedingEnd)) {
|
||||||
|
return labels.unknown
|
||||||
|
}
|
||||||
|
return (daysToEnd === 0 ? '0' : `0 - ${daysToEnd}`)
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export const getLabelsList =
|
||||||
|
(categories) => categories.map((label, i) => ({ label, value: i }))
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { View } from 'react-native'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
import Button from './button'
|
||||||
|
|
||||||
|
import styles from '../styles'
|
||||||
|
|
||||||
|
const HomeElement = ({ children, onPress, buttonColor, buttonLabel }) => {
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
onPress={ onPress }
|
||||||
|
style={ styles.homeElement }
|
||||||
|
>
|
||||||
|
<View style={styles.homeIconAndText}>
|
||||||
|
{children[0]}
|
||||||
|
{children[1]}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={{paddingLeft: 15}}>
|
||||||
|
{children.slice(2)}
|
||||||
|
<Button
|
||||||
|
style={styles.homeButton}
|
||||||
|
onPress={ onPress }
|
||||||
|
backgroundColor={ buttonColor }>
|
||||||
|
{ buttonLabel }
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
HomeElement.propTypes = {
|
||||||
|
buttonColor: PropTypes.string,
|
||||||
|
buttonLabel: PropTypes.string,
|
||||||
|
children: PropTypes.node,
|
||||||
|
onPress: PropTypes.func,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default HomeElement
|
||||||
+89
-153
@@ -1,221 +1,157 @@
|
|||||||
import { ChronoUnit, LocalDate } from 'js-joda'
|
import { LocalDate } from 'js-joda'
|
||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { Dimensions, ScrollView, TouchableHighlight, View } from 'react-native'
|
import { ScrollView, View } from 'react-native'
|
||||||
import Icon from 'react-native-vector-icons/Entypo'
|
import { connect } from 'react-redux'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
import { navigate } from '../slices/navigation'
|
||||||
|
import { getDate, setDate } from '../slices/date'
|
||||||
|
|
||||||
import DripHomeIcon from '../assets/drip-home-icons'
|
import DripHomeIcon from '../assets/drip-home-icons'
|
||||||
import { getCycleDay } from '../db'
|
|
||||||
import {
|
import AppText from './app-text'
|
||||||
bleedingPrediction as predictLabels,
|
import IconText from './icon-text'
|
||||||
home as labels,
|
import HomeElement from './home-element'
|
||||||
shared,
|
|
||||||
} from '../i18n/en/labels'
|
import { home as labels } from '../i18n/en/labels'
|
||||||
import links from '../i18n/en/links'
|
import links from '../i18n/en/links'
|
||||||
|
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
import { getFertilityStatusForDay } from '../lib/sympto-adapter'
|
import { getFertilityStatusForDay } from '../lib/sympto-adapter'
|
||||||
|
import {
|
||||||
|
determinePredictionText,
|
||||||
|
getBleedingPredictionRange
|
||||||
|
} from './helpers/home'
|
||||||
|
|
||||||
import styles, { cycleDayColor, periodColor, secondaryColor } from '../styles'
|
import styles, { cycleDayColor, periodColor, secondaryColor } from '../styles'
|
||||||
import AppText from './app-text'
|
|
||||||
import Button from './button'
|
|
||||||
|
|
||||||
const ShowMoreToggler = ({ isShowingMore, onToggle }) => {
|
class Home extends Component {
|
||||||
const {height, width} = Dimensions.get('window')
|
|
||||||
const leftPosition = isShowingMore ? 10 : width - 40
|
|
||||||
const style = isShowingMore ? styles.showLess : styles.showMore
|
|
||||||
const topPosition = height / 2 - styles.header.height - 30
|
|
||||||
|
|
||||||
return (
|
static propTypes = {
|
||||||
<TouchableHighlight
|
navigate: PropTypes.func,
|
||||||
onPress={onToggle}
|
setDate: PropTypes.func,
|
||||||
style={[style, { top: topPosition, left: leftPosition}]}
|
// The following are not being used,
|
||||||
>
|
// we could see if it's possible to not pass them from the <App />
|
||||||
<View style={{alignItems: 'center'}}>
|
cycleDay: PropTypes.object,
|
||||||
<AppText>{isShowingMore ? shared.less : shared.more}</AppText>
|
date: PropTypes.string,
|
||||||
<Icon name='chevron-thin-down' />
|
}
|
||||||
</View>
|
|
||||||
</TouchableHighlight>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const IconText = ({ children, wrapperStyles }) => {
|
|
||||||
return (
|
|
||||||
<View style={[styles.homeIconTextWrapper, wrapperStyles]}>
|
|
||||||
<AppText style={styles.iconText}>
|
|
||||||
{ children }
|
|
||||||
</AppText>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const HomeElement = ({ children, onPress, buttonColor, buttonLabel }) => {
|
|
||||||
return (
|
|
||||||
<View
|
|
||||||
onPress={ onPress }
|
|
||||||
style={ styles.homeIconElement }
|
|
||||||
>
|
|
||||||
{ children }
|
|
||||||
<Button
|
|
||||||
style={styles.homeButton}
|
|
||||||
onPress={ onPress }
|
|
||||||
backgroundColor={ buttonColor }>
|
|
||||||
{ buttonLabel }
|
|
||||||
</Button>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class Home extends Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
const { getCycleDayNumber, getPredictedMenses } = cycleModule()
|
const { getCycleDayNumber, getPredictedMenses } = cycleModule()
|
||||||
this.getCycleDayNumber = getCycleDayNumber
|
|
||||||
this.getBleedingPrediction = getPredictedMenses
|
|
||||||
this.todayDateString = LocalDate.now().toString()
|
this.todayDateString = LocalDate.now().toString()
|
||||||
const prediction = this.getBleedingPrediction()
|
this.cycleDayNumber = getCycleDayNumber(this.todayDateString)
|
||||||
const fertilityStatus = getFertilityStatusForDay(this.todayDateString)
|
|
||||||
|
|
||||||
this.state = {
|
const prediction = getPredictedMenses()
|
||||||
isShowingMore: false,
|
this.predictionText = determinePredictionText(prediction)
|
||||||
cycleDayNumber: this.getCycleDayNumber(this.todayDateString),
|
this.bleedingPredictionRange = getBleedingPredictionRange(prediction)
|
||||||
predictionText: determinePredictionText(prediction),
|
|
||||||
bleedingPredictionRange: getBleedingPredictionRange(prediction),
|
this.fertilityStatus = getFertilityStatusForDay(this.todayDateString)
|
||||||
...fertilityStatus
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
passTodayTo(componentName) {
|
navigateToCycleDayView = () => {
|
||||||
const { navigate } = this.props
|
this.props.setDate(this.todayDateString)
|
||||||
navigate(componentName, {
|
this.props.navigate('CycleDay')
|
||||||
date: this.todayDateString,
|
|
||||||
cycleDay: getCycleDay(this.todayDateString)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleShowingMore = () => {
|
navigateToBleedingEditView = () => {
|
||||||
this.setState({ isShowingMore: !this.state.isShowingMore })
|
this.props.setDate(this.todayDateString)
|
||||||
|
this.props.navigate('BleedingEditView')
|
||||||
|
}
|
||||||
|
|
||||||
|
navigateToChart = () => {
|
||||||
|
this.props.navigate('Chart')
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { isShowingMore, cycleDayNumber, phase, status } = this.state
|
const {
|
||||||
const { navigate } = this.props
|
cycleDayNumber,
|
||||||
|
predictionText,
|
||||||
|
bleedingPredictionRange,
|
||||||
|
} = this
|
||||||
|
|
||||||
|
const { phase, status, statusText } = this.fertilityStatus
|
||||||
|
|
||||||
const cycleDayMoreText = cycleDayNumber ?
|
const cycleDayMoreText = cycleDayNumber ?
|
||||||
labels.cycleDayKnown(cycleDayNumber) :
|
labels.cycleDayKnown(cycleDayNumber) :
|
||||||
labels.cycleDayNotEnoughInfo
|
labels.cycleDayNotEnoughInfo
|
||||||
|
|
||||||
const { statusText } = this.state
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View flex={1}>
|
<View flex={1}>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<View style={styles.homeView}>
|
<View style={styles.homeView}>
|
||||||
|
|
||||||
<HomeElement
|
<HomeElement
|
||||||
onPress={ () => this.passTodayTo('CycleDay') }
|
onPress={this.navigateToCycleDayView}
|
||||||
buttonColor={ cycleDayColor }
|
buttonColor={ cycleDayColor }
|
||||||
buttonLabel={ labels.editToday }
|
buttonLabel={ labels.editToday }
|
||||||
>
|
>
|
||||||
<View>
|
<View>
|
||||||
<DripHomeIcon name="circle" size={80} color={cycleDayColor}/>
|
<DripHomeIcon name="circle" size={80} color={cycleDayColor}/>
|
||||||
</View>
|
</View>
|
||||||
<IconText wrapperStyles={styles.wrapperCycle}>
|
<IconText>{cycleDayNumber || labels.unknown}</IconText>
|
||||||
{cycleDayNumber || labels.unknown}
|
|
||||||
</IconText>
|
|
||||||
|
|
||||||
{ isShowingMore &&
|
<AppText style={styles.homeDescriptionText}>
|
||||||
<AppText style={styles.paragraph}>{cycleDayMoreText}</AppText>
|
{cycleDayMoreText}
|
||||||
}
|
</AppText>
|
||||||
</HomeElement>
|
</HomeElement>
|
||||||
|
|
||||||
<HomeElement
|
<HomeElement
|
||||||
onPress={ () => this.passTodayTo('BleedingEditView') }
|
onPress={this.navigateToBleedingEditView}
|
||||||
buttonColor={ periodColor }
|
buttonColor={ periodColor }
|
||||||
buttonLabel={ labels.trackPeriod }
|
buttonLabel={ labels.trackPeriod }
|
||||||
>
|
>
|
||||||
<View>
|
<DripHomeIcon name="drop" size={100} color={periodColor} />
|
||||||
<DripHomeIcon name="drop" size={105} color={periodColor} />
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<IconText wrapperStyles={styles.wrapperDrop}>
|
<IconText wrapperStyles={{ top: '45%' }}>
|
||||||
{this.state.bleedingPredictionRange}
|
{bleedingPredictionRange}
|
||||||
</IconText>
|
</IconText>
|
||||||
|
|
||||||
{ isShowingMore &&
|
<AppText style={styles.homeDescriptionText}>
|
||||||
<AppText style={styles.paragraph}>
|
{predictionText}
|
||||||
{this.state.predictionText}
|
</AppText>
|
||||||
</AppText>
|
|
||||||
}
|
|
||||||
</HomeElement>
|
</HomeElement>
|
||||||
|
|
||||||
<HomeElement
|
<HomeElement
|
||||||
onPress={ () => navigate('Chart') }
|
onPress={this.navigateToChart}
|
||||||
buttonColor={ secondaryColor }
|
buttonColor={ secondaryColor }
|
||||||
buttonLabel={ labels.checkFertility }
|
buttonLabel={ labels.checkFertility }
|
||||||
>
|
>
|
||||||
<View style={styles.homeCircle}/>
|
<View style={styles.homeCircle}/>
|
||||||
|
|
||||||
<IconText wrapperStyles={styles.wrapperCircle}>
|
<IconText>{ phase ? phase.toString() : labels.unknown }</IconText>
|
||||||
{ phase ? phase.toString() : labels.unknown }
|
|
||||||
</IconText>
|
|
||||||
|
|
||||||
{ phase &&
|
{ phase &&
|
||||||
<AppText>{`${labels.phase(phase)} (${status})`}</AppText>
|
<AppText style={styles.homeDescriptionText}>
|
||||||
}
|
{`${labels.phase(phase)} (${status})`}
|
||||||
{ isShowingMore &&
|
</AppText>
|
||||||
<View>
|
|
||||||
<AppText styles={styles.paragraph}>
|
|
||||||
{ `${statusText} ${links.wiki.url}.` }
|
|
||||||
</AppText>
|
|
||||||
</View>
|
|
||||||
}
|
}
|
||||||
|
<AppText style={styles.homeDescriptionText}>
|
||||||
|
{ `${statusText} Visit ${links.wiki.url}.` }
|
||||||
|
</AppText>
|
||||||
</HomeElement>
|
</HomeElement>
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
<ShowMoreToggler
|
|
||||||
isShowingMore={isShowingMore}
|
|
||||||
onToggle={this.toggleShowingMore}
|
|
||||||
/>
|
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function determinePredictionText(bleedingPrediction) {
|
const mapStateToProps = (state) => {
|
||||||
if (!bleedingPrediction.length) return predictLabels.noPrediction
|
return({
|
||||||
const todayDate = LocalDate.now()
|
date: getDate(state),
|
||||||
const bleedingStart = LocalDate.parse(bleedingPrediction[0][0])
|
})
|
||||||
const bleedingEnd = LocalDate.parse(
|
|
||||||
bleedingPrediction[0][ bleedingPrediction[0].length - 1 ]
|
|
||||||
)
|
|
||||||
if (todayDate.isBefore(bleedingStart)) {
|
|
||||||
return predictLabels.predictionInFuture(
|
|
||||||
todayDate.until(bleedingStart, ChronoUnit.DAYS),
|
|
||||||
todayDate.until(bleedingEnd, ChronoUnit.DAYS)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (todayDate.isAfter(bleedingEnd)) {
|
|
||||||
return predictLabels.predictionInPast(
|
|
||||||
bleedingStart.toString(), bleedingEnd.toString()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
const daysToEnd = todayDate.until(bleedingEnd, ChronoUnit.DAYS)
|
|
||||||
if (daysToEnd === 0) {
|
|
||||||
return predictLabels.predictionStartedNoDaysLeft
|
|
||||||
} else if (daysToEnd === 1) {
|
|
||||||
return predictLabels.predictionStarted1DayLeft
|
|
||||||
} else {
|
|
||||||
return predictLabels.predictionStartedXDaysLeft(daysToEnd)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBleedingPredictionRange(prediction) {
|
const mapDispatchToProps = (dispatch) => {
|
||||||
if (!prediction.length) return labels.unknown
|
return({
|
||||||
const todayDate = LocalDate.now()
|
navigate: (page) => dispatch(navigate(page)),
|
||||||
const bleedingStart = LocalDate.parse(prediction[0][0])
|
setDate: (date) => dispatch(setDate(date)),
|
||||||
const bleedingEnd = LocalDate.parse(prediction[0][ prediction[0].length - 1 ])
|
})
|
||||||
if (todayDate.isBefore(bleedingStart)) {
|
}
|
||||||
return `${todayDate.until(bleedingStart, ChronoUnit.DAYS)}-${todayDate.until(bleedingEnd, ChronoUnit.DAYS)}`
|
|
||||||
}
|
export default connect(
|
||||||
if (todayDate.isAfter(bleedingEnd)) {
|
mapStateToProps,
|
||||||
return labels.unknown
|
mapDispatchToProps,
|
||||||
}
|
)(Home)
|
||||||
return '0'
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { View } from 'react-native'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
import AppText from './app-text'
|
||||||
|
|
||||||
|
import styles from '../styles'
|
||||||
|
|
||||||
|
const IconText = ({ children, wrapperStyles }) => {
|
||||||
|
return (
|
||||||
|
<View style={[ styles.homeIconTextWrapper, wrapperStyles ]}>
|
||||||
|
<AppText style={styles.iconText}>
|
||||||
|
{ children }
|
||||||
|
</AppText>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
IconText.propTypes = {
|
||||||
|
children: PropTypes.node,
|
||||||
|
wrapperStyles: PropTypes.object,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default IconText
|
||||||
+10
-3
@@ -1,4 +1,5 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
import { ScrollView, View, BackHandler } from 'react-native'
|
import { ScrollView, View, BackHandler } from 'react-native'
|
||||||
import AppText from './app-text'
|
import AppText from './app-text'
|
||||||
import { shared } from '../i18n/en/labels'
|
import { shared } from '../i18n/en/labels'
|
||||||
@@ -10,14 +11,15 @@ import { saveLicenseFlag } from '../local-storage'
|
|||||||
const labels = settingsLabels.license
|
const labels = settingsLabels.license
|
||||||
export default function License({setLicense}) {
|
export default function License({setLicense}) {
|
||||||
return (
|
return (
|
||||||
<ScrollView style={styles.licensePage}>
|
<ScrollView testID='licensePage' style={styles.licensePage}>
|
||||||
<AppText style={styles.framedSegmentTitle}>{labels.title}</AppText>
|
<AppText style={styles.framedSegmentTitle}>{labels.title}</AppText>
|
||||||
<AppText>{labels.text}</AppText>
|
<AppText testID='test'>{labels.text}</AppText>
|
||||||
<View style={styles.licenseButtons}>
|
<View style={styles.licenseButtons}>
|
||||||
<Button
|
<Button
|
||||||
style={styles.licenseButton}
|
style={styles.licenseButton}
|
||||||
backgroundColor={'grey'}
|
backgroundColor={'grey'}
|
||||||
onPress={() => BackHandler.exitApp()}
|
onPress={() => BackHandler.exitApp()}
|
||||||
|
testID='licenseCancelButton'
|
||||||
>
|
>
|
||||||
{shared.cancel}
|
{shared.cancel}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -28,10 +30,15 @@ export default function License({setLicense}) {
|
|||||||
await saveLicenseFlag()
|
await saveLicenseFlag()
|
||||||
setLicense()
|
setLicense()
|
||||||
}}
|
}}
|
||||||
|
testID='licenseOkButton'
|
||||||
>
|
>
|
||||||
{shared.ok}
|
{shared.ok}
|
||||||
</Button>
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
License.propTypes = {
|
||||||
|
setLicense: PropTypes.func.isRequired
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
import Hyperlink from 'react-native-hyperlink'
|
import Hyperlink from 'react-native-hyperlink'
|
||||||
import styles from '../styles'
|
import styles from '../styles'
|
||||||
import links from '../i18n/en/links'
|
import links from '../i18n/en/links'
|
||||||
@@ -15,6 +16,13 @@ export default function Link(props) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Link.propTypes = {
|
||||||
|
children: PropTypes.oneOfType([
|
||||||
|
PropTypes.arrayOf(PropTypes.node),
|
||||||
|
PropTypes.node
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
function replaceUrlWithText(url) {
|
function replaceUrlWithText(url) {
|
||||||
const link = Object.values(links).find(l => l.url === url)
|
const link = Object.values(links).find(l => l.url === url)
|
||||||
return (link && link.text) || url
|
return (link && link.text) || url
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import {
|
|
||||||
View,
|
|
||||||
Text,
|
|
||||||
TouchableOpacity
|
|
||||||
} from 'react-native'
|
|
||||||
|
|
||||||
import settingsViews from './settings'
|
|
||||||
|
|
||||||
import { menuTitles } from '../i18n/en/labels'
|
|
||||||
|
|
||||||
import styles, { iconStyles, secondaryColor } from '../styles'
|
|
||||||
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
|
|
||||||
|
|
||||||
const menuTitlesLowerCase = Object.keys(menuTitles).reduce((acc, curr) => {
|
|
||||||
acc[curr] = menuTitles[curr].toLowerCase()
|
|
||||||
return acc
|
|
||||||
}, {})
|
|
||||||
|
|
||||||
const menuItems = [
|
|
||||||
{
|
|
||||||
labelKey: 'Home',
|
|
||||||
icon: 'home',
|
|
||||||
component: 'Home',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
labelKey: 'Calendar',
|
|
||||||
icon: 'calendar-range',
|
|
||||||
component: 'Calendar',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
labelKey: 'Chart',
|
|
||||||
icon: 'chart-line',
|
|
||||||
component: 'Chart',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
labelKey: 'Stats',
|
|
||||||
icon: 'chart-pie',
|
|
||||||
component: 'Stats',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
labelKey: 'Settings',
|
|
||||||
icon: 'settings',
|
|
||||||
component: 'SettingsMenu',
|
|
||||||
children: Object.keys(settingsViews),
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
const MenuItem = ({ icon, labelKey, active, onPress }) => {
|
|
||||||
const styleActive = active ? { color: secondaryColor } : null
|
|
||||||
return (
|
|
||||||
<TouchableOpacity
|
|
||||||
style={styles.menuItem}
|
|
||||||
onPress={onPress}
|
|
||||||
>
|
|
||||||
<Icon name={icon} {...iconStyles.menuIcon} {...styleActive} />
|
|
||||||
<Text style={[styles.menuText, styleActive]}>
|
|
||||||
{menuTitlesLowerCase[labelKey]}
|
|
||||||
</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const Menu = ({ currentPage, navigate }) => {
|
|
||||||
return (
|
|
||||||
<View style={styles.menu}>
|
|
||||||
{ menuItems.map(({ icon, labelKey, component, children }) => {
|
|
||||||
const isActive = (component === currentPage) ||
|
|
||||||
(children && children.indexOf(currentPage) !== -1)
|
|
||||||
return (
|
|
||||||
<MenuItem
|
|
||||||
key={labelKey}
|
|
||||||
labelKey={labelKey}
|
|
||||||
icon={icon}
|
|
||||||
active={isActive}
|
|
||||||
onPress={() => navigate(component)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
)}
|
|
||||||
</View >
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Menu
|
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { View } from 'react-native'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
import MenuItem from './menu-item'
|
||||||
|
|
||||||
|
import { connect } from 'react-redux'
|
||||||
|
import { getNavigation, navigate } from '../../slices/navigation'
|
||||||
|
|
||||||
|
import { pages } from '../pages'
|
||||||
|
|
||||||
|
import styles from '../../styles'
|
||||||
|
|
||||||
|
const Menu = ({ navigate, navigation }) => {
|
||||||
|
const menuItems = pages.filter(page => page.isInMenu)
|
||||||
|
return (
|
||||||
|
<View style={styles.menu}>
|
||||||
|
{ menuItems.map(({ icon, label, component, children }) => {
|
||||||
|
const isActive = (component === navigation.currentPage) ||
|
||||||
|
(children && children.indexOf(navigation.currentPage) !== -1)
|
||||||
|
return (
|
||||||
|
<MenuItem
|
||||||
|
key={label}
|
||||||
|
label={label}
|
||||||
|
icon={icon}
|
||||||
|
active={isActive}
|
||||||
|
onPress={() => navigate(component)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
)}
|
||||||
|
</View >
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu.propTypes = {
|
||||||
|
navigation: PropTypes.object,
|
||||||
|
navigate: PropTypes.func,
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => {
|
||||||
|
return({
|
||||||
|
navigation: getNavigation(state),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => {
|
||||||
|
return({
|
||||||
|
navigate: (page) => dispatch(navigate(page)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(
|
||||||
|
mapStateToProps,
|
||||||
|
mapDispatchToProps,
|
||||||
|
)(Menu)
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { Text, TouchableOpacity } from 'react-native'
|
||||||
|
|
||||||
|
import styles, { iconStyles, secondaryColor } from '../../styles'
|
||||||
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
|
||||||
|
|
||||||
|
import { menuTitles } from '../../i18n/en/labels'
|
||||||
|
|
||||||
|
const menuTitlesLowerCase = Object.keys(menuTitles).reduce((acc, curr) => {
|
||||||
|
acc[curr] = menuTitles[curr].toLowerCase()
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
|
||||||
|
export default function MenuItem({ active, icon, label, onPress }) {
|
||||||
|
const styleActive = active ? { color: secondaryColor } : null
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TouchableOpacity style={styles.menuItem} onPress={onPress} >
|
||||||
|
<Icon name={icon} {...iconStyles.menuIcon} {...styleActive} />
|
||||||
|
<Text
|
||||||
|
testID={active ? 'activeMenuItem' : `menuItem${label}`}
|
||||||
|
style={[styles.menuText, styleActive]}
|
||||||
|
>
|
||||||
|
{menuTitlesLowerCase[label]}
|
||||||
|
</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuItem.propTypes = {
|
||||||
|
active: PropTypes.bool,
|
||||||
|
icon: PropTypes.string.isRequired,
|
||||||
|
label: PropTypes.string.isRequired,
|
||||||
|
onPress: PropTypes.func.isRequired
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
import symptomViews from './cycle-day/symptoms'
|
||||||
|
import settingsViews from './settings'
|
||||||
|
|
||||||
|
import settingsLabels from '../i18n/en/settings'
|
||||||
|
const labels = settingsLabels.menuTitles
|
||||||
|
|
||||||
|
const symptomsPages = Object.keys(symptomViews).map(symptomView => ({
|
||||||
|
component: symptomView,
|
||||||
|
parent: 'CycleDay',
|
||||||
|
}))
|
||||||
|
|
||||||
|
export const isSymptomView =
|
||||||
|
(page) => Object.keys(symptomViews).includes(page)
|
||||||
|
|
||||||
|
export const isSettingsView =
|
||||||
|
(page) => Object.keys(settingsViews).includes(page)
|
||||||
|
|
||||||
|
export const pages = [
|
||||||
|
{
|
||||||
|
component: 'Home',
|
||||||
|
icon: 'home',
|
||||||
|
isInMenu: true,
|
||||||
|
label: 'Home',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Calendar',
|
||||||
|
icon: 'calendar-range',
|
||||||
|
isInMenu: true,
|
||||||
|
label: 'Calendar',
|
||||||
|
parent: 'Home',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Chart',
|
||||||
|
icon: 'chart-line',
|
||||||
|
isInMenu: true,
|
||||||
|
label: 'Chart',
|
||||||
|
parent: 'Home',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Stats',
|
||||||
|
icon: 'chart-pie',
|
||||||
|
isInMenu: true,
|
||||||
|
label: 'Stats',
|
||||||
|
parent: 'Home',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
children: Object.keys(settingsViews),
|
||||||
|
component: 'SettingsMenu',
|
||||||
|
icon: 'settings',
|
||||||
|
isInMenu: true,
|
||||||
|
label: 'Settings',
|
||||||
|
parent: 'Home',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Reminders',
|
||||||
|
label: labels.reminders,
|
||||||
|
parent: 'SettingsMenu',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'NfpSettings',
|
||||||
|
label: labels.nfpSettings,
|
||||||
|
parent: 'SettingsMenu',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'DataManagement',
|
||||||
|
label: labels.dataManagement,
|
||||||
|
parent: 'SettingsMenu',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Password',
|
||||||
|
label: labels.password,
|
||||||
|
parent: 'SettingsMenu',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'About',
|
||||||
|
label: labels.about,
|
||||||
|
parent: 'SettingsMenu',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'License',
|
||||||
|
label: labels.license,
|
||||||
|
parent: 'SettingsMenu',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'CycleDay',
|
||||||
|
parent: 'Home',
|
||||||
|
},
|
||||||
|
...symptomsPages
|
||||||
|
]
|
||||||
@@ -1,13 +1,19 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { View, TextInput, TouchableOpacity, Alert, Image } from 'react-native'
|
import PropTypes from 'prop-types'
|
||||||
|
import { View, TextInput, TouchableOpacity, Alert } from 'react-native'
|
||||||
import nodejs from 'nodejs-mobile-react-native'
|
import nodejs from 'nodejs-mobile-react-native'
|
||||||
import { saveEncryptionFlag } from '../local-storage'
|
import { saveEncryptionFlag } from '../local-storage'
|
||||||
import AppText from './app-text'
|
import AppText from './app-text'
|
||||||
|
import Header from './header'
|
||||||
import styles from '../styles'
|
import styles from '../styles'
|
||||||
import { passwordPrompt as labels, shared } from '../i18n/en/labels'
|
import { passwordPrompt as labels, shared, menuTitles } from '../i18n/en/labels'
|
||||||
import { requestHash, deleteDbAndOpenNew, openDb } from '../db'
|
import { requestHash, deleteDbAndOpenNew, openDb } from '../db'
|
||||||
|
|
||||||
export default class PasswordPrompt extends Component {
|
export default class PasswordPrompt extends Component {
|
||||||
|
static propTypes = {
|
||||||
|
enableShowApp: PropTypes.func.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
@@ -19,19 +25,6 @@ export default class PasswordPrompt extends Component {
|
|||||||
this.passHashToDb,
|
this.passHashToDb,
|
||||||
this
|
this
|
||||||
)
|
)
|
||||||
|
|
||||||
this.tryToOpenDb()
|
|
||||||
}
|
|
||||||
|
|
||||||
async tryToOpenDb() {
|
|
||||||
const connected = await openDb()
|
|
||||||
if (!connected) {
|
|
||||||
this.setState({ showPasswordPrompt: true })
|
|
||||||
await saveEncryptionFlag(true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
await saveEncryptionFlag(false)
|
|
||||||
this.props.showApp()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
passHashToDb = async hash => {
|
passHashToDb = async hash => {
|
||||||
@@ -47,7 +40,7 @@ export default class PasswordPrompt extends Component {
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.props.showApp()
|
this.props.enableShowApp()
|
||||||
}
|
}
|
||||||
|
|
||||||
confirmDeletion = async () => {
|
confirmDeletion = async () => {
|
||||||
@@ -71,7 +64,7 @@ export default class PasswordPrompt extends Component {
|
|||||||
onPress: async () => {
|
onPress: async () => {
|
||||||
await deleteDbAndOpenNew()
|
await deleteDbAndOpenNew()
|
||||||
await saveEncryptionFlag(false)
|
await saveEncryptionFlag(false)
|
||||||
this.props.showApp()
|
this.props.enableShowApp()
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
)
|
)
|
||||||
@@ -87,38 +80,33 @@ export default class PasswordPrompt extends Component {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<View flex={1}>
|
<View flex={1}>
|
||||||
{this.state.showPasswordPrompt &&
|
<Header title={menuTitles.PasswordPrompt.toLowerCase()} />
|
||||||
<View style={styles.passwordPromptPage}>
|
<View style={styles.passwordPromptPage}>
|
||||||
<Image
|
<TextInput
|
||||||
source={require('../assets/drip_small.png')}
|
onChangeText={val => this.setState({ password: val })}
|
||||||
style={styles.passwordPromptImage}
|
style={styles.passwordPromptField}
|
||||||
/>
|
secureTextEntry={true}
|
||||||
<TextInput
|
placeholder={labels.enterPassword}
|
||||||
onChangeText={val => this.setState({ password: val })}
|
/>
|
||||||
style={styles.passwordPromptField}
|
<TouchableOpacity
|
||||||
secureTextEntry={true}
|
style={styles.passwordPromptButton}
|
||||||
placeholder={labels.enterPassword}
|
onPress={() => {
|
||||||
/>
|
requestHash('check-pw', this.state.password)
|
||||||
<TouchableOpacity
|
}}
|
||||||
style={styles.passwordPromptButton}
|
disabled={!this.state.password}
|
||||||
onPress={() => {
|
>
|
||||||
requestHash('check-pw', this.state.password)
|
<AppText style={styles.passwordPromptButtonText}>
|
||||||
}}
|
{labels.title}
|
||||||
disabled={!this.state.password}
|
</AppText>
|
||||||
>
|
</TouchableOpacity>
|
||||||
<AppText style={styles.passwordPromptButtonText}>
|
<TouchableOpacity
|
||||||
{labels.title}
|
onPress={this.confirmDeletion}
|
||||||
</AppText>
|
>
|
||||||
</TouchableOpacity>
|
<AppText style={styles.passwordPromptForgotPasswordText}>
|
||||||
<TouchableOpacity
|
{labels.forgotPassword}
|
||||||
onPress={this.confirmDeletion}
|
</AppText>
|
||||||
>
|
</TouchableOpacity>
|
||||||
<AppText style={styles.passwordPromptForgotPasswordText}>
|
</View>
|
||||||
{labels.forgotPassword}
|
|
||||||
</AppText>
|
|
||||||
</TouchableOpacity>
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ export default class AboutSection extends Component {
|
|||||||
<FramedSegment title={labels.credits.title}>
|
<FramedSegment title={labels.credits.title}>
|
||||||
<AppText>{labels.credits.note}</AppText>
|
<AppText>{labels.credits.note}</AppText>
|
||||||
</FramedSegment>
|
</FramedSegment>
|
||||||
|
<FramedSegment title={labels.donate.title}>
|
||||||
|
<AppText>{labels.donate.note}</AppText>
|
||||||
|
</FramedSegment>
|
||||||
<FramedSegment title={labels.website.title}>
|
<FramedSegment title={labels.website.title}>
|
||||||
<AppText>{links.website.url}</AppText>
|
<AppText>{links.website.url}</AppText>
|
||||||
</FramedSegment>
|
</FramedSegment>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import RNFS from 'react-native-fs'
|
import RNFS from 'react-native-fs'
|
||||||
import { Alert, ToastAndroid } from 'react-native'
|
import { Alert, ToastAndroid } from 'react-native'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
import { clearDb, isDbEmpty } from '../../../db'
|
import { clearDb, isDbEmpty } from '../../../db'
|
||||||
import { hasEncryptionObservable } from '../../../local-storage'
|
import { hasEncryptionObservable } from '../../../local-storage'
|
||||||
@@ -24,6 +25,7 @@ export default class DeleteData extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onAlertConfirmation = () => {
|
onAlertConfirmation = () => {
|
||||||
|
this.props.onStartDeletion()
|
||||||
if (this.state.isPasswordSet) {
|
if (this.state.isPasswordSet) {
|
||||||
this.setState({ isConfirmingWithPassword: true })
|
this.setState({ isConfirmingWithPassword: true })
|
||||||
} else {
|
} else {
|
||||||
@@ -78,8 +80,9 @@ export default class DeleteData extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { isConfirmingWithPassword } = this.state
|
const { isConfirmingWithPassword } = this.state
|
||||||
|
const { isDeletingData } = this.props
|
||||||
|
|
||||||
if (isConfirmingWithPassword) {
|
if (isConfirmingWithPassword && isDeletingData) {
|
||||||
return (
|
return (
|
||||||
<ConfirmWithPassword
|
<ConfirmWithPassword
|
||||||
onSuccess={this.deleteAppData}
|
onSuccess={this.deleteAppData}
|
||||||
@@ -94,4 +97,9 @@ export default class DeleteData extends Component {
|
|||||||
</SettingsButton>
|
</SettingsButton>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DeleteData.propTypes = {
|
||||||
|
isDeletingData: PropTypes.bool,
|
||||||
|
onStartDeletion: PropTypes.func.isRequired
|
||||||
}
|
}
|
||||||
@@ -6,23 +6,23 @@ import { shared as sharedLabels } from '../../../i18n/en/labels'
|
|||||||
import labels from '../../../i18n/en/settings'
|
import labels from '../../../i18n/en/settings'
|
||||||
import alertError from '../shared/alert-error'
|
import alertError from '../shared/alert-error'
|
||||||
|
|
||||||
export default function openImportDialogAndImport() {
|
export function openImportDialog(onImportData) {
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
labels.import.title,
|
labels.import.title,
|
||||||
labels.import.message,
|
labels.import.message,
|
||||||
[{
|
[{
|
||||||
text: labels.import.replaceOption,
|
text: sharedLabels.cancel, style: 'cancel', onPress: () => { }
|
||||||
onPress: () => getFileContentAndImport({ deleteExisting: false })
|
|
||||||
}, {
|
}, {
|
||||||
text: labels.import.deleteOption,
|
text: labels.import.deleteOption,
|
||||||
onPress: () => getFileContentAndImport({ deleteExisting: true })
|
onPress: () => onImportData(true)
|
||||||
}, {
|
}, {
|
||||||
text: sharedLabels.cancel, style: 'cancel', onPress: () => { }
|
text: labels.import.replaceOption,
|
||||||
|
onPress: () => onImportData(false)
|
||||||
}]
|
}]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getFileContentAndImport({ deleteExisting }) {
|
export async function getFileContent() {
|
||||||
let fileInfo
|
let fileInfo
|
||||||
try {
|
try {
|
||||||
fileInfo = await new Promise((resolve, reject) => {
|
fileInfo = await new Promise((resolve, reject) => {
|
||||||
@@ -45,8 +45,13 @@ async function getFileContentAndImport({ deleteExisting }) {
|
|||||||
return importError(labels.import.errors.couldNotOpenFile)
|
return importError(labels.import.errors.couldNotOpenFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return fileContent
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function importData(shouldDeleteExistingData, fileContent) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await importCsv(fileContent, deleteExisting)
|
await importCsv(fileContent, shouldDeleteExistingData)
|
||||||
Alert.alert(sharedLabels.successTitle, labels.import.success.message)
|
Alert.alert(sharedLabels.successTitle, labels.import.success.message)
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
importError(err.message)
|
importError(err.message)
|
||||||
|
|||||||
@@ -1,37 +1,91 @@
|
|||||||
import React from 'react'
|
import React, { Component } from 'react'
|
||||||
import { ScrollView } from 'react-native'
|
import { ScrollView, View } from 'react-native'
|
||||||
import AppText from '../../app-text'
|
import AppText from '../../app-text'
|
||||||
import FramedSegment from '../../framed-segment'
|
import FramedSegment from '../../framed-segment'
|
||||||
|
import AppLoadingView from '../../app-loading'
|
||||||
import SettingsButton from '../shared/settings-button'
|
import SettingsButton from '../shared/settings-button'
|
||||||
import openImportDialogAndImport from './import-dialog'
|
import { openImportDialog, getFileContent, importData } from './import-dialog'
|
||||||
import openShareDialogAndExport from './export-dialog'
|
import openShareDialogAndExport from './export-dialog'
|
||||||
import DeleteData from './delete-data'
|
import DeleteData from './delete-data'
|
||||||
import labels from '../../../i18n/en/settings'
|
import labels from '../../../i18n/en/settings'
|
||||||
|
|
||||||
const DataManagement = () => {
|
export default class DataManagement extends Component {
|
||||||
return (
|
|
||||||
<ScrollView>
|
|
||||||
<FramedSegment title={labels.export.button}>
|
|
||||||
<AppText>{labels.export.segmentExplainer}</AppText>
|
|
||||||
<SettingsButton onPress={openShareDialogAndExport}>
|
|
||||||
{labels.export.button}
|
|
||||||
</SettingsButton>
|
|
||||||
</FramedSegment>
|
|
||||||
<FramedSegment title={labels.import.button}>
|
|
||||||
<AppText>{labels.import.segmentExplainer}</AppText>
|
|
||||||
<SettingsButton onPress={openImportDialogAndImport}>
|
|
||||||
{labels.import.button}
|
|
||||||
</SettingsButton>
|
|
||||||
</FramedSegment>
|
|
||||||
<FramedSegment
|
|
||||||
title={labels.deleteSegment.title}
|
|
||||||
last
|
|
||||||
>
|
|
||||||
<AppText>{labels.deleteSegment.explainer}</AppText>
|
|
||||||
<DeleteData />
|
|
||||||
</FramedSegment>
|
|
||||||
</ScrollView>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default DataManagement
|
constructor(props) {
|
||||||
|
super(props)
|
||||||
|
this.state = {
|
||||||
|
isLoading: false,
|
||||||
|
currentAction: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
startLoading = () => {
|
||||||
|
this.setState({ isLoading: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
endLoading = () => {
|
||||||
|
this.setState({ isLoading: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
startImportFlow = async (shouldDeleteExistingData) => {
|
||||||
|
this.startLoading()
|
||||||
|
const fileContent = await getFileContent()
|
||||||
|
if (fileContent) {
|
||||||
|
await importData(shouldDeleteExistingData, fileContent)
|
||||||
|
}
|
||||||
|
this.endLoading()
|
||||||
|
}
|
||||||
|
|
||||||
|
startExport = () => {
|
||||||
|
this.setCurrentAction('export')
|
||||||
|
openShareDialogAndExport()
|
||||||
|
}
|
||||||
|
|
||||||
|
startImport = () => {
|
||||||
|
this.setCurrentAction('import')
|
||||||
|
openImportDialog(this.startImportFlow)
|
||||||
|
}
|
||||||
|
|
||||||
|
setCurrentAction = (action) => {
|
||||||
|
this.setState({ currentAction: action })
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { currentAction } = this.state
|
||||||
|
return (
|
||||||
|
<View flex={1}>
|
||||||
|
{this.state.isLoading && <AppLoadingView />}
|
||||||
|
{!this.state.isLoading &&
|
||||||
|
<ScrollView>
|
||||||
|
<View>
|
||||||
|
<FramedSegment title={labels.export.button}>
|
||||||
|
<AppText>{labels.export.segmentExplainer}</AppText>
|
||||||
|
<SettingsButton onPress={this.startExport}>
|
||||||
|
{labels.export.button}
|
||||||
|
</SettingsButton>
|
||||||
|
</FramedSegment>
|
||||||
|
<FramedSegment title={labels.import.button}>
|
||||||
|
<AppText>{labels.import.segmentExplainer}</AppText>
|
||||||
|
<SettingsButton
|
||||||
|
onPress= {this.startImport}
|
||||||
|
>
|
||||||
|
{labels.import.button}
|
||||||
|
</SettingsButton>
|
||||||
|
</FramedSegment>
|
||||||
|
<FramedSegment
|
||||||
|
title={labels.deleteSegment.title}
|
||||||
|
last
|
||||||
|
>
|
||||||
|
<AppText>{labels.deleteSegment.explainer}</AppText>
|
||||||
|
<DeleteData
|
||||||
|
isDeletingData = { currentAction === 'delete' }
|
||||||
|
onStartDeletion = {() => this.setCurrentAction('delete')}
|
||||||
|
/>
|
||||||
|
</FramedSegment>
|
||||||
|
</View>
|
||||||
|
</ScrollView>
|
||||||
|
}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ import React, { Component } from 'react'
|
|||||||
import {
|
import {
|
||||||
ScrollView, View
|
ScrollView, View
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import styles, { iconStyles } from '../../../styles'
|
import styles from '../../../styles'
|
||||||
import labels from '../../../i18n/en/settings'
|
import labels from '../../../i18n/en/settings'
|
||||||
import AppText from '../../app-text'
|
import AppText from '../../app-text'
|
||||||
import FramedSegment from '../../framed-segment'
|
import FramedSegment from '../../framed-segment'
|
||||||
@@ -28,8 +28,8 @@ export default class Settings extends Component {
|
|||||||
</FramedSegment>
|
</FramedSegment>
|
||||||
<FramedSegment style={styles.framedSegmentLast} >
|
<FramedSegment style={styles.framedSegmentLast} >
|
||||||
<View style={{flexDirection: 'row', alignItems: 'center'}}>
|
<View style={{flexDirection: 'row', alignItems: 'center'}}>
|
||||||
<Icon name="info-with-circle" style={iconStyles.infoInHeading}/>
|
<Icon name="info-with-circle"/>
|
||||||
<AppText style={styles.framedSegmentTitle}>{`${labels.preOvu.title} `}</AppText>
|
<AppText style={styles.framedSegmentTitle}>{` ${labels.preOvu.title} `}</AppText>
|
||||||
</View>
|
</View>
|
||||||
<AppText>{labels.preOvu.note}</AppText>
|
<AppText>{labels.preOvu.note}</AppText>
|
||||||
</FramedSegment>
|
</FramedSegment>
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {
|
import PropTypes from 'prop-types'
|
||||||
TouchableOpacity,
|
import { TouchableOpacity, ScrollView } from 'react-native'
|
||||||
ScrollView,
|
import { connect } from 'react-redux'
|
||||||
} from 'react-native'
|
|
||||||
|
import { navigate } from '../../slices/navigation'
|
||||||
|
|
||||||
import styles from '../../styles/index'
|
import styles from '../../styles/index'
|
||||||
|
|
||||||
import settingsLabels from '../../i18n/en/settings'
|
import settingsLabels from '../../i18n/en/settings'
|
||||||
|
|
||||||
import AppText from '../app-text'
|
import AppText from '../app-text'
|
||||||
|
|
||||||
const labels = settingsLabels.menuTitles
|
const labels = settingsLabels.menuTitles
|
||||||
@@ -18,7 +22,7 @@ const menu = [
|
|||||||
{title: labels.license, component: 'License'}
|
{title: labels.license, component: 'License'}
|
||||||
]
|
]
|
||||||
|
|
||||||
export default function SettingsMenu(props) {
|
const SettingsMenu = ({ navigate }) => {
|
||||||
return (
|
return (
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
{ menu.map(menuItem)}
|
{ menu.map(menuItem)}
|
||||||
@@ -30,10 +34,25 @@ export default function SettingsMenu(props) {
|
|||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
style={styles.framedSegment}
|
style={styles.framedSegment}
|
||||||
key={item.title}
|
key={item.title}
|
||||||
onPress={() => props.navigate(item.component)}
|
onPress={() => navigate(item.component)}
|
||||||
>
|
>
|
||||||
<AppText>{item.title.toLowerCase()}</AppText>
|
<AppText>{item.title.toLowerCase()}</AppText>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsMenu.propTypes = {
|
||||||
|
navigate: PropTypes.func.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => {
|
||||||
|
return({
|
||||||
|
navigate: (page) => dispatch(navigate(page)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(
|
||||||
|
null,
|
||||||
|
mapDispatchToProps
|
||||||
|
)(SettingsMenu)
|
||||||
@@ -1,19 +1,22 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { TextInput } from 'react-native'
|
import PropTypes from 'prop-types'
|
||||||
import styles, {secondaryColor} from '../../../styles'
|
import AppTextInput from '../../app-text-input'
|
||||||
|
|
||||||
|
import styles from '../../../styles'
|
||||||
|
|
||||||
export default function PasswordField(props) {
|
export default function PasswordField(props) {
|
||||||
return (
|
return (
|
||||||
<TextInput
|
<AppTextInput
|
||||||
style={styles.passwordField}
|
style={ styles.passwordField }
|
||||||
autoFocus={props.autoFocus === false ? false : true}
|
secureTextEntry
|
||||||
secureTextEntry={true}
|
{...props}
|
||||||
onChangeText={props.onChangeText}
|
|
||||||
value={props.value}
|
|
||||||
placeholder={props.placeholder}
|
|
||||||
borderWidth={1}
|
|
||||||
borderColor={secondaryColor}
|
|
||||||
borderStyle={'solid'}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PasswordField.propTypes = {
|
||||||
|
placeholder: PropTypes.string,
|
||||||
|
value: PropTypes.string,
|
||||||
|
onChangeText: PropTypes.func,
|
||||||
|
autoFocus: PropTypes.bool
|
||||||
|
}
|
||||||
|
|||||||
@@ -28,8 +28,11 @@ const SettingsButton = ({ children, style, secondary, ...props }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SettingsButton.propTypes = {
|
SettingsButton.propTypes = {
|
||||||
|
children: PropTypes.node,
|
||||||
|
disabled: PropTypes.bool,
|
||||||
onPress: PropTypes.func.isRequired,
|
onPress: PropTypes.func.isRequired,
|
||||||
disabled: PropTypes.bool
|
secondary: PropTypes.bool,
|
||||||
|
style: PropTypes.object
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SettingsButton
|
export default SettingsButton
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user