mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
add desktop version for notifications
This commit is contained in:
parent
5e14ea6f87
commit
59f131f788
@ -38,17 +38,27 @@ let GlobalNotification = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
extractFirstElem(l) {
|
extractFirstElem(l) {
|
||||||
return l.length > 0 ? l[0] : {message: ''};
|
if(l.length > 0) {
|
||||||
|
return {
|
||||||
|
show: true,
|
||||||
|
message: l[0]
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
show: false,
|
||||||
|
message: ''
|
||||||
|
};
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onChange(state) {
|
onChange(state) {
|
||||||
let notification = this.extractFirstElem(state.notificationQue);
|
let notification = this.extractFirstElem(state.notificationQue);
|
||||||
|
|
||||||
if(notification) {
|
if(notification.show) {
|
||||||
this.setState(notification);
|
this.setState(notification);
|
||||||
} else {
|
} else {
|
||||||
this.replaceState({
|
this.setState({
|
||||||
message: ''
|
show: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -62,39 +72,44 @@ let GlobalNotification = React.createClass({
|
|||||||
render() {
|
render() {
|
||||||
let notificationClass = 'ascribe-global-notification';
|
let notificationClass = 'ascribe-global-notification';
|
||||||
let textClass;
|
let textClass;
|
||||||
let message = this.state && this.state.message ? this.state.message : null;
|
|
||||||
|
|
||||||
if(message) {
|
if(this.state.containerWidth > 768) {
|
||||||
|
notificationClass = 'ascribe-global-notification-bubble';
|
||||||
|
|
||||||
|
if(this.state.show) {
|
||||||
|
notificationClass += ' ascribe-global-notification-bubble-on';
|
||||||
|
} else {
|
||||||
|
notificationClass += ' ascribe-global-notification-bubble-off';
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
notificationClass = 'ascribe-global-notification';
|
||||||
|
|
||||||
|
if(this.state.show) {
|
||||||
notificationClass += ' ascribe-global-notification-on';
|
notificationClass += ' ascribe-global-notification-on';
|
||||||
} else {
|
} else {
|
||||||
notificationClass += ' ascribe-global-notification-off';
|
notificationClass += ' ascribe-global-notification-off';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.state) {
|
}
|
||||||
switch(this.state.type) {
|
|
||||||
case 'warning':
|
switch(this.state.message.type) {
|
||||||
textClass = 'ascribe-global-notification-warning';
|
|
||||||
break;
|
|
||||||
case 'success':
|
case 'success':
|
||||||
textClass = 'ascribe-global-notification-success';
|
textClass = 'ascribe-global-notification-success';
|
||||||
break;
|
break;
|
||||||
case 'info':
|
|
||||||
textClass = 'ascribe-global-notification-info';
|
|
||||||
break;
|
|
||||||
case 'danger':
|
case 'danger':
|
||||||
textClass = 'ascribe-global-notification-danger';
|
textClass = 'ascribe-global-notification-danger';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.warn('Could not find a matching type in global_notification.js');
|
console.warn('Could not find a matching type in global_notification.js');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref="notificationWrapper">
|
<div ref="notificationWrapper">
|
||||||
<Row>
|
<Row>
|
||||||
<Col>
|
<Col>
|
||||||
<div className={notificationClass}>
|
<div className={notificationClass}>
|
||||||
<div className={textClass}>{message ? message : null}</div>
|
<div className={textClass}>{this.state.message.message}</div>
|
||||||
</div>
|
</div>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
@ -113,7 +113,7 @@ let Header = React.createClass({
|
|||||||
<Nav navbar left>
|
<Nav navbar left>
|
||||||
</Nav>
|
</Nav>
|
||||||
<Nav navbar right>
|
<Nav navbar right>
|
||||||
<HeaderNotificationDebug />
|
<HeaderNotificationDebug show={false}/>
|
||||||
{addNewWork}
|
{addNewWork}
|
||||||
{collection}
|
{collection}
|
||||||
{account}
|
{account}
|
||||||
|
@ -14,15 +14,37 @@ import MenuItem from 'react-bootstrap/lib/MenuItem';
|
|||||||
*/
|
*/
|
||||||
let HeaderNotificationDebug = React.createClass({
|
let HeaderNotificationDebug = React.createClass({
|
||||||
|
|
||||||
|
propTypes: {
|
||||||
|
show: React.PropTypes.bool
|
||||||
|
},
|
||||||
|
|
||||||
|
getInitialState() {
|
||||||
|
return {
|
||||||
|
index: 0
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
triggerNotification() {
|
triggerNotification() {
|
||||||
let notification = new GlobalNotificationModel('this is a test, please ignore', 'success');
|
if(this.state.index === 1) {
|
||||||
|
this.setState({index: 0});
|
||||||
|
} else {
|
||||||
|
this.setState({index: this.state.index + 1});
|
||||||
|
}
|
||||||
|
|
||||||
|
let actions = ['success', 'danger'];
|
||||||
|
|
||||||
|
let notification = new GlobalNotificationModel('this is a test, please ignore', actions[this.state.index]);
|
||||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
if(this.props.show) {
|
||||||
return (
|
return (
|
||||||
<MenuItem onClick={this.triggerNotification}>Notification</MenuItem>
|
<MenuItem onClick={this.triggerNotification}>Notification</MenuItem>
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
position: fixed;
|
position: fixed;
|
||||||
|
|
||||||
background-color: #212121;
|
background-color: #212121;
|
||||||
|
color: white;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height:3.5em;
|
height:3.5em;
|
||||||
left:0;
|
left:0;
|
||||||
@ -18,7 +19,7 @@
|
|||||||
bottom: 0;
|
bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ascribe-global-notification > div {
|
.ascribe-global-notification > div, .ascribe-global-notification-bubble > div {
|
||||||
display:table-cell;
|
display:table-cell;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
font-size: 1.25em;
|
font-size: 1.25em;
|
||||||
@ -27,18 +28,39 @@
|
|||||||
padding-right: 3em;
|
padding-right: 3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ascribe-global-notification-warning {
|
.ascribe-global-notification-bubble > div {
|
||||||
color: #f0ad4e;
|
padding: .75em 1.5em .75em 1.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ascribe-global-notification-bubble {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 3em;
|
||||||
|
right: -50em;
|
||||||
|
|
||||||
|
display:table;
|
||||||
|
|
||||||
|
height: 3.5em;
|
||||||
|
|
||||||
|
background-color: #212121;
|
||||||
|
border-radius: 2px;
|
||||||
|
|
||||||
|
color: white;
|
||||||
|
|
||||||
|
transition: 1s right ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ascribe-global-notification-bubble-off {
|
||||||
|
right: -50em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ascribe-global-notification-bubble-on {
|
||||||
|
right: 3.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ascribe-global-notification-danger {
|
.ascribe-global-notification-danger {
|
||||||
color: #d9534f;
|
background-color: #d9534f;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ascribe-global-notification-success {
|
.ascribe-global-notification-success {
|
||||||
color: #5cb85c;
|
background-color: rgba(2, 182, 163, 1);
|
||||||
}
|
|
||||||
|
|
||||||
.ascribe-global-notification-info {
|
|
||||||
color: rgba(2, 182, 163, 1);
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user