Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 1a93fa7

Browse files
feat: add custom logo to user profile
1 parent f4e3a43 commit 1a93fa7

File tree

3 files changed

+85
-13
lines changed

3 files changed

+85
-13
lines changed

studio/src/app/models/data/user.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ export interface UserSocial {
44
dev?: string;
55
medium?: string;
66
github?: string;
7+
78
custom?: string;
9+
custom_logo_url?: string;
810
}
911

1012
export interface UserData {

studio/src/app/pages/core/app-settings/app-settings.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ app-settings {
2424
div.avatar {
2525
--deckgo-avatar-size: 3rem;
2626

27+
deckgo-lazy-img {
28+
width: 3rem;
29+
height: 3rem;
30+
}
31+
2732
input {
2833
padding-left: 8px;
2934
padding-right: 8px;

studio/src/app/pages/core/app-settings/app-settings.tsx

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import {StorageService} from '../../../services/storage/storage.service';
2323
import {ApiUserFactoryService} from '../../../services/api/user/api.user.factory.service';
2424
import {ThemeService} from '../../../services/theme/theme.service';
2525

26+
import {EnvironmentDeckDeckGoConfig} from '../../../services/core/environment/environment-config';
27+
import {EnvironmentConfigService} from '../../../services/core/environment/environment-config.service';
28+
2629
@Component({
2730
tag: 'app-settings',
2831
styleUrl: 'app-settings.scss',
@@ -56,6 +59,8 @@ export class AppHome {
5659

5760
private profilePicture: File;
5861

62+
private customLogo: File;
63+
5964
private storageService: StorageService;
6065

6166
private themeService: ThemeService;
@@ -81,6 +86,8 @@ export class AppHome {
8186
private destroyUserListener;
8287
private destroyApiUserListener;
8388

89+
private config: EnvironmentDeckDeckGoConfig = EnvironmentConfigService.getInstance().get('deckdeckgo');
90+
8491
constructor() {
8592
this.apiUserService = ApiUserFactoryService.getInstance();
8693
this.imageHistoryService = ImageHistoryService.getInstance();
@@ -243,6 +250,8 @@ export class AppHome {
243250
this.saving = true;
244251

245252
await this.uploadProfilePicture();
253+
await this.uploadCustomLogo();
254+
246255
await this.saveUser();
247256
await this.saveApiUser();
248257

@@ -323,6 +332,37 @@ export class AppHome {
323332
});
324333
}
325334

335+
private uploadCustomLogo(): Promise<void> {
336+
return new Promise<void>(async (resolve, reject) => {
337+
if (!this.valid || !this.user || !this.user.data) {
338+
resolve();
339+
return;
340+
}
341+
342+
if (!this.user.data.social || !this.user.data.social.custom) {
343+
resolve();
344+
return;
345+
}
346+
347+
if (!this.customLogo) {
348+
resolve();
349+
return;
350+
}
351+
352+
try {
353+
const storageFile: StorageFile = await this.storageService.uploadFile(this.customLogo, 'images', 524288);
354+
355+
if (storageFile) {
356+
this.user.data.social.custom_logo_url = storageFile.downloadUrl;
357+
}
358+
359+
resolve();
360+
} catch (err) {
361+
reject('Could not upload your profile picture!');
362+
}
363+
});
364+
}
365+
326366
private async presentConfirmDelete() {
327367
const modal: HTMLIonModalElement = await modalController.create({
328368
component: 'app-user-delete',
@@ -377,21 +417,28 @@ export class AppHome {
377417
});
378418
}
379419

380-
private selectProfilePicture(): Promise<void> {
381-
return new Promise<void>(async (resolve) => {
382-
const filePicker: HTMLInputElement = this.el.querySelector('input#inputProfilePicture');
420+
private async selectProfilePicture() {
421+
const filePicker: HTMLInputElement = this.el.querySelector('input#inputProfilePicture');
383422

384-
if (!filePicker) {
385-
resolve();
386-
return;
387-
}
423+
if (!filePicker) {
424+
return;
425+
}
388426

389-
if (filePicker.files && filePicker.files.length > 0) {
390-
this.profilePicture = filePicker.files[0];
391-
}
427+
if (filePicker.files && filePicker.files.length > 0) {
428+
this.profilePicture = filePicker.files[0];
429+
}
430+
}
392431

393-
resolve();
394-
});
432+
private async selectCustomLogo() {
433+
const filePicker: HTMLInputElement = this.el.querySelector('input#inputCustomLogo');
434+
435+
if (!filePicker) {
436+
return;
437+
}
438+
439+
if (filePicker.files && filePicker.files.length > 0) {
440+
this.customLogo = filePicker.files[0];
441+
}
395442
}
396443

397444
render() {
@@ -732,7 +779,7 @@ export class AppHome {
732779
</ion-item>,
733780
<p>
734781
<small>
735-
Your website or any custom url (for example: <strong>{this.custom ? this.custom : 'https://yourwebsite.com'}</strong>)
782+
Your website or any url (for example: <strong>{this.custom ? this.custom : 'https://yourwebsite.com'}</strong>)
736783
</small>
737784
</p>,
738785
<ion-item>
@@ -744,6 +791,24 @@ export class AppHome {
744791
disabled={this.saving}
745792
onIonInput={($event: CustomEvent<KeyboardEvent>) => this.handleSocialInput($event, 'custom')}></ion-input>
746793
</ion-item>,
794+
795+
<p class="ion-margin-top">
796+
<small>A logo for this custom address</small>
797+
</p>,
798+
<div class="avatar">
799+
{this.user && this.user.data && this.user.data.social && this.user.data.social.custom_logo_url ? (
800+
<app-avatar src={this.user.data.social.custom_logo_url} aria-label="Custom logo"></app-avatar>
801+
) : (
802+
<deckgo-lazy-img slot="icon" svg-src={`${this.config.globalAssetsUrl}/icons/ionicons/globe.svg`} aria-label="Web"></deckgo-lazy-img>
803+
)}
804+
<input
805+
id="inputCustomLogo"
806+
type="file"
807+
accept="image/x-png,image/jpeg,image/gif"
808+
onChange={() => this.selectCustomLogo()}
809+
disabled={this.saving || !this.user || !this.user.data || !this.user.data.social || !this.user.data.social.custom}
810+
/>
811+
</div>,
747812
];
748813
}
749814
}

0 commit comments

Comments
 (0)