mirror of
https://github.com/ascribe/onion.git
synced 2025-02-14 21:10:27 +01:00
add debug component for globalnotifications
This commit is contained in:
parent
c945fc315b
commit
16dfe3f224
@ -7,18 +7,33 @@ import GlobalNotificationStore from '../stores/global_notification_store';
|
|||||||
import Row from 'react-bootstrap/lib/Row';
|
import Row from 'react-bootstrap/lib/Row';
|
||||||
import Col from 'react-bootstrap/lib/Col';
|
import Col from 'react-bootstrap/lib/Col';
|
||||||
|
|
||||||
|
import { mergeOptions } from '../utils/general_utils';
|
||||||
|
|
||||||
let GlobalNotification = React.createClass({
|
let GlobalNotification = React.createClass({
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
GlobalNotificationStore.listen(this.onChange);
|
GlobalNotificationStore.listen(this.onChange);
|
||||||
|
|
||||||
|
// init container width
|
||||||
|
this.handleContainerResize();
|
||||||
|
|
||||||
|
// we're using an event listener on window here,
|
||||||
|
// as it was not possible to listen to the resize events of a dom node
|
||||||
|
window.addEventListener('resize', this.handleContainerResize);
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
GlobalNotificationStore.unlisten(this.onChange);
|
GlobalNotificationStore.unlisten(this.onChange);
|
||||||
|
window.removeEventListener('resize', this.handleContainerResize);
|
||||||
},
|
},
|
||||||
|
|
||||||
getInititalState() {
|
getInititalState() {
|
||||||
return this.extractFirstElem(GlobalNotificationStore.getState().notificationQue);
|
return mergeOptions(
|
||||||
|
this.extractFirstElem(GlobalNotificationStore.getState().notificationQue),
|
||||||
|
{
|
||||||
|
containerWidth: 0
|
||||||
|
}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
extractFirstElem(l) {
|
extractFirstElem(l) {
|
||||||
@ -35,7 +50,14 @@ let GlobalNotification = React.createClass({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleContainerResize() {
|
||||||
|
this.setState({
|
||||||
|
containerWidth: this.refs.containerWrapper.getDOMNode().offsetWidth
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
console.log(this.state);
|
||||||
let notificationClass = 'ascribe-global-notification ';
|
let notificationClass = 'ascribe-global-notification ';
|
||||||
let message = this.state && this.state.message ? this.state.message : null;
|
let message = this.state && this.state.message ? this.state.message : null;
|
||||||
|
|
||||||
|
@ -19,11 +19,12 @@ import MenuItem from 'react-bootstrap/lib/MenuItem';
|
|||||||
import MenuItemLink from 'react-router-bootstrap/lib/MenuItemLink';
|
import MenuItemLink from 'react-router-bootstrap/lib/MenuItemLink';
|
||||||
import NavItemLink from 'react-router-bootstrap/lib/NavItemLink';
|
import NavItemLink from 'react-router-bootstrap/lib/NavItemLink';
|
||||||
|
|
||||||
|
import HeaderNotificationDebug from './header_notification_debug';
|
||||||
|
|
||||||
|
|
||||||
import { mergeOptions } from '../utils/general_utils';
|
import { mergeOptions } from '../utils/general_utils';
|
||||||
import { getLangText } from '../utils/lang_utils';
|
import { getLangText } from '../utils/lang_utils';
|
||||||
|
|
||||||
let Link = Router.Link;
|
|
||||||
|
|
||||||
let Header = React.createClass({
|
let Header = React.createClass({
|
||||||
mixins: [Router.Navigation],
|
mixins: [Router.Navigation],
|
||||||
@ -43,11 +44,13 @@ let Header = React.createClass({
|
|||||||
UserStore.unlisten(this.onChange);
|
UserStore.unlisten(this.onChange);
|
||||||
WhitelabelStore.unlisten(this.onChange);
|
WhitelabelStore.unlisten(this.onChange);
|
||||||
},
|
},
|
||||||
|
|
||||||
handleLogout(){
|
handleLogout(){
|
||||||
UserActions.logoutCurrentUser();
|
UserActions.logoutCurrentUser();
|
||||||
Alt.flush();
|
Alt.flush();
|
||||||
this.transitionTo('login');
|
this.transitionTo('login');
|
||||||
},
|
},
|
||||||
|
|
||||||
getLogo(){
|
getLogo(){
|
||||||
let logo = (
|
let logo = (
|
||||||
<span>
|
<span>
|
||||||
@ -110,6 +113,7 @@ let Header = React.createClass({
|
|||||||
<Nav navbar left>
|
<Nav navbar left>
|
||||||
</Nav>
|
</Nav>
|
||||||
<Nav navbar right>
|
<Nav navbar right>
|
||||||
|
<HeaderNotificationDebug />
|
||||||
{addNewWork}
|
{addNewWork}
|
||||||
{collection}
|
{collection}
|
||||||
{account}
|
{account}
|
||||||
|
29
js/components/header_notification_debug.js
Normal file
29
js/components/header_notification_debug.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import GlobalNotificationModel from '../models/global_notification_model';
|
||||||
|
import GlobalNotificationActions from '../actions/global_notification_actions';
|
||||||
|
|
||||||
|
import MenuItem from 'react-bootstrap/lib/MenuItem';
|
||||||
|
|
||||||
|
/*
|
||||||
|
This components purpose is to be inserted into the page's navigation in order
|
||||||
|
debug the globalnotificationsaction easily
|
||||||
|
|
||||||
|
*/
|
||||||
|
let HeaderNotificationDebug = React.createClass({
|
||||||
|
|
||||||
|
triggerNotification() {
|
||||||
|
let notification = new GlobalNotificationModel('this is a test, please ignore', 'success');
|
||||||
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<MenuItem onClick={this.triggerNotification}>Notification</MenuItem>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default HeaderNotificationDebug;
|
Loading…
x
Reference in New Issue
Block a user