Created
March 9, 2017 20:35
-
-
Save anonymous/a42e855b60477a2e48717a45d6687b85 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React, { Component } from 'react'; | |
class Notification extends Component { | |
render() { | |
var type = this.props.type == null ? 'default' : this.props.type; | |
return <div className={"notification " + type}>{this.props.message}{this.props.cancellable == 1 && <i className="material-icons"></i>}</div>; | |
} | |
} | |
export default Notification; |
This file contains hidden or 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
import React, { Component } from 'react'; | |
import Notification from './Notification'; | |
class NotificationList extends Component { | |
render() { | |
var notifications = this.props.notifications.map(function(notification){ | |
return (<Notification | |
key={notification.ID} | |
message={notification.Message} | |
type={notification.Type} | |
cancellable={notification.Cancellable} | |
endDate={notification.EndDate} | |
/>); | |
}); | |
return ( | |
<div className="notifications"> | |
<div className="subtitle">Notifications</div> | |
<div className="content"> | |
{notifications} | |
</div> | |
</div> | |
) | |
} | |
} | |
export default NotificationList; |
This file contains hidden or 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
import React, { Component } from 'react'; | |
import NotificationList from './NotificationList'; | |
class NotificationListContainer extends Component { | |
constructor() { | |
super(); | |
this.state = { data: [] } | |
} | |
componentDidMount() { | |
// This is for testing purposes, in my actual code it fetches the API endpoint. | |
this.setState({data: [ | |
{ | |
"ID": 1, | |
"Message": "Make sure to eat your vegetables", | |
"Type": null, | |
"Cancellable": 0, | |
"StartDate": "", | |
"EndDate": "" | |
}, | |
{ | |
"ID": 2, | |
"Message": "Do not use gasoline as carpet cleaner", | |
"Type": null, | |
"Cancellable": 1, | |
"StartDate": "", | |
"EndDate": "" | |
} | |
]}) | |
} | |
render() { | |
return ( | |
<NotificationList notifications={this.state.data} /> | |
) | |
} | |
} | |
export default NotificationListContainer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment