Skip to content

Commit

Permalink
Making eventlog scrollable
Browse files Browse the repository at this point in the history
  • Loading branch information
pradeepvairamani committed Dec 25, 2020
1 parent 754e46c commit ac4880b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 0 additions & 3 deletions coup-client/src/components/game/Coup.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ export default class Coup extends Component {
return <>{item+' '}</>
})
bind.state.logs = [...bind.state.logs, coloredLog]
if(bind.state.logs.length === 5){
bind.state.logs.shift();
}
bind.setState({logs :bind.state.logs})
})
this.props.socket.on('g-chooseAction', () => {
Expand Down
2 changes: 2 additions & 0 deletions coup-client/src/components/game/CoupStyles.css
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@
position: absolute;
right: 10VW;
top: 10VH;
overflow-y: scroll;
height: 9VH;
}
.GameHeader {
height: 15VH;
Expand Down
15 changes: 15 additions & 0 deletions coup-client/src/components/game/EventLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,22 @@ export default class EventLog extends Component {
}
return <p>{x}</p>
})}
<div style={{ float:"left", clear: "both" }}
ref={(el) => { this.messagesEnd = el; }}>
</div>
</div>
)
}

scrollToBottom = () => {
this.messagesEnd.scrollIntoView({ behavior: "smooth" });
}

componentDidMount() {
this.scrollToBottom();
}

componentDidUpdate() {
this.scrollToBottom();
}
}

0 comments on commit ac4880b

Please sign in to comment.