Commit 8e571c0e authored by Lukas Burgey's avatar Lukas Burgey

Put ssh keys into a map

parent 6eac125b
......@@ -28,7 +28,7 @@ export class UserService {
private user: User;
private user$: BehaviorSubject<User>;
private sshKeys: SSHKey[] = new Array<SSHKey>();
private sshKeys: Map<number, SSHKey> = new Map([]);
private sshKeys$ = new BehaviorSubject<SSHKey[]>([]);
private deploymentStates: Map<number, DeploymentState> = new Map([]);
......@@ -71,11 +71,10 @@ export class UserService {
this.user = undefined;
this.deployments = new Map([]);
this.deployments$.next([]);
this.sshKeys = [];
this.sshKeys = new Map([]);
this.sshKeys$.next([]);
}
this.loggedIn = false;
} else {
// LOGGED IN
......@@ -88,8 +87,11 @@ export class UserService {
this.connectLiveUpdates(newUser.id);
}
if (newUser.ssh_keys) {
this.sshKeys = newUser.ssh_keys;
this.sshKeys$.next(this.sshKeys);
this.sshKeys = new Map([]);
newUser.ssh_keys.forEach(
(key: SSHKey) => this.sshKeys.set(key.id, key),
);
this.sshKeys$.next(Array.from(this.sshKeys.values()));
}
if (newUser.deployments) {
newUser.deployments.forEach(
......@@ -294,8 +296,8 @@ export class UserService {
catchError(this.handleError(true, "Error changing deployment")),
).subscribe(
(newKey: SSHKey) => {
this.sshKeys.push(newKey);
this.sshKeys$.next(this.sshKeys);
this.sshKeys.set(newKey.id, newKey);
this.sshKeys$.next(Array.from(this.sshKeys.values()));
},
this.logErrorAndFetch,
);
......@@ -307,10 +309,8 @@ export class UserService {
catchError(this.handleError(true, "Error changing deployment")),
).subscribe(
_ => {
this.sshKeys = this.sshKeys.filter(
k => key.id != k.id
);
this.sshKeys$.next(this.sshKeys);
this.sshKeys.delete(key.id);
this.sshKeys$.next(Array.from(this.sshKeys.values()));
},
this.logErrorAndFetch,
);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment