-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
449 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import React, {Component} from 'react'; | ||
import { | ||
StyleSheet, | ||
Text, | ||
View, | ||
Image, | ||
ScrollView, | ||
TouchableOpacity, | ||
Platform, | ||
} from 'react-native'; | ||
import colors from 'assets/colors'; | ||
import {strings} from 'locales/i18n'; | ||
import SummaryList from './SummaryList'; | ||
import Share from 'react-native-share'; | ||
import RealmObj from 'realm/realm'; | ||
import * as RNFS from 'react-native-fs'; | ||
|
||
const Buffer = require('buffer').Buffer; | ||
|
||
class Complete extends Component { | ||
async export() { | ||
let real = await RealmObj.init(); | ||
|
||
const locations = real.objects('Location'); | ||
const locationCSV = locations.map(location => { | ||
let locationObj = JSON.parse(JSON.stringify(location)); | ||
return Object.values(locationObj).map(val => { | ||
return val; | ||
}).join('\t'); | ||
}).join('\r\n'); | ||
|
||
const symptoms = real.objects('Symptoms'); | ||
const symptomsCSV = symptoms.map(symptom => { | ||
let symptomsObj = JSON.parse(JSON.stringify(symptom)); | ||
return Object.values(symptomsObj).map(val => { | ||
return val; | ||
}).join('\t'); | ||
}).join('\r\n'); | ||
|
||
let locationPath; | ||
let symptomsPath; | ||
|
||
try { | ||
let locationURL; | ||
let symptomsURL; | ||
if (Platform.OS === 'android') { | ||
let encodedLocation = new Buffer(JSON.stringify(locationCSV)).toString('base64'); | ||
let encodedSymptoms = new Buffer(JSON.stringify(symptomsCSV)).toString('base64'); | ||
|
||
locationURL = 'data:text/csv;base64,' + encodedLocation; | ||
symptomsURL = 'data:text/csv;base64,' + encodedSymptoms; | ||
} else { | ||
locationPath = RNFS.DocumentDirectoryPath + '/location.csv'; | ||
symptomsPath = RNFS.DocumentDirectoryPath + '/symptoms.csv'; | ||
try { | ||
await RNFS.unlink(locationPath); | ||
await RNFS.unlink(symptomsPath); | ||
} catch (e) { | ||
// unlink fails if the file doesn't exist, which is fine | ||
} | ||
|
||
await RNFS.writeFile(locationPath, locationCSV, 'utf8'); | ||
await RNFS.writeFile(symptomsPath, symptomsCSV, 'utf8'); | ||
locationURL = 'file://' + locationPath; | ||
symptomsURL = 'file://' + symptomsPath; | ||
} | ||
console.log('dump created successfully'); | ||
|
||
let res = await Share.open({ | ||
urls: [locationURL, symptomsURL], | ||
filename: 'common-circle-dump', | ||
message: strings('export.message'), | ||
failOnCancel: false, | ||
}); | ||
console.log('sharing ok:' + JSON.stringify(res)); | ||
} catch (e) { | ||
console.log('sharing failed due to: ' + JSON.stringify(e)); | ||
} | ||
|
||
//delete the file regardless of what happened | ||
if (Platform.OS !== 'android') { | ||
try { | ||
console.log('removing file'); | ||
await RNFS.unlink(locationPath); | ||
await RNFS.unlink(symptomsPath); | ||
} catch (e) { | ||
// unlink fails if the file doesn't exist, which is fine | ||
} | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<ScrollView> | ||
<Image | ||
style={styles.hero} | ||
source={require('assets/health/interview_prep_bg.png')} | ||
/> | ||
<View style={styles.container}> | ||
<Text style={styles.title}> | ||
{strings('interview_prep_complete.title')} | ||
</Text> | ||
<Text style={styles.description}> | ||
{strings('interview_prep_complete.description')} | ||
</Text> | ||
<TouchableOpacity style={styles.send_button} onPress={this.export}> | ||
<Text style={styles.send_button_text}> | ||
{strings('interview_prep_complete.send_btn')} | ||
</Text> | ||
</TouchableOpacity> | ||
</View> | ||
<SummaryList /> | ||
</ScrollView> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
hero: { | ||
width: '100%', | ||
height: 104, | ||
}, | ||
container: { | ||
paddingVertical: 20, | ||
paddingHorizontal: 18, | ||
}, | ||
title: { | ||
fontSize: 20, | ||
lineHeight: 26, | ||
paddingBottom: 5, | ||
}, | ||
description: { | ||
fontSize: 14, | ||
lineHeight: 18, | ||
color: colors.body_copy, | ||
marginBottom: 12, | ||
}, | ||
send_button: { | ||
borderRadius: 8, | ||
backgroundColor: colors.primary_theme, | ||
paddingVertical: 15, | ||
alignItems: 'center', | ||
marginBottom: 15, | ||
}, | ||
send_button_text: { | ||
fontWeight: '500', | ||
fontSize: 15, | ||
lineHeight: 20, | ||
letterSpacing: -0.24, | ||
color: 'white', | ||
}, | ||
}); | ||
|
||
export default Complete; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.