Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f3d115aca | |||
| 2f187b1007 |
+3
-2
@@ -18,9 +18,11 @@ import {
|
|||||||
import { Colors, Fonts, Sizes, Spacing } from '../styles'
|
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'
|
||||||
|
import { useDate } from '../hooks/useDate'
|
||||||
|
|
||||||
const Home = ({ navigate, setDate }) => {
|
const Home = ({ navigate }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const { setDate } = useDate()
|
||||||
|
|
||||||
function navigateToCycleDayView() {
|
function navigateToCycleDayView() {
|
||||||
setDate(todayDateString)
|
setDate(todayDateString)
|
||||||
@@ -110,7 +112,6 @@ const styles = StyleSheet.create({
|
|||||||
|
|
||||||
Home.propTypes = {
|
Home.propTypes = {
|
||||||
navigate: PropTypes.func,
|
navigate: PropTypes.func,
|
||||||
setDate: PropTypes.func,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Home
|
export default Home
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import AppStatusBar from './common/app-status-bar'
|
|||||||
import AcceptLicense from './AcceptLicense'
|
import AcceptLicense from './AcceptLicense'
|
||||||
import PasswordPrompt from './password-prompt'
|
import PasswordPrompt from './password-prompt'
|
||||||
|
|
||||||
|
import { DateProvider } from '../hooks/useDate'
|
||||||
|
|
||||||
export default function AppWrapper() {
|
export default function AppWrapper() {
|
||||||
const [isLoading, setIsLoading] = useState(true)
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
const [isLicenseAccepted, setIsLicenseAccepted] = useState(false)
|
const [isLicenseAccepted, setIsLicenseAccepted] = useState(false)
|
||||||
@@ -47,7 +49,9 @@ export default function AppWrapper() {
|
|||||||
{isDbEncrypted ? (
|
{isDbEncrypted ? (
|
||||||
<PasswordPrompt enableShowApp={() => setIsDbEncrypted(false)} />
|
<PasswordPrompt enableShowApp={() => setIsDbEncrypted(false)} />
|
||||||
) : (
|
) : (
|
||||||
|
<DateProvider>
|
||||||
<App restartApp={() => checkIsDbEncrypted()} />
|
<App restartApp={() => checkIsDbEncrypted()} />
|
||||||
|
</DateProvider>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
+3
-4
@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'
|
|||||||
import { BackHandler, StyleSheet, View } from 'react-native'
|
import { BackHandler, StyleSheet, View } from 'react-native'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
import { LocalDate } from '@js-joda/core'
|
import { useDate } from '../hooks/useDate'
|
||||||
|
|
||||||
import Header from './header'
|
import Header from './header'
|
||||||
import Menu from './menu'
|
import Menu from './menu'
|
||||||
@@ -13,7 +13,8 @@ import setupNotifications from '../lib/notifications'
|
|||||||
import { closeDb } from '../db'
|
import { closeDb } from '../db'
|
||||||
|
|
||||||
const App = ({ restartApp }) => {
|
const App = ({ restartApp }) => {
|
||||||
const [date, setDate] = useState(LocalDate.now().toString())
|
const { setDate } = useDate()
|
||||||
|
|
||||||
const [currentPage, setCurrentPage] = useState('Home')
|
const [currentPage, setCurrentPage] = useState('Home')
|
||||||
const goBack = () => {
|
const goBack = () => {
|
||||||
if (currentPage === 'Home') {
|
if (currentPage === 'Home') {
|
||||||
@@ -43,8 +44,6 @@ const App = ({ restartApp }) => {
|
|||||||
const isTemperatureEditView = currentPage === 'TemperatureEditView'
|
const isTemperatureEditView = currentPage === 'TemperatureEditView'
|
||||||
const headerProps = { navigate: setCurrentPage }
|
const headerProps = { navigate: setCurrentPage }
|
||||||
const pageProps = {
|
const pageProps = {
|
||||||
date,
|
|
||||||
setDate,
|
|
||||||
isTemperatureEditView,
|
isTemperatureEditView,
|
||||||
navigate: setCurrentPage,
|
navigate: setCurrentPage,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import PropTypes from 'prop-types'
|
|||||||
import { StyleSheet, View } from 'react-native'
|
import { StyleSheet, View } from 'react-native'
|
||||||
import { CalendarList } from 'react-native-calendars'
|
import { CalendarList } from 'react-native-calendars'
|
||||||
|
|
||||||
|
import { useDate } from '../hooks/useDate'
|
||||||
|
|
||||||
import { getBleedingDaysSortedByDate } from '../db'
|
import { getBleedingDaysSortedByDate } from '../db'
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
import {
|
import {
|
||||||
@@ -12,7 +14,8 @@ import {
|
|||||||
todayToCalFormat,
|
todayToCalFormat,
|
||||||
} from './helpers/calendar'
|
} from './helpers/calendar'
|
||||||
|
|
||||||
const CalendarView = ({ setDate, navigate }) => {
|
const CalendarView = ({ navigate }) => {
|
||||||
|
const { setDate } = useDate()
|
||||||
const bleedingDays = getBleedingDaysSortedByDate()
|
const bleedingDays = getBleedingDaysSortedByDate()
|
||||||
const predictedMenses = cycleModule().getPredictedMenses()
|
const predictedMenses = cycleModule().getPredictedMenses()
|
||||||
|
|
||||||
@@ -49,7 +52,6 @@ const styles = StyleSheet.create({
|
|||||||
})
|
})
|
||||||
|
|
||||||
CalendarView.propTypes = {
|
CalendarView.propTypes = {
|
||||||
setDate: PropTypes.func.isRequired,
|
|
||||||
navigate: PropTypes.func.isRequired,
|
navigate: PropTypes.func.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 = ({ navigate }) => {
|
||||||
const [shouldShowHint, setShouldShowHint] = useState(true)
|
const [shouldShowHint, setShouldShowHint] = useState(true)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -84,7 +84,6 @@ const CycleChart = ({ navigate, setDate }) => {
|
|||||||
const renderColumn = ({ item }) => {
|
const renderColumn = ({ item }) => {
|
||||||
return (
|
return (
|
||||||
<DayColumn
|
<DayColumn
|
||||||
setDate={setDate}
|
|
||||||
dateString={item}
|
dateString={item}
|
||||||
navigate={navigate}
|
navigate={navigate}
|
||||||
symptomHeight={symptomHeight}
|
symptomHeight={symptomHeight}
|
||||||
@@ -136,7 +135,6 @@ const CycleChart = ({ navigate, setDate }) => {
|
|||||||
|
|
||||||
CycleChart.propTypes = {
|
CycleChart.propTypes = {
|
||||||
navigate: PropTypes.func,
|
navigate: PropTypes.func,
|
||||||
setDate: PropTypes.func,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import SymptomCell from './symptom-cell'
|
|||||||
import TemperatureColumn from './temperature-column'
|
import TemperatureColumn from './temperature-column'
|
||||||
import CycleDayLabel from './cycle-day-label'
|
import CycleDayLabel from './cycle-day-label'
|
||||||
|
|
||||||
|
import { useDate } from '../../hooks/useDate'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
symptomColorMethods,
|
symptomColorMethods,
|
||||||
getTemperatureProps,
|
getTemperatureProps,
|
||||||
@@ -19,13 +21,13 @@ const DayColumn = ({
|
|||||||
dateString,
|
dateString,
|
||||||
chartSymptoms,
|
chartSymptoms,
|
||||||
columnHeight,
|
columnHeight,
|
||||||
setDate,
|
|
||||||
navigate,
|
navigate,
|
||||||
shouldShowTemperatureColumn,
|
shouldShowTemperatureColumn,
|
||||||
symptomHeight,
|
symptomHeight,
|
||||||
symptomRowSymptoms,
|
symptomRowSymptoms,
|
||||||
xAxisHeight,
|
xAxisHeight,
|
||||||
}) => {
|
}) => {
|
||||||
|
const { setDate } = useDate()
|
||||||
const cycleDayData = getCycleDay(dateString)
|
const cycleDayData = getCycleDay(dateString)
|
||||||
let data = {}
|
let data = {}
|
||||||
|
|
||||||
@@ -105,7 +107,6 @@ DayColumn.propTypes = {
|
|||||||
chartSymptoms: PropTypes.array,
|
chartSymptoms: PropTypes.array,
|
||||||
columnHeight: PropTypes.number.isRequired,
|
columnHeight: PropTypes.number.isRequired,
|
||||||
navigate: PropTypes.func.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,
|
||||||
|
|||||||
@@ -9,10 +9,13 @@ import SymptomPageTitle from './symptom-page-title'
|
|||||||
import { getCycleDay } from '../../db'
|
import { getCycleDay } from '../../db'
|
||||||
import { getData, nextDate, prevDate } from '../helpers/cycle-day'
|
import { getData, nextDate, prevDate } from '../helpers/cycle-day'
|
||||||
|
|
||||||
|
import { useDate } from '../../hooks/useDate'
|
||||||
|
|
||||||
import { Spacing } from '../../styles'
|
import { Spacing } from '../../styles'
|
||||||
import { SYMPTOMS } from '../../config'
|
import { SYMPTOMS } from '../../config'
|
||||||
|
|
||||||
const CycleDayOverView = ({ date, setDate, isTemperatureEditView }) => {
|
const CycleDayOverView = ({ isTemperatureEditView }) => {
|
||||||
|
const { date, setDate } = useDate()
|
||||||
const cycleDay = getCycleDay(date)
|
const cycleDay = getCycleDay(date)
|
||||||
|
|
||||||
const [editedSymptom, setEditedSymptom] = useState(
|
const [editedSymptom, setEditedSymptom] = useState(
|
||||||
@@ -58,8 +61,6 @@ const CycleDayOverView = ({ date, setDate, isTemperatureEditView }) => {
|
|||||||
|
|
||||||
CycleDayOverView.propTypes = {
|
CycleDayOverView.propTypes = {
|
||||||
cycleDay: PropTypes.object,
|
cycleDay: PropTypes.object,
|
||||||
date: PropTypes.string,
|
|
||||||
setDate: PropTypes.func,
|
|
||||||
isTemperatureEditView: PropTypes.bool,
|
isTemperatureEditView: PropTypes.bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import React, { createContext, useContext, useState } from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { LocalDate } from '@js-joda/core'
|
||||||
|
|
||||||
|
const DateContext = createContext()
|
||||||
|
|
||||||
|
export const DateProvider = ({ children }) => {
|
||||||
|
const [date, setDate] = useState(LocalDate.now().toString())
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DateContext.Provider value={{ date, setDate }}>
|
||||||
|
{children}
|
||||||
|
</DateContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
DateProvider.propTypes = {
|
||||||
|
children: PropTypes.node,
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useDate = () => {
|
||||||
|
const { date, setDate } = useContext(DateContext)
|
||||||
|
return { date, setDate }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user