@@ -23,6 +23,9 @@ import {StorageService} from '../../../services/storage/storage.service';
2323import { ApiUserFactoryService } from '../../../services/api/user/api.user.factory.service' ;
2424import { 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,33 @@ export class AppHome {
744791 disabled = { this . saving }
745792 onIonInput = { ( $event : CustomEvent < KeyboardEvent > ) => this . handleSocialInput ( $event , 'custom' ) } > </ ion-input >
746793 </ ion-item > ,
794+
795+ this . renderCustomLogo ( ) ,
796+ ] ;
797+ }
798+
799+ private renderCustomLogo ( ) {
800+ return [
801+ < p class = "ion-margin-top" >
802+ < small > A logo for this custom address</ small >
803+ </ p > ,
804+ < div class = "avatar" >
805+ { this . user && this . user . data && this . user . data . social && this . user . data . social . custom_logo_url ? (
806+ < deckgo-lazy-img slot = "icon" img-src = { this . user . data . social . custom_logo_url } aria-label = "Custom logo" > </ deckgo-lazy-img >
807+ ) : (
808+ < deckgo-lazy-img
809+ slot = "icon"
810+ svg-src = { `${ this . config . globalAssetsUrl } /icons/ionicons/globe.svg` }
811+ aria-label = "Custom logo image placeholder" > </ deckgo-lazy-img >
812+ ) }
813+ < input
814+ id = "inputCustomLogo"
815+ type = "file"
816+ accept = "image/x-png,image/jpeg,image/gif"
817+ onChange = { ( ) => this . selectCustomLogo ( ) }
818+ disabled = { this . saving || ! this . user || ! this . user . data || ! this . user . data . social || ! this . user . data . social . custom }
819+ />
820+ </ div > ,
747821 ] ;
748822 }
749823}
0 commit comments