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

Commit b3218d3

Browse files
feat: first editable content of the first slide is the master for the title
1 parent abf4f87 commit b3218d3

File tree

3 files changed

+83
-10
lines changed

3 files changed

+83
-10
lines changed

studio/src/app/components/core/app-menu-user/app-menu-user.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, State} from '@stencil/core';
1+
import {Component, Element, State} from '@stencil/core';
22

33
import {Subscription} from 'rxjs';
44
import {filter} from 'rxjs/operators';
@@ -22,6 +22,8 @@ import {DeckEditorService} from '../../../services/deck/deck-editor.service';
2222
})
2323
export class AppMenuUser {
2424

25+
@Element() el: HTMLElement;
26+
2527
private authService: AuthService;
2628
private authSubscription: Subscription;
2729

@@ -81,6 +83,9 @@ export class AppMenuUser {
8183
componentDidLoad() {
8284
this.deckSubscription = this.deckEditorService.watch().subscribe(async (deck: Deck) => {
8385
await this.updateDeckList(deck);
86+
87+
const filter: string = await this.getCurrentFilter();
88+
await this.filterDecks(filter);
8489
});
8590
}
8691

@@ -159,14 +164,14 @@ export class AppMenuUser {
159164
private filterDecks(value: string): Promise<void> {
160165
return new Promise<void>((resolve) => {
161166
if (!value || value === undefined || value === '') {
162-
this.filteredDecks = [...this.decks];
167+
this.filteredDecks = this.decks ? [...this.decks] : null;
163168

164169
resolve();
165170
return;
166171
}
167172

168173
if (!this.decks || this.decks.length <= 0) {
169-
this.filteredDecks = [...this.decks];
174+
this.filteredDecks = this.decks ? [...this.decks] : null;
170175

171176
resolve();
172177
return;
@@ -182,6 +187,26 @@ export class AppMenuUser {
182187
});
183188
}
184189

190+
private getCurrentFilter(): Promise<string> {
191+
return new Promise<string>(async (resolve) => {
192+
const searchBar: HTMLIonSearchbarElement = this.el.querySelector('ion-searchbar');
193+
194+
if (!searchBar) {
195+
resolve(null);
196+
return;
197+
}
198+
199+
const input: HTMLInputElement = await searchBar.getInputElement();
200+
201+
if (!input) {
202+
resolve(null);
203+
return;
204+
}
205+
206+
resolve(input.value);
207+
});
208+
}
209+
185210
render() {
186211
return <ion-list>
187212
{this.renderUser()}

studio/src/app/handlers/editor/deck-events/deck-events.handler.tsx

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ export class DeckEventsHandler {
2424
private errorService: ErrorService;
2525
private deckBusyService: DeckBusyService;
2626

27-
private userSubscription: Subscription;
2827
private userService: UserService;
2928

3029
private updateSlideSubscription: Subscription;
3130
private updateSlideSubject: Subject<HTMLElement> = new Subject();
3231

3332
private deckEditorService: DeckEditorService;
3433

34+
private updateDeckTitleSubscription: Subscription;
35+
private updateDeckTitleSubject: Subject<string> = new Subject();
36+
3537
constructor() {
3638
this.slideService = SlideService.getInstance();
3739
this.deckService = DeckService.getInstance();
@@ -56,6 +58,10 @@ export class DeckEventsHandler {
5658
this.updateSlideSubscription = this.updateSlideSubject.pipe(debounceTime(500)).subscribe(async (element: HTMLElement) => {
5759
await this.updateSlide(element);
5860
});
61+
62+
this.updateDeckTitleSubscription = this.updateDeckTitleSubject.pipe(debounceTime(500)).subscribe(async (title: string) => {
63+
await this.updateDeckTitle(title);
64+
});
5965
}
6066

6167
destroy() {
@@ -69,8 +75,8 @@ export class DeckEventsHandler {
6975
this.updateSlideSubscription.unsubscribe();
7076
}
7177

72-
if (this.userSubscription) {
73-
this.userSubscription.unsubscribe();
78+
if (this.updateDeckTitleSubscription) {
79+
this.updateDeckTitleSubscription.unsubscribe();
7480
}
7581

7682
this.deckEditorService.next(null);
@@ -87,7 +93,7 @@ export class DeckEventsHandler {
8793
return;
8894
}
8995

90-
await this.updateDeck($event.detail);
96+
await this.updateDeckAttributes($event.detail);
9197
};
9298

9399
private onSlideChange = async ($event: CustomEvent) => {
@@ -103,13 +109,20 @@ export class DeckEventsHandler {
103109
return;
104110
}
105111

106-
const parent: HTMLElement = ($event.target as HTMLElement).parentElement;
112+
const element: HTMLElement = $event.target as HTMLElement;
113+
114+
const parent: HTMLElement = element.parentElement;
107115

108116
if (!parent || !parent.nodeName || parent.nodeName.toLowerCase().indexOf('deckgo-slide') <= -1) {
109117
return;
110118
}
111119

112120
this.updateSlideSubject.next(parent);
121+
122+
// The first content editable element on the first slide is the title of the presentation
123+
if (parent && !parent.previousElementSibling && !element.previousElementSibling) {
124+
this.updateDeckTitleSubject.next(element.textContent);
125+
}
113126
};
114127

115128
private onSlideDelete = async ($event: CustomEvent) => {
@@ -218,7 +231,7 @@ export class DeckEventsHandler {
218231
});
219232
}
220233

221-
private updateDeck(deck: HTMLElement): Promise<void> {
234+
private updateDeckAttributes(deck: HTMLElement): Promise<void> {
222235
return new Promise<void>(async (resolve) => {
223236
try {
224237
if (!deck) {
@@ -238,6 +251,8 @@ export class DeckEventsHandler {
238251

239252
if (attributes && Object.keys(attributes).length > 0) {
240253
currentDeck.attributes = attributes;
254+
} else {
255+
currentDeck.attributes = null;
241256
}
242257

243258
const updatedDeck: Deck = await this.deckService.put(currentDeck);
@@ -255,6 +270,39 @@ export class DeckEventsHandler {
255270
});
256271
}
257272

273+
private updateDeckTitle(title: string): Promise<void> {
274+
return new Promise<void>(async (resolve) => {
275+
try {
276+
if (!title || title === undefined || title === '') {
277+
resolve();
278+
return;
279+
}
280+
281+
this.deckBusyService.busy(true);
282+
283+
this.deckEditorService.watch().pipe(take(1)).subscribe(async (currentDeck: Deck) => {
284+
if (!currentDeck) {
285+
resolve();
286+
return;
287+
}
288+
289+
currentDeck.name = title;
290+
291+
const updatedDeck: Deck = await this.deckService.put(currentDeck);
292+
this.deckEditorService.next(updatedDeck);
293+
294+
this.deckBusyService.busy(false);
295+
296+
resolve();
297+
});
298+
} catch (err) {
299+
this.errorService.error(err);
300+
this.deckBusyService.busy(false);
301+
resolve();
302+
}
303+
});
304+
}
305+
258306
private updateSlide(slide: HTMLElement): Promise<void> {
259307
return new Promise<void>(async (resolve) => {
260308
try {

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';
1211
import 'deckdeckgo';
1312
import 'deckdeckgo-inline-editor';
13+
import 'ionicons';
1414
import {
1515
EventEmitter,
1616
} from '@stencil/core';

0 commit comments

Comments
 (0)