1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

Improve autocomplete closing #558

This commit is contained in:
Patrik J. Braun 2023-03-30 23:46:12 +02:00
parent f2ac6debd9
commit 74e4a8160b

View File

@ -1,33 +1,11 @@
import { import {Component, ElementRef, EventEmitter, forwardRef, Input, OnDestroy, Output, ViewChild,} from '@angular/core';
Component, import {Router, RouterLink} from '@angular/router';
ElementRef, import {BehaviorSubject, Subscription} from 'rxjs';
EventEmitter, import {AutoCompleteService, RenderableAutoCompleteItem,} from '../autocomplete.service';
forwardRef, import {MetadataSearchQueryTypes, SearchQueryTypes,} from '../../../../../../common/entities/SearchQueryDTO';
Input, import {Config} from '../../../../../../common/config/public/Config';
OnDestroy, import {ControlValueAccessor, NG_VALIDATORS, NG_VALUE_ACCESSOR, UntypedFormControl, ValidationErrors, Validator,} from '@angular/forms';
Output, import {AutoCompleteRenderItem} from '../AutoCompleteRenderItem';
ViewChild,
} from '@angular/core';
import { Router, RouterLink } from '@angular/router';
import { BehaviorSubject, Subscription } from 'rxjs';
import {
AutoCompleteService,
RenderableAutoCompleteItem,
} from '../autocomplete.service';
import {
MetadataSearchQueryTypes,
SearchQueryTypes,
} from '../../../../../../common/entities/SearchQueryDTO';
import { Config } from '../../../../../../common/config/public/Config';
import {
ControlValueAccessor,
UntypedFormControl,
NG_VALIDATORS,
NG_VALUE_ACCESSOR,
ValidationErrors,
Validator,
} from '@angular/forms';
import { AutoCompleteRenderItem } from '../AutoCompleteRenderItem';
@Component({ @Component({
selector: 'app-gallery-search-field-base', selector: 'app-gallery-search-field-base',
@ -49,13 +27,12 @@ import { AutoCompleteRenderItem } from '../AutoCompleteRenderItem';
], ],
}) })
export class GallerySearchFieldBaseComponent export class GallerySearchFieldBaseComponent
implements ControlValueAccessor, Validator, OnDestroy implements ControlValueAccessor, Validator, OnDestroy {
{
@Input() placeholder = $localize`Search`; @Input() placeholder = $localize`Search`;
@Output() search = new EventEmitter<void>(); @Output() search = new EventEmitter<void>();
@ViewChild('SearchField', { static: false }) searchField: ElementRef; @ViewChild('SearchField', {static: false}) searchField: ElementRef;
@ViewChild('SearchHintField', { static: false }) searchHintField: ElementRef; @ViewChild('SearchHintField', {static: false}) searchHintField: ElementRef;
autoCompleteRenders: AutoCompleteRenderItem[] = []; autoCompleteRenders: AutoCompleteRenderItem[] = [];
public rawSearchText = ''; public rawSearchText = '';
@ -129,7 +106,7 @@ export class GallerySearchFieldBaseComponent
getAutocompleteToken(): { current: string; prev: string } { getAutocompleteToken(): { current: string; prev: string } {
if (this.rawSearchText.trim().length === 0) { if (this.rawSearchText.trim().length === 0) {
return { current: '', prev: '' }; return {current: '', prev: ''};
} }
const tokens = this.rawSearchText.split(' '); const tokens = this.rawSearchText.split(' ');
return { return {
@ -231,7 +208,8 @@ export class GallerySearchFieldBaseComponent
} }
// eslint-disable-next-line @typescript-eslint/no-empty-function // eslint-disable-next-line @typescript-eslint/no-empty-function
public onTouched(): void {} public onTouched(): void {
}
public writeValue(obj: string): void { public writeValue(obj: string): void {
this.rawSearchText = obj; this.rawSearchText = obj;
@ -250,7 +228,7 @@ export class GallerySearchFieldBaseComponent
} }
validate(control: UntypedFormControl): ValidationErrors { validate(control: UntypedFormControl): ValidationErrors {
return { required: true }; return {required: true};
} }
Scrolled(): void { Scrolled(): void {
@ -259,6 +237,7 @@ export class GallerySearchFieldBaseComponent
} }
private emptyAutoComplete(): void { private emptyAutoComplete(): void {
this.mouseOverAutoComplete = false;
this.highlightedAutoCompleteItem = -1; this.highlightedAutoCompleteItem = -1;
this.autoCompleteRenders = []; this.autoCompleteRenders = [];
} }
@ -314,9 +293,11 @@ export class GallerySearchFieldBaseComponent
} }
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function // eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
private propagateChange = (_: string): void => {}; private propagateChange = (_: string): void => {
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function // eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
private propagateTouch = (_: never): void => {}; private propagateTouch = (_: never): void => {
};
} }