Giter Site home page Giter Site logo

react-notification-system-redux's Introduction

build status version downloads license

react-notification-system-redux

Wraps react-notification-system into a component and exposes actions and reducer.

Open for PR's and contributions!

Use versions below v2.0.0 for react versions lower than 16.

Demo & Examples

Live demo: gor181.github.io/react-notification-system-redux

To build the examples locally, run:

npm install
npm start

Then open localhost:8000 in a browser.

Installation via NPM

npm install react-notification-system-redux react-notification-system --save

Usage

Import the reducer and pass it to your store:

import {createStore, combineReducers} from 'redux';

import {reducer as notifications} from 'react-notification-system-redux';

export function configureStore(initialState = {}) {
  return createStore(
    combineReducers({
      notifications
    }),
    initialState
  );
}

Include the Notifications component and pass the data from the reducer by using connect:

import React, {PropTypes} from 'react';
import {connect} from 'react-redux';
import ReactDOM from 'react-dom';

import Notifications from 'react-notification-system-redux';

class DemoComponent extends React.Component {

  render() {
    const {notifications} = this.props;

    //Optional styling
    const style = {
      NotificationItem: { // Override the notification item
        DefaultStyle: { // Applied to every notification, regardless of the notification level
          margin: '10px 5px 2px 1px'
        },

        success: { // Applied only to the success notification item
          color: 'red'
        }
      }
    };

    return (
      <Notifications
        notifications={notifications}
        style={style}
      />
    );
  }
}

DemoComponent.contextTypes = {
  store: PropTypes.object
};

DemoComponent.propTypes = {
  notifications: PropTypes.array
};

export default connect(
  state => ({ notifications: state.notifications })
)(DemoComponent);

Dispatch notification actions from any other component:

import React, {PropTypes} from 'react';
import ReactDOM from 'react-dom';

import Notifications, { success } from 'react-notification-system-redux';

const notificationOpts = {
  // uid: 'once-please', // you can specify your own uid if required
  title: 'Hey, it\'s good to see you!',
  message: 'Now you can see how easy it is to use notifications in React!',
  position: 'tr',
  autoDismiss: 0,
  action: {
    label: 'Click me!!',
    callback: () => alert('clicked!')
  }
};

class OtherComponent extends React.Component {

  constructor() {
    super();

    this.handleClick = this.handleClick.bind(this);
  }

  handleClick() {
    this.context.store.dispatch(
      success(notificationOpts)
    );
  }

  render() {
    return (
      <div>
        <button onClick={this.handleClick}>
          Spawn some notifications!!!
        </button>
      </div>
    );
  }
}

OtherComponent.contextTypes = {
  store: PropTypes.object
};

export default OtherComponent;

There is a working example in example/src/**

Properties

It accepts all properties as react-notification-system does, actually it pipes them in the react-notification-system.

Actions

import Notifications from 'react-notification-system-redux';

dispatch(Notifications.show(notification, level));
dispatch(Notifications.success(notification));
dispatch(Notifications.error(notification));
dispatch(Notifications.warning(notification));
dispatch(Notifications.info(notification));
dispatch(Notifications.hide(uid)); // Hides notification based on uid
dispatch(Notifications.removeAll()); // Removes all notifications

// OR //

import { show, success, error, warning, info, hide, removeAll } from 'react-notification-system-redux';

dispatch(show(notification, level));
dispatch(success(notification));
dispatch(error(notification));
dispatch(warning(notification));
dispatch(info(notification));
dispatch(hide(uid)); // Hides notification based on uid
dispatch(removeAll()); // Removes all notifications

Development (src, lib and the build process)

NOTE: The source code for the component is in src. A transpiled CommonJS version (generated with Babel) is available in lib for use with node.js, browserify and webpack. A UMD bundle is also built to dist, which can be included without the need for any build system.

To build, watch and serve the examples (which will also watch the component source), run npm start. If you just want to watch changes to src and rebuild lib, run npm run watch (this is useful if you are working with npm link).

Thanks

Jed Watson for making react-component yo builder!

License

MIT Licensed
Copyright (c) 2016 Goran Udosic

react-notification-system-redux's People

Contributors

dependabot[bot] avatar dpuscher avatar eliyahut123 avatar epotockiy avatar fidelisclayton avatar fkretzer avatar gor181 avatar ikonrad avatar jochenberger avatar michelebertoli avatar oskku avatar saibamen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-notification-system-redux's Issues

Can I pass multiple error notification when dispatching?

Hey,
I am passing notification in my dispatchNotification method. So, I wanna pass multiple error and show a bunch of notification. How can I pass "message" like an array?

dispatchNotification(status, message) {
const notificationOpts = {
message,
position: 'tc'
};
if (status === 'success') {
this.props.success(notificationOpts);
}
if (status === 'error') {
this.props.error(notificationOpts);
}
}

How to hide all notifications?

I used ur system and it's so great. I've read ur source code and i saw function hide but i don't know how to hide all notification. Can you help me please? Thanks

Example for props

Thanks for this wrapper, it's very useful. Is it possible for you to update the Readme file with examples with use of props like style and others?

I tryed something like
<Notifications notifications={ this.props.notifications} style={false} noAnimation={true}/>
but it's not working.

Tests

  • Write tests for actions and reducers

notifications state not clearing with autoDismiss

Hi -

I have a situation where i call a Notifications.success() and the notifications state in redux (using autoDismiss) does not auto remove. This causes a double notification to show up when the next notification is triggered.

It doesnt happen every time but every so often i see this case. autoDismiss is set to 5 and the next event happens well after 5 seconds.

Any ideas ?

[suggestions] improve docs and info

Hi, what do you think about improve the docs. I recently have issue when DemoComponent which is showed up in the docs didn't use properly.

It should be imported at the top level component in the application, so when the user dispatch the action as suggested at the next step of the docs, it will show the DemoComponent.

The docs should also info that the notifications props cannot be renamed, otherwise it will turn error.

Error when passing a function as argument

Following you example and getting an error when trying to pass a function as an argument to the dispatch call.

Your Example:

    setTimeout(() => {
      this.context.store.dispatch(fn(notificationOpts));
    }, timeout);
  }

  handleClick() {
    this.dispatchNotification(success, 250);
    this.dispatchNotification(error, 500);
    this.dispatchNotification(warning, 750);
    this.dispatchNotification(info, 1000);
  }

When I try this on my machine I get an error saying:
Uncaught TypeError: _reactNotificationSystemRedux2.default.fn is not a function

Below is my code:

import Notifications, { success, error, warning, info, removeAll } from 'react-notification-system-redux';

export const notifyErrorAction = (fn, notification) => dispatch => {
  dispatch(Notifications.fn({
      title: notification.title,
      message: notification.message,
      position: 'tr',
      autoDismiss: 5000,
    })
  )
}

const notification = {
  title: 'Error',
  message: 'There is an error'
}

this.props.notifyError(error, notification)

The this.props.notifyError() is being called and does pass the error() to notifyErrorAction(). When I log out fn in the notifyErrorAction() I get:

ฦ’ error(opts) {
  return show(opts, 'error');
} 

I'm not sure if there is a step I'm missing. The only difference I can see is that you called dispatchNotification with a timeout. Was this just for effect or does the timing matter?

fbjs@^0.8.9

"react-notification-system#create-react-class#fbjs@^0.8.9" could be deduped from "0.8.16" to "react-notification-system#[email protected]"

Uncaught TypeError: Cannot read property 'dispatch' of undefined

So. I create a notification using createNotification("error"), it is displayed, then when the notification should be deleted I receive this

image

This is my configuration:

{ 
"dependencies": {
    "@sentry/browser": "^4.5.3",
    "babel-core": "^6.26.3",
    "babel-eslint": "^10.0.1",
    "babel-jest": "^23.6.0",
    "babel-loader": "^8.0.4",
    "babel-plugin-add-module-exports": "^1.0.0",
    "babel-plugin-flow-react-proptypes": "^24.1.2",
    "babel-plugin-react-html-attrs": "^2.1.0",
    "babel-plugin-syntax-flow": "^6.18.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-decorators-legacy": "^1.3.5",
    "babel-plugin-transform-flow-strip-types": "^6.22.0",
    "babel-plugin-transform-react-constant-elements": "^6.23.0",
    "babel-plugin-transform-react-inline-elements": "^6.22.0",
    "babel-plugin-transform-react-remove-prop-types": "^0.4.20",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "big.js": "^5.2.2",
    "bootstrap": "^4.1.3",
    "classnames": "^2.2.6",
    "copy": "^0.3.2",
    "cross-env": "^5.2.0",
    "css-loader": "^1.0.1",
    "dezalgo": "^1.0.3",
    "es3ify": "^0.2.2",
    "eslint": "^5.9.0",
    "eslint-plugin-flowtype": "^3.2.0",
    "eslint-plugin-jsx-a11y": "^6.1.2",
    "eslint-plugin-react": "^7.11.1",
    "file-loader": "^2.0.0",
    "flow-bin": "^0.86.0",
    "flow-status-webpack-plugin": "^0.1.7",
    "font-awesome": "^4.7.0",
    "fs": "0.0.1-security",
    "glob": "^7.1.3",
    "history": "^4.7.2",
    "humps": "^2.0.1",
    "immutable": "^4.0.0-rc.12",
    "jest": "^23.6.0",
    "jest-immutable-matchers": "^2.0.1",
    "json-loader": "^0.5.7",
    "lodash.memoize": "^4.1.2",
    "moment": "^2.22.2",
    "node-sass": "^4.10.0",
    "normalizr": "^3.3.0",
    "npm": "^6.4.1",
    "postcss-loader": "^3.0.0",
    "query-string": "^6.2.0",
    "react": "^16.6.3",
    "react-addons-shallow-compare": "^15.6.2",
    "react-autosuggest": "^9.4.2",
    "react-dom": "^16.6.3",
    "react-dropzone": "^7.0.1",
    "react-hot-loader": "^4.3.12",
    "react-loadable": "^5.5.0",
    "react-notification-system-redux": "^1.2.0",
    "react-raphael": "^0.9.0",
    "react-redux": "^6.0.1",
    "react-router": "^4.3.1",
    "react-router-dom": "^4.3.1",
    "react-router-redux": "^5.0.0-alpha.9",
    "react-select": "^2.3.0",
    "react-sidebar": "^3.0.2",
    "reactstrap": "^6.5.0",
    "redux": "^4.0.1",
    "redux-form": "^8.1.0",
    "redux-immutable": "^4.0.0",
    "redux-injector": "^0.1.0",
    "redux-promise-middleware": "^5.1.1",
    "redux-saga": "^0.16.2",
    "redux-thunk": "^2.3.0",
    "redux-ui": "0.1.1",
    "reselect": "^4.0.0",
    "sass-loader": "^7.1.0",
    "scss-compile": "^0.1.7",
    "style-loader": "^0.23.1",
    "superagent": "^4.0.0",
    "superagent-promise": "^1.1.0",
    "url-loader": "^1.1.2",
    "webpack": "^4.26.0",
    "webpack-cli": "^3.1.2",
    "webpack-git-hash": "^1.0.2",
    "webpack-preset": "^0.2.0",
    "webpack-preset-babel": "^0.2.0",
    "webpack-preset-babel-stage-2": "^0.2.0"
  }
}

Cannot clear notification

Hi. Is it possible to clear all notifications?
In react-notification-system-redux there is function clearNotifications, could not find similar here.

Callback `onRemove` not being called

According to #10 onRemove should be called and when I check the code pulled from npm it is as described. Unfortunately the callback is never fired in case the notification is auto or manually dismissed.

Code to reproduce:

const id = "someID"

function onDismiss () {
        store.dispatch(hide(id))
    }

const notification = {
        children    : (<Notification id={ uid } onDismiss={ onDismiss } level={ "info" } message={ message } title={ title }  />), /* custom body component */
        dismissible : false,
        level       : "info",
        uid,
        autoDismiss : 5,
        onRemove    : () => console.log("callback") /* this is never fired */
    }

store.dispatch(show(notification))

This only happens when notifications container is rendered with style={ false } property.

Can I re-render a notification?

I LOVE this library, very elegant. I want to use it beyond it's intended purpose as well, to display some bulk edit elements as I select them from a list. Is there a way to re-render the message prop so as I add elements, the message bosy updates? I'm trying something like this:

toggleRowsWithBulkEdit(item) {
  const rowsWithBulkEdit = toggleBulkEditItem(this.state.rowsWithBulkEdit, item)

  this.setState({rowsWithBulkEdit})

  const makeMessage = bulkEditProps => {
    console.log(bulkEditProps)
    return (
      <BulkEdit {...bulkEditProps}/>
    )
  }

  this.props.showNotification({
    title: 'hi',
    message: makeMessage({
      rowsWithBulkEdit,
    }),
    autoDismiss: 0,
    position: 'br',
    uid: 'bulkEditing',
  }, 'info')
}

and the console.log inside makeMessage is displaying the proper list, but obviously if I console log inside the BulkEdit component, it remains at 1.

Document possible functions

Document possible functions for using this plugin

`
Notifications.show(opts = {}, level = 'success')

Notifications.success(opts)

Notifications.error(opts)

Notifications.warning(opts)

Notifications.info(opts)

Notifications.hide(uid)
`

Had to dig into the source to understand how to send other types of notifications since .show is not in the example

Notification not displayed after route change

I'm currently investigating issue related to notification not being displayed after route change. Following scenario describes the case:

  1. I have separate route which presents form for adding new entity
  2. When I click "Save" button AJAX request is dispatched and on success of that request I dispatch new notification and immediately change route using history.push('/some-url')

Following pseudo-code presents that:

function onSuccess(data){
   dispatch(Notifications.success( .... ));
   history.push('/some-url');
}
  1. After route is changed notification is not displayed however notification is still inside Redux store. Also no RNS_HIDE_NOTIFICATION is fired.
  2. When I invoke an action which displays another notification but does not change the route "old" notifications are displayed too what looks like queuing up of notifications.. All notifications disappear after expected time.

Here's list of dependencies:

    "axios": "^0.16.2",
    "common-tags": "^1.4.0",
    "immutability-helper": "^2.3.0",
    "jwt-decode": "^2.2.0",
    "prop-types": "^15.5.10",
    "query-string": "^5.0.0",
    "react": "^15.5.4",
    "react-autosize-textarea": "^0.4.8",
    "react-bootstrap": "^0.31.0",
    "react-bootstrap-typeahead": "^2.0.0-alpha.1",
    "react-collapsible": "^1.5.0",
    "react-cookies": "0.0.1",
    "react-dom": "^15.5.4",
    "react-html-id": "^0.1.1",
    "react-notification-system": "^0.2.14",
    "react-notification-system-redux": "^1.1.4",
    "react-numeric-input": "^2.0.7",
    "react-redux": "^5.0.5",
    "react-router-bootstrap": "^0.24.2",
    "react-router-dom": "^4.1.1",
    "redux": "^3.6.0",
    "redux-form": "^6.7.0",
    "redux-thunk": "^2.2.0"

I'm relatively new to React and Redux and I'm trying to build minimal app which reproduces that issue but maybe you could figure out faster what's going on.

react-notification-system as a peer dependency

Currently, your installation instructions says to install both react-notification-system and react-notification-system-redux. However, you included react-notification-system as a dependency in your package.json as well. Is there a reason for that?

shouldn't it be moved to peerDependencies section instead?

React v16 not working with this plugin

Using this plugin while also using react@^16.0.0 causes the following error in the browser:

invariant.js:42 Uncaught Error: Element ref was specified as a string (notify) but no owner was set. You may have multiple copies of React loaded. (details: https://fb.me/react-refs-must-have-owner).
    at invariant (invariant.js:42)
    at coerceRef (react-dom.development.js:8579)
    at reconcileSingleElement (react-dom.development.js:9379)
    at reconcileChildFibers (react-dom.development.js:9477)
    at reconcileChildrenAtPriority (react-dom.development.js:10127)
    at reconcileChildren (react-dom.development.js:10118)
    at finishClassComponent (react-dom.development.js:10254)
    at updateClassComponent (react-dom.development.js:10226)
    at beginWork (react-dom.development.js:10605)
    at performUnitOfWork (react-dom.development.js:12573)
invariant @ invariant.js:42
coerceRef @ react-dom.development.js:8579
reconcileSingleElement @ react-dom.development.js:9379
reconcileChildFibers @ react-dom.development.js:9477
reconcileChildrenAtPriority @ react-dom.development.js:10127
reconcileChildren @ react-dom.development.js:10118
finishClassComponent @ react-dom.development.js:10254
updateClassComponent @ react-dom.development.js:10226
beginWork @ react-dom.development.js:10605
performUnitOfWork @ react-dom.development.js:12573
workLoop @ react-dom.development.js:12682
callCallback @ react-dom.development.js:1299
invokeGuardedCallbackDev @ react-dom.development.js:1338
invokeGuardedCallback @ react-dom.development.js:1195
performWork @ react-dom.development.js:12800
scheduleUpdateImpl @ react-dom.development.js:13185
scheduleUpdate @ react-dom.development.js:13124
enqueueSetState @ react-dom.development.js:9646
ReactComponent.setState @ react.development.js:218
(anonymous) @ Router.js:103
(anonymous) @ createTransitionManager.js:228
(anonymous) @ createTransitionManager.js:83
done @ AsyncUtils.js:74
(anonymous) @ AsyncUtils.js:80
(anonymous) @ authRoutes.js:17
Promise resolved (async)
getComponent @ authRoutes.js:15
getComponentsForRoute @ getComponents.js:12
(anonymous) @ getComponents.js:30
(anonymous) @ AsyncUtils.js:79
mapAsync @ AsyncUtils.js:78
getComponents @ getComponents.js:29
finishEnterHooks @ createTransitionManager.js:77
next @ AsyncUtils.js:47
loopAsync @ AsyncUtils.js:51
runTransitionHooks @ TransitionUtils.js:83
runEnterHooks @ TransitionUtils.js:107
(anonymous) @ createTransitionManager.js:70
runTransitionHooks @ TransitionUtils.js:74
runChangeHooks @ TransitionUtils.js:131
finishMatch @ createTransitionManager.js:67
(anonymous) @ createTransitionManager.js:45
done @ AsyncUtils.js:16
(anonymous) @ matchRoutes.js:234
(anonymous) @ matchRoutes.js:185
next @ AsyncUtils.js:41
loopAsync @ AsyncUtils.js:51
matchRoutes @ matchRoutes.js:231
onChildRoutes @ matchRoutes.js:179
(anonymous) @ matchRoutes.js:32
(anonymous) @ rootRoute.js:12
Promise resolved (async)
getChildRoutes @ rootRoute.js:11
getChildRoutes @ matchRoutes.js:25
matchRouteDeep @ matchRoutes.js:195
(anonymous) @ matchRoutes.js:232
next @ AsyncUtils.js:34
loopAsync @ AsyncUtils.js:51
matchRoutes @ matchRoutes.js:231
match @ createTransitionManager.js:41
historyListener @ createTransitionManager.js:222
listen @ createTransitionManager.js:246
Router_componentWillMount @ Router.js:96
callComponentWillMount @ react-dom.development.js:9777
mountClassInstance @ react-dom.development.js:9834
updateClassComponent @ react-dom.development.js:10216
beginWork @ react-dom.development.js:10605
performUnitOfWork @ react-dom.development.js:12573
workLoop @ react-dom.development.js:12682
callCallback @ react-dom.development.js:1299
invokeGuardedCallbackDev @ react-dom.development.js:1338
invokeGuardedCallback @ react-dom.development.js:1195
performWork @ react-dom.development.js:12800
scheduleUpdateImpl @ react-dom.development.js:13185
scheduleUpdate @ react-dom.development.js:13124
scheduleTopLevelUpdate @ react-dom.development.js:13395
updateContainer @ react-dom.development.js:13425
renderSubtreeIntoContainer @ react-dom.development.js:17108
render @ react-dom.development.js:17129
renderApp @ index.js:49
(anonymous) @ index.js:94
configureAPI @ api-setup.js:86
(anonymous) @ index.js:62
__webpack_require__ @ bootstrap 674ca770b414c16b5448:54
(anonymous) @ bundle.js:76060
__webpack_require__ @ bootstrap 674ca770b414c16b5448:54
webpackJsonpCallback @ bootstrap 674ca770b414c16b5448:25
(anonymous) @ bundle.js:1
react-dom.development.js:8305 The above error occurred in the <Notifications> component:
    in Notifications (created by AppWrapper)
    in div (created by AppWrapper)
    in AppWrapper (created by Connect(AppWrapper))
    in Connect(AppWrapper) (created by RouterContext)
    in RouterContext (created by Router)
    in Router
    in Provider```

Feature request: Remove notifications by level

It would be nice to have an .remove(level) or .removeByLevel(level) that removes all notifications from a specific level (warning, success, info).

I think it would be very simple to implement 'cause is the same logic from .hide(uid), using a different filter condition in the reducer.

If this is a desired feature, I can implement it and open a PR.

[Question] about using the came uid

Hi, I was wondering if you could do something like below. When I use the code now it only renders the first one but ignores the success notification. The idea is to inform the user that we are waiting for a response, and when it finishes update the notification to a success notification.

Or am I doing this wrong and is there another way to do this?

this.props.dispatch(Notifications.info({
	uid: 'propertySettings',
	title: 'Saving property settings'
}));

// if API returns with data
// Update the previous info notification to a success
this.props.dispatch(Notifications.success({
	uid: 'propertySettings',
	title: 'Property settings saved'
}));

Ofcourse I can use the Notifications.hide() but still feel that this would be nice to have (eg. cleaner)

Update Peer Dependencies to support react-redux v7.x

Hi!

react-redux v7.0 released not too long ago and is it should be backward compatible with version v6.0, unless bad assumptions were made about some of the internals of react-redux.

See the note from the release note of 7.0:

Note: connect now uses React.memo() internally, which returns a special object rather than a function. Any code that assumed React components are only functions is wrong, and has been wrong since the release of React 16.6. If you were using PropTypes to check for valid component types, you should change from PropTypes.func to PropTypes.elementType instead.

I've been using react-notification-system-redux with version 7 of react-redux and haven't noticed any errors so far (though my usage is very light). Have you looked into upgrading the peer dependency and are you aware of any breaking changes?

I'd be happy to help submit a PR!

notifications is undefined in state

HI @gor181

import {reducer as notifications} from 'react-notification-system-redux'

const App = combineReducers({
    notifications,
})

export default App

notification is undefined and unavailable in state.

simple and quite straightfoward issue but I can't find the error.

Thanks.

API Improvement

Hi. First off, this Notification Center works great. Thanks for making it.
There's a small API improvement I'd like to suggest though.

Instead of importing the entire Notifications object, and calling .show, .info, ... functions on it. It would be nicer if you could import those functions directly.

So instead of:

import Notifications from 'react-notification-system-redux';

dispatch(Notifications.show(notification, level));
dispatch(Notifications.success(notification));
dispatch(Notifications.error(notification));
dispatch(Notifications.warning(notification));
dispatch(Notifications.info(notification));
dispatch(Notifications.hide(uid)); // Hides notification based on uid
dispatch(Notifications.removeAll()); // Removes all notifications

You will have:

import { show, success, error, warning, info, hide, removeAll } from 'react-notification-system-redux';

dispatch(show(notification, level));
dispatch(success(notification));
dispatch(error(notification));
dispatch(warning(notification));
dispatch(info(notification));
dispatch(hide(uid)); // Hides notification based on uid
dispatch(removeAll()); // Removes all notifications

You of course only would have to import the one's you need. And if one of the function names clashes with existing functions (for the importer). They could always do

import { show a showNotification } from 'react-notification-system-redux'

Or something like that.

Keep up the good work!

Hide action is not being dispatched and notification still exists in DOM

This is related to #16. Creating new issue as the problem still exists.

When creating notification it is shown correctly. But when autoDismiss option the hide action is not being dispatched and notification still resides in the state.

Console

Also when triggering dismiss manually, the action is dispatched, but the notification is not being removed from the DOM.

Everything works fine when using just base react-notification-system without redux wrapper, so I believe problem lies here.

Using Date.now() inside a reducer

I noticed Date.now() is being used inside the reducer to generate a fallback action uid.

This makes the reducer function impure by depending on external state, which should not be the case when working with redux. This will cause all sorts of trouble with redux-devtools or any kind of time travelling debugger.

I'd suggesting moving the Date.now() uid fallback logic to the action generators and depend exclusively on action data inside the reducer.

For anyone having trouble with this: a simple workaround is to always pass a uid parameter when showing a notification.

removeAll() TypeScript definition missing

TypeScript definition needs the following line to be added right after const warning: NotificationShow; for removeAll() to be usable:

function removeAll(): Action;

Ability to limit the max # of notifications displayed in the UI?

Hello, currently notifications will pile on top of one another... Is there a way to display a max of 1 notification at a time? In this particular use case, if one notification is still showing, it would be instantly removed and then the new notification would be shown.

I tried that by doing:

  dispatch(removeAll());
  dispatch(info({....

The problem with the above is the animations cause some crazy jumpiness and isn't very smooth. The removeAll seems to animate the removal which is the problem vs being instantly removed so the new notification can animated in nicely.

Thanks

where is the `onRemove` function

hi @gor181 , i found this

onRemove: () => {
this.context.store.dispatch(actions.hide(notification.uid));
}

you override the notification 's onRemove function, can you tell me how to use the onRemove in the options ?

i think

onRemove: () => {
    this.context.store.dispatch(actions.hide(notification.uid));
}

should be

onRemove: () => {
    this.context.store.dispatch(actions.hide(notification.uid));
    if(notification.onRemove) notification.OnRemove(notification);
}

How to import in typescript

Using these types: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/07352da21a909cb2786a40106aad1fea562d5973/types/react-notification-system-redux/index.d.ts

I see that the element Notifications is exported both as a class and as a namespace. I cannot figure out how to import the component, because the interpreter always tells me it's ambiguous:

import * as Notifications from 'react-notification-system-redux'
<Notifications notifications={notifications} /> <- tells me: [ts] JSX element type 'Notifications' does not have any construct or call signatures.

import Notifications from 'react-notification-system-redux' <- tells me there is no default export

import {Notifications} from 'react-notification-system-redux' <- has no exported member 'Notifications'.

is `allowHTML` supported?

I know that allowHtml is supported by react-notification-system, but still receive plain text notification

Unnecessary rerender/readding for existing messages

In this fragment you remove all notifications that are no longer in the state, which is totally fine.

    // Get all active notifications from react-notification-system
    /// and remove all where uid is not found in the reducer
    (this.system().state.notifications || []).forEach(notification => {
      if (notificationIds.indexOf(notification.uid) < 0) {
        this.system().removeNotification(notification.uid);
      }
    });

But here you are looping for each notifications in the redux state even if some are already displayed. You should filter the redux notifications against notification that are already displayed and add only new ones.

    notifications.forEach(notification => {
      this.system().addNotification({
        ...notification,
        onRemove: () => {
          this.context.store.dispatch(actions.hide(notification.uid));
          notification.onRemove && notification.onRemove();
        }
      });
    });

[question] Showing notifications makes browser to scroll up

Hi, first of all, thank you for great job!!!

After a while, when I get page taller than one screen, new notification make the browser to scroll me up to most top of the page, then it renders notification component (in correct place, of course)
May be you have some ideas, how to avoid it and render notification over invisible area, on top of this view port, instead of on top of page itself?

Much appreciated for any hints.

Update peerDependencies in package.json

Upon updating to React 16, and running yarn check I get the following errors:

error "react-notification-system-redux#react@^0.14 || ^15.0.0-rc || ^15.0" doesn't satisfy found match of "[email protected]"
error "react-notification-system-redux#react-dom@^0.14 || ^15.0.0-rc || ^15.0" doesn't satisfy found match of "[email protected]"

It would be nice if you can include react and react-dom 16 in your package.json peerDependencies as well if possible.

Size of library too large

importing react-notification-system-redux into my application increases the size by ~1.45 MB for me, as opposed to only react-notification-system, which adds 60 KB.

Not sure what's up, but it's not good.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.