lbry-desktop/ui/js/component/snackBar/view.jsx

49 lines
994 B
React
Raw Normal View History

2017-05-23 09:21:21 +02:00
import React from 'react';
import Link from 'component/link'
class SnackBar extends React.Component {
constructor(props) {
super(props);
this._displayTime = 5; // in seconds
this._hideTimeout = null;
}
render() {
const {
navigate,
snacks,
removeSnack,
} = this.props
if (!snacks.length) {
this._hideTimeout = null; //should be unmounting anyway, but be safe?
return null;
}
const snack = snacks[0];
const {
message,
linkText,
linkTarget,
} = snack
if (this._hideTimeout === null) {
this._hideTimeout = setTimeout(() => {
this._hideTimeout = null;
removeSnack()
}, this._displayTime * 1000);
}
return (
<div className="snack-bar">
{message}
{linkText && linkTarget &&
2017-05-25 02:07:16 +02:00
<Link onClick={() => navigate(linkTarget)} className="snack-bar__action" label={linkText} />
2017-05-23 09:21:21 +02:00
}
</div>
);
}
}
export default SnackBar;