Skip to content

Commit 8b607e3

Browse files
feat: adding landing page for desktop application
1 parent 84c554a commit 8b607e3

File tree

7 files changed

+141
-10
lines changed

7 files changed

+141
-10
lines changed

src/src/app/app.routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import {TwitchBotIndexComponent} from './view/twitch/twitch-bot-index/twitch-bot
99
import {TwitchBotConfigComponent} from './view/twitch/twitch-bot-config/twitch-bot-config.component';
1010
import {ImdbSearchComponent} from './view/imdb-search/imdb-search.component';
1111
import {BackgroundWebglExampleComponent} from "./view/background-webgl-example/background-webgl-example.component";
12+
import {LoginLandingDesktopComponent} from "./view/login-landing-desktop/login-landing-desktop.component";
1213

1314
export const routes: Routes = [
1415
{path: '', component: HomeComponent},
1516
{path: 'background', component: BackgroundWebglExampleComponent},
1617
{path: 'user/auth', component: LoginComponent},
1718
{path: 'user/login', component: LoginLandingComponent},
19+
{path: 'user/login/desktop', component: LoginLandingDesktopComponent},
1820
{path: 'home', component: HomeComponent},
1921
{path: 'vm-admin', component: VmManagerComponent, canActivate: [authGuard]},
2022
{path: 'twitch-bot', component: TwitchBotIndexComponent},
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface OAuth {
2+
bearer: string,
3+
refresh: string,
4+
expiresUtc: string
5+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<div class="centered-box">
2+
<div class="centered-box_logo-container">
3+
<app-logo />
4+
</div>
5+
<div class="centered-box_content-container">
6+
@if (loading) {
7+
<app-loading-icon fontSize="24px" height="35px" width="35px">Logging in</app-loading-icon>
8+
} @else {
9+
@if (error !== '') {
10+
<div class="error-banner">{{ error }}</div>
11+
} @else {
12+
@if (null !== oAuth) {
13+
<h2>DO NOT SHOW ON STREAM</h2>
14+
<button mat-stroked-button color="primary" [cdkCopyToClipboard]="JSON.stringify(oAuth)">Copy to Clipboard</button>
15+
} @else {
16+
<div class="error-banner">Failed to get you authenticated, please try again</div>
17+
}
18+
}
19+
}
20+
</div>
21+
</div>

src/src/app/view/login-landing-desktop/login-landing-desktop.component.scss

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { LoginLandingDesktopComponent } from './login-landing-desktop.component';
4+
5+
describe('LoginLandingDesktopComponent', () => {
6+
let component: LoginLandingDesktopComponent;
7+
let fixture: ComponentFixture<LoginLandingDesktopComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
imports: [LoginLandingDesktopComponent]
12+
})
13+
.compileComponents();
14+
15+
fixture = TestBed.createComponent(LoginLandingDesktopComponent);
16+
component = fixture.componentInstance;
17+
fixture.detectChanges();
18+
});
19+
20+
it('should create', () => {
21+
expect(component).toBeTruthy();
22+
});
23+
});
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import {Component, OnInit} from '@angular/core';
2+
import {NullinsideService} from "../../service/nullinside.service";
3+
import {ActivatedRoute, ParamMap} from "@angular/router";
4+
import {Errors} from "../login-landing/errors";
5+
import {HttpErrorResponse} from "@angular/common/http";
6+
import {LoadingIconComponent} from "../../common/components/loading-icon/loading-icon.component";
7+
import {LogoComponent} from "../../common/components/logo/logo.component";
8+
import {OAuth} from "../../common/interface/oauth";
9+
import {MatButton} from "@angular/material/button";
10+
import {CdkCopyToClipboard} from "@angular/cdk/clipboard";
11+
12+
@Component({
13+
selector: 'app-login-landing-desktop',
14+
imports: [
15+
LoadingIconComponent,
16+
LogoComponent,
17+
MatButton,
18+
CdkCopyToClipboard
19+
],
20+
templateUrl: './login-landing-desktop.component.html',
21+
styleUrl: './login-landing-desktop.component.scss'
22+
})
23+
export class LoginLandingDesktopComponent implements OnInit {
24+
error: string = '';
25+
oAuth: OAuth | null = null;
26+
loading: boolean = true;
27+
28+
constructor(private api: NullinsideService, private route: ActivatedRoute) {
29+
}
30+
31+
ngOnInit(): void {
32+
this.route.queryParamMap.subscribe({
33+
next: (params: ParamMap) => {
34+
const error = params.get('error');
35+
if (null !== error) {
36+
const errorNum = +error;
37+
if (Errors.TwitchAccountHasNoEmail === errorNum) {
38+
this.onLoginFailed('Your Twitch account must have a valid e-mail address, please add one and try again')
39+
} else if (Errors.TwitchErrorWithToken === errorNum) {
40+
this.onLoginFailed('Twitch failed to give us a valid token, please try again')
41+
} else {
42+
this.onLoginFailed('Sorry we did something wrong trying to log you in, please try again')
43+
}
44+
45+
return;
46+
}
47+
48+
const oAuth = {
49+
bearer: params.get('bearer'),
50+
refresh: params.get('refresh'),
51+
expiresUtc: params.get('expiresUtc'),
52+
};
53+
54+
if (null === oAuth.bearer || null === oAuth.refresh || null === oAuth.expiresUtc) {
55+
this.onLoginFailed();
56+
return;
57+
}
58+
59+
this.oAuth = {
60+
bearer: oAuth.bearer,
61+
refresh: oAuth.refresh,
62+
expiresUtc: oAuth.expiresUtc
63+
};
64+
65+
navigator.clipboard.writeText(JSON.stringify(oAuth));
66+
this.loading = false;
67+
},
68+
error: (_: HttpErrorResponse) => {
69+
this.onLoginFailed();
70+
}
71+
});
72+
}
73+
74+
onLoginFailed(message = ':( Failed to login, please try again'): void {
75+
this.error = message;
76+
this.loading = false;
77+
}
78+
79+
protected readonly JSON = JSON;
80+
}

src/src/app/view/login-landing/login-landing.component.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import { environment } from "../../../environments/environment";
77
import { HttpErrorResponse } from "@angular/common/http";
88
import { Errors } from "./errors";
99

10-
@Component({
11-
selector: 'app-login-landing',
12-
imports: [
13-
LogoComponent,
14-
LoadingIconComponent
15-
],
16-
templateUrl: './login-landing.component.html',
17-
styleUrl: './login-landing.component.scss'
10+
@Component({
11+
selector: 'app-login-landing',
12+
imports: [
13+
LogoComponent,
14+
LoadingIconComponent
15+
],
16+
templateUrl: './login-landing.component.html',
17+
styleUrl: './login-landing.component.scss'
1818
})
1919
export class LoginLandingComponent implements OnInit, OnDestroy {
2020
timerId: number = -1;
@@ -38,9 +38,9 @@ export class LoginLandingComponent implements OnInit, OnDestroy {
3838
if (Errors.TwitchAccountHasNoEmail === errorNum) {
3939
this.onLoginFailed('Your Twitch account must have a valid e-mail address, please add one and try again', false)
4040
} else if (Errors.TwitchErrorWithToken === errorNum) {
41-
this.onLoginFailed('Twitch failed to give us a valid token, please add one and try again', false)
41+
this.onLoginFailed('Twitch failed to give us a valid token, please try again', false)
4242
} else {
43-
this.onLoginFailed('Sorry we did something wrong trying to log you in, please add one and try again', false)
43+
this.onLoginFailed('Sorry we did something wrong trying to log you in, please try again', false)
4444
}
4545

4646
return;

0 commit comments

Comments
 (0)