Substitute navigate&setDate props with naviation&route props

This commit is contained in:
MariaZ
2022-09-28 19:59:17 +02:00
parent b6024ae921
commit e2d6387647
5 changed files with 38 additions and 35 deletions
+11 -9
View File
@@ -1,4 +1,4 @@
import React from 'react' import React, { useEffect } from 'react'
import { ScrollView, StyleSheet, View } from 'react-native' import { ScrollView, StyleSheet, View } from 'react-native'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import moment from 'moment' import moment from 'moment'
@@ -10,6 +10,7 @@ import Footnote from './common/Footnote'
import cycleModule from '../lib/cycle' import cycleModule from '../lib/cycle'
import { getFertilityStatusForDay } from '../lib/sympto-adapter' import { getFertilityStatusForDay } from '../lib/sympto-adapter'
import setupNotifications from '../lib/notifications'
import { import {
determinePredictionText, determinePredictionText,
formatWithOrdinalSuffix, formatWithOrdinalSuffix,
@@ -19,13 +20,10 @@ import { Colors, Fonts, Sizes, Spacing } from '../styles'
import { LocalDate } from '@js-joda/core' import { LocalDate } from '@js-joda/core'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
const Home = ({ navigate, setDate }) => { const Home = ({ navigation }) => {
const { t } = useTranslation() const { t } = useTranslation()
function navigateToCycleDayView() { useEffect(() => setupNotifications(navigation), [])
setDate(todayDateString)
navigate('CycleDay')
}
const todayDateString = LocalDate.now().toString() const todayDateString = LocalDate.now().toString()
const { getCycleDayNumber, getPredictedMenses } = cycleModule() const { getCycleDayNumber, getPredictedMenses } = cycleModule()
@@ -33,11 +31,14 @@ const Home = ({ navigate, setDate }) => {
const { status, phase, statusText } = const { status, phase, statusText } =
getFertilityStatusForDay(todayDateString) getFertilityStatusForDay(todayDateString)
const prediction = determinePredictionText(getPredictedMenses(), t) const prediction = determinePredictionText(getPredictedMenses(), t)
const cycleDayText = cycleDayNumber const cycleDayText = cycleDayNumber
? formatWithOrdinalSuffix(cycleDayNumber) ? formatWithOrdinalSuffix(cycleDayNumber)
: '' : ''
function navigateToCycleDayView() {
navigation.navigate('CycleDayOverview', { date: todayDateString })
}
return ( return (
<ScrollView <ScrollView
style={styles.container} style={styles.container}
@@ -109,8 +110,9 @@ const styles = StyleSheet.create({
}) })
Home.propTypes = { Home.propTypes = {
navigate: PropTypes.func, navigation: PropTypes.shape({
setDate: PropTypes.func, navigate: PropTypes.func.isRequired,
}).isRequired,
} }
export default Home export default Home
+4 -4
View File
@@ -12,13 +12,12 @@ import {
todayToCalFormat, todayToCalFormat,
} from './helpers/calendar' } from './helpers/calendar'
const CalendarView = ({ setDate, navigate }) => { const CalendarView = ({ navigation }) => {
const bleedingDays = getBleedingDaysSortedByDate() const bleedingDays = getBleedingDaysSortedByDate()
const predictedMenses = cycleModule().getPredictedMenses() const predictedMenses = cycleModule().getPredictedMenses()
const passDateToDayView = ({ dateString }) => { const passDateToDayView = ({ dateString }) => {
setDate(dateString) navigation.navigate('CycleDayOverview', { date: dateString })
navigate('CycleDay')
} }
const markedDates = Object.assign( const markedDates = Object.assign(
@@ -49,8 +48,9 @@ const styles = StyleSheet.create({
}) })
CalendarView.propTypes = { CalendarView.propTypes = {
setDate: PropTypes.func.isRequired, navigation: PropTypes.shape({
navigate: PropTypes.func.isRequired, navigate: PropTypes.func.isRequired,
}).isRequired,
} }
export default CalendarView export default CalendarView
+6 -6
View File
@@ -28,7 +28,7 @@ import { Spacing } from '../../styles'
const getSymptomsFromCycleDays = (cycleDays) => const getSymptomsFromCycleDays = (cycleDays) =>
SYMPTOMS.filter((symptom) => cycleDays.some((cycleDay) => cycleDay[symptom])) SYMPTOMS.filter((symptom) => cycleDays.some((cycleDay) => cycleDay[symptom]))
const CycleChart = ({ navigate, setDate }) => { const CycleChart = ({ navigation }) => {
const [shouldShowHint, setShouldShowHint] = useState(true) const [shouldShowHint, setShouldShowHint] = useState(true)
useEffect(() => { useEffect(() => {
@@ -84,9 +84,8 @@ const CycleChart = ({ navigate, setDate }) => {
const renderColumn = ({ item }) => { const renderColumn = ({ item }) => {
return ( return (
<DayColumn <DayColumn
setDate={setDate}
dateString={item} dateString={item}
navigate={navigate} navigation={navigation}
symptomHeight={symptomHeight} symptomHeight={symptomHeight}
columnHeight={columnHeight} columnHeight={columnHeight}
symptomRowSymptoms={symptomRowSymptoms} symptomRowSymptoms={symptomRowSymptoms}
@@ -100,7 +99,7 @@ const CycleChart = ({ navigate, setDate }) => {
const hasDataToDisplay = chartSymptoms.length > 0 const hasDataToDisplay = chartSymptoms.length > 0
if (!hasDataToDisplay) { if (!hasDataToDisplay) {
return <NoData navigate={navigate} /> return <NoData />
} }
return ( return (
@@ -135,8 +134,9 @@ const CycleChart = ({ navigate, setDate }) => {
} }
CycleChart.propTypes = { CycleChart.propTypes = {
navigate: PropTypes.func, navigation: PropTypes.shape({
setDate: PropTypes.func, navigate: PropTypes.func.isRequired,
}).isRequired,
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({
+6 -8
View File
@@ -19,8 +19,7 @@ const DayColumn = ({
dateString, dateString,
chartSymptoms, chartSymptoms,
columnHeight, columnHeight,
setDate, navigation,
navigate,
shouldShowTemperatureColumn, shouldShowTemperatureColumn,
symptomHeight, symptomHeight,
symptomRowSymptoms, symptomRowSymptoms,
@@ -60,10 +59,8 @@ const DayColumn = ({
columnHeight columnHeight
) )
const onDaySelect = (date) => { const onDaySelect = (date) =>
setDate(date) navigation.navigate('CycleDayOverview', { date })
navigate('CycleDay')
}
return ( return (
<TouchableOpacity onPress={() => onDaySelect(dateString)} activeOpacity={1}> <TouchableOpacity onPress={() => onDaySelect(dateString)} activeOpacity={1}>
@@ -104,12 +101,13 @@ DayColumn.propTypes = {
dateString: PropTypes.string.isRequired, dateString: PropTypes.string.isRequired,
chartSymptoms: PropTypes.array, chartSymptoms: PropTypes.array,
columnHeight: PropTypes.number.isRequired, columnHeight: PropTypes.number.isRequired,
navigate: PropTypes.func.isRequired,
setDate: PropTypes.func.isRequired,
shouldShowTemperatureColumn: PropTypes.bool, shouldShowTemperatureColumn: PropTypes.bool,
symptomHeight: PropTypes.number.isRequired, symptomHeight: PropTypes.number.isRequired,
symptomRowSymptoms: PropTypes.array, symptomRowSymptoms: PropTypes.array,
xAxisHeight: PropTypes.number, xAxisHeight: PropTypes.number,
navigation: PropTypes.shape({
navigate: PropTypes.func.isRequired,
}).isRequired,
} }
export default DayColumn export default DayColumn
+8 -5
View File
@@ -12,7 +12,8 @@ import { getData, nextDate, prevDate } from '../helpers/cycle-day'
import { Spacing } from '../../styles' import { Spacing } from '../../styles'
import { SYMPTOMS } from '../../config' import { SYMPTOMS } from '../../config'
const CycleDayOverView = ({ date, setDate, isTemperatureEditView }) => { const CycleDayOverView = ({ route }) => {
const { date, isTemperatureEditView } = route.params
const cycleDay = getCycleDay(date) const cycleDay = getCycleDay(date)
const [editedSymptom, setEditedSymptom] = useState( const [editedSymptom, setEditedSymptom] = useState(
@@ -20,11 +21,11 @@ const CycleDayOverView = ({ date, setDate, isTemperatureEditView }) => {
) )
const showNextCycleDay = () => { const showNextCycleDay = () => {
setDate(nextDate(date)) //setDate(nextDate(date))
} }
const showPrevCycleDay = () => { const showPrevCycleDay = () => {
setDate(prevDate(date)) //setDate(prevDate(date))
} }
return ( return (
@@ -57,10 +58,12 @@ const CycleDayOverView = ({ date, setDate, isTemperatureEditView }) => {
} }
CycleDayOverView.propTypes = { CycleDayOverView.propTypes = {
cycleDay: PropTypes.object, route: PropTypes.shape({
params: PropTypes.shape({
date: PropTypes.string, date: PropTypes.string,
setDate: PropTypes.func,
isTemperatureEditView: PropTypes.bool, isTemperatureEditView: PropTypes.bool,
}),
}),
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({