Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

fix bug of refresh from disable refresh to refresh #2274

Merged
merged 2 commits into from
Apr 7, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/webui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ interface AppState {
}

class App extends React.Component<{}, AppState> {
private timerId!: number | null;
private timerId!: number | undefined;
private flag: boolean = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a meaningful name. I can't really understand what this flag does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

private dataFormatimer!: number;

constructor(props: {}) {
Expand Down Expand Up @@ -66,13 +67,12 @@ class App extends React.Component<{}, AppState> {
}
}
}

changeInterval = (interval: number): void => {
this.setState({ interval });
if (this.timerId === null && interval !== 0) {
window.setTimeout(this.refresh);
} else if (this.timerId !== null && interval === 0) {
window.clearTimeout(this.timerId);
if (this.flag === false) {
this.refresh();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refresh() will setup a (sequence of) timer. If I spam changing interval, there will be bunch of timers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had updated.

this.flag = true;
}
}

Expand Down Expand Up @@ -133,14 +133,18 @@ class App extends React.Component<{}, AppState> {

if (['DONE', 'ERROR', 'STOPPED'].includes(EXPERIMENT.status)) {
// experiment finished, refresh once more to ensure consistency
if (this.state.interval > 0) {
this.setState({ interval: 0 });
this.lastRefresh();
}
this.setState({ interval: 0 });
this.lastRefresh();
return;
}

} else if (this.state.interval !== 0) {
this.timerId = window.setTimeout(this.refresh, this.state.interval * 1000);
if(this.state.interval === 0){
this.flag = false;
return;
}

this.timerId = window.setTimeout(this.refresh, this.state.interval * 1000);

}

public async lastRefresh(): Promise<void> {
Expand Down