From 9fbe99e23bde82e27477958d0375e0cd85e61624 Mon Sep 17 00:00:00 2001 From: Liv Date: Mon, 20 Nov 2023 12:13:42 +0100 Subject: [PATCH] Basic working version that includes period products --- components/cycle-day/symptom-edit-view.js | 2 +- components/helpers/cycle-day.js | 67 ++++++-- db/schemas/5.js | 192 ++++++++++++++++++++++ db/schemas/index.js | 3 +- i18n/en/cycle-day.js | 14 ++ 5 files changed, 266 insertions(+), 12 deletions(-) create mode 100644 db/schemas/5.js diff --git a/components/cycle-day/symptom-edit-view.js b/components/cycle-day/symptom-edit-view.js index b87ae58..6bb5a6f 100644 --- a/components/cycle-day/symptom-edit-view.js +++ b/components/cycle-day/symptom-edit-view.js @@ -136,7 +136,7 @@ const SymptomEditView = ({ date, onClose, symptom, symptomData }) => { {group.title} onSelectTab(group, value)} /> diff --git a/components/helpers/cycle-day.js b/components/helpers/cycle-day.js index 98cbea7..571b47f 100644 --- a/components/helpers/cycle-day.js +++ b/components/helpers/cycle-day.js @@ -23,9 +23,17 @@ const noteDescription = labels.noteExplainer const painLabels = labels.pain.categories const sexLabels = labels.sex.categories const temperatureLabels = labels.temperature +const productLabels = labels.products.categories const minutes = ChronoUnit.MINUTES +const getOptionsFromCategories = (categories) => { + return Object.keys(categories).map((key, _) => ({ + label: categories[key], + value: key, // or index, depending on what you want to use as the value + })) +} + const isNumber = (value) => typeof value === 'number' export const shouldShow = (value) => (value !== null ? true : false) @@ -60,6 +68,13 @@ export const blank = { bleeding: { exclude: false, value: null, + pad: null, + tampon: null, + underwear: null, + cup: null, + softTampon: null, + none: null, + other: null, }, cervix: { exclude: false, @@ -129,7 +144,6 @@ export const symtomPage = { bleeding: { excludeText: labels.bleeding.exclude.explainer, note: null, - selectBoxGroups: null, selectTabGroups: [ { key: 'value', @@ -137,6 +151,13 @@ export const symtomPage = { title: labels.bleeding.heaviness.explainer, }, ], + selectBoxGroups: [ + { + key: 'products', + options: productLabels, + title: 'Product', + }, + ], }, cervix: { excludeText: cervixLabels.excludeExplainer, @@ -246,12 +267,12 @@ export const symtomPage = { export const save = { bleeding: (data, date, shouldDeleteData) => { - const { exclude, value } = data - const isDataEntered = isNumber(value) - const valuesToSave = - shouldDeleteData || !isDataEntered ? null : { value, exclude } + //const { exclude, value, products } = data + //const isDataEntered = isNumber(value) + //const valuesToSave = + // shouldDeleteData || !isDataEntered ? null : { value, exclude, products } - saveSymptom('bleeding', date, valuesToSave) + saveBoxSymptom(data, date, shouldDeleteData, 'bleeding') }, cervix: (data, date, shouldDeleteData) => { const { opening, firmness, position, exclude } = data @@ -329,10 +350,36 @@ const saveBoxSymptom = (data, date, shouldDeleteData, symptom) => { } const label = { - bleeding: ({ value, exclude }) => { - if (isNumber(value)) { - const bleedingLabel = bleedingLabels[value] - return exclude ? `(${bleedingLabel})` : bleedingLabel + bleeding: (bleeding) => { + bleeding = mapRealmObjToJsObj(bleeding) + console.log(bleeding) + const bleedingLabel = [] + if (bleeding && Object.values({ ...bleeding }).some((val) => val)) { + Object.keys(bleeding).forEach((key) => { + if (key == 'value') { + console.log(bleedingLabel) + bleedingLabel.push(bleedingLabels[bleeding[key]]) + } + if ( + bleeding[key] && + key !== 'other' && + key !== 'note' && + key != 'value' && + key != 'exclude' + ) { + console.log(bleedingLabel) + bleedingLabel.push(bleedingLabels[key] || productLabels[key]) + } + if (key === 'other' && bleeding.other) { + let label = productLabels[key] + if (bleeding.note) { + label = `${label} (${bleeding.note})` + } + console.log(bleedingLabel) + bleedingLabel.push(label) + } + }) + return bleedingLabel.join(', ') } }, temperature: ({ value, time, exclude }) => { diff --git a/db/schemas/5.js b/db/schemas/5.js new file mode 100644 index 0000000..6d548b8 --- /dev/null +++ b/db/schemas/5.js @@ -0,0 +1,192 @@ +const TemperatureSchema = { + name: 'Temperature', + properties: { + value: 'double', + exclude: 'bool', + time: { + type: 'string', + optional: true, + }, + note: { + type: 'string', + optional: true, + }, + }, +} + +const BleedingSchema = { + name: 'Bleeding', + properties: { + value: 'int', + exclude: 'bool', + pad: { type: 'bool', optional: true }, + tampon: { type: 'bool', optional: true }, + underwear: { type: 'bool', optional: true }, + cup: { type: 'bool', optional: true }, + softTampon: { type: 'bool', optional: true }, + none: { type: 'bool', optional: true }, + other: { type: 'bool', optional: true }, + }, +} + +const MucusSchema = { + name: 'Mucus', + properties: { + feeling: { type: 'int', optional: true }, + texture: { type: 'int', optional: true }, + value: { type: 'int', optional: true }, + exclude: 'bool', + }, +} + +const CervixSchema = { + name: 'Cervix', + properties: { + opening: { type: 'int', optional: true }, + firmness: { type: 'int', optional: true }, + position: { type: 'int', optional: true }, + exclude: 'bool', + }, +} + +const NoteSchema = { + name: 'Note', + properties: { + value: 'string', + }, +} + +const DesireSchema = { + name: 'Desire', + properties: { + value: 'int', + }, +} + +const SexSchema = { + name: 'Sex', + properties: { + solo: { type: 'bool', optional: true }, + partner: { type: 'bool', optional: true }, + condom: { type: 'bool', optional: true }, + pill: { type: 'bool', optional: true }, + iud: { type: 'bool', optional: true }, + patch: { type: 'bool', optional: true }, + ring: { type: 'bool', optional: true }, + implant: { type: 'bool', optional: true }, + diaphragm: { type: 'bool', optional: true }, + none: { type: 'bool', optional: true }, + other: { type: 'bool', optional: true }, + note: { type: 'string', optional: true }, + }, +} + +const PainSchema = { + name: 'Pain', + properties: { + cramps: { type: 'bool', optional: true }, + ovulationPain: { type: 'bool', optional: true }, + headache: { type: 'bool', optional: true }, + backache: { type: 'bool', optional: true }, + nausea: { type: 'bool', optional: true }, + tenderBreasts: { type: 'bool', optional: true }, + migraine: { type: 'bool', optional: true }, + other: { type: 'bool', optional: true }, + note: { type: 'string', optional: true }, + }, +} + +const MoodSchema = { + name: 'Mood', + properties: { + happy: { type: 'bool', optional: true }, + sad: { type: 'bool', optional: true }, + stressed: { type: 'bool', optional: true }, + balanced: { type: 'bool', optional: true }, + fine: { type: 'bool', optional: true }, + anxious: { type: 'bool', optional: true }, + energetic: { type: 'bool', optional: true }, + fatigue: { type: 'bool', optional: true }, + angry: { type: 'bool', optional: true }, + other: { type: 'bool', optional: true }, + note: { type: 'string', optional: true }, + }, +} + +const CycleDaySchema = { + name: 'CycleDay', + primaryKey: 'date', + properties: { + date: 'string', + temperature: { + type: 'Temperature', + optional: true, + }, + isCycleStart: 'bool', + bleeding: { + type: 'Bleeding', + optional: true, + }, + mucus: { + type: 'Mucus', + optional: true, + }, + cervix: { + type: 'Cervix', + optional: true, + }, + note: { + type: 'Note', + optional: true, + }, + desire: { + type: 'Desire', + optional: true, + }, + sex: { + type: 'Sex', + optional: true, + }, + pain: { + type: 'Pain', + optional: true, + }, + mood: { + type: 'Mood', + optional: true, + }, + }, +} + +export default { + schema: [ + CycleDaySchema, + TemperatureSchema, + BleedingSchema, + MucusSchema, + CervixSchema, + NoteSchema, + DesireSchema, + SexSchema, + PainSchema, + MoodSchema, + ], + schemaVersion: 5, + migration: (oldRealm, newRealm) => { + if (oldRealm.schemaVersion < 5) { + const oldObjects = oldRealm.objects('Bleeding') + const newObjects = newRealm.objects('Bleeding') + + // loop through all objects and assign a default value for new properties + for (let i = 0; i < oldObjects.length; i++) { + newObjects[i].pad = false + newObjects[i].tampon = false + newObjects[i].underwear = false + newObjects[i].cup = false + newObjects[i].softTampon = false + newObjects[i].none = false + newObjects[i].other = false + } + } + }, +} diff --git a/db/schemas/index.js b/db/schemas/index.js index 4530908..871f8e1 100644 --- a/db/schemas/index.js +++ b/db/schemas/index.js @@ -3,5 +3,6 @@ import schema1 from './1.js' import schema2 from './2.js' import schema3 from './3.js' import schema4 from './4.js' +import schema5 from './5.js' -export default [schema0, schema1, schema2, schema3, schema4] \ No newline at end of file +export default [schema0, schema1, schema2, schema3, schema4, schema5] diff --git a/i18n/en/cycle-day.js b/i18n/en/cycle-day.js index 3505f56..875d649 100644 --- a/i18n/en/cycle-day.js +++ b/i18n/en/cycle-day.js @@ -13,6 +13,20 @@ export const bleeding = { }, } +export const products = { + categories: { + pad: 'pad', + tampon: 'tampon', + underwear: 'underwear', + cup: 'cup', + softTampon: 'soft tampon', + none: 'none', + other: 'other', + }, + header: 'period products', + explainer: 'Did you use period products?', +} + export const cervix = { subcategories: { opening: 'opening',