Added notifications. Closes #101
- Using react-notifications to manage redux state - Refactored Toast component to be stateless - Toasts can be stacked - Cleaned up CSS - Updated stories
This commit is contained in:
parent
863d90c8ee
commit
f3b448106d
@ -46,7 +46,6 @@
|
|||||||
"author": "Netlify",
|
"author": "Netlify",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@kadira/storybook": "^1.36.0",
|
|
||||||
"babel-core": "^6.5.1",
|
"babel-core": "^6.5.1",
|
||||||
"babel-jest": "^15.0.0",
|
"babel-jest": "^15.0.0",
|
||||||
"babel-loader": "^6.2.2",
|
"babel-loader": "^6.2.2",
|
||||||
@ -91,6 +90,7 @@
|
|||||||
"webpack-postcss-tools": "^1.1.1"
|
"webpack-postcss-tools": "^1.1.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@kadira/storybook": "^1.36.0",
|
||||||
"autoprefixer": "^6.3.3",
|
"autoprefixer": "^6.3.3",
|
||||||
"bricks.js": "^1.7.0",
|
"bricks.js": "^1.7.0",
|
||||||
"dateformat": "^1.0.12",
|
"dateformat": "^1.0.12",
|
||||||
@ -124,6 +124,7 @@
|
|||||||
"react-toolbox": "^1.2.1",
|
"react-toolbox": "^1.2.1",
|
||||||
"react-waypoint": "^3.1.3",
|
"react-waypoint": "^3.1.3",
|
||||||
"redux": "^3.3.1",
|
"redux": "^3.3.1",
|
||||||
|
"redux-notifications": "^2.1.1",
|
||||||
"redux-thunk": "^1.0.3",
|
"redux-thunk": "^1.0.3",
|
||||||
"selection-position": "^1.0.0",
|
"selection-position": "^1.0.0",
|
||||||
"semaphore": "^1.0.5",
|
"semaphore": "^1.0.5",
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
import { actions as notifActions } from 'redux-notifications';
|
||||||
import { currentBackend } from '../backends/backend';
|
import { currentBackend } from '../backends/backend';
|
||||||
import { getIntegrationProvider } from '../integrations';
|
import { getIntegrationProvider } from '../integrations';
|
||||||
import { getMedia, selectIntegration } from '../reducers';
|
import { getMedia, selectIntegration } from '../reducers';
|
||||||
|
|
||||||
|
const { notifSend } = notifActions;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Contant Declarations
|
* Contant Declarations
|
||||||
*/
|
*/
|
||||||
@ -190,7 +193,9 @@ export function loadEntry(entry, collection, slug) {
|
|||||||
|
|
||||||
export function loadEntries(collection, page = 0) {
|
export function loadEntries(collection, page = 0) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
if (collection.get('isFetching')) { return; }
|
if (collection.get('isFetching')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const integration = selectIntegration(state, collection.get('name'), 'listEntries');
|
const integration = selectIntegration(state, collection.get('name'), 'listEntries');
|
||||||
const provider = integration ? getIntegrationProvider(state.integrations, integration) : currentBackend(state.config);
|
const provider = integration ? getIntegrationProvider(state.integrations, integration) : currentBackend(state.config);
|
||||||
@ -218,10 +223,24 @@ export function persistEntry(collection, entryDraft) {
|
|||||||
const mediaProxies = entryDraft.get('mediaFiles').map(path => getMedia(state, path));
|
const mediaProxies = entryDraft.get('mediaFiles').map(path => getMedia(state, path));
|
||||||
const entry = entryDraft.get('entry');
|
const entry = entryDraft.get('entry');
|
||||||
dispatch(entryPersisting(collection, entry));
|
dispatch(entryPersisting(collection, entry));
|
||||||
backend.persistEntry(state.config, collection, entryDraft, mediaProxies.toJS()).then(
|
backend
|
||||||
() => dispatch(entryPersisted(collection, entry)),
|
.persistEntry(state.config, collection, entryDraft, mediaProxies.toJS())
|
||||||
error => dispatch(entryPersistFail(collection, entry, error))
|
.then(() => {
|
||||||
);
|
dispatch(notifSend({
|
||||||
|
message: 'Entry saved',
|
||||||
|
kind: 'success',
|
||||||
|
dismissAfter: 4000,
|
||||||
|
}));
|
||||||
|
dispatch(entryPersisted(collection, entry));
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
dispatch(notifSend({
|
||||||
|
message: 'Failed to persist entry',
|
||||||
|
kind: 'danger',
|
||||||
|
dismissAfter: 4000,
|
||||||
|
}));
|
||||||
|
dispatch(entryPersistFail(collection, entry, error));
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,10 +2,13 @@
|
|||||||
--defaultColor: #333;
|
--defaultColor: #333;
|
||||||
--defaultColorLight: #eee;
|
--defaultColorLight: #eee;
|
||||||
--backgroundColor: #fff;
|
--backgroundColor: #fff;
|
||||||
--shadowColor: rgba(0, 0, 0, 0.117647);
|
--shadowColor: rgba(0, 0, 0, .25);
|
||||||
|
--infoColor: #69c;
|
||||||
--successColor: #1c7;
|
--successColor: #1c7;
|
||||||
--warningColor: #fa0;
|
--warningColor: #fa0;
|
||||||
--errorColor: #f52;
|
--errorColor: #f52;
|
||||||
|
--borderRadius: 2px;
|
||||||
|
--topmostZindex: 99999;
|
||||||
}
|
}
|
||||||
|
|
||||||
.base {
|
.base {
|
||||||
@ -13,14 +16,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
color: var(--defaultColor);
|
|
||||||
background-color: var(--backgroundColor);
|
background-color: var(--backgroundColor);
|
||||||
|
color: var(--defaultColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
.rounded {
|
.rounded {
|
||||||
border-radius: 2px;
|
border-radius: var(--borderRadius);
|
||||||
}
|
}
|
||||||
|
|
||||||
.depth {
|
.depth {
|
||||||
box-shadow: var(--shadowColor) 0px 1px 6px, var(--shadowColor) 0px 1px 4px;
|
box-shadow: var(--shadowColor) 0 1px 6px;
|
||||||
}
|
}
|
||||||
|
@ -1,40 +1,41 @@
|
|||||||
@import "../theme.css";
|
@import '../theme.css';
|
||||||
|
|
||||||
.toast {
|
:root {
|
||||||
composes: base container rounded depth;
|
--iconSize: 30px;
|
||||||
position: absolute;
|
|
||||||
top: 10px;
|
|
||||||
right: 10px;
|
|
||||||
z-index: 100;
|
|
||||||
width: 350px;
|
|
||||||
padding: 20px 10px;
|
|
||||||
font-size: 0.9rem;
|
|
||||||
text-align: center;
|
|
||||||
color: var(--defaultColorLight);
|
|
||||||
overflow: hidden;
|
|
||||||
opacity: 1;
|
|
||||||
transition: opacity .3s ease-in;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.hidden {
|
.root {
|
||||||
opacity: 0;
|
composes: base container rounded depth from '../theme.css';
|
||||||
|
overflow: hidden;
|
||||||
|
margin: 10px;
|
||||||
|
padding: 10px 10px 15px;
|
||||||
|
color: var(--defaultColorLight);
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
position: absolute;
|
position: relative;
|
||||||
top: calc(50% - 15px);
|
top: .15em;
|
||||||
left: 15px;
|
margin-right: .25em;
|
||||||
font-size: 30px;
|
font-size: var(--iconSize);
|
||||||
|
line-height: var(--iconSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
.info {
|
||||||
|
composes: root;
|
||||||
|
background-color: var(--infoColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
.success {
|
.success {
|
||||||
|
composes: root;
|
||||||
background-color: var(--successColor);
|
background-color: var(--successColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
.warning {
|
.warning {
|
||||||
|
composes: root;
|
||||||
background-color: var(--warningColor);
|
background-color: var(--warningColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
.error {
|
.danger {
|
||||||
|
composes: root;
|
||||||
background-color: var(--errorColor);
|
background-color: var(--errorColor);
|
||||||
}
|
}
|
||||||
|
@ -2,69 +2,23 @@ import React, { PropTypes } from 'react';
|
|||||||
import { Icon } from '../index';
|
import { Icon } from '../index';
|
||||||
import styles from './Toast.css';
|
import styles from './Toast.css';
|
||||||
|
|
||||||
export default class Toast extends React.Component {
|
const icons = {
|
||||||
|
info: 'info',
|
||||||
state = {
|
|
||||||
shown: false
|
|
||||||
};
|
|
||||||
|
|
||||||
componentWillMount() {
|
|
||||||
if (this.props.show) {
|
|
||||||
this.autoHideTimeout();
|
|
||||||
this.setState({ shown: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
|
||||||
if (nextProps !== this.props) {
|
|
||||||
if (nextProps.show) this.autoHideTimeout();
|
|
||||||
this.setState({ shown: nextProps.show });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
if (this.timeOut) {
|
|
||||||
clearTimeout(this.timeOut);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
autoHideTimeout = () => {
|
|
||||||
clearTimeout(this.timeOut);
|
|
||||||
this.timeOut = setTimeout(() => {
|
|
||||||
this.setState({ shown: false });
|
|
||||||
}, 4000);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { style, type, className, children } = this.props;
|
|
||||||
const icons = {
|
|
||||||
success: 'check',
|
success: 'check',
|
||||||
warning: 'attention',
|
warning: 'attention',
|
||||||
error: 'alert'
|
danger: 'alert',
|
||||||
};
|
};
|
||||||
const classes = [styles.toast];
|
|
||||||
if (className) classes.push(className);
|
|
||||||
|
|
||||||
let icon = '';
|
|
||||||
if (type) {
|
|
||||||
classes.push(styles[type]);
|
|
||||||
icon = <Icon type={icons[type]} className={styles.icon} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.state.shown) {
|
|
||||||
classes.push(styles.hidden);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export default function Toast({ kind, message }) {
|
||||||
return (
|
return (
|
||||||
<div className={classes.join(' ')} style={style}>{icon}{children}</div>
|
<div className={styles[kind]}>
|
||||||
|
<Icon type={icons[kind]} className={styles.icon} />
|
||||||
|
{message}
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Toast.propTypes = {
|
Toast.propTypes = {
|
||||||
style: PropTypes.object,
|
kind: PropTypes.oneOf(['info', 'success', 'warning', 'danger']).isRequired,
|
||||||
type: PropTypes.oneOf(['success', 'warning', 'error']).isRequired,
|
message: PropTypes.string,
|
||||||
className: PropTypes.string,
|
|
||||||
show: PropTypes.bool,
|
|
||||||
children: PropTypes.node
|
|
||||||
};
|
};
|
||||||
|
@ -1,19 +1,41 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Toast } from '../UI';
|
|
||||||
import { storiesOf } from '@kadira/storybook';
|
import { storiesOf } from '@kadira/storybook';
|
||||||
|
import { Toast } from '../UI';
|
||||||
|
|
||||||
|
const containerStyle = {
|
||||||
|
position: 'fixed',
|
||||||
|
top: 0,
|
||||||
|
right: 0,
|
||||||
|
width: 360,
|
||||||
|
height: '100%',
|
||||||
|
};
|
||||||
|
|
||||||
storiesOf('Toast', module)
|
storiesOf('Toast', module)
|
||||||
|
.add('All kinds stacked', () => (
|
||||||
|
<div style={containerStyle}>
|
||||||
|
<Toast kind="info" message="A Toast Message" />
|
||||||
|
<Toast kind="success" message="A Toast Message" />
|
||||||
|
<Toast kind="warning" message="A Toast Message" />
|
||||||
|
<Toast kind="danger" message="A Toast Message" />
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
.add('Info', () => (
|
||||||
|
<div style={containerStyle}>
|
||||||
|
<Toast kind="info" message="A Toast Message" />
|
||||||
|
</div>
|
||||||
|
))
|
||||||
.add('Success', () => (
|
.add('Success', () => (
|
||||||
<div>
|
<div style={containerStyle}>
|
||||||
<Toast type='success' show>A Toast Message</Toast>
|
<Toast kind="success" message="A Toast Message" />
|
||||||
</div>
|
</div>
|
||||||
)).add('Waring', () => (
|
))
|
||||||
<div>
|
.add('Waring', () => (
|
||||||
<Toast type='warning' show>A Toast Message</Toast>
|
<div style={containerStyle}>
|
||||||
|
<Toast kind="warning" message="A Toast Message" />
|
||||||
</div>
|
</div>
|
||||||
)).add('Error', () => (
|
))
|
||||||
<div>
|
.add('Error', () => (
|
||||||
<Toast type='error' show>A Toast Message</Toast>
|
<div style={containerStyle}>
|
||||||
|
<Toast kind="danger" message="A Toast Message" />
|
||||||
</div>
|
</div>
|
||||||
));
|
));
|
||||||
|
@ -1,20 +1,30 @@
|
|||||||
|
@import '../components/UI/theme.css';
|
||||||
|
|
||||||
.layout .navDrawer .drawerContent {
|
.layout .navDrawer .drawerContent {
|
||||||
padding-top: 54px;
|
padding-top: 54px;
|
||||||
|
max-width: 240px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav {
|
.nav {
|
||||||
display: block;
|
display: block;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
|
|
||||||
& .heading {
|
& .heading {
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.main {
|
.main {
|
||||||
padding-top: 54px;
|
padding-top: 54px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navDrawer {
|
.notifsContainer {
|
||||||
max-width: 240px !important;
|
position: fixed;
|
||||||
& .drawerContent {
|
top: 60px;
|
||||||
max-width: 240px !important;
|
right: 0;
|
||||||
}
|
bottom: 60px;
|
||||||
|
z-index: var(--topmostZindex);
|
||||||
|
width: 360px;
|
||||||
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import { connect } from 'react-redux';
|
|||||||
import { Layout, Panel, NavDrawer } from 'react-toolbox/lib/layout';
|
import { Layout, Panel, NavDrawer } from 'react-toolbox/lib/layout';
|
||||||
import { Navigation } from 'react-toolbox/lib/navigation';
|
import { Navigation } from 'react-toolbox/lib/navigation';
|
||||||
import { Link } from 'react-toolbox/lib/link';
|
import { Link } from 'react-toolbox/lib/link';
|
||||||
|
import { Notifs } from 'redux-notifications';
|
||||||
import { loadConfig } from '../actions/config';
|
import { loadConfig } from '../actions/config';
|
||||||
import { loginUser } from '../actions/auth';
|
import { loginUser } from '../actions/auth';
|
||||||
import { currentBackend } from '../backends/backend';
|
import { currentBackend } from '../backends/backend';
|
||||||
@ -17,7 +18,7 @@ import {
|
|||||||
createNewEntryInCollection,
|
createNewEntryInCollection,
|
||||||
} from '../actions/findbar';
|
} from '../actions/findbar';
|
||||||
import AppHeader from '../components/AppHeader/AppHeader';
|
import AppHeader from '../components/AppHeader/AppHeader';
|
||||||
import { Loader } from '../components/UI/index';
|
import { Loader, Toast } from '../components/UI/index';
|
||||||
import styles from './App.css';
|
import styles from './App.css';
|
||||||
|
|
||||||
class App extends React.Component {
|
class App extends React.Component {
|
||||||
@ -147,6 +148,10 @@ class App extends React.Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout theme={styles}>
|
<Layout theme={styles}>
|
||||||
|
<Notifs
|
||||||
|
className={styles.notifsContainer}
|
||||||
|
CustomComponent={Toast}
|
||||||
|
/>
|
||||||
<NavDrawer
|
<NavDrawer
|
||||||
active={navDrawerIsVisible}
|
active={navDrawerIsVisible}
|
||||||
scrollY
|
scrollY
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import { combineReducers } from 'redux';
|
import { combineReducers } from 'redux';
|
||||||
import { routerReducer } from 'react-router-redux';
|
import { routerReducer } from 'react-router-redux';
|
||||||
|
import { reducer as notifReducer } from 'redux-notifications';
|
||||||
import reducers from '.';
|
import reducers from '.';
|
||||||
|
|
||||||
export default combineReducers({
|
export default combineReducers({
|
||||||
...reducers,
|
...reducers,
|
||||||
routing: routerReducer
|
notifs: notifReducer,
|
||||||
|
routing: routerReducer,
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user