| @@ -5,8 +5,6 @@ import { HeaderComponent } from "./header/header.component"; | |||||
| import { HomeComponent } from "./home/home.component"; | import { HomeComponent } from "./home/home.component"; | ||||
| import { SharedModule } from "../shared/shared.module"; | import { SharedModule } from "../shared/shared.module"; | ||||
| import { AppRoutingModule } from "../app-routing.module"; | import { AppRoutingModule } from "../app-routing.module"; | ||||
| import { RecipeService } from "../recipes/recipe.service"; | |||||
| import { DataStorageService } from "../shared/data-storage.service"; | |||||
| import { AuthInterceptor } from "../shared/auth.interceptor"; | import { AuthInterceptor } from "../shared/auth.interceptor"; | ||||
| import { LoggingInterceptor } from "../shared/logging.interceptor"; | import { LoggingInterceptor } from "../shared/logging.interceptor"; | ||||
| @@ -24,8 +22,6 @@ import { LoggingInterceptor } from "../shared/logging.interceptor"; | |||||
| HeaderComponent | HeaderComponent | ||||
| ], | ], | ||||
| providers: [ | providers: [ | ||||
| RecipeService, | |||||
| DataStorageService, | |||||
| {provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true}, | {provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true}, | ||||
| {provide: HTTP_INTERCEPTORS, useClass: LoggingInterceptor, multi: true} | {provide: HTTP_INTERCEPTORS, useClass: LoggingInterceptor, multi: true} | ||||
| ], | ], | ||||
| @@ -2,7 +2,6 @@ import { Component, OnInit } from "@angular/core"; | |||||
| import { Store } from "@ngrx/store"; | import { Store } from "@ngrx/store"; | ||||
| import { Observable } from "rxjs/Observable"; | import { Observable } from "rxjs/Observable"; | ||||
| import { DataStorageService } from "../../shared/data-storage.service"; | |||||
| import * as fromApp from '../../ngrx/app.reducers'; | import * as fromApp from '../../ngrx/app.reducers'; | ||||
| import * as fromAuth from '../../auth/ngrx/auth.reducers'; | import * as fromAuth from '../../auth/ngrx/auth.reducers'; | ||||
| import * as AuthActions from '../../auth/ngrx/auth.actions'; | import * as AuthActions from '../../auth/ngrx/auth.actions'; | ||||
| @@ -15,7 +14,7 @@ import * as RecipeActions from '../../recipes/ngrx/recipe.actions'; | |||||
| export class HeaderComponent implements OnInit { | export class HeaderComponent implements OnInit { | ||||
| authState: Observable<fromAuth.State>; | authState: Observable<fromAuth.State>; | ||||
| constructor(private dataStorageService: DataStorageService, private store: Store<fromApp.AppState>) {} | |||||
| constructor(private store: Store<fromApp.AppState>) {} | |||||
| ngOnInit() { | ngOnInit() { | ||||
| this.authState = this.store.select('auth') | this.authState = this.store.select('auth') | ||||
| @@ -7,7 +7,7 @@ import { Recipe } from '../recipe.model'; | |||||
| import * as ShoppingListActions from '../../shopping-list/ngrx/shopping-list.actions'; | import * as ShoppingListActions from '../../shopping-list/ngrx/shopping-list.actions'; | ||||
| import * as fromApp from '../../ngrx/app.reducers'; | import * as fromApp from '../../ngrx/app.reducers'; | ||||
| import * as fromRecipe from '../ngrx/recipe.reducers'; | import * as fromRecipe from '../ngrx/recipe.reducers'; | ||||
| import * as RecipeACtions from '../ngrx/recipe.actions'; | |||||
| import * as RecipeActions from '../ngrx/recipe.actions'; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-recipe-detail', | selector: 'app-recipe-detail', | ||||
| @@ -45,7 +45,7 @@ export class RecipeDetailComponent implements OnInit { | |||||
| } | } | ||||
| onDelete() { | onDelete() { | ||||
| this.store.dispatch(new RecipeACtions.DeleteRecipe(this.id)); | |||||
| this.store.dispatch(new RecipeActions.DeleteRecipe(this.id)); | |||||
| this.router.navigate(['/recipes']); | this.router.navigate(['/recipes']); | ||||
| } | } | ||||
| } | } | ||||
| @@ -3,9 +3,6 @@ import { Router, ActivatedRoute } from '@angular/router'; | |||||
| import { Store } from '@ngrx/store'; | import { Store } from '@ngrx/store'; | ||||
| import { Observable } from 'rxjs/Observable'; | import { Observable } from 'rxjs/Observable'; | ||||
| import { Recipe } from '../recipe.model'; | |||||
| import { RecipeService } from '../recipe.service'; | |||||
| import * as fromRecipe from '../ngrx/recipe.reducers'; | import * as fromRecipe from '../ngrx/recipe.reducers'; | ||||
| @Component({ | @Component({ | ||||
| @@ -1,19 +0,0 @@ | |||||
| import { EventEmitter } from "@angular/core"; | |||||
| import { Subject } from "rxjs/Subject"; | |||||
| import { Recipe } from "./recipe.model"; | |||||
| import { Ingredient } from "../shared/ingredient.model"; | |||||
| export class RecipeService { | |||||
| recipesChanged = new Subject<Recipe[]>(); | |||||
| private recipes: Recipe[] = []; | |||||
| replaceRecipes(recipes: Recipe[]) { | |||||
| this.recipes = recipes; | |||||
| this.recipesChanged.next(this.recipes.slice()); | |||||
| } | |||||
| getRecipes() { | |||||
| return this.recipes.slice(); | |||||
| } | |||||
| } | |||||
| @@ -1,7 +1,5 @@ | |||||
| import { Component, OnInit } from '@angular/core'; | import { Component, OnInit } from '@angular/core'; | ||||
| import { RecipeService } from './recipe.service'; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-recipes', | selector: 'app-recipes', | ||||
| templateUrl: './recipes.component.html', | templateUrl: './recipes.component.html', | ||||
| @@ -1,29 +0,0 @@ | |||||
| import { Injectable } from '@angular/core'; | |||||
| import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http'; | |||||
| import { RecipeService } from '../recipes/recipe.service'; | |||||
| import { Recipe } from '../recipes/recipe.model'; | |||||
| @Injectable() | |||||
| export class DataStorageService { | |||||
| readonly baseUrl: string = 'https://my-recipe-book-cb837.firebaseio.com/'; | |||||
| constructor(private httpClient: HttpClient, | |||||
| private recipeService: RecipeService) {} | |||||
| storeRecipes() { | |||||
| // const token = this.authService.getToken(); | |||||
| // return this.httpClient.put(this.baseUrl + 'recipes.json?auth=' + token, this.recipeService.getRecipes()); | |||||
| // const req = new HttpRequest('PUT', this.baseUrl, this.recipeService.getRecipes(), {reportProgress: true, params: new HttpParams().set('auth', token)}); | |||||
| // return this.httpClient.request(req); | |||||
| return this.httpClient.put(this.baseUrl + 'recipes.json', this.recipeService.getRecipes()); | |||||
| } | |||||
| fetchRecipes() { | |||||
| this.httpClient.get<Recipe[]>(this.baseUrl + 'recipes.json').subscribe( | |||||
| recipes => { | |||||
| this.recipeService.replaceRecipes(recipes); | |||||
| } | |||||
| ) | |||||
| } | |||||
| } | |||||