-
Notifications
You must be signed in to change notification settings - Fork 386
/
app.ts
58 lines (47 loc) · 1.67 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
import { reactive } from 'vue';
import { defineStore } from 'pinia';
import { PlacementInfo, PlacementManagementHttpApiV1, Project, ProjectManagementHttpApiV1, UserAccount, UserManagementHttpApiV1 } from '@/api/client.gen';
class AppState {
public placements: PlacementInfo[];
public userAccount: UserAccount | null = null;
public selectedProject: Project | null = null;
}
export const useAppStore = defineStore('app', () => {
const state = reactive<AppState>(new AppState());
const userApi = new UserManagementHttpApiV1();
const placementApi = new PlacementManagementHttpApiV1();
const projectApi = new ProjectManagementHttpApiV1();
async function getUserByEmail(email: string): Promise<void> {
state.userAccount = await userApi.getUserByEmail(email);
}
function clearUser(): void {
state.userAccount = null;
}
async function getPlacements(): Promise<void> {
state.placements = await placementApi.getPlacements();
}
function getPlacementText(code: number): string {
for (const placement of state.placements) {
if (placement.id === code) {
if (placement.location) {
return placement.location;
}
break;
}
}
return `Unknown (${code})`;
}
async function selectProject(id: string): Promise<void> {
state.selectedProject = await projectApi.getProject(id);
}
return {
state,
getUserByEmail,
clearUser,
getPlacements,
getPlacementText,
selectProject,
};
});