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

Commit 5ecf832

Browse files
feat(#256): remove debounce when entering tags and prevent enter
1 parent b5c74db commit 5ecf832

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

studio/src/app/components/editor/publish/app-publish-edit/app-publish-edit.tsx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import {ApiUserService} from '../../../../services/api/user/api.user.service';
1515
import {PublishService} from '../../../../services/editor/publish/publish.service';
1616
import {FeedService} from '../../../../services/data/feed/feed.service';
1717

18+
interface CustomInputEvent extends KeyboardEvent {
19+
data: string | null;
20+
}
21+
1822
@Component({
1923
tag: 'app-publish-edit',
2024
styleUrl: 'app-publish-edit.scss'
@@ -246,18 +250,46 @@ export class AppPublishEdit {
246250

247251
private onTagInput($event: CustomEvent<KeyboardEvent>): Promise<void> {
248252
return new Promise<void>((resolve) => {
253+
if (!$event || !$event.detail) {
254+
resolve();
255+
return;
256+
}
257+
258+
if (($event.detail as CustomInputEvent).data === ' ' || ($event.detail as CustomInputEvent).data === ',') {
259+
this.addTag();
260+
resolve();
261+
return;
262+
}
263+
249264
this.tag = ($event.target as InputTargetEvent).value;
250265

251266
resolve();
252267
});
253268
}
254269

255-
private onTagChange() {
270+
private onTagInputKeyUp($event: KeyboardEvent): Promise<void> {
271+
return new Promise<void>((resolve) => {
272+
if (!$event) {
273+
resolve();
274+
return;
275+
}
276+
277+
if ($event.code === 'Enter') {
278+
this.addTag();
279+
}
280+
281+
resolve();
282+
});
283+
}
284+
285+
private addTag() {
256286
if (this.tag && this.tag !== undefined && this.tag !== null && this.tag.length >= 3) {
257287
if (this.tag.charAt(0) === '#') {
258288
this.tag = this.tag.substr(1);
259289
}
260290

291+
this.tag = this.tag.replace(' ', '');
292+
261293
if (this.tags && this.tags.indexOf(this.tag) === -1) {
262294
this.tags = [...this.tags, this.tag.trim()];
263295
this.tag = null;
@@ -305,7 +337,7 @@ export class AppPublishEdit {
305337
<p class="meta-text">But first, edit or review your presentation's title and summary and add or change tags (up to 5) to
306338
make your presentation more inviting to readers.</p>
307339

308-
<form onSubmit={(e: Event) => this.handleSubmit(e)}>
340+
<form onSubmit={(e: Event) => this.handleSubmit(e)} onKeyPress={(e) => { e.key === 'Enter' && e.preventDefault(); }}>
309341
<ion-list class="inputs-list">
310342
<ion-item class="item-title">
311343
<ion-label>Title</ion-label>
@@ -337,8 +369,8 @@ export class AppPublishEdit {
337369
<ion-item>
338370
<ion-input debounce={500} input-mode="text" value={this.tag} placeholder="Add a tag..."
339371
disabled={!this.tags || this.tags.length >= 5 || this.publishing}
340-
onIonInput={(e: CustomEvent<KeyboardEvent>) => this.onTagInput(e)}
341-
onIonChange={() => this.onTagChange()}></ion-input>
372+
onKeyUp={($event: KeyboardEvent) => this.onTagInputKeyUp($event)}
373+
onIonInput={(e: CustomEvent<KeyboardEvent>) => this.onTagInput(e)}></ion-input>
342374
</ion-item>
343375

344376
<app-feed-card-tags tags={this.tags} editable={true} disable-remove={this.publishing} onRemoveTag={($event: CustomEvent) => this.removeTag($event)}></app-feed-card-tags>

0 commit comments

Comments
 (0)