Skip to content

Instantly share code, notes, and snippets.

Created March 9, 2017 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/a42e855b60477a2e48717a45d6687b85 to your computer and use it in GitHub Desktop.
Save anonymous/a42e855b60477a2e48717a45d6687b85 to your computer and use it in GitHub Desktop.
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">&#xE5CD;</i>}</div>;
}
}
export default Notification;
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;
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