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

46 lines
1,004 B
React
Raw Normal View History

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