Fix labels and clean up code

This commit is contained in:
Liv
2023-11-20 11:50:46 +01:00
committed by bl00dymarie
parent 9fbe99e23b
commit 583c9c032c
5 changed files with 19 additions and 29 deletions
+2 -2
View File
@@ -63,11 +63,11 @@ const SymptomBox = ({
/> />
<View style={styles.textContainer}> <View style={styles.textContainer}>
<AppText style={symptomNameStyle}>{t(symptom)}</AppText> <AppText style={symptomNameStyle}>{t(symptom)}</AppText>
{symptomDataToDisplay && ( {symptomDataToDisplay ? (
<AppText style={textStyle} numberOfLines={4}> <AppText style={textStyle} numberOfLines={4}>
{symptomDataToDisplay} {symptomDataToDisplay}
</AppText> </AppText>
)} ) : null}
</View> </View>
</TouchableOpacity> </TouchableOpacity>
</> </>
+1 -1
View File
@@ -136,7 +136,7 @@ const SymptomEditView = ({ date, onClose, symptom, symptomData }) => {
<Segment key={group.key} style={styles.segmentBorder}> <Segment key={group.key} style={styles.segmentBorder}>
<AppText style={styles.title}>{group.title}</AppText> <AppText style={styles.title}>{group.title}</AppText>
<SelectTabGroup <SelectTabGroup
activeButton={data[group.key]} //this is supposed to be a number activeButton={data[group.key]}
buttons={group.options} buttons={group.options}
onSelect={(value) => onSelectTab(group, value)} onSelect={(value) => onSelectTab(group, value)}
/> />
+10 -21
View File
@@ -27,13 +27,6 @@ const productLabels = labels.products.categories
const minutes = ChronoUnit.MINUTES 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' const isNumber = (value) => typeof value === 'number'
export const shouldShow = (value) => (value !== null ? true : false) export const shouldShow = (value) => (value !== null ? true : false)
@@ -75,6 +68,7 @@ export const blank = {
softTampon: null, softTampon: null,
none: null, none: null,
other: null, other: null,
note: null,
}, },
cervix: { cervix: {
exclude: false, exclude: false,
@@ -155,7 +149,7 @@ export const symtomPage = {
{ {
key: 'products', key: 'products',
options: productLabels, options: productLabels,
title: 'Product', title: labels.products.explainer,
}, },
], ],
}, },
@@ -267,11 +261,6 @@ export const symtomPage = {
export const save = { export const save = {
bleeding: (data, date, shouldDeleteData) => { bleeding: (data, date, shouldDeleteData) => {
//const { exclude, value, products } = data
//const isDataEntered = isNumber(value)
//const valuesToSave =
// shouldDeleteData || !isDataEntered ? null : { value, exclude, products }
saveBoxSymptom(data, date, shouldDeleteData, 'bleeding') saveBoxSymptom(data, date, shouldDeleteData, 'bleeding')
}, },
cervix: (data, date, shouldDeleteData) => { cervix: (data, date, shouldDeleteData) => {
@@ -352,22 +341,23 @@ const saveBoxSymptom = (data, date, shouldDeleteData, symptom) => {
const label = { const label = {
bleeding: (bleeding) => { bleeding: (bleeding) => {
bleeding = mapRealmObjToJsObj(bleeding) bleeding = mapRealmObjToJsObj(bleeding)
console.log(bleeding)
const bleedingLabel = [] const bleedingLabel = []
if (bleeding && Object.values({ ...bleeding }).some((val) => val)) { if (bleeding && Object.values({ ...bleeding }).some((val) => val)) {
Object.keys(bleeding).forEach((key) => { Object.keys(bleeding).forEach((key) => {
if (key == 'value') { if (bleeding[key] != null && key === 'value') {
console.log(bleedingLabel) bleedingLabel.push(
bleedingLabel.push(bleedingLabels[bleeding[key]]) bleeding.exclude
? `(${bleedingLabels[bleeding[key]]})`
: bleedingLabels[bleeding[key]]
)
} }
if ( if (
bleeding[key] && bleeding[key] &&
key !== 'other' && key !== 'other' &&
key !== 'note' && key !== 'note' &&
key != 'value' && key !== 'value' &&
key != 'exclude' key !== 'exclude'
) { ) {
console.log(bleedingLabel)
bleedingLabel.push(bleedingLabels[key] || productLabels[key]) bleedingLabel.push(bleedingLabels[key] || productLabels[key])
} }
if (key === 'other' && bleeding.other) { if (key === 'other' && bleeding.other) {
@@ -375,7 +365,6 @@ const label = {
if (bleeding.note) { if (bleeding.note) {
label = `${label} (${bleeding.note})` label = `${label} (${bleeding.note})`
} }
console.log(bleedingLabel)
bleedingLabel.push(label) bleedingLabel.push(label)
} }
}) })
+2 -2
View File
@@ -65,6 +65,7 @@ export function getBleedingDaysSortedByDate() {
return db return db
.objects('CycleDay') .objects('CycleDay')
.filtered('bleeding != null') .filtered('bleeding != null')
.filtered('bleeding.value != null')
.sorted('date', true) .sorted('date', true)
} }
export function getTemperatureDaysSortedByDate() { export function getTemperatureDaysSortedByDate() {
@@ -88,9 +89,8 @@ export function getCycleStartsSortedByDate() {
export function saveSymptom(symptom, date, val) { export function saveSymptom(symptom, date, val) {
let cycleDay = getCycleDay(date) let cycleDay = getCycleDay(date)
if (!cycleDay) cycleDay = createCycleDay(date) if (!cycleDay) cycleDay = createCycleDay(date)
db.write(() => { db.write(() => {
if (symptom === 'bleeding') { if (symptom === 'bleeding' && val != null && val.value != null) {
const mensesDaysAfter = getMensesDaysRightAfter(cycleDay) const mensesDaysAfter = getMensesDaysRightAfter(cycleDay)
maybeSetNewCycleStart({ maybeSetNewCycleStart({
val, val,
+4 -3
View File
@@ -17,7 +17,7 @@ const TemperatureSchema = {
const BleedingSchema = { const BleedingSchema = {
name: 'Bleeding', name: 'Bleeding',
properties: { properties: {
value: 'int', value: { type: 'int', optional: true },
exclude: 'bool', exclude: 'bool',
pad: { type: 'bool', optional: true }, pad: { type: 'bool', optional: true },
tampon: { type: 'bool', optional: true }, tampon: { type: 'bool', optional: true },
@@ -26,6 +26,7 @@ const BleedingSchema = {
softTampon: { type: 'bool', optional: true }, softTampon: { type: 'bool', optional: true },
none: { type: 'bool', optional: true }, none: { type: 'bool', optional: true },
other: { type: 'bool', optional: true }, other: { type: 'bool', optional: true },
note: { type: 'string', optional: true },
}, },
} }
@@ -174,11 +175,10 @@ export default {
schemaVersion: 5, schemaVersion: 5,
migration: (oldRealm, newRealm) => { migration: (oldRealm, newRealm) => {
if (oldRealm.schemaVersion < 5) { if (oldRealm.schemaVersion < 5) {
const oldObjects = oldRealm.objects('Bleeding')
const newObjects = newRealm.objects('Bleeding') const newObjects = newRealm.objects('Bleeding')
// loop through all objects and assign a default value for new properties // loop through all objects and assign a default value for new properties
for (let i = 0; i < oldObjects.length; i++) { for (let i = 0; i < newObjects.length; i++) {
newObjects[i].pad = false newObjects[i].pad = false
newObjects[i].tampon = false newObjects[i].tampon = false
newObjects[i].underwear = false newObjects[i].underwear = false
@@ -186,6 +186,7 @@ export default {
newObjects[i].softTampon = false newObjects[i].softTampon = false
newObjects[i].none = false newObjects[i].none = false
newObjects[i].other = false newObjects[i].other = false
newObjects[i].note = null
} }
} }
}, },