Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
safetcut-app
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
atichat
safetcut-app
Commits
f1b46072
Commit
f1b46072
authored
Aug 21, 2019
by
Tonk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update notification, add notification mock-data
parent
08f1b4ed
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
51 deletions
+97
-51
screens/Private/NotificationScreen/NotificationScreen.js
+83
-51
screens/Private/NotificationScreen/notification.json
+14
-0
No files found.
screens/Private/NotificationScreen/NotificationScreen.js
View file @
f1b46072
...
...
@@ -3,63 +3,91 @@ import { Text, Tab, Tabs, ScrollableTab, Icon } from 'native-base';
import
{
View
,
StyleSheet
,
FlatList
,
ScrollView
}
from
'react-native'
;
import
{
color
,
theme
}
from
'../../../constants/Styles'
;
import
{
SearchBar
}
from
'react-native-elements'
;
import
{
format
,
sort
}
from
'date-fns'
;
import
{
format
,
isToday
,
isYesterday
,
isSameDay
}
from
'date-fns'
;
const
mockdata
=
[
{
time
:
1566207933
,
user
:
'Sukanya161'
,
log
:
'Switch on sub breaker1'
,
type
:
'notification'
},
{
time
:
1566299471
,
user
:
'Sukanya161'
,
log
:
'Switch off sub breaker1'
,
type
:
'notification'
},
{
time
:
1566271564
,
user
:
'Sukanya161'
,
log
:
'Switch on sub breaker1'
,
type
:
'log'
},
{
time
:
1573514603
,
user
:
'Sukanya161'
,
log
:
'Switch off sub breaker1'
,
type
:
'notification'
},
const
tabHeader
=
[
{
type
:
'all'
,
label
:
'All'
},
{
type
:
'notification'
,
label
:
'Notifications'
},
{
type
:
'log'
,
label
:
'Logging'
},
];
const
dt2
=
require
(
'./notification.json'
);
export
default
class
NotificationScreen
extends
React
.
Component
{
static
navigationOptions
=
({
navigation
})
=>
({
title
:
'Notifications'
,
});
state
=
{
search
:
''
};
state
=
{
search
:
''
,
data
:
[]
};
componentDidMount
()
{
this
.
sortDate
();
}
updateSearch
=
search
=>
{
this
.
setState
({
search
});
};
renderActi
vity
Card
(
data
)
{
renderActi
on
Card
(
data
)
{
return
(
<
View
style
=
{[
theme
.
rowContainer
,
{
paddingHorizontal
:
30
,
paddingVertical
:
10
,
alignItems
:
'flex-start'
,
backgroundColor
:
color
.
white
,
width
:
'100%'
,
},
]}
>
<
View
style
=
{{
width
:
16
,
height
:
16
,
marginRight
:
10
,
borderRadius
:
100
,
backgroundColor
:
color
.
primary
,
alignItems
:
'center'
,
justifyContent
:
'center'
,
}}
>
<
View
style
=
{[
theme
.
rowContainer
,
styles
.
actionContainer
]}
>
<
View
style
=
{
styles
.
thumbnail
}
>
{
/* first letter of operate's username */
}
<
Text
style
=
{{
color
:
color
.
white
,
fontSize
:
8
}}
>
A
<
/Text
>
<
Text
style
=
{{
color
:
color
.
white
,
fontSize
:
8
}}
>
{
data
.
user
.
charAt
(
0
).
toUpperCase
()}
<
/Text
>
<
/View
>
<
View
style
=
{{
display
:
'flex'
,
flexDirection
:
'column'
,
flex
:
1
}}
>
<
View
style
=
{[
theme
.
rowContainer
,
{
justifyContent
:
'space-between'
,
marginBottom
:
5
}]}
>
{
/* operate's username */
}
<
Text
style
=
{[
theme
.
smDescription
]}
>
{
data
.
user
||
'
JohnDoe
'
}
<
/Text
>
<
Text
style
=
{[
theme
.
smDescription
]}
>
{
data
.
user
||
'
unknown
'
}
<
/Text
>
{
/* operate time */
}
<
Text
style
=
{[
theme
.
smDescription
]}
>
{
format
(
data
.
time
,
'hh:mm A'
)
||
'00:00 AM'
}
<
/Text
>
<
Text
style
=
{[
theme
.
smDescription
]}
>
{
format
(
data
.
time
*
1000
,
'hh:mm A'
)
}
<
/Text
>
<
/View
>
{
/* operate activity. */
}
<
Text
style
=
{[
theme
.
normalText
,
theme
.
textDark
]}
>
{
data
.
log
||
'Unknown activity'
}
<
/Text
>
{
/* operate action. */
}
<
Text
style
=
{[
theme
.
normalText
,
theme
.
textDark
]}
>
{
data
.
action
}
{
data
.
device
}
<
/Text
>
<
/View
>
<
/View
>
);
}
sortDate
()
{
this
.
setState
({
data
:
dt2
.
sort
(
function
(
a
,
b
)
{
var
dateA
=
new
Date
(
a
.
time
),
dateB
=
new
Date
(
b
.
time
);
return
dateB
-
dateA
;
}),
});
}
renderDayList
(
type
)
{
const
data
=
type
===
'all'
?
this
.
state
.
data
:
this
.
state
.
data
.
filter
(
x
=>
{
return
x
.
type
===
type
;
});
let
view
=
[];
let
day
;
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
if
(
isToday
(
data
[
i
].
time
*
1000
)
&&
i
===
0
)
{
view
.
push
(
<>
<
Text
style
=
{[
theme
.
normalText
,
{
paddingHorizontal
:
30
,
paddingVertical
:
10
}]}
>
Today
<
/Text
>
{
this
.
renderActionCard
(
data
[
i
])}
<
/
>
);
day
=
data
[
i
].
time
*
1000
;
}
else
if
(
isSameDay
(
day
,
data
[
i
].
time
*
1000
))
{
view
.
push
(
this
.
renderActionCard
(
data
[
i
]));
day
=
data
[
i
].
time
*
1000
;
}
else
{
view
.
push
(
<>
<
Text
style
=
{[
theme
.
normalText
,
{
paddingHorizontal
:
30
,
paddingVertical
:
10
}]}
>
{
isYesterday
(
data
[
i
].
time
*
1000
)
?
'Yesterday'
:
format
(
data
[
i
].
time
*
1000
,
'DD/MM/YYYY'
)}
<
/Text
>
{
this
.
renderActionCard
(
data
[
i
])}
<
/
>
);
day
=
data
[
i
].
time
*
1000
;
}
}
return
view
;
}
render
()
{
const
TabStyle
=
{
textStyle
:
theme
.
description
,
...
...
@@ -68,15 +96,14 @@ export default class NotificationScreen extends React.Component {
activeTabStyle
:
{
backgroundColor
:
color
.
primary
,
borderRadius
:
100
,
margin
:
10
},
style
:
{
backgroundColor
:
color
.
defaultBg
},
};
const
today
=
new
Date
();
return
(
<
View
style
=
{
theme
.
container
}
>
<
Tabs
tabBarUnderlineStyle
=
{{
backgroundColor
:
'transparent'
}}
renderTabBar
=
{()
=>
<
ScrollableTab
style
=
{{
backgroundColor
:
color
.
defaultBg
,
borderWidth
:
0
}}
/>
}
>
{
[
'All'
,
'Notifications'
,
'Logging'
]
.
map
((
item
,
index
)
=>
(
<
Tab
heading
=
{
item
}
{...
TabStyle
}
>
{
tabHeader
.
map
((
item
,
index
)
=>
(
<
Tab
heading
=
{
item
.
label
}
{...
TabStyle
}
key
=
{
index
}
>
<
View
style
=
{{
padding
:
15
,
...
...
@@ -100,19 +127,8 @@ export default class NotificationScreen extends React.Component {
onPress
=
{()
=>
this
.
setState
({
isfilterVisible
:
true
})}
/
>
<
/View
>
{
/* filter date length */
}
<
ScrollView
>
{
/* >date */
}
<
View
>
<
Text
style
=
{[
theme
.
normalText
,
{
paddingHorizontal
:
30
,
paddingVertical
:
10
}]}
>
Today
{
/* Today/Yesterday/date.. */
}
<
/Text
>
{
/* >>log list */
}
<
FlatList
data
=
{
mockdata
}
renderItem
=
{({
item
,
index
})
=>
this
.
renderActivityCard
(
item
)}
/
>
<
/View
>
<
View
>
{
this
.
renderDayList
(
item
.
type
)}
<
/View
>
<
/ScrollView
>
<
/Tab
>
))}
...
...
@@ -145,4 +161,20 @@ const styles = StyleSheet.create({
fontSize
:
12
,
color
:
color
.
grey
,
},
actionContainer
:
{
paddingHorizontal
:
30
,
paddingVertical
:
10
,
alignItems
:
'flex-start'
,
backgroundColor
:
color
.
white
,
width
:
'100%'
,
},
thumbnail
:
{
width
:
16
,
height
:
16
,
marginRight
:
10
,
borderRadius
:
100
,
backgroundColor
:
color
.
primary
,
alignItems
:
'center'
,
justifyContent
:
'center'
,
},
});
screens/Private/NotificationScreen/notification.json
0 → 100644
View file @
f1b46072
[
{
"type"
:
"log"
,
"user"
:
"Sukanya161"
,
"time"
:
1566370057
,
"action"
:
"Switched on"
,
"device"
:
"sub breaker 4"
},
{
"type"
:
"log"
,
"user"
:
"Sukanya161"
,
"time"
:
1564639200
,
"action"
:
"Switched off"
,
"device"
:
"sub breaker 1"
},
{
"type"
:
"notification"
,
"user"
:
"Sukanya161"
,
"time"
:
1566370196
,
"action"
:
"Switched on"
,
"device"
:
"sub breaker 2"
},
{
"type"
:
"log"
,
"user"
:
"Sukanya161"
,
"time"
:
1566371305
,
"action"
:
"Switched on"
,
"device"
:
"sub breaker 1"
},
{
"type"
:
"log"
,
"user"
:
"Sukanya161"
,
"time"
:
1566374629
,
"action"
:
"Switched on"
,
"device"
:
"sub breaker 3"
},
{
"type"
:
"notification"
,
"user"
:
"Tonk"
,
"time"
:
1566317460
,
"action"
:
"leaved"
,
"device"
:
"office"
}
]
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