Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
pill_minder
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Phuengton Chummuel
pill_minder
Commits
98a82f75
Commit
98a82f75
authored
Mar 22, 2018
by
Phuengton Chummuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apply redux to reminder list
parent
3f2f06d2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
205 deletions
+66
-205
AppointmentListScreen.js
src/screens/AppointmentListScreen.js
+1
-54
HomeScreen.js
src/screens/HomeScreen.js
+5
-5
MedicationListScreen.js
src/screens/MedicationListScreen.js
+6
-58
MedicationsScreen.js
src/screens/MedicationsScreen.js
+54
-88
No files found.
src/screens/AppointmentListScreen.js
View file @
98a82f75
...
...
@@ -24,12 +24,7 @@ class AppointmentListScreen extends Component {
constructor
(
props
)
{
super
(
props
)
this
.
state
=
{
appointmentList
:
[],
}
}
componentWillMount
()
{
this
.
_queryDbAppointment
()
};
}
render
()
{
...
...
@@ -54,27 +49,6 @@ class AppointmentListScreen extends Component {
/
>
<
Content
>
<
AppointmentList
/>
{
/* <View style={{ flex: 1, backgroundColor: 'white', height: 60 }}>
<Text style={headerStyle}>Appointment List</Text>
</View>
<View>
<List dataArray={this.state.appointmentList}
renderRow={(item) =>
<ListItem style={appointmentListStyle}>
<View style={{ flex: 1 }}>
<Text>{"Doctor: " + item.doctorName}</Text>
<Text>{"Date: " + moment(item.date).format("DD MMM YYYY")}</Text>
<Text>{"Time: " + moment(item.date).format("HH:mm")}</Text>
<Text>{"Place: " + item.place}</Text>
</View>
<TouchableOpacity onPress={() => this._deleteAppointment(item)}>
<Icon name='more' />
</TouchableOpacity>
</ListItem>
}>
</List>
</View> */
}
<
/Content
>
<
/Container
>
)
...
...
@@ -84,33 +58,6 @@ class AppointmentListScreen extends Component {
this
.
props
.
navigation
.
navigate
(
"AddAppointment"
)
}
_queryDbAppointment
()
{
const
tmpAppointment
=
realm
.
objects
(
"Appointments"
)
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
=
{
...
...
src/screens/HomeScreen.js
View file @
98a82f75
...
...
@@ -18,7 +18,7 @@ import {
Grid
}
from
'react-native-easy-grid'
import
AppHeader
from
'./../components/Header'
;
import
Reminder
List
from
'./../components/Reminder
List'
;
import
Reminder
BoxList
from
'./../components/ReminderBox
List'
;
import
{
formatDate
}
from
'./../Utils'
;
import
realm
from
'./../Database'
;
...
...
@@ -68,7 +68,7 @@ class HomeScreen extends Component {
<
Col
>
<
Row
>
<
TouchableOpacity
style
=
{
timePeriodLeftStyle
}
onPress
=
{()
=>
this
.
_timePeriodPress
(
this
.
state
.
morningReminder
,
1
)}
>
<
ReminderList
<
Reminder
Box
List
periodText
=
{
"Morning"
}
items
=
{
this
.
state
.
morningReminder
}
/
>
...
...
@@ -76,7 +76,7 @@ class HomeScreen extends Component {
<
/Row
>
<
Row
>
<
TouchableOpacity
style
=
{
timePeriodLeftStyle
}
onPress
=
{()
=>
this
.
_timePeriodPress
(
this
.
state
.
afternoonReminder
,
2
)}
>
<
ReminderList
<
Reminder
Box
List
periodText
=
{
"Afternoon"
}
items
=
{
this
.
state
.
afternoonReminder
}
/
>
...
...
@@ -86,7 +86,7 @@ class HomeScreen extends Component {
<
Col
>
<
Row
>
<
TouchableOpacity
style
=
{
timePeriodRightStyle
}
onPress
=
{()
=>
this
.
_timePeriodPress
(
this
.
state
.
eveningReminder
,
3
)}
>
<
ReminderList
<
Reminder
Box
List
periodText
=
{
"Evening"
}
items
=
{
this
.
state
.
eveningReminder
}
/
>
...
...
@@ -94,7 +94,7 @@ class HomeScreen extends Component {
<
/Row
>
<
Row
>
<
TouchableOpacity
style
=
{
timePeriodRightStyle
}
onPress
=
{()
=>
this
.
_timePeriodPress
(
this
.
state
.
nightReminder
,
4
)}
>
<
ReminderList
<
Reminder
Box
List
periodText
=
{
"Night"
}
items
=
{
this
.
state
.
nightReminder
}
/
>
...
...
src/screens/MedicationListScreen.js
View file @
98a82f75
...
...
@@ -5,11 +5,9 @@ import {
Content
,
View
,
Button
,
Icon
,
Text
,
List
,
ListItem
Icon
}
from
'native-base'
;
import
ReminderList
from
'./../components/ReminderList'
;
import
{
cancleNotification
}
from
'./../Utils'
;
import
AppHeader
from
'./../components/Header'
;
import
realm
from
'./../Database/'
;
...
...
@@ -20,14 +18,9 @@ class MedicationListScreen extends Component {
constructor
(
props
)
{
super
(
props
)
this
.
state
=
{
reminderList
:
[]
}
}
componentWillMount
()
{
this
.
_queryMedicineList
()
}
render
()
{
const
{
reminderListStyle
,
headerStyle
}
=
styles
...
...
@@ -50,65 +43,17 @@ class MedicationListScreen extends Component {
}
/
>
<
Content
>
<
View
style
=
{{
flex
:
1
,
backgroundColor
:
'white'
,
height
:
60
}}
>
<
Text
style
=
{
headerStyle
}
>
Medication
List
<
/Text
>
<
/View
>
<
View
>
<
List
dataArray
=
{
this
.
state
.
reminderList
}
renderRow
=
{(
item
)
=>
<
ListItem
style
=
{
reminderListStyle
}
>
<
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
>
<
ReminderList
/>
<
/Content
>
<
/Container
>
)
}
_queryMedicineList
()
{
var
tmpReminder
=
realm
.
objects
(
"Reminder"
)
this
.
setState
({
reminderList
:
tmpReminder
})
}
_addReminder
()
{
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
=
{
reminderListStyle
:
{
marginLeft
:
0
,
...
...
@@ -124,4 +69,6 @@ const styles = {
}
}
export
default
MedicationListScreen
;
\ No newline at end of file
src/screens/MedicationsScreen.js
View file @
98a82f75
import
React
,
{
Component
}
from
'react'
;
import
{
DeviceEventEmitter
,
ToastAndroid
,
Alert
}
from
'react-native'
;
import
{
formatDate
,
scheduleLocalNotification
}
from
'./../Utils'
;
import
{
formatDate
,
scheduleLocalNotification
,
generateID
}
from
'./../Utils'
;
import
{
Grid
,
Col
}
from
'react-native-easy-grid'
;
import
{
SinglePickerMaterialDialog
}
from
'react-native-material-dialog'
;
import
PushNotification
from
'react-native-push-notification'
;
...
...
@@ -24,8 +24,10 @@ import {
import
DatePicker
from
'react-native-datepicker'
;
import
AppHeader
from
'./../components/Header'
;
import
MedForm
from
'../components/MedForm'
;
import
moment
from
'moment'
import
realm
from
'./../Database'
import
{
connect
}
from
'react-redux'
;
import
{
reminderCreate
}
from
'./../actions'
;
import
moment
from
'moment'
;
import
realm
from
'./../Database'
;
PushNotification
.
configure
({
// (required) Called when a remote or local notification is opened or received
...
...
@@ -96,7 +98,52 @@ class MedicationsScreen extends Component {
this
.
setState
({
morningTime
,
afternoonTime
,
eveningTime
,
nightTime
})
// ToastAndroid.show(morningTime + afternoonTime + eveningTime + nightTime, ToastAndroid.SHORT)
}
_addReminder
()
{
let
reminder
=
""
if
(
this
.
state
.
morning
===
true
)
{
var
time
=
this
.
state
.
morningTime
.
split
(
':'
)
reminder
=
this
.
_setNotification
(
time
[
0
],
time
[
1
],
1
)
this
.
props
.
reminderCreate
(
reminder
)
}
if
(
this
.
state
.
afternoon
===
true
)
{
var
time
=
this
.
state
.
afternoonTime
.
split
(
':'
)
reminder
=
this
.
_setNotification
(
time
[
0
],
time
[
1
],
2
)
this
.
props
.
reminderCreate
(
reminder
)
}
if
(
this
.
state
.
evening
===
true
)
{
var
time
=
this
.
state
.
eveningTime
.
split
(
':'
)
reminder
=
this
.
_setNotification
(
time
[
0
],
time
[
1
],
3
)
this
.
props
.
reminderCreate
(
reminder
)
}
if
(
this
.
state
.
night
===
true
)
{
var
time
=
this
.
state
.
nightTime
.
split
(
':'
)
reminder
=
this
.
_setNotification
(
time
[
0
],
time
[
1
],
4
)
this
.
props
.
reminderCreate
(
reminder
)
}
this
.
props
.
navigation
.
goBack
(
null
)
}
_setNotification
(
hour
,
minute
,
period
)
{
var
id
=
generateID
()
var
reminderDate
=
moment
().
hour
(
hour
).
minute
(
minute
).
second
(
0
).
toDate
()
var
beforeMeal
=
this
.
state
.
beforeMeal
?
"
\
tก่อนอาหาร"
:
"
\
tหลังอาหาร"
;
// var msg = "แจ้งเตือนกินยา\n" + "เวลา: " + hour + ":" + minute + "\nยา: " + this.state.text + beforeMeal;
// scheduleLocalNotification(msg, reminderDate, id)
return
{
id
:
id
,
medName
:
this
.
state
.
text
,
reminderTime
:
reminderDate
,
meal
:
beforeMeal
.
trim
(),
period
:
period
,
dose
:
this
.
state
.
dose
}
}
...
...
@@ -189,19 +236,7 @@ class MedicationsScreen extends Component {
<
/MedForm
>
<
MedForm
titleText
=
{
"Schedule"
}
>
<
Text
style
=
{
timeStyle
}
>
Start
date
:
{
formatDate
(
new
Date
(
Date
.
now
()))}
<
/Text
>
{
/* <DatePicker
style={timeStyle}
date={new Date(this.state.date).toISOString().split('T')[0]}
mode="date"
placeholder="placeholder"
format="YYYY-MM-DD"
minDate={this.state.minDate}
confirmBtnText="Confirm"
cancelBtnText="Cancel"
onDateChange={(date) => { this.setState({ date: date }); }}
/> */
}
<
/MedForm
>
<
MedForm
titleText
=
{
"Dose"
}
>
...
...
@@ -232,7 +267,7 @@ class MedicationsScreen extends Component {
<
/Button
>
<
/Col
>
<
Col
>
<
Button
full
style
=
{
btnAddNoti
}
onPress
=
{()
=>
this
.
_
onAddNotificationPressed
()}
>
<
Button
full
style
=
{
btnAddNoti
}
onPress
=
{()
=>
this
.
_
addReminder
()}
>
<
Text
style
=
{{
color
:
"#1686C4"
}}
>
Add
<
/Text
>
<
/Button
>
<
/Col
>
...
...
@@ -259,75 +294,6 @@ class MedicationsScreen extends Component {
}
}
_onAddNotificationPressed
()
{
if
(
this
.
state
.
text
&&
this
.
state
.
morning
||
this
.
state
.
afternoon
||
this
.
state
.
evening
||
this
.
state
.
night
)
{
if
(
this
.
state
.
morning
===
true
)
{
var
time
=
this
.
state
.
morningTime
.
split
(
':'
)
this
.
_setNotification
(
time
[
0
],
time
[
1
],
1
)
}
if
(
this
.
state
.
afternoon
===
true
)
{
var
time
=
this
.
state
.
afternoonTime
.
split
(
':'
)
this
.
_setNotification
(
time
[
0
],
time
[
1
],
2
)
}
if
(
this
.
state
.
evening
===
true
)
{
var
time
=
this
.
state
.
eveningTime
.
split
(
':'
)
this
.
_setNotification
(
time
[
0
],
time
[
1
],
3
)
}
if
(
this
.
state
.
night
===
true
)
{
var
time
=
this
.
state
.
nightTime
.
split
(
':'
)
this
.
_setNotification
(
time
[
0
],
time
[
1
],
4
)
}
Alert
.
alert
(
'Successful'
,
''
,
[
// { text: 'OK', onPress: () => ToastAndroid.show("Successful", ToastAndroid.SHORT) },
{
text
:
'OK'
,
onPress
:
()
=>
{
}
},
],
{
cancelable
:
false
}
)
}
else
{
Alert
.
alert
(
'Please enter medine name / Select reminder time'
,
''
,
[
// { text: 'OK', onPress: () => ToastAndroid.show("Please enter medine name / Select reminder time", ToastAndroid.SHORT) },
{
text
:
'OK'
,
onPress
:
()
=>
{
}
},
],
{
cancelable
:
false
}
)
}
}
_setNotification
(
hour
,
minute
,
period
)
{
var
id
=
Math
.
random
()
*
10000
var
reminderDate
=
moment
().
hour
(
hour
).
minute
(
minute
).
second
(
0
).
toDate
()
var
beforeMeal
=
this
.
state
.
beforeMeal
?
"
\
tก่อนอาหาร"
:
"
\
tหลังอาหาร"
;
var
msg
=
"แจ้งเตือนกินยา
\n
"
+
"เวลา: "
+
hour
+
":"
+
minute
+
"
\n
ยา: "
+
this
.
state
.
text
+
beforeMeal
;
scheduleLocalNotification
(
msg
,
reminderDate
,
id
)
realm
.
write
(()
=>
{
realm
.
create
(
'Reminder'
,
{
id
:
id
,
medName
:
this
.
state
.
text
,
reminderTime
:
reminderDate
,
meal
:
beforeMeal
.
trim
(),
period
:
period
,
dose
:
this
.
state
.
dose
,
timeStamp
:
moment
().
toDate
()
})
})
}
_onResetPressed
()
{
realm
.
write
(()
=>
{
...
...
@@ -377,4 +343,4 @@ const styles = {
}
}
export
default
MedicationsScreen
;
\ No newline at end of file
export
default
connect
(
null
,
{
reminderCreate
})(
MedicationsScreen
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment