From e1479f6078c971861407dc03f654cec1a5e794a4 Mon Sep 17 00:00:00 2001 From: Jesse Brault Date: Thu, 19 Feb 2026 18:11:38 -0600 Subject: [PATCH] MME-34 Remove tanstack from recipe upload page and ai-or-manual step. --- .../recipe-upload-page/recipe-upload-page.ts | 5 --- .../steps/ai-or-manual/ai-or-manual.css | 18 ++++++++++ .../steps/ai-or-manual/ai-or-manual.html | 23 ++++++++----- .../steps/ai-or-manual/ai-or-manual.ts | 34 +++++++++++++------ src/app/shared/services/RecipeDraftService.ts | 12 +++---- 5 files changed, 61 insertions(+), 31 deletions(-) diff --git a/src/app/pages/recipe-upload-page/recipe-upload-page.ts b/src/app/pages/recipe-upload-page/recipe-upload-page.ts index 6a5b58b..9473261 100644 --- a/src/app/pages/recipe-upload-page/recipe-upload-page.ts +++ b/src/app/pages/recipe-upload-page/recipe-upload-page.ts @@ -15,7 +15,6 @@ import { tryMaybeInt } from '../../shared/util'; import { from, map, switchMap, tap } from 'rxjs'; import { Review } from './steps/review/review'; import { RecipeEditFormSubmitEvent } from '../../shared/components/recipe-edit-form/RecipeEditFormSubmitEvent'; -import { QueryClient } from '@tanstack/angular-query-experimental'; import { ToastrService } from 'ngx-toastr'; @Component({ @@ -37,7 +36,6 @@ export class RecipeUploadPage implements OnInit { private readonly router = inject(Router); private readonly activatedRoute = inject(ActivatedRoute); private readonly recipeDraftService = inject(RecipeDraftService); - private readonly queryClient = inject(QueryClient); private readonly toastrService = inject(ToastrService); private isValidStep(step: number): boolean { @@ -163,9 +161,6 @@ export class RecipeUploadPage implements OnInit { protected async onDeleteDraft(): Promise { await this.recipeDraftService.deleteDraft(this.model().draft!.id); - await this.queryClient.invalidateQueries({ - queryKey: ['recipe-upload', 'in-progress-drafts'], - }); await this.switchModel( { inProgressStep: RecipeUploadStep.START, diff --git a/src/app/pages/recipe-upload-page/steps/ai-or-manual/ai-or-manual.css b/src/app/pages/recipe-upload-page/steps/ai-or-manual/ai-or-manual.css index e69de29..5f2122c 100644 --- a/src/app/pages/recipe-upload-page/steps/ai-or-manual/ai-or-manual.css +++ b/src/app/pages/recipe-upload-page/steps/ai-or-manual/ai-or-manual.css @@ -0,0 +1,18 @@ +.in-progress-draft-link, +.in-progress-draft-list-item { + display: flex; + column-gap: 5px; + align-items: baseline; +} + +.in-progress-draft-link * { + cursor: pointer; +} + +.last-saved { + font-size: 0.8em; +} + +.no-title { + font-style: italic; +} diff --git a/src/app/pages/recipe-upload-page/steps/ai-or-manual/ai-or-manual.html b/src/app/pages/recipe-upload-page/steps/ai-or-manual/ai-or-manual.html index c527e63..f47ba50 100644 --- a/src/app/pages/recipe-upload-page/steps/ai-or-manual/ai-or-manual.html +++ b/src/app/pages/recipe-upload-page/steps/ai-or-manual/ai-or-manual.html @@ -1,19 +1,24 @@

Start

- @if (inProgressDrafts.isLoading()) { -

Loading drafts...

- } @else if (inProgressDrafts.isError()) { -

Could not fetch drafts!

- } @else if (inProgressDrafts.isSuccess() && inProgressDrafts.data().length) { + @if (loadingDrafts()) { + + } @else if (drafts().length) {

In Progress Drafts

diff --git a/src/app/pages/recipe-upload-page/steps/ai-or-manual/ai-or-manual.ts b/src/app/pages/recipe-upload-page/steps/ai-or-manual/ai-or-manual.ts index 86e62bb..00955ed 100644 --- a/src/app/pages/recipe-upload-page/steps/ai-or-manual/ai-or-manual.ts +++ b/src/app/pages/recipe-upload-page/steps/ai-or-manual/ai-or-manual.ts @@ -1,29 +1,32 @@ -import { Component, computed, inject, input, output } from '@angular/core'; +import { Component, computed, inject, input, OnInit, output, signal } from '@angular/core'; import { MatButton } from '@angular/material/button'; import { ReactiveFormsModule } from '@angular/forms'; import { AIOrManualSubmitEvent } from './AIOrManualSubmitEvent'; import { FileUpload } from '../../../../shared/components/file-upload/file-upload'; import { FileUploadEvent } from '../../../../shared/components/file-upload/FileUploadEvent'; -import { injectQuery } from '@tanstack/angular-query-experimental'; import { RecipeDraftService } from '../../../../shared/services/RecipeDraftService'; import { FaIconComponent } from '@fortawesome/angular-fontawesome'; import { faFilePen } from '@fortawesome/free-solid-svg-icons'; import { Router } from '@angular/router'; import { RecipeDraftViewModel } from '../../../../shared/models/RecipeDraftView.model'; +import { Spinner } from '../../../../shared/components/spinner/spinner'; +import { ToastrService } from 'ngx-toastr'; +import { DatePipe } from '@angular/common'; @Component({ selector: 'app-ai-or-manual', - imports: [MatButton, ReactiveFormsModule, FileUpload, FaIconComponent], + imports: [MatButton, ReactiveFormsModule, FileUpload, FaIconComponent, Spinner, DatePipe], templateUrl: './ai-or-manual.html', styleUrl: './ai-or-manual.css', }) -export class AiOrManual { +export class AiOrManual implements OnInit { public sourceFile = input.required(); public sourceFileChange = output(); public submitStep = output(); private readonly recipeDraftService = inject(RecipeDraftService); private readonly router = inject(Router); + private readonly toastrService = inject(ToastrService); protected readonly sourceFilesArray = computed(() => { const maybeSourceFile = this.sourceFile(); @@ -34,12 +37,23 @@ export class AiOrManual { } }); - protected readonly inProgressDrafts = injectQuery(() => ({ - queryKey: ['recipe-upload', 'in-progress-drafts'], - queryFn: () => { - return this.recipeDraftService.getInProgressDrafts(); - }, - })); + protected readonly loadingDrafts = signal(false); + protected readonly drafts = signal([]); + + public ngOnInit(): void { + this.loadingDrafts.set(true); + this.recipeDraftService.getInProgressDrafts().subscribe({ + next: (drafts) => { + this.loadingDrafts.set(false); + this.drafts.set(drafts); + }, + error: (e) => { + this.loadingDrafts.set(false); + console.error(e); + this.toastrService.error('There was an error Recipe drafts'); + }, + }); + } protected onFileChange(event: FileUploadEvent) { this.sourceFileChange.emit(event); diff --git a/src/app/shared/services/RecipeDraftService.ts b/src/app/shared/services/RecipeDraftService.ts index 8e1ad71..a733416 100644 --- a/src/app/shared/services/RecipeDraftService.ts +++ b/src/app/shared/services/RecipeDraftService.ts @@ -34,13 +34,11 @@ export class RecipeDraftService { }; } - public getInProgressDrafts(): Promise { - return firstValueFrom( - this.http.get[]>(this.endpointService.getUrl('recipeDrafts')).pipe( - map((rawViews) => { - return rawViews.map((rawView) => this.hydrateView(rawView)); - }), - ), + public getInProgressDrafts(): Observable { + return this.http.get[]>(this.endpointService.getUrl('recipeDrafts')).pipe( + map((rawViews) => { + return rawViews.map((rawView) => this.hydrateView(rawView)); + }), ); }