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