Merge branch 'master' into '129-extract-text-from-stats-and-layout'

# Conflicts:
#   components/labels.js
This commit is contained in:
tina
2018-08-22 10:07:47 +00:00
44 changed files with 2928 additions and 1963 deletions
+3 -3
View File
@@ -1,6 +1,6 @@
import React, { Component } from 'react'
import { View } from 'react-native'
import { Calendar } from 'react-native-calendars'
import { CalendarList } from 'react-native-calendars'
import * as styles from '../styles'
import { getOrCreateCycleDay, bleedingDaysSortedByDate } from '../db'
@@ -29,13 +29,13 @@ export default class CalendarView extends Component {
passDateToDayView(result) {
const cycleDay = getOrCreateCycleDay(result.dateString)
const navigate = this.props.navigation.navigate
navigate('cycleDay', { cycleDay })
navigate('CycleDay', { cycleDay })
}
render() {
return (
<View style={styles.container}>
<Calendar
<CalendarList
onDayPress={ this.passDateToDayView.bind(this) }
markedDates = { this.state.bleedingDaysInCalFormat }
markingType = {'period'}
+67 -271
View File
@@ -1,35 +1,34 @@
import React, { Component } from 'react'
import { Text as ReactNativeText, View, FlatList, ScrollView } from 'react-native'
import { View, FlatList } from 'react-native'
import range from 'date-range'
import Svg,{
G,
Rect,
Text,
Circle,
Line,
Path
} from 'react-native-svg'
import { LocalDate } from 'js-joda'
import { getCycleDay, getOrCreateCycleDay, cycleDaysSortedByDate } from '../../db'
import cycleModule from '../../lib/cycle'
import { yAxis, normalizeToScale, horizontalGrid } from './y-axis'
import setUpFertilityStatusFunc from './nfp-lines'
import DayColumn from './day-column'
import { getCycleDay, cycleDaysSortedByDate, getAmountOfCycleDays } from '../../db'
import styles from './styles'
import config from './config'
import { getCycleStatusForDay } from '../../lib/sympto-adapter'
const getCycleDayNumber = cycleModule().getCycleDayNumber
const yAxis = makeYAxis(config)
const yAxisView = <View {...styles.yAxis}>{yAxis.labels}</View>
export default class CycleChart extends Component {
constructor(props) {
super(props)
this.state = {
columns: makeColumnInfo(config.xAxisRangeInDays)
columns: makeColumnInfo(setUpFertilityStatusFunc()),
}
this.renderColumn = ({item, index}) => {
return (
<DayColumn
{...item}
index={index}
navigate={this.props.navigation.navigate}
/>
)
}
this.reCalculateChartInfo = (function(Chart) {
return function() {
Chart.setState({columns: makeColumnInfo(config.xAxisRangeInDays)})
Chart.setState({columns: makeColumnInfo(setUpFertilityStatusFunc())})
}
})(this)
@@ -40,159 +39,37 @@ export default class CycleChart extends Component {
cycleDaysSortedByDate.removeListener(this.reCalculateChartInfo)
}
passDateToDayView(dateString) {
const cycleDay = getOrCreateCycleDay(dateString)
this.props.navigation.navigate('cycleDay', { cycleDay })
}
placeHorizontalGrid() {
return yAxis.tickPositions.map(tick => {
return (
<Line
x1={0}
y1={tick}
x2={config.columnWidth}
y2={tick}
{...styles.horizontalGrid}
key={tick}
/>
)
})
}
makeDayColumn({ dateString, cycleDay, y }, index) {
const cycleDayNumber = getCycleDayNumber(dateString)
const label = styles.column.label
const dateLabel = dateString.split('-').slice(1).join('-')
const getFhmAndLtlInfo = setUpFertilityStatusFunc()
const nfpLineInfo = getFhmAndLtlInfo(dateString, cycleDay)
return (
<G onPress={() => this.passDateToDayView(dateString)}>
<Rect {...styles.column.rect} />
{nfpLineInfo.drawFhmLine ?
<Line
x1={0 + styles.nfpLine.strokeWidth / 2}
y1="20"
x2={0 + styles.nfpLine.strokeWidth / 2}
y2={config.chartHeight - 20}
{...styles.nfpLine}
/> : null}
{this.placeHorizontalGrid()}
<Text {...label.number} y={config.cycleDayNumberRowY}>
{cycleDayNumber}
</Text>
<Text {...label.date} y={config.dateRowY}>
{dateLabel}
</Text>
{cycleDay && cycleDay.bleeding ?
<Path {...styles.bleedingIcon}
d="M15 3
Q16.5 6.8 25 18
A12.8 12.8 0 1 1 5 18
Q13.5 6.8 15 3z" />
: null}
{nfpLineInfo.drawLtlAt ?
<Line
x1="0"
y1={nfpLineInfo.drawLtlAt}
x2={config.columnWidth}
y2={nfpLineInfo.drawLtlAt}
{...styles.nfpLine}
/> : null}
{y ?
this.drawDotAndLines(y, cycleDay.temperature.exclude, index)
: null
}
{cycleDay && cycleDay.mucus ?
<Circle
{...styles.mucusIcon}
fill={styles.mucusIconShades[cycleDay.mucus.value]}
/> : null}
{y ?
this.drawDotAndLines(y, cycleDay.temperature.exclude, index)
: null}
</G>
)
}
drawDotAndLines(currY, exclude, index) {
let lineToRight
let lineToLeft
const cols = this.state.columns
function makeLine(otherColY, x, excludeLine) {
const middleY = ((otherColY - currY) / 2) + currY
const target = [x, middleY]
const lineStyle = excludeLine ? styles.curveExcluded : styles.curve
return <Line
x1={config.columnMiddle}
y1={currY}
x2={target[0]}
y2={target[1]}
{...lineStyle}
/>
}
const thereIsADotToTheRight = index > 0 && cols[index - 1].y
const thereIsADotToTheLeft = index < cols.length - 1 && cols[index + 1].y
if (thereIsADotToTheRight) {
const otherDot = cols[index - 1]
const excludedLine = otherDot.cycleDay.temperature.exclude || exclude
lineToRight = makeLine(otherDot.y, config.columnWidth, excludedLine)
}
if (thereIsADotToTheLeft) {
const otherDot = cols[index + 1]
const excludedLine = otherDot.cycleDay.temperature.exclude || exclude
lineToLeft = makeLine(otherDot.y, 0, excludedLine)
}
const dotStyle = exclude ? styles.curveDotsExcluded : styles.curveDots
return (<G>
{lineToRight}
{lineToLeft}
<Circle
cx={config.columnMiddle}
cy={currY}
{...dotStyle}
/>
</G>)
}
render() {
return (
<ScrollView contentContainerStyle={{flexDirection: 'row'}}>
<View {...styles.yAxis}>{yAxis.labels}</View>
<FlatList
<View style={{ flexDirection: 'row', marginTop: 50 }}>
{yAxisView}
{horizontalGrid}
{<FlatList
horizontal={true}
inverted={true}
showsHorizontalScrollIndicator={false}
data={this.state.columns}
renderItem={({ item, index }) => {
return (
<Svg width={config.columnWidth} height={config.chartHeight}>
{this.makeDayColumn(item, index)}
</Svg>
)
}}
renderItem={this.renderColumn}
keyExtractor={item => item.dateString}
initialNumToRender={15}
maxToRenderPerBatch={5}
>
</FlatList>
</ScrollView>
</FlatList>}
</View>
)
}
}
function makeColumnInfo(n) {
const xAxisDates = getPreviousDays(n).map(jsDate => {
function makeColumnInfo(getFhmAndLtlInfo) {
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 xAxisDates = getTodayAndPreviousDays(amountOfCycleDays).map(jsDate => {
return LocalDate.of(
jsDate.getFullYear(),
jsDate.getMonth() + 1,
@@ -200,18 +77,29 @@ function makeColumnInfo(n) {
).toString()
})
return xAxisDates.map(dateString => {
const columns = xAxisDates.map(dateString => {
const cycleDay = getCycleDay(dateString)
const temp = cycleDay && cycleDay.temperature && cycleDay.temperature.value
const symptoms = ['temperature', 'mucus', 'bleeding'].reduce((acc, symptom) => {
acc[symptom] = cycleDay && cycleDay[symptom] && cycleDay[symptom].value
acc[`${symptom}Exclude`] = cycleDay && cycleDay[symptom] && cycleDay[symptom].exclude
return acc
}, {})
return {
dateString,
cycleDay,
y: temp ? normalizeToScale(temp) : null
y: symptoms.temperature ? normalizeToScale(symptoms.temperature) : null,
...symptoms,
...getFhmAndLtlInfo(dateString, symptoms.temperature)
}
})
return columns.map((col, i) => {
const info = getInfoForNeighborColumns(i, columns)
return Object.assign(col, info)
})
}
function getPreviousDays(n) {
function getTodayAndPreviousDays(n) {
const today = new Date()
today.setHours(0)
today.setMinutes(0)
@@ -222,114 +110,22 @@ function getPreviousDays(n) {
return range(earlierDate, today).reverse()
}
function normalizeToScale(temp) {
const scale = config.temperatureScale
const valueRelativeToScale = (scale.high - temp) / (scale.high - scale.low)
const scaleHeight = config.chartHeight
return scaleHeight * valueRelativeToScale
}
function makeYAxis() {
const scaleMin = config.temperatureScale.low
const scaleMax = config.temperatureScale.high
const numberOfTicks = (scaleMax - scaleMin) * 2
const tickDistance = config.chartHeight / numberOfTicks
const tickPositions = []
const labels = []
// for style reasons, we don't want the first and last tick
for (let i = 1; i < numberOfTicks - 1; i++) {
const y = tickDistance * i
const style = styles.yAxisLabel
// 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
style.top = y - 8
labels.push(
<ReactNativeText
style={{...style}}
key={i}>
{scaleMax - i * 0.5}
</ReactNativeText>
)
tickPositions.push(y)
function getInfoForNeighborColumns(index, cols) {
const ret = {
rightY: null,
rightTemperatureExclude: null,
leftY: null,
leftTemperatureExclude: null
}
return {labels, tickPositions}
}
function setUpFertilityStatusFunc() {
let cycleStatus
let cycleStartDate
let noMoreCycles = false
function updateCurrentCycle(dateString) {
cycleStatus = getCycleStatusForDay(dateString)
if(!cycleStatus) {
noMoreCycles = true
return
}
if (cycleStatus.phases.preOvulatory) {
cycleStartDate = cycleStatus.phases.preOvulatory.start.date
} else {
cycleStartDate = cycleStatus.phases.periOvulatory.start.date
}
const right = index > 0 ? cols[index - 1] : undefined
const left = index < cols.length - 1 ? cols[index + 1] : undefined
if (right && right.y) {
ret.rightY = right.y
ret.rightTemperatureExclude = right.temperatureExclude
}
function dateIsInPeriOrPostPhase(dateString) {
return (
dateString >= cycleStatus.phases.periOvulatory.start.date
)
}
function precededByAnotherTempValue(dateString) {
return (
// we are only interested in days that have a preceding
// temp
Object.keys(cycleStatus.phases).some(phaseName => {
return cycleStatus.phases[phaseName].cycleDays.some(day => {
return day.temperature && day.date < dateString
})
})
// and also a following temp, so we don't draw the line
// longer than necessary
&&
cycleStatus.phases.postOvulatory.cycleDays.some(day => {
return day.temperature && day.date > dateString
})
)
}
function isInTempMeasuringPhase(cycleDay, dateString) {
return (
cycleDay && cycleDay.temperature
|| precededByAnotherTempValue(dateString)
)
}
return function(dateString, cycleDay) {
const ret = {}
if (!cycleStatus && !noMoreCycles) updateCurrentCycle(dateString)
if (noMoreCycles) return ret
if (dateString < cycleStartDate) updateCurrentCycle(dateString)
if (noMoreCycles) return ret
const tempShift = cycleStatus.temperatureShift
if (tempShift) {
if (tempShift.firstHighMeasurementDay.date === dateString) {
ret.drawFhmLine = true
}
if (
dateIsInPeriOrPostPhase(dateString) &&
isInTempMeasuringPhase(cycleDay, dateString)
) {
ret.drawLtlAt = normalizeToScale(tempShift.ltl)
}
}
return ret
if (left && left.y) {
ret.leftY = left.y
ret.leftTemperatureExclude = left.temperatureExclude
}
return ret
}
+5 -5
View File
@@ -1,11 +1,11 @@
const config = {
chartHeight: 350,
columnWidth: 30,
columnWidth: 25,
temperatureScale: {
low: 33,
high: 40
},
xAxisRangeInDays: 40
low: 35,
high: 38,
units: 0.1
}
}
const margin = 3
+136
View File
@@ -0,0 +1,136 @@
import React, { Component } from 'react'
import {
Text, View, TouchableOpacity
} from 'react-native'
import Icon from 'react-native-vector-icons/Entypo'
import styles from './styles'
import config from './config'
import { getOrCreateCycleDay } from '../../db'
import cycleModule from '../../lib/cycle'
import DotAndLine from './dot-and-line'
const getCycleDayNumber = cycleModule().getCycleDayNumber
const label = styles.column.label
export default class DayColumn extends Component {
passDateToDayView(dateString) {
const cycleDay = getOrCreateCycleDay(dateString)
this.props.navigate('cycleDay', { cycleDay })
}
shouldComponentUpdate(newProps) {
return Object.keys(newProps).some(key => newProps[key] != this.props[key])
}
render() {
const {
dateString,
y,
temperatureExclude,
bleeding,
mucus,
drawFhmLine,
drawLtlAt,
rightY,
rightTemperatureExclude,
leftY,
leftTemperatureExclude
} = this.props
const columnElements = []
if (typeof bleeding === 'number') {
columnElements.push(
<Icon
name='drop'
position='absolute'
size={18}
color='#900'
style={{ marginTop: 10, marginLeft: 3 }}
key='bleeding'
/>
)
}
if (typeof mucus === 'number') {
const mucusIcon = (
<View
position='absolute'
top = {40}
left = {config.columnMiddle - styles.mucusIcon.width / 2}
{...styles.mucusIcon}
backgroundColor={styles.mucusIconShades[mucus]}
key='mucus'
/>
)
columnElements.push(mucusIcon)
}
if(drawFhmLine) {
const fhmLine = (<View
position = 'absolute'
top={100}
width={styles.nfpLine.strokeWidth}
height={200}
{...styles.nfpLine}
key='fhm'
/>)
columnElements.push(fhmLine)
}
if(drawLtlAt) {
const ltlLine = (<View
position = 'absolute'
width={'100%'}
top={drawLtlAt}
{...styles.nfpLine}
key='ltl'
/>)
columnElements.push(ltlLine)
}
if (y) {
columnElements.push(
<DotAndLine
y={y}
exclude={temperatureExclude}
rightY={rightY}
rightTemperatureExclude={rightTemperatureExclude}
leftY={leftY}
leftTemperatureExclude={leftTemperatureExclude}
key='dotandline'
/>
)
}
const cycleDayNumber = getCycleDayNumber(dateString)
const shortDate = dateString.split('-').slice(1).join('-')
const cycleDayLabel = (
<Text style={label.number} y={config.cycleDayNumberRowY}>
{cycleDayNumber}
</Text>)
const dateLabel = (
<Text style = {label.date} y={config.dateRowY}>
{shortDate}
</Text>
)
columnElements.push(
<View position='absolute' bottom={0} key='date'>
{cycleDayLabel}
{dateLabel}
</View>
)
return React.createElement(
TouchableOpacity,
{
style: styles.column.rect,
key: this.props.index.toString(),
onPress: () => {
this.passDateToDayView(dateString)
},
activeOpacity: 1
},
columnElements
)
}
}
+71
View File
@@ -0,0 +1,71 @@
import React, { Component } from 'react'
import { View } from 'react-native'
import styles from './styles'
import config from './config'
export default class DotAndLine extends Component {
shouldComponentUpdate(newProps) {
return Object.keys(newProps).some(key => newProps[key] != this.props[key])
}
render() {
const y = this.props.y
const exclude = this.props.exclude
let lineToRight
let lineToLeft
if (this.props.leftY) {
const middleY = ((this.props.leftY - y) / 2) + y
const excludedLine = this.props.leftTemperatureExclude || exclude
lineToLeft = makeLine(middleY, y, 'left', excludedLine)
}
if (this.props.rightY) {
const middleY = ((y - this.props.rightY) / 2) + this.props.rightY
const excludedLine = this.props.rightTemperatureExclude || exclude
lineToRight = makeLine(y, middleY, 'right', excludedLine)
}
const dotStyle = exclude ? styles.curveDotsExcluded : styles.curveDots
const dot = (
<View
position='absolute'
top={y - (dotStyle.height / 2)}
left={config.columnMiddle - (dotStyle.width / 2)}
style={dotStyle}
key='dot'
/>
)
return [lineToLeft, lineToRight, dot]
}
}
function makeLine(leftY, rightY, direction, excludeLine) {
const colWidth = config.columnWidth
const heightDiff = -leftY - -rightY
const angle = Math.atan2(heightDiff, colWidth / 2)
const lineStyle = excludeLine ? styles.curveExcluded : styles.curve
// hypotenuse, we add 3px for good measure, because otherwise the lines
// don't quite touch at the day border
const h = (colWidth / 2) / Math.cos(angle) + 10
// the rotation by default rotates from the middle of the line,
// but we want the transform origin to be at its beginning
// react native doesn't have transformOrigin, so we do this manually
// if it's the right line, we put the pivot at 3/4 of the column
// if it's to the left, at 1/4
const pivot = direction === 'right' ? colWidth / 4 : -(colWidth / 4)
const projectedX = -(h - colWidth) / 2 + pivot
return (<View
width={h}
position='absolute'
top={((leftY + rightY) / 2) - lineStyle.borderWidth / 2}
left={projectedX}
style={{
transform: [
{ rotateZ: `${angle}rad` }
],
}}
{...lineStyle}
key ={direction}
/>)
}
+12
View File
@@ -0,0 +1,12 @@
<svg version="1.1"
baseProfile="full"
width="300" height="200"
xmlns="http://www.w3.org/2000/svg">
<path d="
M15 3
Q16.5 6.8 25 18
A12.8 12.8 0 1 1 5 18
Q13.5 6.8 15 3z
" />
</svg>

After

Width:  |  Height:  |  Size: 217 B

+80
View File
@@ -0,0 +1,80 @@
import { getCycleStatusForDay } from '../../lib/sympto-adapter'
import { normalizeToScale } from './y-axis'
export default function () {
const cycle = {
status: null
}
function updateCurrentCycle(dateString) {
cycle.status = getCycleStatusForDay(dateString)
if(!cycle.status) {
cycle.noMoreCycles = true
return
}
if (cycle.status.phases.preOvulatory) {
cycle.startDate = cycle.status.phases.preOvulatory.start.date
} else {
cycle.startDate = cycle.status.phases.periOvulatory.start.date
}
}
function dateIsInPeriOrPostPhase(dateString) {
return (
dateString >= cycle.status.phases.periOvulatory.start.date
)
}
function precededByAnotherTempValue(dateString) {
return (
// we are only interested in days that have a preceding
// temp
Object.keys(cycle.status.phases).some(phaseName => {
return cycle.status.phases[phaseName].cycleDays.some(day => {
return day.temperature && day.date < dateString
})
})
// and also a following temp, so we don't draw the line
// longer than necessary
&&
cycle.status.phases.postOvulatory.cycleDays.some(day => {
return day.temperature && day.date > dateString
})
)
}
function isInTempMeasuringPhase(temperature, dateString) {
return (
temperature || precededByAnotherTempValue(dateString)
)
}
return function(dateString, temperature) {
const ret = {
drawLtlAt: null,
drawFhmLine: false
}
if (!cycle.status && !cycle.noMoreCycles) updateCurrentCycle(dateString)
if (cycle.noMoreCycles) return ret
if (dateString < cycle.startDate) updateCurrentCycle(dateString)
if (cycle.noMoreCycles) return ret
const tempShift = cycle.status.temperatureShift
if (tempShift) {
if (tempShift.firstHighMeasurementDay.date === dateString) {
ret.drawFhmLine = true
}
if (
dateIsInPeriOrPostPhase(dateString) &&
isInTempMeasuringPhase(temperature, dateString)
) {
ret.drawLtlAt = normalizeToScale(tempShift.ltl)
}
}
return ret
}
}
+40 -30
View File
@@ -2,44 +2,46 @@ import config from './config'
const styles = {
curve: {
stroke: '#ffc425',
strokeWidth: 2
borderStyle: 'solid',
borderColor: '#ffc425',
borderWidth: 2,
},
curveExcluded: {
stroke: 'lightgrey',
strokeWidth: 2,
strokeDashArray: [4]
borderColor: 'lightgrey',
borderWidth: 2,
borderStyle: 'solid'
},
curveDots: {
fill: '#00aedb',
r: 6
backgroundColor: '#00aedb',
width: 12,
height: 12,
borderRadius: 50
},
curveDotsExcluded: {
fill: 'lightgrey',
r: 6
backgroundColor: 'lightgrey',
width: 12,
height: 12,
borderRadius: 50
},
column: {
label: {
date: {
stroke: 'grey',
fontSize: 10,
x: 2,
color: 'grey',
fontSize: 9,
fontWeight: '100'
},
number: {
stroke: '#00b159',
color: '#00b159',
fontSize: 13,
x: config.columnMiddle - 1
textAlign: 'center'
}
},
rect: {
fill: '#f9f9f9',
strokeWidth: 1,
stroke: 'grey',
x: 0,
y: 0,
width: config.columnWidth,
height: config.chartHeight
height: config.chartHeight,
borderStyle: 'solid',
borderColor: 'grey',
borderWidth: 0.5
}
},
bleedingIcon: {
@@ -49,9 +51,9 @@ const styles = {
y: 3
},
mucusIcon: {
cx: config.columnWidth / 2,
cy: 50,
r: 10
width: 12,
height: 12,
borderRadius: 50,
},
mucusIconShades: [
'#cc99cc',
@@ -63,21 +65,29 @@ const styles = {
yAxis: {
height: config.chartHeight,
width: config.columnWidth,
borderRightWidth: 0.5,
borderColor: 'lightgrey',
borderStyle: 'solid'
},
yAxisLabel: {
position: 'absolute',
right: 3,
left: 3,
color: 'grey',
fontSize: 12,
fontWeight: 'bold'
fontSize: 11,
textAlign: 'left'
},
horizontalGrid: {
stroke: 'lightgrey',
strokeWidth: 1
position:'absolute',
borderColor: 'lightgrey',
borderWidth: 0.5,
width: '100%',
borderStyle: 'solid',
left: config.columnWidth
},
nfpLine: {
stroke: '#00b159',
strokeWidth: 3
borderColor: '#00b159',
borderWidth: 2,
borderStyle: 'solid'
}
}
+53
View File
@@ -0,0 +1,53 @@
import React from 'react'
import { Text, View } from 'react-native'
import config from './config'
import styles from './styles'
function makeYAxis() {
const scale = config.temperatureScale
const scaleMin = scale.low
const scaleMax = scale.high
const numberOfTicks = (scaleMax - scaleMin) * (1 / scale.units)
const tickDistance = config.chartHeight / numberOfTicks
const tickPositions = []
const labels = []
// for style reasons, we don't want the first and last tick
for (let i = 1; i < numberOfTicks - 1; i++) {
const y = tickDistance * i
const style = styles.yAxisLabel
// 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
style.top = y - 8
labels.push(
<Text
style={{...style}}
key={i}>
{scaleMax - i * scale.units}
</Text>
)
tickPositions.push(y)
}
return {labels, tickPositions}
}
export const yAxis = makeYAxis()
export const horizontalGrid = yAxis.tickPositions.map(tick => {
return (
<View
top={tick}
{...styles.horizontalGrid}
key={tick}
/>
)
})
export function normalizeToScale(temp) {
const scale = config.temperatureScale
const valueRelativeToScale = (scale.high - temp) / (scale.high - scale.low)
const scaleHeight = config.chartHeight
return scaleHeight * valueRelativeToScale
}
+31 -4
View File
@@ -98,11 +98,20 @@ export default class DayView extends Component {
<Text style={styles.symptomDayView}>Desire</Text>
<View style={styles.symptomEditButton}>
<Button
onPress={() => this.showView('desireEditView')}
onPress={() => this.showView('DesireEditView')}
title={getLabel('desire', cycleDay.desire)}>
</Button>
</View>
</View>
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>Sex</Text>
<View style={styles.symptomEditButton}>
<Button
onPress={() => this.showView('SexEditView')}
title={getLabel('sex', cycleDay.sex)}>
</Button>
</View>
</View>
</View >
)
}
@@ -132,15 +141,22 @@ function getLabel(symptomName, symptom) {
typeof mucus.texture === 'number' &&
typeof mucus.value === 'number'
) {
let mucusLabel = `${feelingLabels[mucus.feeling]} + ${textureLabels[mucus.texture]} ( ${computeSensiplanMucusLabels[mucus.value]} )`
let mucusLabel =
`${feelingLabels[mucus.feeling]} +
${textureLabels[mucus.texture]}
( ${computeSensiplanMucusLabels[mucus.value]} )`
if (mucus.exclude) mucusLabel = "( " + mucusLabel + " )"
return mucusLabel
}
},
cervix: cervix => {
if (cervix.opening > -1 && cervix.firmness > -1) {
let cervixLabel = `${openingLabels[cervix.opening]} + ${firmnessLabels[cervix.firmness]}`
if (cervix.position > -1) cervixLabel += `+ ${positionLabels[cervix.position]}`
let cervixLabel =
`${openingLabels[cervix.opening]} +
${firmnessLabels[cervix.firmness]}`
if (cervix.position > -1) {
cervixLabel += `+ ${positionLabels[cervix.position]}`
}
if (cervix.exclude) cervixLabel = "( " + cervixLabel + " )"
return cervixLabel
}
@@ -153,6 +169,17 @@ function getLabel(symptomName, symptom) {
const desireLabel = `${intensityLabels[desire.value]}`
return desireLabel
}
},
sex: sex => {
let sexLabel = ''
if ( sex.solo || sex.partner ) {
sexLabel += 'Activity '
}
if (sex.condom || sex.pill || sex.iud ||
sex.patch || sex.ring || sex.implant || sex.other) {
sexLabel += 'Contraceptive'
}
return sexLabel ? sexLabel : 'edit'
}
}
+13
View File
@@ -6,6 +6,19 @@ export const cervixOpening = ['closed', 'medium', 'open']
export const cervixFirmness = ['hard', 'soft']
export const cervixPosition = ['low', 'medium', 'high']
export const intensity = ['low', 'medium', 'high']
export const sexActivity = {
solo: 'Solo',
partner: 'Partner'
}
export const contraceptives = {
condom: 'Condom',
pill: 'Pill',
iud: 'IUD',
patch: 'Patch',
ring: 'Ring',
implant: 'Implant',
other: 'Other'
}
export const fertilityStatus = {
fertile: 'fertile',
+4 -2
View File
@@ -4,6 +4,7 @@ import MucusEditView from './mucus'
import CervixEditView from './cervix'
import NoteEditView from './note'
import DesireEditView from './desire'
import SexEditView from './sex'
export default {
BleedingEditView,
@@ -11,5 +12,6 @@ export default {
MucusEditView,
CervixEditView,
NoteEditView,
DesireEditView
}
DesireEditView,
SexEditView
}
+156
View File
@@ -0,0 +1,156 @@
import React, { Component } from 'react'
import {
CheckBox,
Text,
TextInput,
View
} from 'react-native'
import styles from '../../../styles'
import { saveSymptom } from '../../../db'
import {
sexActivity as activityLabels,
contraceptives as contraceptiveLabels
} from '../labels/labels'
export default class Sex extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
this.state = {}
if (this.cycleDay.sex !== null ) {
Object.assign(this.state, this.cycleDay.sex)
// We make sure other is always true when there is a note,
// e.g. when import is messed up.
if (this.cycleDay.sex && this.cycleDay.sex.note) {
this.state.other = true
}
}
}
render() {
return (
<View style={styles.symptomEditView}>
<Text style={styles.symptomDayView}>SEX</Text>
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>{activityLabels.solo}</Text>
<CheckBox
value={this.state.solo}
onValueChange={(val) => {
this.setState({solo: val})
}}
/>
<Text style={styles.symptomDayView}>{activityLabels.partner}</Text>
<CheckBox
value={this.state.partner}
onValueChange={(val) => {
this.setState({partner: val})
}}
/>
</View>
<Text style={styles.symptomDayView}>CONTRACEPTIVES</Text>
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>
{contraceptiveLabels.condom}
</Text>
<CheckBox
value={this.state.condom}
onValueChange={(val) => {
this.setState({condom: val})
}}
/>
<Text style={styles.symptomDayView}>
{contraceptiveLabels.pill}
</Text>
<CheckBox
value={this.state.pill}
onValueChange={(val) => {
this.setState({pill: val})
}}
/>
</View>
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>
{contraceptiveLabels.iud}
</Text>
<CheckBox
value={this.state.iud}
onValueChange={(val) => {
this.setState({iud: val})
}}
/>
<Text style={styles.symptomDayView}>
{contraceptiveLabels.patch}
</Text>
<CheckBox
value={this.state.patch}
onValueChange={(val) => {
this.setState({patch: val})
}}
/>
</View>
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>
{contraceptiveLabels.ring}
</Text>
<CheckBox
value={this.state.ring}
onValueChange={(val) => {
this.setState({ring: val})
}}
/>
<Text style={styles.symptomDayView}>
{contraceptiveLabels.implant}
</Text>
<CheckBox
value={this.state.implant}
onValueChange={(val) => {
this.setState({implant: val})
}}
/>
</View>
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>
{contraceptiveLabels.other}
</Text>
<CheckBox
value={this.state.other}
onValueChange={(val) => {
this.setState({
other: val,
focusTextArea: true
})
}}
/>
</View>
{ this.state.other &&
<TextInput
autoFocus={this.state.focusTextArea}
multiline={true}
placeholder="Enter"
value={this.state.note}
onChangeText={(val) => {
this.setState({note: val})
}}
/>
}
<View style={styles.actionButtonRow}>
{this.props.makeActionButtons(
{
symptom: 'sex',
cycleDay: this.cycleDay,
saveAction: () => {
const copyOfState = Object.assign({}, this.state)
if (!copyOfState.other) {
copyOfState.note = null
}
saveSymptom('sex', this.cycleDay, copyOfState)
},
saveDisabled: Object.values(this.state).every(value => !value)
}
)}
</View>
</View>
)
}
}
+5 -1
View File
@@ -70,8 +70,12 @@ export default class Temp extends Component {
mode="time"
isVisible={this.state.isTimePickerVisible}
onConfirm={jsDate => {
let hours = jsDate.getHours()
if (hours < 10) hours = `0${hours}`
let minutes = jsDate.getMinutes()
if (minutes < 10) minutes = `0${minutes}`
this.setState({
time: `${jsDate.getHours()}:${jsDate.getMinutes()}`,
time: `${hours}:${minutes}`,
isTimePickerVisible: false
})
}}
+1 -26
View File
@@ -42,11 +42,10 @@ export default class Home extends Component {
const todayDateString = LocalDate.now().toString()
const cycleDay = getOrCreateCycleDay(todayDateString)
const navigate = this.props.navigation.navigate
navigate('cycleDay', { cycleDay })
navigate('CycleDay', { cycleDay })
}
render() {
const navigate = this.props.navigation.navigate
return (
<ScrollView>
<Text style={styles.welcome}>{this.state.welcomeText}</Text>
@@ -57,24 +56,6 @@ export default class Home extends Component {
title="Edit symptoms for today">
</Button>
</View>
<View style={styles.homeButton}>
<Button
onPress={() => navigate('calendar')}
title="Go to calendar">
</Button>
</View>
<View style={styles.homeButton}>
<Button
onPress={() => navigate('chart')}
title="Go to chart">
</Button>
</View>
<View style={styles.homeButton}>
<Button
onPress={() => navigate('settings')}
title="Go to settings">
</Button>
</View>
<View style={styles.homeButton}>
<Button
onPress={() => fillWithDummyData()}
@@ -87,12 +68,6 @@ export default class Home extends Component {
title="delete everything">
</Button>
</View>
<View style={styles.homeButton}>
<Button
onPress={() => navigate('stats')}
title="Go to stats">
</Button>
</View>
</View>
</ScrollView>
)
+30 -7
View File
@@ -1,12 +1,35 @@
export const settings = {
errors: {
noData: 'There is no data to export',
couldNotConvert: 'Could not convert data to CSV',
problemSharing: 'There was a problem sharing the data export file'
shared: {
cancel: 'Cancel',
errorTitle: 'Error',
successTitle: 'Success'
},
exportTitle: 'My Drip data export',
exportSubject: 'My Drip data export',
buttonLabel: 'Export data'
export: {
errors: {
noData: 'There is no data to export',
couldNotConvert: 'Could not convert data to CSV',
problemSharing: 'There was a problem sharing the data export file'
},
title: 'My Drip data export',
subject: 'My Drip data export',
button: 'Export data',
},
import: {
button: 'Import data',
title: 'Keep existing data?',
message: `There are two options for the import:
1. Keep existing cycle days and replace only the ones in the import file.
2. Delete all existing cycle days and import cycle days from file.`,
replaceOption: 'Import and replace',
deleteOption: 'Import and delete existing',
errors: {
couldNotOpenFile: 'Could not open file',
postFix: 'No data was imported or changed'
},
success: {
message: 'Data successfully imported'
}
}
}
export const stats = {
+94 -27
View File
@@ -7,9 +7,12 @@ import {
} from 'react-native'
import Share from 'react-native-share'
import getDataAsCsvDataUri from '../lib/export-to-csv'
import { DocumentPicker, DocumentPickerUtil } from 'react-native-document-picker'
import rnfs from 'react-native-fs'
import styles from '../styles/index'
import { settings as labels } from './labels'
import getDataAsCsvDataUri from '../lib/import-export/export-to-csv'
import importCsv from '../lib/import-export/import-from-csv'
export default class Settings extends Component {
render() {
@@ -18,36 +21,100 @@ export default class Settings extends Component {
<View style={styles.homeButtons}>
<View style={styles.homeButton}>
<Button
onPress={async () => {
let data
try {
data = getDataAsCsvDataUri()
if (!data) {
return Alert.alert(labels.errors.noData)
}
} catch (err) {
console.error(err)
return Alert.alert(labels.errors.couldNotConvert)
}
try {
await Share.open({
title: labels.exportTitle,
url: data,
subject: labels.exportSubject,
type: 'text/csv',
showAppsToView: true
})
} catch (err) {
console.error(err)
return Alert.alert(labels.errors.problemSharing)
}
}}
title={labels.buttonLabel}>
onPress={ openShareDialogAndExport }
title={labels.export.button}>
</Button>
</View>
<View style={styles.homeButton}>
<Button
title={labels.import.button}
onPress={ openImportDialogAndImport }>
</Button>
</View>
</View>
</ScrollView>
)
}
}
async function openShareDialogAndExport() {
let data
try {
data = getDataAsCsvDataUri()
if (!data) {
return alertError(labels.errors.noData)
}
} catch (err) {
console.error(err)
return alertError(labels.errors.couldNotConvert)
}
try {
await Share.open({
title: labels.export.title,
url: data,
subject: labels.export.subject,
type: 'text/csv',
showAppsToView: true
})
} catch (err) {
console.error(err)
return alertError(labels.export.errors.problemSharing)
}
}
function openImportDialogAndImport() {
Alert.alert(
labels.import.title,
labels.import.message,
[{
text: labels.import.replaceOption,
onPress: () => getFileContentAndImport({ deleteExisting: false })
}, {
text: labels.import.deleteOption,
onPress: () => getFileContentAndImport({ deleteExisting: true })
}, {
text: labels.shared.cancel, style: 'cancel', onPress: () => { }
}]
)
}
async function getFileContentAndImport({ deleteExisting }) {
let fileInfo
try {
fileInfo = await new Promise((resolve, reject) => {
DocumentPicker.show({
filetype: [DocumentPickerUtil.allFiles()],
}, (err, res) => {
if (err) return reject(err)
resolve(res)
})
})
} catch (err) {
// because cancelling also triggers an error, we do nothing here
return
}
let fileContent
try {
fileContent = await rnfs.readFile(fileInfo.uri, 'utf8')
} catch (err) {
return importError(labels.import.errors.couldNotOpenFile)
}
try {
await importCsv(fileContent, deleteExisting)
Alert.alert(labels.import.success.title, labels.import.success.message)
} catch(err) {
importError(err.message)
}
}
function alertError(msg) {
Alert.alert(labels.shared.errorTitle, msg)
}
function importError(msg) {
const postFixed = `${msg}\n\n${labels.import.errors.postFix}`
alertError(postFixed)
}