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

Commit 19284b4

Browse files
Merge pull request #792 from deckgo/header-footer-custom-logo
feat: header and footer custom logo
2 parents f4e3a43 + d52ccfc commit 19284b4

File tree

5 files changed

+109
-18
lines changed

5 files changed

+109
-18
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: 87 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,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
}

studio/src/app/utils/editor/header-footer.utils.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class HeaderFooterUtils {
2626
deck.removeChild(currentSlotElement);
2727
}
2828

29-
const promises: Promise<HTMLElement>[] = [this.createContainer(slotName), this.createSocial(user, type), this.createImg(type)];
29+
const promises: Promise<HTMLElement>[] = [this.createContainer(slotName), this.createSocial(user, type), this.createImg(user, type)];
3030
const [div, social, deckgoImg] = await Promise.all(promises);
3131

3232
social.appendChild(deckgoImg);
@@ -60,7 +60,7 @@ export class HeaderFooterUtils {
6060
return socialElement;
6161
}
6262

63-
private static async createImg(type: 'twitter' | 'linkedin' | 'dev' | 'medium' | 'github' | 'custom'): Promise<HTMLElement> {
63+
private static async createImg(user: User, type: 'twitter' | 'linkedin' | 'dev' | 'medium' | 'github' | 'custom'): Promise<HTMLElement> {
6464
const deckgoImg: HTMLElement = document.createElement(SlotType.IMG);
6565
deckgoImg.setAttribute('slot', 'icon');
6666
deckgoImg.setAttribute('aria-label', type);
@@ -71,6 +71,8 @@ export class HeaderFooterUtils {
7171
deckgoImg.setAttribute('svg-src', `${config.globalAssetsUrl}/icons/ionicons/${type}.svg`);
7272
} else if (type === 'medium' || type === 'dev') {
7373
deckgoImg.setAttribute('svg-src', `${config.globalAssetsUrl}/icons/${type}.svg`);
74+
} else if (user.data.social.custom_logo_url !== undefined && user.data.social.custom_logo_url !== '') {
75+
deckgoImg.setAttribute('img-src', user.data.social.custom_logo_url);
7476
} else {
7577
deckgoImg.setAttribute('svg-src', `${config.globalAssetsUrl}/icons/ionicons/globe.svg`);
7678
}

studio/src/app/utils/editor/social.utils.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,23 @@ export class SocialUtils {
4141
}
4242

4343
static createCustom(user: User): JSX.IntrinsicElements {
44-
const config: EnvironmentDeckDeckGoConfig = EnvironmentConfigService.getInstance().get('deckdeckgo');
45-
4644
return (
4745
<deckgo-social slot={`social-link`} fullUrl={user.data.social.custom}>
48-
<deckgo-lazy-img slot="icon" svg-src={`${config.globalAssetsUrl}/icons/ionicons/globe.svg`} aria-label="Web"></deckgo-lazy-img>
46+
{this.createCustomLogo(user)}
4947
</deckgo-social>
5048
);
5149
}
5250

51+
private static createCustomLogo(user: User): JSX.IntrinsicElements {
52+
if (user.data.social.custom_logo_url) {
53+
return <deckgo-lazy-img slot="icon" img-src={user.data.social.custom_logo_url} aria-label="Web"></deckgo-lazy-img>;
54+
}
55+
56+
const config: EnvironmentDeckDeckGoConfig = EnvironmentConfigService.getInstance().get('deckdeckgo');
57+
58+
return <deckgo-lazy-img slot="icon" svg-src={`${config.globalAssetsUrl}/icons/ionicons/globe.svg`} aria-label="Web"></deckgo-lazy-img>;
59+
}
60+
5361
static createGitHub(user: User): JSX.IntrinsicElements {
5462
const config: EnvironmentDeckDeckGoConfig = EnvironmentConfigService.getInstance().get('deckdeckgo');
5563

0 commit comments

Comments
 (0)