Skip to content

Commit

Permalink
fix(front): show add button instantly upon enter valid name into map …
Browse files Browse the repository at this point in the history
…sub placeholder input
  • Loading branch information
tsa96 committed Feb 21, 2024
1 parent 6c24d42 commit 870d2e3
Showing 1 changed file with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {
ControlValueAccessor,
NG_VALUE_ACCESSOR,
FormsModule
FormsModule,
FormControl,
Validators,
ReactiveFormsModule
} from '@angular/forms';
import { Component, forwardRef, QueryList, ViewChildren } from '@angular/core';
import {
Expand All @@ -18,7 +21,7 @@ import {
CdkDrag
} from '@angular/cdk/drag-drop';
import { Enum } from '@momentum/enum';
import { KeyValuePipe } from '@angular/common';
import { KeyValuePipe, NgIf } from '@angular/common';
import { UserSearchComponent } from '../search/user-search/user-search.component';
import { IconComponent } from '../../icons';
import { TooltipDirective } from '../../directives';
Expand All @@ -44,7 +47,9 @@ import { GroupedMapCredits } from '../../util';
UserSearchComponent,
KeyValuePipe,
TooltipDirective,
AvatarComponent
AvatarComponent,
NgIf,
ReactiveFormsModule
]
})
export class MapCreditsSelectionComponent implements ControlValueAccessor {
Expand All @@ -55,6 +60,19 @@ export class MapCreditsSelectionComponent implements ControlValueAccessor {

protected readonly connectedTo = Enum.values(MapCreditType).map(String);

protected readonly placeholderInputs = new Map(
Enum.values(MapCreditType).map((type) => [
type,
new FormControl<string>('', {
validators: [
Validators.required,
Validators.minLength(3),
Validators.maxLength(32)
]
})
])
);

@ViewChildren(TooltipDirective)
tooltips: QueryList<TooltipDirective>;

Expand Down Expand Up @@ -89,14 +107,13 @@ export class MapCreditsSelectionComponent implements ControlValueAccessor {
this.onChange(this.value);
}

addPlaceholder(type: MapCreditType, input: HTMLInputElement) {
const alias = input.value;
input.value = '';
addPlaceholder(type: MapCreditType, input: string) {
this.value[type].push({
user: { alias, avatarURL: STEAM_MISSING_AVATAR_URL },
user: { alias: input, avatarURL: STEAM_MISSING_AVATAR_URL },
type,
placeholder: true
});
this.placeholderInputs.get(type).reset();
this.onChange(this.value);
}

Expand Down

0 comments on commit 870d2e3

Please sign in to comment.