Browse Source

feat(lib): take until destroyed

pull/6497/head
KenTandrian 3 weeks ago
parent
commit
c903022878
  1. 15
      libs/ui/src/lib/tags-selector/tags-selector.component.ts

15
libs/ui/src/lib/tags-selector/tags-selector.component.ts

@ -7,11 +7,11 @@ import {
ElementRef, ElementRef,
Input, Input,
OnChanges, OnChanges,
OnDestroy,
OnInit, OnInit,
signal, signal,
ViewChild ViewChild
} from '@angular/core'; } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { import {
ControlValueAccessor, ControlValueAccessor,
FormControl, FormControl,
@ -30,7 +30,7 @@ import { IonIcon } from '@ionic/angular/standalone';
import { Tag } from '@prisma/client'; import { Tag } from '@prisma/client';
import { addIcons } from 'ionicons'; import { addIcons } from 'ionicons';
import { addCircleOutline, closeOutline } from 'ionicons/icons'; import { addCircleOutline, closeOutline } from 'ionicons/icons';
import { BehaviorSubject, Subject, takeUntil } from 'rxjs'; import { BehaviorSubject, Subject } from 'rxjs';
@Component({ @Component({
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
@ -57,7 +57,7 @@ import { BehaviorSubject, Subject, takeUntil } from 'rxjs';
templateUrl: 'tags-selector.component.html' templateUrl: 'tags-selector.component.html'
}) })
export class GfTagsSelectorComponent export class GfTagsSelectorComponent
implements ControlValueAccessor, OnChanges, OnDestroy, OnInit implements ControlValueAccessor, OnChanges, OnInit
{ {
@Input() hasPermissionToCreateTag = false; @Input() hasPermissionToCreateTag = false;
@Input() readonly = false; @Input() readonly = false;
@ -71,11 +71,9 @@ export class GfTagsSelectorComponent
public readonly tagInputControl = new FormControl(''); public readonly tagInputControl = new FormControl('');
public readonly tagsSelected = signal<Tag[]>([]); public readonly tagsSelected = signal<Tag[]>([]);
private unsubscribeSubject = new Subject<void>();
public constructor() { public constructor() {
this.tagInputControl.valueChanges this.tagInputControl.valueChanges
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed())
.subscribe((value) => { .subscribe((value) => {
this.filteredOptions.next(this.filterTags(value ?? '')); this.filteredOptions.next(this.filterTags(value ?? ''));
}); });
@ -154,11 +152,6 @@ export class GfTagsSelectorComponent
this.updateFilters(); this.updateFilters();
} }
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
private filterTags(query: string = ''): Tag[] { private filterTags(query: string = ''): Tag[] {
const tags = this.tagsSelected() ?? []; const tags = this.tagsSelected() ?? [];
const tagIds = tags.map(({ id }) => { const tagIds = tags.map(({ id }) => {

Loading…
Cancel
Save