diff --git a/components/home.js b/components/home.js index 56e59e8d944b28b0a9b74ba984fe67035ea5d191..364ba27cbd3a28fcace21b895b78a12ee0894fe5 100644 --- a/components/home.js +++ b/components/home.js @@ -11,6 +11,7 @@ import { getOrCreateCycleDay, getCycleDaysSortedByDate } from '../db' import { getFertilityStatusForDay } from '../lib/sympto-adapter' import styles from '../styles' import AppText, { AppTextLight } from './app-text' +import nothingChanged from '../helpers/db-unchanged' export default class Home extends Component { constructor(props) { @@ -32,7 +33,8 @@ export default class Home extends Component { this.cycleDays.addListener(this.updateState) } - updateState = () => { + updateState = (_, changes) => { + if (nothingChanged(changes)) return const prediction = this.getBleedingPrediction() const fertilityStatus = getFertilityStatusForDay(this.todayDateString) this.setState({ diff --git a/helpers/db-unchanged.js b/helpers/db-unchanged.js new file mode 100644 index 0000000000000000000000000000000000000000..4625a804b2183ec34bb8e26d47aba3d632ced6c0 --- /dev/null +++ b/helpers/db-unchanged.js @@ -0,0 +1,3 @@ +export default function (dbChanges) { + return Object.values(dbChanges).every(changeArray => changeArray.length === 0) +} \ No newline at end of file diff --git a/lib/notifications.js b/lib/notifications.js index 0eab38a3f7b75b739cf076431e261513d70e80a6..8c1934dcdf74813da9d92543361603e22f9b54b0 100644 --- a/lib/notifications.js +++ b/lib/notifications.js @@ -5,6 +5,7 @@ import Moment from 'moment' import { settings as labels } from '../components/labels' import { getOrCreateCycleDay, getBleedingDaysSortedByDate } from '../db' import cycleModule from './cycle' +import nothingChanged from '../helpers/db-unchanged' export default function setupNotifications(navigate) { Notification.configure({ @@ -80,7 +81,3 @@ function setupPeriodReminder() { } } } - -function nothingChanged(dbChanges) { - return Object.values(dbChanges).every(changeArray => changeArray.length === 0) -} \ No newline at end of file