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}>
<AppText style={symptomNameStyle}>{t(symptom)}</AppText>
{symptomDataToDisplay && (
{symptomDataToDisplay ? (
<AppText style={textStyle} numberOfLines={4}>
{symptomDataToDisplay}
</AppText>
)}
) : null}
</View>
</TouchableOpacity>
</>
+1 -1
View File
@@ -136,7 +136,7 @@ const SymptomEditView = ({ date, onClose, symptom, symptomData }) => {
<Segment key={group.key} style={styles.segmentBorder}>
<AppText style={styles.title}>{group.title}</AppText>
<SelectTabGroup
activeButton={data[group.key]} //this is supposed to be a number
activeButton={data[group.key]}
buttons={group.options}
onSelect={(value) => onSelectTab(group, value)}
/>
+10 -21
View File
@@ -27,13 +27,6 @@ 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)
@@ -75,6 +68,7 @@ export const blank = {
softTampon: null,
none: null,
other: null,
note: null,
},
cervix: {
exclude: false,
@@ -155,7 +149,7 @@ export const symtomPage = {
{
key: 'products',
options: productLabels,
title: 'Product',
title: labels.products.explainer,
},
],
},
@@ -267,11 +261,6 @@ export const symtomPage = {
export const save = {
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')
},
cervix: (data, date, shouldDeleteData) => {
@@ -352,22 +341,23 @@ const saveBoxSymptom = (data, date, shouldDeleteData, symptom) => {
const label = {
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] != null && key === 'value') {
bleedingLabel.push(
bleeding.exclude
? `(${bleedingLabels[bleeding[key]]})`
: bleedingLabels[bleeding[key]]
)
}
if (
bleeding[key] &&
key !== 'other' &&
key !== 'note' &&
key != 'value' &&
key != 'exclude'
key !== 'value' &&
key !== 'exclude'
) {
console.log(bleedingLabel)
bleedingLabel.push(bleedingLabels[key] || productLabels[key])
}
if (key === 'other' && bleeding.other) {
@@ -375,7 +365,6 @@ const label = {
if (bleeding.note) {
label = `${label} (${bleeding.note})`
}
console.log(bleedingLabel)
bleedingLabel.push(label)
}
})
+2 -2
View File
@@ -65,6 +65,7 @@ export function getBleedingDaysSortedByDate() {
return db
.objects('CycleDay')
.filtered('bleeding != null')
.filtered('bleeding.value != null')
.sorted('date', true)
}
export function getTemperatureDaysSortedByDate() {
@@ -88,9 +89,8 @@ export function getCycleStartsSortedByDate() {
export function saveSymptom(symptom, date, val) {
let cycleDay = getCycleDay(date)
if (!cycleDay) cycleDay = createCycleDay(date)
db.write(() => {
if (symptom === 'bleeding') {
if (symptom === 'bleeding' && val != null && val.value != null) {
const mensesDaysAfter = getMensesDaysRightAfter(cycleDay)
maybeSetNewCycleStart({
val,
+4 -3
View File
@@ -17,7 +17,7 @@ const TemperatureSchema = {
const BleedingSchema = {
name: 'Bleeding',
properties: {
value: 'int',
value: { type: 'int', optional: true },
exclude: 'bool',
pad: { type: 'bool', optional: true },
tampon: { type: 'bool', optional: true },
@@ -26,6 +26,7 @@ const BleedingSchema = {
softTampon: { type: 'bool', optional: true },
none: { type: 'bool', optional: true },
other: { type: 'bool', optional: true },
note: { type: 'string', optional: true },
},
}
@@ -174,11 +175,10 @@ export default {
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++) {
for (let i = 0; i < newObjects.length; i++) {
newObjects[i].pad = false
newObjects[i].tampon = false
newObjects[i].underwear = false
@@ -186,6 +186,7 @@ export default {
newObjects[i].softTampon = false
newObjects[i].none = false
newObjects[i].other = false
newObjects[i].note = null
}
}
},