Clean up
This commit is contained in:
@@ -72,7 +72,7 @@ export default class CycleChart extends Component {
|
|||||||
'pain',
|
'pain',
|
||||||
'note'
|
'note'
|
||||||
].filter((symptomName) => {
|
].filter((symptomName) => {
|
||||||
return cycleDaysSortedByDate.some(cycleDay => cycleDay[symptomName])
|
return this.cycleDaysSortedByDate.some(cycleDay => cycleDay[symptomName])
|
||||||
})
|
})
|
||||||
|
|
||||||
const columns = xAxisDates.map(dateString => {
|
const columns = xAxisDates.map(dateString => {
|
||||||
|
|||||||
+1
-7
@@ -9,7 +9,7 @@ import { LocalDate, ChronoUnit } from 'js-joda'
|
|||||||
import nodejs from 'nodejs-mobile-react-native'
|
import nodejs from 'nodejs-mobile-react-native'
|
||||||
import styles from '../styles/index'
|
import styles from '../styles/index'
|
||||||
import cycleModule from '../lib/cycle'
|
import cycleModule from '../lib/cycle'
|
||||||
import { requestHash, getOrCreateCycleDay, getBleedingDaysSortedByDate, fillWithMucusDummyData, fillWithCervixDummyData, deleteAll, changeEncryptionAndRestartApp } from '../db'
|
import { requestHash, getOrCreateCycleDay, getBleedingDaysSortedByDate, fillWithMucusDummyData, fillWithCervixDummyData, changeEncryptionAndRestartApp } from '../db'
|
||||||
import {bleedingPrediction as labels} from './labels'
|
import {bleedingPrediction as labels} from './labels'
|
||||||
|
|
||||||
export default class Home extends Component {
|
export default class Home extends Component {
|
||||||
@@ -84,12 +84,6 @@ export default class Home extends Component {
|
|||||||
title="fill with example data for cervix&temp">
|
title="fill with example data for cervix&temp">
|
||||||
</Button>
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.homeButton}>
|
|
||||||
<Button
|
|
||||||
onPress={() => deleteAll()}
|
|
||||||
title="delete everything">
|
|
||||||
</Button>
|
|
||||||
</View>
|
|
||||||
<View style={styles.homeButton}>
|
<View style={styles.homeButton}>
|
||||||
<Button
|
<Button
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ export default class PasswordPrompt extends Component {
|
|||||||
try {
|
try {
|
||||||
await openDb({hash: msg.message, persistConnection: true })
|
await openDb({hash: msg.message, persistConnection: true })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
shared.incorrectPassword,
|
shared.incorrectPassword,
|
||||||
shared.incorrectPasswordMessage,
|
shared.incorrectPasswordMessage,
|
||||||
@@ -49,6 +50,35 @@ export default class PasswordPrompt extends Component {
|
|||||||
this.props.showApp()
|
this.props.showApp()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
confirmDeletion = async () => {
|
||||||
|
Alert.alert(
|
||||||
|
labels.deleteDatabaseTitle,
|
||||||
|
labels.deleteDatabaseExplainer,
|
||||||
|
[{
|
||||||
|
text: shared.cancel,
|
||||||
|
style: 'cancel'
|
||||||
|
}, {
|
||||||
|
text: labels.deleteData,
|
||||||
|
onPress: () => {
|
||||||
|
Alert.alert(
|
||||||
|
labels.areYouSureTitle,
|
||||||
|
labels.areYouSure,
|
||||||
|
[{
|
||||||
|
text: shared.cancel,
|
||||||
|
style: 'cancel'
|
||||||
|
}, {
|
||||||
|
text: labels.reallyDeleteData,
|
||||||
|
onPress: async () => {
|
||||||
|
await deleteDbAndOpenNew()
|
||||||
|
this.props.showApp()
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
nodejs.channel.removeListener('message', this.passHashToDb)
|
nodejs.channel.removeListener('message', this.passHashToDb)
|
||||||
}
|
}
|
||||||
@@ -79,34 +109,7 @@ export default class PasswordPrompt extends Component {
|
|||||||
</AppText>
|
</AppText>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={async () => {
|
onPress={this.confirmDeletion}
|
||||||
Alert.alert(
|
|
||||||
labels.deleteDatabaseTitle,
|
|
||||||
labels.deleteDatabaseExplainer,
|
|
||||||
[{
|
|
||||||
text: shared.cancel,
|
|
||||||
style: 'cancel'
|
|
||||||
}, {
|
|
||||||
text: labels.deleteData,
|
|
||||||
onPress: () => {
|
|
||||||
Alert.alert(
|
|
||||||
labels.areYouSureTitle,
|
|
||||||
labels.areYouSure,
|
|
||||||
[{
|
|
||||||
text: shared.cancel,
|
|
||||||
style: 'cancel'
|
|
||||||
}, {
|
|
||||||
text: labels.reallyDeleteData,
|
|
||||||
onPress: async () => {
|
|
||||||
await deleteDbAndOpenNew()
|
|
||||||
this.props.showApp()
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<AppText style={styles.passwordPromptForgotPasswordText}>
|
<AppText style={styles.passwordPromptForgotPasswordText}>
|
||||||
{labels.forgotPassword}
|
{labels.forgotPassword}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ export default class PasswordSetting extends Component {
|
|||||||
try {
|
try {
|
||||||
await openDb({ hash: msg.message, persistConnection: false })
|
await openDb({ hash: msg.message, persistConnection: false })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
Alert.alert(
|
Alert.alert(
|
||||||
shared.incorrectPassword,
|
shared.incorrectPassword,
|
||||||
shared.incorrectPasswordMessage,
|
shared.incorrectPasswordMessage,
|
||||||
|
|||||||
+16
-42
@@ -19,23 +19,23 @@ const realmConfig = {
|
|||||||
schema: dbSchema
|
schema: dbSchema
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBleedingDaysSortedByDate() {
|
export function getBleedingDaysSortedByDate() {
|
||||||
return db.objects('CycleDay').filtered('bleeding != null').sorted('date', true)
|
return db.objects('CycleDay').filtered('bleeding != null').sorted('date', true)
|
||||||
}
|
}
|
||||||
function getTemperatureDaysSortedByDate() {
|
export function getTemperatureDaysSortedByDate() {
|
||||||
return db.objects('CycleDay').filtered('temperature != null').sorted('date', true)
|
return db.objects('CycleDay').filtered('temperature != null').sorted('date', true)
|
||||||
}
|
}
|
||||||
function getCycleDaysSortedByDate() {
|
export function getCycleDaysSortedByDate() {
|
||||||
return db.objects('CycleDay').sorted('date', true)
|
return db.objects('CycleDay').sorted('date', true)
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveSymptom(symptom, cycleDay, val) {
|
export function saveSymptom(symptom, cycleDay, val) {
|
||||||
db.write(() => {
|
db.write(() => {
|
||||||
cycleDay[symptom] = val
|
cycleDay[symptom] = val
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOrCreateCycleDay(localDate) {
|
export function getOrCreateCycleDay(localDate) {
|
||||||
let result = db.objectForPrimaryKey('CycleDay', localDate)
|
let result = db.objectForPrimaryKey('CycleDay', localDate)
|
||||||
if (!result) {
|
if (!result) {
|
||||||
db.write(() => {
|
db.write(() => {
|
||||||
@@ -47,11 +47,11 @@ function getOrCreateCycleDay(localDate) {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCycleDay(localDate) {
|
export function getCycleDay(localDate) {
|
||||||
return db.objectForPrimaryKey('CycleDay', localDate)
|
return db.objectForPrimaryKey('CycleDay', localDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillWithMucusDummyData() {
|
export function fillWithMucusDummyData() {
|
||||||
const dummyCycles = [
|
const dummyCycles = [
|
||||||
cycleWithFhmMucus,
|
cycleWithFhmMucus,
|
||||||
longAndComplicatedCycleWithMucus,
|
longAndComplicatedCycleWithMucus,
|
||||||
@@ -76,7 +76,7 @@ function fillWithMucusDummyData() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillWithCervixDummyData() {
|
export function fillWithCervixDummyData() {
|
||||||
const dummyCycles = [
|
const dummyCycles = [
|
||||||
cycleWithFhmCervix,
|
cycleWithFhmCervix,
|
||||||
longAndComplicatedCycleWithCervix,
|
longAndComplicatedCycleWithCervix,
|
||||||
@@ -101,14 +101,7 @@ function fillWithCervixDummyData() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getPreviousTemperature(cycleDay) {
|
||||||
function deleteAll() {
|
|
||||||
db.write(() => {
|
|
||||||
db.deleteAll()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPreviousTemperature(cycleDay) {
|
|
||||||
cycleDay.wrappedDate = LocalDate.parse(cycleDay.date)
|
cycleDay.wrappedDate = LocalDate.parse(cycleDay.date)
|
||||||
const winner = getTemperatureDaysSortedByDate().find(day => {
|
const winner = getTemperatureDaysSortedByDate().find(day => {
|
||||||
const wrappedDate = LocalDate.parse(day.date)
|
const wrappedDate = LocalDate.parse(day.date)
|
||||||
@@ -118,7 +111,7 @@ function getPreviousTemperature(cycleDay) {
|
|||||||
return winner.temperature.value
|
return winner.temperature.value
|
||||||
}
|
}
|
||||||
|
|
||||||
function tryToCreateCycleDay(day, i) {
|
export function tryToCreateCycleDay(day, i) {
|
||||||
try {
|
try {
|
||||||
db.create('CycleDay', day)
|
db.create('CycleDay', day)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -127,7 +120,7 @@ function tryToCreateCycleDay(day, i) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAmountOfCycleDays() {
|
export function getAmountOfCycleDays() {
|
||||||
const cycleDaysSortedByDate = getCycleDaysSortedByDate()
|
const cycleDaysSortedByDate = getCycleDaysSortedByDate()
|
||||||
const amountOfCycleDays = cycleDaysSortedByDate.length
|
const amountOfCycleDays = cycleDaysSortedByDate.length
|
||||||
if (!amountOfCycleDays) return 0
|
if (!amountOfCycleDays) return 0
|
||||||
@@ -137,21 +130,21 @@ function getAmountOfCycleDays() {
|
|||||||
return earliestAsLocalDate.until(today, ChronoUnit.DAYS)
|
return earliestAsLocalDate.until(today, ChronoUnit.DAYS)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSchema() {
|
export function getSchema() {
|
||||||
return db.schema.reduce((acc, curr) => {
|
return db.schema.reduce((acc, curr) => {
|
||||||
acc[curr.name] = curr.properties
|
acc[curr.name] = curr.properties
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
}
|
}
|
||||||
|
|
||||||
function tryToImportWithDelete(cycleDays) {
|
export function tryToImportWithDelete(cycleDays) {
|
||||||
db.write(() => {
|
db.write(() => {
|
||||||
db.delete(db.objects('CycleDay'))
|
db.delete(db.objects('CycleDay'))
|
||||||
cycleDays.forEach(tryToCreateCycleDay)
|
cycleDays.forEach(tryToCreateCycleDay)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function tryToImportWithoutDelete(cycleDays) {
|
export function tryToImportWithoutDelete(cycleDays) {
|
||||||
db.write(() => {
|
db.write(() => {
|
||||||
cycleDays.forEach((day, i) => {
|
cycleDays.forEach((day, i) => {
|
||||||
const existing = getCycleDay(day.date)
|
const existing = getCycleDay(day.date)
|
||||||
@@ -161,7 +154,7 @@ function tryToImportWithoutDelete(cycleDays) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function requestHash(pw) {
|
export function requestHash(pw) {
|
||||||
nodejs.channel.send(JSON.stringify({
|
nodejs.channel.send(JSON.stringify({
|
||||||
type: 'request-SHA512',
|
type: 'request-SHA512',
|
||||||
message: pw || 'mypassword'
|
message: pw || 'mypassword'
|
||||||
@@ -201,7 +194,7 @@ export async function changeEncryptionAndRestartApp(hash) {
|
|||||||
restart.Restart()
|
restart.Restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteDbAndOpenNew() {
|
export async function deleteDbAndOpenNew() {
|
||||||
const exists = await fs.exists(Realm.defaultPath)
|
const exists = await fs.exists(Realm.defaultPath)
|
||||||
if (exists) await fs.unlink(Realm.defaultPath)
|
if (exists) await fs.unlink(Realm.defaultPath)
|
||||||
await openDb({ persistConnection: true })
|
await openDb({ persistConnection: true })
|
||||||
@@ -216,22 +209,3 @@ function hashToInt8Array(hash) {
|
|||||||
}
|
}
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
|
||||||
saveSymptom,
|
|
||||||
getOrCreateCycleDay,
|
|
||||||
fillWithMucusDummyData,
|
|
||||||
fillWithCervixDummyData,
|
|
||||||
getBleedingDaysSortedByDate,
|
|
||||||
getTemperatureDaysSortedByDate,
|
|
||||||
getCycleDaysSortedByDate,
|
|
||||||
deleteAll,
|
|
||||||
getPreviousTemperature,
|
|
||||||
getCycleDay,
|
|
||||||
getAmountOfCycleDays,
|
|
||||||
getSchema,
|
|
||||||
tryToImportWithDelete,
|
|
||||||
tryToImportWithoutDelete,
|
|
||||||
requestHash,
|
|
||||||
deleteDbAndOpenNew
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user