CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/compute/cloud-filesystem/regions.ts
Views: 687
1
import { redux } from "@cocalc/frontend/app-framework";
2
import { field_cmp } from "@cocalc/util/misc";
3
4
export async function getRecentRegions(project_id): Promise<string[]> {
5
const computeServers = redux
6
.getProjectStore(project_id)
7
.get("compute_servers");
8
if (computeServers == null) {
9
return [];
10
}
11
const v: { last_edited: Date; region: string }[] = [];
12
for (const [, x] of computeServers) {
13
const last_edited = x.get("last_edited");
14
if (last_edited == null) continue;
15
const region = x.getIn(["configuration", "region"]);
16
if (region == null) continue;
17
v.push({ last_edited, region });
18
}
19
const regions = v
20
.sort(field_cmp("last_edited"))
21
.map(({ region }) => region)
22
.reverse();
23
const w: string[] = [];
24
for (const region of regions) {
25
if (!w.includes(region)) {
26
w.push(region);
27
}
28
}
29
return w;
30
}
31
32