Commit 09faea45 authored by Phuengton Chummuel's avatar Phuengton Chummuel

refactor code a little

parent c634a92a
...@@ -53,4 +53,8 @@ export function appointmentNotification(message, date, id, payload) { ...@@ -53,4 +53,8 @@ export function appointmentNotification(message, date, id, payload) {
//schedule the notification //schedule the notification
PushNotification.localNotificationSchedule(notification); PushNotification.localNotificationSchedule(notification);
}
export function cancleNotification(id) {
PushNotification.cancelLocalNotifications({ id: id });
} }
\ No newline at end of file
...@@ -10,6 +10,7 @@ import moment from 'moment' ...@@ -10,6 +10,7 @@ import moment from 'moment'
import { Grid, Col } from 'react-native-easy-grid'; import { Grid, Col } from 'react-native-easy-grid';
import { ToastAndroid } from 'react-native'; import { ToastAndroid } from 'react-native';
import PushNotification from 'react-native-push-notification'; import PushNotification from 'react-native-push-notification';
import cancleNotification from './../Utils';
import realm from './../Database'; import realm from './../Database';
class MedicineDetailCard extends React.Component { class MedicineDetailCard extends React.Component {
...@@ -21,7 +22,7 @@ class MedicineDetailCard extends React.Component { ...@@ -21,7 +22,7 @@ class MedicineDetailCard extends React.Component {
render() { render() {
const { headerStyle, timeTitleStyle, detailStyle, btnStyle } = styles; const { headerStyle, timeTitleStyle, detailStyle, btnStyle } = styles;
const { id, medName, reminderTime, meal } = this.props.item const { id, medName, reminderTime, meal, dose } = this.props.item
return ( return (
<View style={{ flex: 1, marginTop: 10 }}> <View style={{ flex: 1, marginTop: 10 }}>
...@@ -30,7 +31,8 @@ class MedicineDetailCard extends React.Component { ...@@ -30,7 +31,8 @@ class MedicineDetailCard extends React.Component {
</View> </View>
<View style={detailStyle}> <View style={detailStyle}>
<Text>{medName}</Text> <Text>{medName}</Text>
<Text>Take 2</Text> <Text>{meal}</Text>
<Text>{"จำนวน " + dose}</Text>
</View> </View>
<View> <View>
<Grid> <Grid>
...@@ -63,7 +65,7 @@ class MedicineDetailCard extends React.Component { ...@@ -63,7 +65,7 @@ class MedicineDetailCard extends React.Component {
realm.write(() => { realm.write(() => {
let myReminder = realm.objects('Reminder').filtered('id == ' + id) let myReminder = realm.objects('Reminder').filtered('id == ' + id)
realm.delete(myReminder) realm.delete(myReminder)
ToastAndroid.show(JSON.stringify(myReminder), ToastAndroid.SHORT) // ToastAndroid.show(JSON.stringify(myReminder), ToastAndroid.SHORT)
}) })
} }
}, },
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Alert, ToastAndroid, TouchableOpacity } from 'react-native';
import { import {
Container, Container,
Content, Content,
...@@ -14,6 +15,7 @@ import { ...@@ -14,6 +15,7 @@ import {
import AppHeader from './../components/Header'; import AppHeader from './../components/Header';
import realm from './../Database/'; import realm from './../Database/';
import moment from 'moment'; import moment from 'moment';
import { cancleNotification } from './../Utils';
class AppointmentListScreen extends Component { class AppointmentListScreen extends Component {
...@@ -30,7 +32,7 @@ class AppointmentListScreen extends Component { ...@@ -30,7 +32,7 @@ class AppointmentListScreen extends Component {
render() { render() {
const { appointmentListStyle } = styles const { appointmentListStyle, headerStyle } = styles
const { goBack } = this.props.navigation const { goBack } = this.props.navigation
return ( return (
...@@ -49,22 +51,27 @@ class AppointmentListScreen extends Component { ...@@ -49,22 +51,27 @@ class AppointmentListScreen extends Component {
} }
/> />
<Content> <Content>
<Text>Appointment List</Text> <View style={{ flex: 1, backgroundColor: 'white', height: 60 }}>
<List dataArray={this.state.appointmentList} <Text style={headerStyle}>Appointment List</Text>
renderRow={(item) => </View>
<ListItem style={appointmentListStyle}> <View>
<View style={{ flex: 1 }}> <List dataArray={this.state.appointmentList}
<Text>{"Doctor: " + item.doctorName}</Text> renderRow={(item) =>
<Text>{"Date: " + moment(item.date).format("DD MM YYYY")}</Text> <ListItem style={appointmentListStyle}>
<Text>{"Time: " + moment(item.date).format("HH:mm")}</Text> <View style={{ flex: 1 }}>
<Text>{"Place: " + item.place}</Text> <Text>{"Doctor: " + item.doctorName}</Text>
</View> <Text>{"Date: " + moment(item.date).format("DD MMM YYYY")}</Text>
<View> <Text>{"Time: " + moment(item.date).format("HH:mm")}</Text>
<Icon name='more' /> <Text>{"Place: " + item.place}</Text>
</View> </View>
</ListItem>
}> <TouchableOpacity onPress={() => this._deleteAppointment(item)}>
</List> <Icon name='more' />
</TouchableOpacity>
</ListItem>
}>
</List>
</View>
</Content> </Content>
</Container> </Container>
) )
...@@ -79,6 +86,28 @@ class AppointmentListScreen extends Component { ...@@ -79,6 +86,28 @@ class AppointmentListScreen extends Component {
this.setState({ appointmentList: tmpAppointment }) this.setState({ appointmentList: tmpAppointment })
} }
_deleteAppointment(data) {
// ToastAndroid.show("Clicked", ToastAndroid.SHORT)
Alert.alert(
'Confirm',
'Want to delete this appointment?',
[
{ text: 'CANCLE', onPress: () => this.setState({ addItemVisible: true }) },
{
text: 'OK', onPress: () => {
const tmpAppointment = realm.objects("Appointments").filtered('id == ' + data.id)
cancleNotification(data.id)
realm.write(() => {
realm.delete(tmpAppointment)
})
}
},
],
{ cancelable: false }
)
}
} }
const styles = { const styles = {
...@@ -88,8 +117,13 @@ const styles = { ...@@ -88,8 +117,13 @@ const styles = {
marginTop: 0, marginTop: 0,
marginBottom: 0, marginBottom: 0,
padding: 15, padding: 15,
},
headerStyle: {
color: "#1686C4",
fontSize: 20,
paddingTop: 15,
paddingLeft: 15
} }
} }
export default AppointmentListScreen; export default AppointmentListScreen;
\ No newline at end of file
...@@ -102,7 +102,7 @@ class AppointmentsScreen extends React.Component { ...@@ -102,7 +102,7 @@ class AppointmentsScreen extends React.Component {
let allReminder = realm.objects('Appointments') let allReminder = realm.objects('Appointments')
realm.delete(allReminder) realm.delete(allReminder)
}) })
ToastAndroid.show("reset", ToastAndroid.SHORT) // ToastAndroid.show("reset", ToastAndroid.SHORT)
} }
_addAppointment() { _addAppointment() {
...@@ -112,7 +112,8 @@ class AppointmentsScreen extends React.Component { ...@@ -112,7 +112,8 @@ class AppointmentsScreen extends React.Component {
'Confrim?', 'Confrim?',
'Are you sure to add this appointment?', 'Are you sure to add this appointment?',
[ [
{ text: 'CANCLE', onPress: () => ToastAndroid.show("Cancled", ToastAndroid.SHORT) }, // { text: 'CANCLE', onPress: () => ToastAndroid.show("Cancled", ToastAndroid.SHORT) },
{ text: 'CANCLE', onPress: () => { } },
{ {
text: 'OK', onPress: () => { text: 'OK', onPress: () => {
var id = Math.random() * 10000 var id = Math.random() * 10000
...@@ -143,7 +144,8 @@ class AppointmentsScreen extends React.Component { ...@@ -143,7 +144,8 @@ class AppointmentsScreen extends React.Component {
'Please enter Doctor name / Select appointment date and time', 'Please enter Doctor name / Select appointment date and time',
'', '',
[ [
{ text: 'OK', onPress: () => ToastAndroid.show("Please enter medine name / Select reminder time", ToastAndroid.SHORT) }, // { text: 'OK', onPress: () => ToastAndroid.show("Please enter medine name / Select reminder time", ToastAndroid.SHORT) },
{ text: 'OK', onPress: () => { } },
], ],
{ cancelable: false } { cancelable: false }
) )
......
...@@ -110,10 +110,13 @@ class AppCamera extends Component { ...@@ -110,10 +110,13 @@ class AppCamera extends Component {
break; break;
} }
var timePeriod = data.period == 1 ? 'เช้า' : data.period == 2 ? 'กลางวัน' : data.period == 3 ? 'เย็น' : 'ค่ำ';
var beforeMeal = data.beforeMeal ? "\tก่อนอาหาร" : "\tหลังอาหาร";
Alert.alert( Alert.alert(
'Confrim?', 'Confrim?',
JSON.stringify(data), 'ชื่อยา: ' + data.medName + '\nก่อน/หลัง อาหาร: ' + beforeMeal + '\nช่วงเวลา: ' + timePeriod + '\nจำนวน: ' + data.dose,
[ [
{ text: 'CANCLE', onPress: () => this.setState({ addItemVisible: true }) }, { text: 'CANCLE', onPress: () => this.setState({ addItemVisible: true }) },
{ {
...@@ -122,7 +125,7 @@ class AppCamera extends Component { ...@@ -122,7 +125,7 @@ class AppCamera extends Component {
var id = Math.random() * 10000 var id = Math.random() * 10000
var reminderDate = moment().hour(time[0]).minute(time[1]).second(0).toDate() var reminderDate = moment().hour(time[0]).minute(time[1]).second(0).toDate()
var beforeMeal = data.beforeMeal ? "\tก่อนอาหาร" : "\tหลังอาหาร";
var msg = "แจ้งเตือนกินยา\n" + "เวลา: " + time[0] + ":" + time[1] + "\nยา: " + data.medName + beforeMeal; var msg = "แจ้งเตือนกินยา\n" + "เวลา: " + time[0] + ":" + time[1] + "\nยา: " + data.medName + beforeMeal;
scheduleLocalNotification(msg, reminderDate, id) scheduleLocalNotification(msg, reminderDate, id)
......
...@@ -125,7 +125,7 @@ class HomeScreen extends Component { ...@@ -125,7 +125,7 @@ class HomeScreen extends Component {
} }
_timePeriodPress(data, period) { _timePeriodPress(data, period) {
ToastAndroid.show(JSON.stringify(data), ToastAndroid.SHORT) // ToastAndroid.show(JSON.stringify(data), ToastAndroid.SHORT)
this.props.navigation.navigate('Detail', { items: data, period: period }) this.props.navigation.navigate('Detail', { items: data, period: period })
} }
...@@ -160,7 +160,7 @@ class HomeScreen extends Component { ...@@ -160,7 +160,7 @@ class HomeScreen extends Component {
this.setState({ morningReminder: tmpMorning, afternoonReminder: tmpAfternoon, eveningReminder: tmpEvening, nightReminder: tmpNight }) this.setState({ morningReminder: tmpMorning, afternoonReminder: tmpAfternoon, eveningReminder: tmpEvening, nightReminder: tmpNight })
// ToastAndroid.show(JSON.stringify(myReminder), ToastAndroid.LONG) // ToastAndroid.show(JSON.stringify(myReminder), ToastAndroid.LONG)
ToastAndroid.show(JSON.stringify(this.state.morningReminder), ToastAndroid.LONG) // ToastAndroid.show(JSON.stringify(this.state.morningReminder), ToastAndroid.LONG)
} }
_isFirstLaunched() { _isFirstLaunched() {
...@@ -171,10 +171,10 @@ class HomeScreen extends Component { ...@@ -171,10 +171,10 @@ class HomeScreen extends Component {
ToastAndroid.show(error.toString(), ToastAndroid.SHORT) ToastAndroid.show(error.toString(), ToastAndroid.SHORT)
}) // No need to wait for `setItem` to finish, although you might want to handle errors }) // No need to wait for `setItem` to finish, although you might want to handle errors
this.setState({ firstLaunch: true }); this.setState({ firstLaunch: true });
ToastAndroid.show("Frist Launch:" + this.state.firstLaunch, ToastAndroid.LONG) // ToastAndroid.show("Frist Launch:" + this.state.firstLaunch, ToastAndroid.LONG)
} else { } else {
this.setState({ firstLaunch: false }); this.setState({ firstLaunch: false });
ToastAndroid.show("Frist Launch:" + this.state.firstLaunch, ToastAndroid.LONG) // ToastAndroid.show("Frist Launch:" + this.state.firstLaunch, ToastAndroid.LONG)
} }
}) // Add some error handling, also you can simply do this.setState({fistLaunch: value == null}) }) // Add some error handling, also you can simply do this.setState({fistLaunch: value == null})
} }
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { TouchableOpacity, Alert } from 'react-native';
import { import {
Container, Container,
Content, Content,
...@@ -9,8 +10,10 @@ import { ...@@ -9,8 +10,10 @@ import {
List, List,
ListItem ListItem
} from 'native-base'; } from 'native-base';
import { cancleNotification } from './../Utils';
import AppHeader from './../components/Header'; import AppHeader from './../components/Header';
import realm from './../Database/' import realm from './../Database/';
import moment from 'moment';
class MedicationListScreen extends Component { class MedicationListScreen extends Component {
...@@ -27,7 +30,7 @@ class MedicationListScreen extends Component { ...@@ -27,7 +30,7 @@ class MedicationListScreen extends Component {
render() { render() {
const { reminderListStyle } = styles const { reminderListStyle, headerStyle } = styles
const { goBack } = this.props.navigation const { goBack } = this.props.navigation
...@@ -47,14 +50,26 @@ class MedicationListScreen extends Component { ...@@ -47,14 +50,26 @@ class MedicationListScreen extends Component {
} }
/> />
<Content> <Content>
<Text>Reminder List</Text> <View style={{ flex: 1, backgroundColor: 'white', height: 60 }}>
<List dataArray={this.state.reminderList} <Text style={headerStyle}>Medication List</Text>
renderRow={(item) => </View>
<ListItem style={reminderListStyle}> <View>
<Text>{item.medName}</Text> <List dataArray={this.state.reminderList}
</ListItem> renderRow={(item) =>
}> <ListItem style={reminderListStyle}>
</List> <View style={{ flex: 1 }}>
<Text>{item.medName}</Text>
<Text>{"Take: " + item.dose}</Text>
<Text>{'Time: ' + moment(item.reminderTime).format('HH:mm')}</Text>
</View>
<TouchableOpacity onPress={() => this._deleteMedicine(item)}>
<Icon name='more' />
</TouchableOpacity>
</ListItem>
}>
</List>
</View>
</Content> </Content>
</Container> </Container>
) )
...@@ -71,8 +86,29 @@ class MedicationListScreen extends Component { ...@@ -71,8 +86,29 @@ class MedicationListScreen extends Component {
this.props.navigation.navigate("AddMedication") this.props.navigation.navigate("AddMedication")
} }
_deleteMedicine(data) {
Alert.alert(
'Confirm',
'Want to delete this medicine?',
[
{ text: 'CANCLE', onPress: () => this.setState({ addItemVisible: true }) },
{
text: 'OK', onPress: () => {
const tmpMedicine = realm.objects("Reminder").filtered('id == ' + data.id)
cancleNotification(data.id)
realm.write(() => {
realm.delete(tmpMedicine)
})
}
},
],
{ cancelable: false }
)
}
} }
const styles = { const styles = {
reminderListStyle: { reminderListStyle: {
marginLeft: 0, marginLeft: 0,
...@@ -80,6 +116,11 @@ const styles = { ...@@ -80,6 +116,11 @@ const styles = {
marginTop: 0, marginTop: 0,
marginBottom: 0, marginBottom: 0,
padding: 15 padding: 15
}, headerStyle: {
color: "#1686C4",
fontSize: 20,
paddingTop: 15,
paddingLeft: 15
} }
} }
......
...@@ -50,8 +50,8 @@ PushNotification.configure({ ...@@ -50,8 +50,8 @@ PushNotification.configure({
class MedicationsScreen extends Component { class MedicationsScreen extends Component {
constructor() { constructor(props) {
super(); super(props);
this.state = { this.state = {
text: "", text: "",
date: new Date(Date.now()).toISOString().split('T')[0], date: new Date(Date.now()).toISOString().split('T')[0],
...@@ -285,7 +285,8 @@ class MedicationsScreen extends Component { ...@@ -285,7 +285,8 @@ class MedicationsScreen extends Component {
'Successful', 'Successful',
'', '',
[ [
{ text: 'OK', onPress: () => ToastAndroid.show("Successful", ToastAndroid.SHORT) }, // { text: 'OK', onPress: () => ToastAndroid.show("Successful", ToastAndroid.SHORT) },
{ text: 'OK', onPress: () => { } },
], ],
{ cancelable: false } { cancelable: false }
) )
...@@ -295,7 +296,8 @@ class MedicationsScreen extends Component { ...@@ -295,7 +296,8 @@ class MedicationsScreen extends Component {
'Please enter medine name / Select reminder time', 'Please enter medine name / Select reminder time',
'', '',
[ [
{ text: 'OK', onPress: () => ToastAndroid.show("Please enter medine name / Select reminder time", ToastAndroid.SHORT) }, // { text: 'OK', onPress: () => ToastAndroid.show("Please enter medine name / Select reminder time", ToastAndroid.SHORT) },
{ text: 'OK', onPress: () => { } },
], ],
{ cancelable: false } { cancelable: false }
) )
......
...@@ -19,7 +19,7 @@ class ReminderDetail extends React.Component { ...@@ -19,7 +19,7 @@ class ReminderDetail extends React.Component {
const { params } = this.props.navigation.state; const { params } = this.props.navigation.state;
const { goBack } = this.props.navigation; const { goBack } = this.props.navigation;
const items = params ? params.items : null const items = params ? params.items : null
const period = params.period == 1 ? "Mornign" : params.period == 2 ? "Afternoon" : params.period == 3 ? "Evening" : "Night" const period = params.period == 1 ? "Morning" : params.period == 2 ? "Afternoon" : params.period == 3 ? "Evening" : "Night"
const { headerStyle, headerFontStyle } = styles const { headerStyle, headerFontStyle } = styles
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment