Skip to content

Commit cd56199

Browse files
committed
fix a bug in project start modal which is exasperated by new autostart
- a lot of code changes, but the check for needing to wait or not before showing in show_modal was slightly wrong
1 parent b0c6574 commit cd56199

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

src/packages/frontend/project/project-start-warning.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,23 @@ const explicitly_started: { [project_id: string]: number } = {};
2424

2525
export function is_running_or_starting(project_id: string): boolean {
2626
const t = explicitly_started[project_id];
27-
if (t != null && Date.now() - t <= 15000) return true;
27+
if (t != null && Date.now() - t <= 15000) {
28+
return true;
29+
}
2830

2931
const project_map = redux.getStore("projects")?.get("project_map");
30-
if (!project_map) return false;
32+
if (!project_map) {
33+
return false;
34+
}
3135
const state = project_map.getIn([project_id, "state", "state"]);
32-
if (state == null || state == "running" || state == "starting") return true;
36+
if (state == null || state == "running" || state == "starting") {
37+
return true;
38+
}
3339

3440
const x = project_map?.get(project_id)?.get("action_request");
35-
if (x == null) return false;
41+
if (x == null) {
42+
return false;
43+
}
3644
const action = x.get("action");
3745
const finished = x.get("finished");
3846
const time = new Date(x.get("time"));
@@ -46,14 +54,23 @@ export async function ensure_project_running(
4654
project_id: string,
4755
what: string,
4856
): Promise<boolean> {
57+
const intl = await getIntl();
58+
const project_actions = redux.getProjectActions(project_id);
59+
await project_actions.wait_until_no_modals();
4960
if (is_running_or_starting(project_id)) {
5061
return true;
5162
}
52-
const project_actions = redux.getProjectActions(project_id);
53-
await project_actions.wait_until_no_modals();
5463

5564
let result: string = "";
5665

66+
const project_title = redux.getStore("projects").get_title(project_id);
67+
const title = intl.formatMessage(dialogs.project_start_warning_title);
68+
const content = intl.formatMessage(dialogs.project_start_warning_content, {
69+
project_title,
70+
title,
71+
what,
72+
});
73+
5774
const interval = setInterval(() => {
5875
if (result != "") {
5976
clearInterval(interval);
@@ -65,15 +82,6 @@ export async function ensure_project_running(
6582
}
6683
}, 1000);
6784

68-
const intl = await getIntl();
69-
const project_title = redux.getStore("projects").get_title(project_id);
70-
const title = intl.formatMessage(dialogs.project_start_warning_title);
71-
const content = intl.formatMessage(dialogs.project_start_warning_content, {
72-
project_title,
73-
title,
74-
what,
75-
});
76-
7785
result = await project_actions.show_modal({ title, content });
7886
if (result == "ok") {
7987
explicitly_started[project_id] = Date.now();

src/packages/frontend/project_actions.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,9 +1380,8 @@ export class ProjectActions extends Actions<ProjectStoreState> {
13801380
const computeServerAssociations =
13811381
webapp_client.project_client.computeServers(this.project_id);
13821382
const sidePath = chatFile(path);
1383-
const currentId = await computeServerAssociations.getServerIdForPath(
1384-
sidePath,
1385-
);
1383+
const currentId =
1384+
await computeServerAssociations.getServerIdForPath(sidePath);
13861385
if (currentId != null) {
13871386
// already set
13881387
return;
@@ -2238,8 +2237,8 @@ export class ProjectActions extends Actions<ProjectStoreState> {
22382237
dest_compute_server_id: opts.dest_compute_server_id,
22392238
}
22402239
: opts.src_compute_server_id
2241-
? { compute_server_id: opts.src_compute_server_id }
2242-
: undefined),
2240+
? { compute_server_id: opts.src_compute_server_id }
2241+
: undefined),
22432242
});
22442243

22452244
if (opts.only_contents) {
@@ -3441,9 +3440,7 @@ export class ProjectActions extends Actions<ProjectStoreState> {
34413440
title: string;
34423441
content: string;
34433442
}): Promise<"ok" | "cancel"> {
3444-
if (this.modal != null) {
3445-
await this.wait_until_no_modals();
3446-
}
3443+
await this.wait_until_no_modals();
34473444
let response: "ok" | "cancel" = "cancel";
34483445
const modal = fromJS({
34493446
title,
@@ -3452,17 +3449,25 @@ export class ProjectActions extends Actions<ProjectStoreState> {
34523449
onCancel: () => (response = "cancel"),
34533450
}) as any;
34543451
this.modal = modal;
3455-
this.setState({
3456-
modal,
3457-
});
3452+
this.setState({ modal });
34583453
await this.wait_until_no_modals();
34593454
return response;
34603455
}
34613456

34623457
public async wait_until_no_modals(): Promise<void> {
3463-
if (this.modal == null) return;
3464-
await this.get_store()?.async_wait({
3465-
until: (s) => !s.get("modal") && this.modal == null,
3458+
const store = this.get_store();
3459+
if (store == null) {
3460+
return;
3461+
}
3462+
const noModal = () => {
3463+
return this.modal == null && !store.get("modal");
3464+
};
3465+
3466+
if (noModal()) {
3467+
return;
3468+
}
3469+
await store.async_wait({
3470+
until: noModal,
34663471
timeout: 99999,
34673472
});
34683473
}

0 commit comments

Comments
 (0)