Skip to content

Commit 737897b

Browse files
ert78gbmondalaci
authored andcommitted
feat(agent): Add loading screen (#444)
* feat(uhk-message): Add spin animation * feat(agent): Add loading page * fix device connected / disconnected events
1 parent 01b07a3 commit 737897b

File tree

14 files changed

+125
-11
lines changed

14 files changed

+125
-11
lines changed

.stylelintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
"unit-case": "lower",
2828
"unit-no-unknown": true,
29-
"unit-whitelist": ["px", "%", "deg", "ms", "em", "rem", "vh", "vv"],
29+
"unit-whitelist": ["px", "%", "deg", "ms", "em", "rem", "vh", "vv", "s"],
3030

3131
"value-list-comma-space-after": "always-single-line",
3232
"value-list-comma-space-before": "never",

packages/uhk-web/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(doNotUpdateApp)="doNotUpdateApp()">
44
</app-update-available>
55

6-
<side-menu *ngIf="deviceConnected$ | async"></side-menu>
6+
<side-menu *ngIf="deviceConfigurationLoaded$ | async"></side-menu>
77
<div id="main-content" class="main-content">
88
<router-outlet></router-outlet>
99
</div>

packages/uhk-web/src/app/app.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { DoNotUpdateAppAction, UpdateAppAction } from './store/actions/app-updat
99
import {
1010
AppState,
1111
getShowAppUpdateAvailable,
12-
deviceConnected,
12+
deviceConfigurationLoaded,
1313
runningInElectron,
1414
saveToKeyboardState
1515
} from './store';
@@ -37,13 +37,13 @@ import { SaveUserConfigInBinaryFileAction, SaveUserConfigInJsonFileAction } from
3737
})
3838
export class MainAppComponent {
3939
showUpdateAvailable$: Observable<boolean>;
40-
deviceConnected$: Observable<boolean>;
40+
deviceConfigurationLoaded$: Observable<boolean>;
4141
runningInElectron$: Observable<boolean>;
4242
saveToKeyboardState$: Observable<ProgressButtonState>;
4343

4444
constructor(private store: Store<AppState>) {
4545
this.showUpdateAvailable$ = store.select(getShowAppUpdateAvailable);
46-
this.deviceConnected$ = store.select(deviceConnected);
46+
this.deviceConfigurationLoaded$ = store.select(deviceConfigurationLoaded);
4747
this.runningInElectron$ = store.select(runningInElectron);
4848
this.saveToKeyboardState$ = store.select(saveToKeyboardState);
4949
}

packages/uhk-web/src/app/app.routes.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import { UhkDeviceUninitializedGuard } from './services/uhk-device-uninitialized
1313
import { UhkDeviceInitializedGuard } from './services/uhk-device-initialized.guard';
1414
import { MainPage } from './pages/main-page/main.page';
1515
import { settingsRoutes } from './components/settings/settings.routes';
16+
import { LoadingDevicePageComponent } from './pages/loading-page/loading-device.page';
17+
import { UhkDeviceLoadingGuard } from './services/uhk-device-loading.guard';
18+
import { UhkDeviceLoadedGuard } from './services/uhk-device-loaded.guard';
1619

1720
const appRoutes: Routes = [
1821
{
@@ -25,10 +28,15 @@ const appRoutes: Routes = [
2528
component: PrivilegeCheckerComponent,
2629
canActivate: [UhkDeviceInitializedGuard]
2730
},
31+
{
32+
path: 'loading',
33+
component: LoadingDevicePageComponent,
34+
canActivate: [UhkDeviceLoadedGuard]
35+
},
2836
{
2937
path: '',
3038
component: MainPage,
31-
canActivate: [UhkDeviceDisconnectedGuard],
39+
canActivate: [UhkDeviceDisconnectedGuard, UhkDeviceLoadingGuard],
3240
children: [
3341
...deviceRoutes,
3442
...keymapRoutes,

packages/uhk-web/src/app/components/uhk-message/uhk-message.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<span class="uhk-message-wrapper">
2-
<img class="agent-logo" src="assets/images/agent-icon.png"/>
2+
<img class="agent-logo spin-logo"
3+
[ngClass]="{'spin-logo': rotateLogo}"
4+
src="assets/images/agent-icon.png"/>
35
<div class="messages">
46
<h1> {{ title }} </h1>
57
<h2> {{ subtitle }} </h2>

packages/uhk-web/src/app/components/uhk-message/uhk-message.component.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,23 @@
1717
margin-top: 10px;
1818
}
1919
}
20+
21+
.spin-logo {
22+
-webkit-animation: spin 2s ease-in-out infinite;
23+
-moz-animation: spin 2s ease-in-out infinite;
24+
animation: spin 2s ease-in-out infinite;
25+
}
26+
27+
@keyframes spin {
28+
0% {
29+
transform: rotate(0);
30+
}
31+
32+
50% {
33+
transform: rotate(360deg);
34+
}
35+
36+
100% {
37+
transform: rotate(360deg);
38+
}
39+
}

packages/uhk-web/src/app/components/uhk-message/uhk-message.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
99
export class UhkMessageComponent {
1010
@Input() title: string;
1111
@Input() subtitle: string;
12+
@Input() rotateLogo = false;
1213
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'loading-device',
5+
template: `
6+
<uhk-message title="Loading Agent..."
7+
subtitle="Hang tight!"
8+
[rotateLogo]="true"></uhk-message>
9+
`
10+
})
11+
export class LoadingDevicePageComponent {
12+
13+
constructor() {
14+
}
15+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { CanActivate, Router } from '@angular/router';
2+
import { Store } from '@ngrx/store';
3+
import { Injectable } from '@angular/core';
4+
5+
import { Observable } from 'rxjs/Observable';
6+
import 'rxjs/add/operator/do';
7+
import 'rxjs/add/operator/map';
8+
9+
import { AppState, deviceConfigurationLoaded } from '../store';
10+
11+
@Injectable()
12+
export class UhkDeviceLoadedGuard implements CanActivate {
13+
14+
constructor(private store: Store<AppState>, private router: Router) { }
15+
16+
canActivate(): Observable<boolean> {
17+
return this.store.select(deviceConfigurationLoaded)
18+
.do(loaded => {
19+
if (loaded) {
20+
this.router.navigate(['/']);
21+
}
22+
})
23+
.map(loaded => !loaded);
24+
}
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { CanActivate, Router } from '@angular/router';
2+
import { Store } from '@ngrx/store';
3+
import { Injectable } from '@angular/core';
4+
5+
import { Observable } from 'rxjs/Observable';
6+
import 'rxjs/add/operator/do';
7+
8+
import { AppState, deviceConfigurationLoaded } from '../store';
9+
10+
@Injectable()
11+
export class UhkDeviceLoadingGuard implements CanActivate {
12+
13+
constructor(private store: Store<AppState>, private router: Router) { }
14+
15+
canActivate(): Observable<boolean> {
16+
return this.store.select(deviceConfigurationLoaded)
17+
.do(loaded => {
18+
if (!loaded) {
19+
this.router.navigate(['/loading']);
20+
}
21+
});
22+
}
23+
}

0 commit comments

Comments
 (0)