Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please give actual examples of usage in your .md file #127

Open
alilland opened this issue May 25, 2017 · 9 comments
Open

Please give actual examples of usage in your .md file #127

alilland opened this issue May 25, 2017 · 9 comments

Comments

@alilland
Copy link

I love what I see is possible to do, but newer developers are going to have a difficult time reading your documentation and understanding at a glance how to implement your product.

if you could give smaller code examples in the MD file and samples on how to include it in an application, your product would likely grow in popularity

@puranjayjain
Copy link
Owner

@aronlmin great idea I see a lot of people getting stuck in implementation, an app demo and code should solve the problem indeed. I'll see if I can cook an example. PRs are also welcome

@alilland
Copy link
Author

also, calling proptypes directly to React is depricated now, https://facebook.github.io/react/warnings/dont-call-proptypes.html

@puranjayjain
Copy link
Owner

Oh need to upgrade them or remove prop type validations wherever not necessary. Thanks again

@Paul-Vandell
Copy link

Yeah, im new, thx for this package but didn't succed to used it. Tell me what wrong here ?

import ReactMaterialUiNotifications from 'react-materialui-notifications';

export default class Main extends Component {
  
  notification() {
    ReactMaterialUiNotifications.showNotification({
      title: 'Title',
      additionalText: `Some message to be displayed`,
    });
  }

  render() {
    return (
      <div className='p-t4'>
        <div className="btn" onTouchTap={()=>this.notification()}>open</div>
        <ReactMaterialUiNotifications
          desktop={true}
          transitionName={{
            leave: 'dummy',
            leaveActive: 'fadeOut',
            appear: 'dummy',
            appearActive: 'zoomInUp',
          }}
          transitionAppear={true}
          transitionLeave={true}
        />
      </div>
    );
  }
}

Im sure that's easy but i dont understand the base to make it work properly...
Thx in advance

@Paul-Vandell
Copy link

Paul-Vandell commented Aug 25, 2017

Ok the issue is coming from that i didn't refresh the state in my own component with a incremental Notifications count in the constructor, but the question is why this package do not refresh his state itself ? not mine.

@Paul-Vandell
Copy link

Oh i see,
https://github.com/puranjayjain/react-materialui-notifications/blob/69726ce67c3df902c76dde27c254280032a0a7b6/src/app/ReactMaterialUiNotifications.js#L19
I think that the notification array should be in constructor ?

export default class ReactMaterialUiNotifications extends Component {
  constructor(props) {
    super(props);
    this.state = {
    notifications : [],
    count : 0,
    };
  }

Then your state will be refresh after a new notification ? i 'll tried this and back then.

@Paul-Vandell
Copy link

Paul-Vandell commented Aug 26, 2017

Ok i got a working solution. I 've remove your static function and replace by simple function.
The great things that with the static function you can access it anywhere but your component did not trigger when a new notification comin unless your refresh your own component
So the best way was to reference your notification component to access the showNotification function();
If some of them don't want to always render for a new <ReactMaterialUiNotifications/>, they can use an event listener in the notification component (only if static keyword remove ).

	componentDidMount(){
		window.addEventListener('addNotification', (e) => {
			const notification = e.detail;
			this.showNotification(notification)
		})
	}

and call it with :

  const call = new CustomEvent('addNotification', {detail: notification});
  window.dispatchEvent(call);

and place <ReactMaterialUiNotifications/> in a higher order

Redux do it well to.
if anyone want the source code to test it with reference, ask me. Hope it help !

@djorg83
Copy link

djorg83 commented Mar 21, 2018

@Vandell63 i was able to use a HOC and keep the static function and get it to work by using this.forceUpdate();

import React from 'react';
import ReactMaterialUiNotifications from 'react-materialui-notifications';

class NotificationHOC extends React.Component {
    componentDidMount(){
        window.addEventListener('addNotification', (e) => {
            const notification = e.detail;
            ReactMaterialUiNotifications.showNotification(notification);
            this.forceUpdate();
	});
    }

    render() {
        return <ReactMaterialUiNotifications {...this.props} />;
    }
};

const NotificationShell = () => (
    <NotificationHOC
        desktop={true}
        transitionName={{
            leave: 'dummy',
            leaveActive: 'fadeOut',
            appear: 'dummy',
            appearActive: 'zoomInUp',
        }}
        transitionAppear={true}
        transitionLeave={true}
    />
);

export default NotificationShell;

then in the root of my app...

<MuiThemeProvider>
        <Router>
            <div>
                <AppBar />
                <div>
                    <SideBar />
                    <MainContent />
                </div>
                <NotificationShell />
          </div>
    </Router>
</MuiThemeProvider>

@djorg83
Copy link

djorg83 commented Mar 21, 2018

Turns out that the above code only worked to get the notifications to render when they are added. But when you click the X button to remove one, it breaks the app because of something related to the animation on the button. This was enough for me to switch to react-toastify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants