Close snacks faster if the queue is filled

This commit is contained in:
Jannis Mattheis 2018-04-02 22:13:07 +02:00 committed by Jannis Mattheis
parent 1262f43846
commit 38fe1800e1
1 changed files with 10 additions and 5 deletions

View File

@ -10,6 +10,7 @@ class SnackBarHandler extends Component {
state = { state = {
current: '', current: '',
hasNext: false,
open: false, open: false,
openWhen: 0, openWhen: 0,
}; };
@ -40,6 +41,7 @@ class SnackBarHandler extends Component {
open: true, open: true,
openWhen: Date.now(), openWhen: Date.now(),
current: SnackBarStore.next(), current: SnackBarStore.next(),
hasNext: SnackBarStore.hasNext(),
}); });
} }
}; };
@ -47,19 +49,22 @@ class SnackBarHandler extends Component {
closeCurrentSnack = () => this.setState({...this.state, open: false}); closeCurrentSnack = () => this.setState({...this.state, open: false});
render() { render() {
const {open, current} = this.state; const {open, current, hasNext} = this.state;
const duration = hasNext
? SnackBarHandler.MIN_VISIBLE_SNACK_TIME_IN_MS
: SnackBarHandler.MAX_VISIBLE_SNACK_TIME_IN_MS;
return ( return (
<Snackbar <Snackbar
anchorOrigin={{vertical: 'bottom', horizontal: 'left'}} anchorOrigin={{vertical: 'bottom', horizontal: 'left'}}
open={open} autoHideDuration={SnackBarHandler.MAX_VISIBLE_SNACK_TIME_IN_MS} open={open} autoHideDuration={duration}
onClose={this.closeCurrentSnack} onExited={this.openNextSnack} onClose={this.closeCurrentSnack} onExited={this.openNextSnack}
message={<span id="message-id">{current}</span>} message={<span id="message-id">{current}</span>}
action={[ action={
<IconButton key="close" aria-label="Close" color="inherit" onClick={this.closeCurrentSnack}> <IconButton key="close" aria-label="Close" color="inherit" onClick={this.closeCurrentSnack}>
<Close/> <Close/>
</IconButton>, </IconButton>
]} }
/> />
); );
} }