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

Commit a6c3dba

Browse files
feat(#96): limit deck.title length to 45 characters
1 parent a740786 commit a6c3dba

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

studio/src/app/components/feed/card/app-feed-card/app-feed-card.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {debounceTime} from 'rxjs/operators';
55

66
import DateTimeFormatOptions = Intl.DateTimeFormatOptions;
77

8+
import {Resources} from '../../../../utils/core/resources';
9+
810
@Component({
911
tag: 'app-feed-card',
1012
styleUrl: 'app-feed-card.scss',
@@ -110,12 +112,30 @@ export class AppFeedCard {
110112
return;
111113
}
112114

113-
const title: string = ($event as InputUIEvent).target.textContent;
115+
let title: string = ($event as InputUIEvent).target.textContent;
114116
if (title && title !== undefined && title !== '') {
117+
118+
if (title.length >= Resources.Constants.DECK.TITLE_MAX_LENGTH) {
119+
title = title.substr(0, Resources.Constants.DECK.TITLE_MAX_LENGTH);
120+
}
121+
115122
this.captionSubject.next(title);
116123
}
117124
}
118125

126+
private onCaptionKeydown($event: KeyboardEvent) {
127+
if ($event && $event.target &&
128+
($event.target as HTMLElement).textContent &&
129+
($event.target as HTMLElement).textContent.length > Resources.Constants.DECK.TITLE_MAX_LENGTH &&
130+
$event.key !== 'Delete' &&
131+
$event.key !== 'Backspace' &&
132+
$event.key !== 'ArrowLeft' &&
133+
$event.key !== 'ArrowRight' &&
134+
!($event.key === 'a' && ($event.metaKey || $event.ctrlKey))) {
135+
$event.preventDefault();
136+
}
137+
}
138+
119139
render() {
120140
return <ion-card class={this.editable ? "ion-no-margin" : undefined}>
121141
{this.renderCardContent()}
@@ -127,7 +147,9 @@ export class AppFeedCard {
127147
{this.renderMiniature()}
128148

129149
<ion-card-header>
130-
<ion-card-title class="ion-text-uppercase" contentEditable={this.editable} onInput={(e: UIEvent) => this.onCaptionInput(e)}>{this.caption}</ion-card-title>
150+
<ion-card-title class="ion-text-uppercase" contentEditable={this.editable}
151+
onInput={(e: UIEvent) => this.onCaptionInput(e)}
152+
onKeyDown={(e: KeyboardEvent) => this.onCaptionKeydown(e)}>{this.caption}</ion-card-title>
131153

132154
<ion-card-subtitle class="ion-text-lowercase">
133155
{this.renderTags()}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {User} from '../../../models/user';
66
import {Deck, DeckAttributes} from '../../../models/deck';
77

88
import {Utils} from '../../../utils/core/utils';
9+
import {Resources} from '../../../utils/core/resources';
910

1011
import {SlideService} from '../../../services/slide/slide.service';
1112
import {DeckService} from '../../../services/deck/deck.service';
@@ -288,6 +289,10 @@ export class DeckEventsHandler {
288289

289290
// TODO: Add a check, we should not update the title from the slide in case it would have been set in the publication
290291

292+
if (title.length >= Resources.Constants.DECK.TITLE_MAX_LENGTH) {
293+
title = title.substr(0, Resources.Constants.DECK.TITLE_MAX_LENGTH);
294+
}
295+
291296
currentDeck.name = title;
292297

293298
const updatedDeck: Deck = await this.deckService.put(currentDeck);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export class Resources {
2+
static get Constants(): any {
3+
return {
4+
DECK: {
5+
TITLE_MAX_LENGTH: 45
6+
}
7+
}
8+
}
9+
}

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)