diff --git a/client/src/app/features/recipes/recipe-details/recipe-details.component.ts b/client/src/app/features/recipes/recipe-details/recipe-details.component.ts index 097788d..398f45d 100644 --- a/client/src/app/features/recipes/recipe-details/recipe-details.component.ts +++ b/client/src/app/features/recipes/recipe-details/recipe-details.component.ts @@ -174,7 +174,6 @@ export class RecipeDetailsComponent implements OnInit { username = this._userService.getCurrentUser()!.name; - // diff with rawValue, then send let to_send = { @@ -218,11 +217,12 @@ export class RecipeDetailsComponent implements OnInit { isShow: (this.rawRecipe as any).isShow, disable: (this.rawRecipe as any).disable, recipes: [...(this.repl.length <= 0 ? [] : this.repl)], - SubMenu: [...((this.rawRecipe! as any).SubMenu!)], - ToppingSet: [...((this.rawRecipe as any).ToppingSet)], + SubMenu: [...(this.rawRecipe! as any).SubMenu!], + ToppingSet: [...(this.rawRecipe as any).ToppingSet], }; - // TODO: update value in targeted recipe + this.concatNoEditKeyToMap(this.rawRecipe, to_send); + console.log('to_send', to_send); this._recipeService.editChanges( await this._recipeService.getCurrentCountry(this.department), @@ -232,7 +232,11 @@ export class RecipeDetailsComponent implements OnInit { } ); console.log('Sending changes'); - void this._router.navigate(['/' + this.department + '/recipes']); + void this._router + .navigate(['/' + this.department + '/recipes']) + .then(() => { + window.location.reload(); + }); }, }; @@ -277,14 +281,27 @@ export class RecipeDetailsComponent implements OnInit { this.tpl = repl[0] as never[]; // check length of toppinglist - console.log("tpl length", this.tpl.length, "original length", (this.rawRecipe! as any).ToppingSet.length); - for(let ti = 0; ti < this.tpl.length; ti++){ + console.log( + 'tpl length', + this.tpl.length, + 'original length', + (this.rawRecipe! as any).ToppingSet.length + ); + for (let ti = 0; ti < this.tpl.length; ti++) { // check at the same index - if(!isEqual(this.tpl[ti][0], (this.rawRecipe as any).ToppingSet[ti])){ - console.log('topping list changed', ti, this.tpl[ti][0], (this.rawRecipe as any).ToppingSet[ti]); + if (!isEqual(this.tpl[ti][0], (this.rawRecipe as any).ToppingSet[ti])) { + console.log( + 'topping list changed', + ti, + this.tpl[ti][0], + (this.rawRecipe as any).ToppingSet[ti] + ); // update raw recipe (this.rawRecipe as any).ToppingSet[ti] = this.tpl[ti][0]; - console.log('after update topping', (this.rawRecipe as any).ToppingSet[ti]); + console.log( + 'after update topping', + (this.rawRecipe as any).ToppingSet[ti] + ); } } @@ -327,5 +344,12 @@ export class RecipeDetailsComponent implements OnInit { console.log('Selected submenu', productCode); } - + // concat remaining unused keys + concatNoEditKeyToMap(source: any, target: any) { + for (const key of Object.keys(source)) { + if (!Object.keys(target).includes(key)) { + target[key] = source[key]; + } + } + } }