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

Commit 52d45fe

Browse files
feat: apply deck style on load
1 parent edbc6fd commit 52d45fe

File tree

4 files changed

+60
-32
lines changed

4 files changed

+60
-32
lines changed

studio/src/app/pages/editor/app-editor/app-editor.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {CreateSlidesUtils} from '../../../utils/editor/create-slides.utils';
88

99
import {AuthUser} from '../../../models/auth-user';
1010
import {Slide, SlideTemplate} from '../../../models/slide';
11+
import {Deck} from '../../../models/deck';
12+
13+
import {ParseStyleUtils} from '../../../utils/editor/parse-style.utils';
1114

1215
import {DeckEventsHandler} from '../../../handlers/editor/deck-events/deck-events.handler';
1316

@@ -17,6 +20,7 @@ import {NavDirection, NavService} from '../../../services/nav/nav.service';
1720

1821
import {EditorHelper} from '../../../helpers/editor/editor.helper';
1922
import {DeckAction} from '../../../popovers/editor/app-deck-actions/deck-action';
23+
import {DeckEditorService} from '../../../services/deck/deck-editor.service';
2024

2125
interface FirstSlideContent {
2226
title: string;
@@ -51,10 +55,14 @@ export class AppEditor {
5155
private guestService: GuestService;
5256
private navService: NavService;
5357

58+
private deckEditorService: DeckEditorService;
59+
private deckStyle: any;
60+
5461
constructor() {
5562
this.authService = AuthService.getInstance();
5663
this.guestService = GuestService.getInstance();
5764
this.navService = NavService.getInstance();
65+
this.deckEditorService = DeckEditorService.getInstance();
5866
}
5967

6068
async componentWillLoad() {
@@ -153,10 +161,26 @@ export class AppEditor {
153161
this.slides = [...slides];
154162
}
155163

164+
await this.initDeckStyle();
165+
156166
resolve();
157167
});
158168
}
159169

170+
private initDeckStyle(): Promise<void> {
171+
return new Promise<void>((resolve) => {
172+
this.deckEditorService.watch().pipe(take(1)).subscribe(async (deck: Deck) => {
173+
if (deck && deck.attributes && deck.attributes.style) {
174+
this.deckStyle = await ParseStyleUtils.convertStyle(deck.attributes.style);
175+
} else {
176+
this.deckStyle = undefined;
177+
}
178+
179+
resolve();
180+
});
181+
});
182+
}
183+
160184
private concatSlide(extraSlide: any): Promise<void> {
161185
return new Promise<void>((resolve) => {
162186
this.slides = [...this.slides, extraSlide];
@@ -562,7 +586,7 @@ export class AppEditor {
562586
<app-navigation publish={true}></app-navigation>,
563587
<ion-content padding>
564588
<main class={this.displaying ? 'idle' : undefined}>
565-
<deckgo-deck embedded={true}
589+
<deckgo-deck embedded={true} style={this.deckStyle}
566590
onMouseDown={(e: MouseEvent) => this.deckTouched(e)}
567591
onTouchStart={(e: TouchEvent) => this.deckTouched(e)}
568592
onSlideNextDidChange={() => this.hideToolbar()}

studio/src/app/utils/editor/parse-slides.utils.tsx

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Slide, SlideTemplate} from '../../models/slide';
2+
import {ParseStyleUtils} from './parse-style.utils';
23

34
export class ParseSlidesUtils {
45

@@ -36,7 +37,7 @@ export class ParseSlidesUtils {
3637

3738
const content = await this.parseElements(div, true);
3839

39-
const style = slide.attributes ? await this.convertStyle(slide.attributes.style) : undefined;
40+
const style = slide.attributes ? await ParseStyleUtils.convertStyle(slide.attributes.style) : undefined;
4041

4142
const src = slide.attributes && slide.attributes.src ? slide.attributes.src : undefined;
4243

@@ -86,7 +87,7 @@ export class ParseSlidesUtils {
8687

8788
const attributes: any = this.getAttributes(element);
8889
if (attributes.style) {
89-
attributes.style = await this.convertStyle(attributes.style);
90+
attributes.style = await ParseStyleUtils.convertStyle(attributes.style);
9091
}
9192

9293
if (attributes.slot) {
@@ -97,34 +98,6 @@ export class ParseSlidesUtils {
9798
});
9899
}
99100

100-
private static convertStyle(originalStyle: string): Promise<any> {
101-
return new Promise<any>((resolve) => {
102-
if (!originalStyle || originalStyle.length <= 0) {
103-
resolve(undefined);
104-
return;
105-
}
106-
107-
const result: any = {};
108-
109-
const styles: string[] = originalStyle.split(';');
110-
111-
if (styles && styles.length > 0) {
112-
styles.forEach((style: string) => {
113-
if (style && style.length > 0) {
114-
const split: string[] = style.split(':');
115-
if (split && split.length > 1) {
116-
result[split[0].trim()] = split[1].trim();
117-
} else if (split && split.length > 0) {
118-
result[split[0].trim()] = undefined;
119-
}
120-
}
121-
});
122-
}
123-
124-
resolve(result);
125-
});
126-
}
127-
128101
private static getAttributes(el): any {
129102
if (!el || !el.attributes) {
130103
return {};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export class ParseStyleUtils {
2+
3+
static convertStyle(originalStyle: string): Promise<any> {
4+
return new Promise<any>((resolve) => {
5+
if (!originalStyle || originalStyle.length <= 0) {
6+
resolve(undefined);
7+
return;
8+
}
9+
10+
const result: any = {};
11+
12+
const styles: string[] = originalStyle.split(';');
13+
14+
if (styles && styles.length > 0) {
15+
styles.forEach((style: string) => {
16+
if (style && style.length > 0) {
17+
const split: string[] = style.split(':');
18+
if (split && split.length > 1) {
19+
result[split[0].trim()] = split[1].trim();
20+
} else if (split && split.length > 0) {
21+
result[split[0].trim()] = undefined;
22+
}
23+
}
24+
});
25+
}
26+
27+
resolve(result);
28+
});
29+
}
30+
31+
}

studio/src/components.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import '@stencil/core';
99

1010
import '@ionic/core';
11+
import 'ionicons';
1112
import 'deckdeckgo';
1213
import 'deckdeckgo-inline-editor';
13-
import 'ionicons';
1414
import {
1515
EventEmitter,
1616
} from '@stencil/core';

0 commit comments

Comments
 (0)