Skip to content

Commit 1f58d23

Browse files
committed
feat(profile-my): show discord server invite
1 parent bbace03 commit 1f58d23

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
lines changed

src/api/backend/api/default.service.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4563,6 +4563,60 @@ export class DefaultService {
45634563
);
45644564
}
45654565

4566+
/**
4567+
*
4568+
*
4569+
* @param usersId
4570+
* @param year
4571+
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
4572+
* @param reportProgress flag to report request and response progress.
4573+
*/
4574+
public usersGetSingleDiscordInvite(usersId: number, year?: number, observe?: 'body', reportProgress?: boolean): Observable<string>;
4575+
public usersGetSingleDiscordInvite(usersId: number, year?: number, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<string>>;
4576+
public usersGetSingleDiscordInvite(usersId: number, year?: number, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<string>>;
4577+
public usersGetSingleDiscordInvite(usersId: number, year?: number, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {
4578+
4579+
if (usersId === null || usersId === undefined) {
4580+
throw new Error('Required parameter usersId was null or undefined when calling usersGetSingleDiscordInvite.');
4581+
}
4582+
4583+
4584+
let headers = this.defaultHeaders;
4585+
if (year !== undefined && year !== null) {
4586+
headers = headers.set('year', String(year));
4587+
}
4588+
4589+
// authentication (ksi) required
4590+
if (this.configuration.accessToken) {
4591+
const accessToken = typeof this.configuration.accessToken === 'function'
4592+
? this.configuration.accessToken()
4593+
: this.configuration.accessToken;
4594+
headers = headers.set('Authorization', 'Bearer ' + accessToken);
4595+
}
4596+
4597+
// to determine the Accept header
4598+
let httpHeaderAccepts: string[] = [
4599+
'application/json'
4600+
];
4601+
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
4602+
if (httpHeaderAcceptSelected != undefined) {
4603+
headers = headers.set('Accept', httpHeaderAcceptSelected);
4604+
}
4605+
4606+
// to determine the Content-Type header
4607+
const consumes: string[] = [
4608+
];
4609+
4610+
return this.httpClient.request<string>('get',`${this.basePath}/users/${encodeURIComponent(String(usersId))}/discord`,
4611+
{
4612+
withCredentials: this.configuration.withCredentials,
4613+
headers: headers,
4614+
observe: observe,
4615+
reportProgress: reportProgress
4616+
}
4617+
);
4618+
}
4619+
45664620
/**
45674621
*
45684622
*

src/app/components/profile/page-profile-my/page-profile-my.component.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,19 @@ <h2>{{'profile.my.about-me.title'|translate}}</h2>
129129
[placeholder]="'profile.my.about-me.github'|translate"
130130
>
131131

132-
<label class="form-label">{{'profile.my.about-me.discord'|translate}}</label>
132+
<label class="form-label">
133+
{{'profile.my.about-me.discord'|translate}}
134+
<ng-container *ngIf="discordInviteLink$ | async as link">
135+
-
136+
<a [href]="link" target="_blank">{{'profile.my.discord-join'|translate}}</a>
137+
</ng-container>
138+
</label>
133139
<input type="text"
134140
class="form-control"
135141
formControlName="discord"
136142
[placeholder]="'profile.my.about-me.discord'|translate"
137143
>
138144

139-
140145
<!-- Address -->
141146
<h2>{{'profile.my.address.title'|translate}}</h2>
142147
<label class="form-label">{{'profile.my.address.street'|translate}}</label>

src/app/components/profile/page-profile-my/page-profile-my.component.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef, OnDestroy } from '@angular/core';
22
import { AddressService, BackendService, IconService, RoutesService, UserService } from '../../../services';
33
import { FormBuilder, Validators } from '@angular/forms';
4-
import { ActivatedRoute, Router } from '@angular/router';
5-
import { catchError, map, mapTo, mergeMap, shareReplay } from 'rxjs/operators';
4+
import { ActivatedRoute } from '@angular/router';
5+
import { catchError, debounceTime, map, mapTo, mergeMap, shareReplay } from 'rxjs/operators';
66
import { Observable, of, Subscription } from 'rxjs';
77
import { ProfileEdit } from '../../../../api/backend';
88
import { environment } from '../../../../environments/environment';
@@ -55,14 +55,14 @@ export class PageProfileMyComponent implements OnInit, OnDestroy {
5555
countries = AddressService.COUNTRIES;
5656

5757
profilePicture$: Observable<string | null>;
58+
discordInviteLink$: Observable<string | null>;
5859

5960
private _subs: Subscription[] = [];
6061

6162
constructor(
6263
private fb: FormBuilder,
6364
public backend: BackendService,
6465
private user: UserService,
65-
private router: Router,
6666
private cd: ChangeDetectorRef,
6767
public icon: IconService,
6868
public routes: RoutesService,
@@ -77,6 +77,14 @@ export class PageProfileMyComponent implements OnInit, OnDestroy {
7777
map((user) => user ? `${user.profile_picture}?${Date.now()}` : user)
7878
);
7979

80+
this.discordInviteLink$ = this.user.isLoggedIn$.pipe(
81+
mergeMap(() => this.backend.user$),
82+
debounceTime(200),
83+
shareReplay(1),
84+
mergeMap((user) => user ? this.backend.http.usersGetSingleDiscordInvite(user.id) : of(null)),
85+
shareReplay(1)
86+
);
87+
8088
// add passwords same validator
8189
this.formPassword.controls.repeat.addValidators((control) => {
8290
return control.value === this.formPassword.controls.new.value ? null : {'not-same': 'not-same'};

src/assets/i18n/cs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@
369369
"password-change-success": "Změna hesla proběhla úspěšně",
370370
"save": "Uložit změny",
371371
"change-picture": "Nahrát nový profilový obrázek",
372+
"discord-join": "přidat se na Discord server KSI",
372373
"about-me": {
373374
"title": "O mě",
374375
"first-name": "Křestní jméno",

0 commit comments

Comments
 (0)