Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit e382f12

Browse files
committed
Snap to bottom when near bottom and job is finished
1 parent b8a2cf5 commit e382f12

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/views/2_SessionComponent.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ interface Props {
1212
updateStatusBar: (() => void) | undefined; // Only the focused session can update the status bar.
1313
}
1414

15+
// The height to snap to bottom when scroll. TODO: Make this the actual height
16+
const FOOTER_HEIGHT = 50;
17+
1518
export class SessionComponent extends React.Component<Props, {}> {
1619
RENDER_JOBS_COUNT = 25;
1720

@@ -26,7 +29,19 @@ export class SessionComponent extends React.Component<Props, {}> {
2629

2730
componentDidMount() {
2831
this.props.session
29-
.on("job", () => this.props.updateStatusBar && this.props.updateStatusBar())
32+
.on("job", () => {
33+
const s = (this.refs as any).session;
34+
if (s) {
35+
if (s.scrollHeight - s.offsetHeight - s.scrollTop > FOOTER_HEIGHT) {
36+
// If we are already close to the bottom,
37+
// scroll all the way to the bottom
38+
s.scrollTop = s.scrollHeight;
39+
}
40+
}
41+
if (this.props.updateStatusBar) {
42+
this.props.updateStatusBar();
43+
}
44+
})
3045
.on("vcs-data", () => this.props.updateStatusBar && this.props.updateStatusBar());
3146
}
3247

@@ -46,8 +61,9 @@ export class SessionComponent extends React.Component<Props, {}> {
4661

4762
return (
4863
<div className="session"
49-
style={css.session(this.props.isFocused)}
50-
onClick={this.handleClick.bind(this)}>
64+
ref="session"
65+
style={css.session(this.props.isFocused)}
66+
onClick={this.handleClick.bind(this)}>
5167

5268
<div className="jobs" style={css.jobs(this.props.isFocused)}>{jobs}</div>
5369
<div className="shutter" style={css.sessionShutter(this.props.isFocused)}></div>

0 commit comments

Comments
 (0)