update recipe endpoint

This commit is contained in:
Kenta420-Poom 2023-09-25 16:59:10 +07:00
parent 9e8efa4cfc
commit e4fdf19c67
5 changed files with 76 additions and 14 deletions

View file

@ -14,6 +14,7 @@ import { DatePipe, NgFor, NgIf } from '@angular/common';
import { Recipe, Recipe01 } from 'src/app/core/models/recipe.model';
import { RecipeService } from 'src/app/core/services/recipe.service';
import { BehaviorSubject } from 'rxjs';
import { environment } from 'src/environments/environment';
@Component({
selector: 'app-dashboard',
@ -40,6 +41,9 @@ export class DashboardComponent implements OnInit {
isLoadMore: boolean = false;
isHasMore: boolean = true;
private searchStr = '';
private oldSearchStr = '';
@ViewChild('table', { static: false }) set content(table: ElementRef) {
table.nativeElement.addEventListener(
'scroll',
@ -56,6 +60,7 @@ export class DashboardComponent implements OnInit {
.getRecipes({
offset: this.offset,
take: this.take,
search: this.oldSearchStr,
})
.subscribe(({ recipes, hasMore }) => {
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
@ -92,6 +97,7 @@ export class DashboardComponent implements OnInit {
.getRecipes({
offset: this.offset,
take: this.take,
search: this.oldSearchStr,
})
.subscribe(({ recipes, hasMore }) => {
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
@ -109,4 +115,35 @@ export class DashboardComponent implements OnInit {
this.isHasMore = hasMore;
});
}
setSearch(event: Event) {
this.searchStr = (event.target as HTMLInputElement).value;
}
search(event: Event) {
this.offset = 0;
this.oldSearchStr = this.searchStr;
this._recipeService
.getRecipes({
offset: this.offset,
take: this.take,
search: this.searchStr,
})
.subscribe(({ recipes, hasMore }) => {
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
this.recipes01 = Recipe01;
this.recipes = {
...recipesWithoutRecipe01,
Recipe01: [],
};
this.offset += 10;
this.isLoaded = true;
this.isHasMore = hasMore;
});
}
openJsonTab() {
window.open(environment.api + '/recipes/json', '_blank');
}
}