- {{ date | date : "dd MMM yyyy" }}
+ {{ date | date : "dd MMM yyyy HH:mm:ss" }}
();
@@ -42,6 +43,21 @@ export class LayoutComponent implements OnInit {
this._userService.currentUser
.pipe(takeUntil(this.exit$))
.subscribe((user) => (this.user = user));
+
+ this.clockSubscription = timer(0, 1000)
+ .pipe(
+ map(() => new Date()),
+ share()
+ )
+ .subscribe((time) => {
+ this.date = time;
+ });
+ }
+
+ ngOnDestroy() {
+ this.exit$.next();
+ this.exit$.complete();
+ this.clockSubscription?.unsubscribe();
}
logout() {
diff --git a/client/src/app/core/services/recipe.service.ts b/client/src/app/core/services/recipe.service.ts
index c6a4509..21abd16 100644
--- a/client/src/app/core/services/recipe.service.ts
+++ b/client/src/app/core/services/recipe.service.ts
@@ -1,6 +1,6 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
-import { BehaviorSubject, Observable, distinctUntilChanged } from 'rxjs';
+import { BehaviorSubject, Observable, distinctUntilChanged, tap } from 'rxjs';
import { Recipe, Recipe01 } from '../models/recipe.model';
import { environment } from 'src/environments/environment';
@@ -20,27 +20,44 @@ export class RecipeService {
take: 10,
offset: 0,
search: '',
- version: 'coffeethai02_580.json',
+ version: this.getCurrentVersion(),
}
): Observable<{
fileName: string;
recipes: Recipe;
hasMore: boolean;
}> {
- return this._httpClient.get<{
- fileName: string;
- recipes: Recipe;
- hasMore: boolean;
- }>(environment.api + '/recipes', {
- params: {
- offset: params.offset,
- take: params.take,
- search: params.search,
- version: params.version,
- },
- withCredentials: true,
- responseType: 'json',
- });
+ return this._httpClient
+ .get<{
+ fileName: string;
+ recipes: Recipe;
+ hasMore: boolean;
+ }>(environment.api + '/recipes', {
+ params: {
+ offset: params.offset,
+ take: params.take,
+ search: params.search,
+ version: params.version,
+ },
+ withCredentials: true,
+ responseType: 'json',
+ })
+ .pipe(
+ tap((data) => {
+ if (data.fileName !== this.getCurrentVersion()) {
+ localStorage.setItem('currentRecipeVersion', data.fileName);
+ }
+ })
+ );
+ }
+
+ getCurrentVersion(): string {
+ const currentRecipeVersion = localStorage.getItem('currentRecipeVersion');
+ if (currentRecipeVersion) {
+ return currentRecipeVersion;
+ }
+
+ return 'coffeethai02_580.json';
}
getRecipesById(id: string): Observable {
diff --git a/client/src/app/features/dashboard/dashboard.component.ts b/client/src/app/features/dashboard/dashboard.component.ts
index effe437..ed57892 100644
--- a/client/src/app/features/dashboard/dashboard.component.ts
+++ b/client/src/app/features/dashboard/dashboard.component.ts
@@ -5,7 +5,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 { environment } from 'src/environments/environment';
-import { RecipeModalComponent } from 'src/app/shared/modal/recipe-modal.component';
+import { RecipeModalComponent } from 'src/app/shared/modal/recipe-details/recipe-modal.component';
import { BehaviorSubject } from 'rxjs';
import * as lodash from 'lodash';
@@ -32,7 +32,6 @@ export class DashboardComponent implements OnInit {
private offset = 0;
private take = 20;
private recipeVersionData: string[] = [];
- private currentRecipeVersion: string = 'coffeethai02_580.json';
recipeVersion: BehaviorSubject = new BehaviorSubject('');
recipeVersion$ = this.recipeVersion.asObservable();
@@ -61,7 +60,7 @@ export class DashboardComponent implements OnInit {
offset: this.offset,
take: this.take,
search: this.oldSearchStr,
- version: this.currentRecipeVersion,
+ version: this._recipeService.getCurrentVersion(),
})
.subscribe(({ recipes, hasMore, fileName }) => {
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
@@ -100,7 +99,7 @@ export class DashboardComponent implements OnInit {
offset: this.offset,
take: this.take,
search: this.oldSearchStr,
- version: this.currentRecipeVersion,
+ version: this._recipeService.getCurrentVersion(),
})
.subscribe(({ recipes, hasMore, fileName }) => {
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
@@ -139,7 +138,7 @@ export class DashboardComponent implements OnInit {
offset: this.offset,
take: this.take,
search: this.searchStr,
- version: this.currentRecipeVersion,
+ version: this._recipeService.getCurrentVersion(),
})
.subscribe(({ recipes, hasMore, fileName }) => {
const { Recipe01, ...recipesWithoutRecipe01 } = recipes;
@@ -165,7 +164,6 @@ export class DashboardComponent implements OnInit {
this.isHasMore = true;
this.isLoadMore = false;
this.oldSearchStr = '';
- this.currentRecipeVersion = recipeVersion;
this._recipeService
.getRecipes({
@@ -206,7 +204,8 @@ export class DashboardComponent implements OnInit {
openJsonTab() {
window.open(
- environment.api + `/recipes/${this.currentRecipeVersion}/json`,
+ environment.api +
+ `/recipes/${this._recipeService.getCurrentVersion()}/json`,
'_blank'
);
}
diff --git a/client/src/app/shared/modal/confirm/confirm-modal.component.ts b/client/src/app/shared/modal/confirm/confirm-modal.component.ts
new file mode 100644
index 0000000..cd3d570
--- /dev/null
+++ b/client/src/app/shared/modal/confirm/confirm-modal.component.ts
@@ -0,0 +1,57 @@
+import {
+ Component,
+ ElementRef,
+ EventEmitter,
+ Input,
+ OnInit,
+ Output,
+ ViewChild,
+} from '@angular/core';
+
+@Component({
+ selector: 'confirm-modal',
+ template: ``,
+ standalone: true,
+})
+export class ConfirmModal implements OnInit {
+ @Input() show: EventEmitter = new EventEmitter();
+ @Input() title: string = 'Confirm Dialog';
+ @Input() message: string =
+ 'This is Confirm Modal. You can change message by using message input';
+ @Input() confirmCallBack: () => void = () => {};
+
+ private confirmModal: ElementRef | null = null;
+
+ @ViewChild('confirmModal', { static: false }) set setConfirmModal(
+ modal: ElementRef
+ ) {
+ this.confirmModal = modal;
+ }
+
+ constructor() {}
+
+ ngOnInit() {
+ this.show.subscribe((show) => {
+ if (show) {
+ this.confirmModal?.nativeElement.showModal();
+ } else {
+ this.confirmModal?.nativeElement.close();
+ }
+ });
+ }
+
+ close() {
+ this.confirmModal?.nativeElement.close();
+ }
+}
diff --git a/client/src/app/shared/modal/recipe-modal.component.html b/client/src/app/shared/modal/recipe-details/recipe-modal.component.html
similarity index 86%
rename from client/src/app/shared/modal/recipe-modal.component.html
rename to client/src/app/shared/modal/recipe-details/recipe-modal.component.html
index 01e3870..7ef38fb 100644
--- a/client/src/app/shared/modal/recipe-modal.component.html
+++ b/client/src/app/shared/modal/recipe-details/recipe-modal.component.html
@@ -97,23 +97,22 @@