From e395730d981e7ce9ebdc3c2aaddccbfd284620e9 Mon Sep 17 00:00:00 2001 From: bl00dymarie Date: Wed, 14 Feb 2024 17:48:50 +0100 Subject: [PATCH] First step for fertilityTracking Toggle --- components/settings/customization/index.js | 25 ++++++++++++++++------ i18n/en/settings.js | 5 +++++ local-storage.js | 8 +++++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/components/settings/customization/index.js b/components/settings/customization/index.js index 4f202de..bd20433 100644 --- a/components/settings/customization/index.js +++ b/components/settings/customization/index.js @@ -10,6 +10,7 @@ import SelectTabGroup from '../../cycle-day/select-tab-group' import { desireTrackingCategoryObservable, + fertilityTrackingObservable, moodTrackingCategoryObservable, noteTrackingCategoryObservable, painTrackingCategoryObservable, @@ -18,6 +19,7 @@ import { mucusTrackingCategoryObservable, cervixTrackingCategoryObservable, saveDesireTrackingCategory, + saveFertilityTrackingEnabled, saveMoodTrackingCategory, saveNoteTrackingCategory, savePainTrackingCategory, @@ -75,8 +77,13 @@ const Settings = () => { const [isSecondarySymptomDisabled, setIsSecondarySymptomDisabled] = useState(false) - const [isEnabled, setIsEnabled] = useState(false) - const toggleSwitch = () => setIsEnabled((previousState) => !previousState) + const [isFertilityTrackingEnabled, setFertilityTrackingEnabled] = useState( + fertilityTrackingObservable.value + ) + const fertilityTrackingToggle = (value) => { + setFertilityTrackingEnabled(value) + saveFertilityTrackingEnabled(value) + } const temperatureTrackingCategoryToggle = (value) => { setTemperatureTrackingCategory(value) @@ -112,6 +119,11 @@ const Settings = () => { setPeriodPrediction(value) savePeriodPrediction(value) } + + const fertilityTrackingText = isFertilityTrackingEnabled + ? labels.fertilityTracking.on + : labels.fertilityTracking.off + const periodPredictionText = isPeriodPredictionEnabled ? labels.periodPrediction.on : labels.periodPrediction.off @@ -234,12 +246,11 @@ const Settings = () => { value={isNoteTrackingCategoryEnabled} /> - - + diff --git a/i18n/en/settings.js b/i18n/en/settings.js index bf26203..eec5ea8 100644 --- a/i18n/en/settings.js +++ b/i18n/en/settings.js @@ -66,6 +66,11 @@ export default { 'To use the period reminder please first enable period predictions in the customization settings.', }, }, + fertilityTracking: { + title: 'Fertility phases calculation', + on: 'The quick brown fox jumps over the lazy dog', + off: 'No no', + }, secondarySymptom: { title: 'Secondary symptom', cervixModeOn: diff --git a/local-storage.js b/local-storage.js index 84b680d..7f2de93 100644 --- a/local-storage.js +++ b/local-storage.js @@ -170,6 +170,14 @@ export async function saveNoteTrackingCategory(bool) { noteTrackingCategoryObservable.set(bool) } +export const fertilityTrackingObservable = Observable() +setObvWithInitValue('fertilityTracking', fertilityTrackingObservable, true) + +export async function saveFertilityTrackingEnabled(bool) { + await AsyncStorage.setItem('fertilityTracking', JSON.stringify(bool)) + fertilityTrackingObservable.set(bool) +} + async function setObvWithInitValue(key, obv, defaultValue) { const result = await AsyncStorage.getItem(key) let value