Parcourir la source

Clean up actions. Fix action types

Tatiana Inama il y a 7 ans
Parent
commit
5d292550de

+ 3 - 14
recipes/src/containers/Recipes/Create/actions.ts

@@ -1,34 +1,23 @@
 import Recipe from 'types/recipes';
 import { scrapeRecipe as Scrape } from '../services';
 import { SCRAPE_RECIPE, RECEIVE_SCRAPE, INVALID_SCRAPE } from './types';
-import { bindActionCreators } from 'redux';
 
 const scrapeRecipe = (url: string) => ({
   type: SCRAPE_RECIPE,
-  scrape: url,
-  fromScrape: true,
-  isFetching: true,
-  didInvalidate: false,
+  url
 });
 
-const receiveScrape = (json: Recipe) => ({
+const receiveScrape = (data: Recipe) => ({
   type: RECEIVE_SCRAPE,
-  isFetching: false,
-  didInvalidate: false,
-  initialState: json,
-  data: json,
+  data,
 });
 
 const invalidateScrape = (error: any) => ({
   type: INVALID_SCRAPE,
-  fromScrape: false,
-  isFetching: false,
-  didInvalidate: true,
   error,
 });
 
 export const fetchScrape = (url: string) => (dispatch: any) => {
-  console.log("fetching");
   dispatch(scrapeRecipe(url));
   return Scrape(url)
     .then(data => dispatch(receiveScrape(data)))

+ 1 - 1
recipes/src/containers/Recipes/Create/index.tsx

@@ -6,7 +6,7 @@ import Btn from 'components/Button';
 import Input from 'components/Input';
 import TagInput from 'components/TagInput';
 import { Form as IngredientForm } from 'components/Ingredient';
-import CreateFormActions, { fetchScrape } from './actions';
+import { fetchScrape } from './actions';
 import { connect } from 'react-redux';
 import { CreateState } from './types';
 

+ 3 - 1
recipes/src/containers/Recipes/Create/reducers.ts

@@ -4,6 +4,7 @@ const initialState: CreateState = {
   data: {},
   initialState: {},
   fromScrape: false,
+  scrapeUrl: null,
   fetchingScrape: false,
   invalidScrape: false,
 };
@@ -19,6 +20,7 @@ export const createReducer = (
         fromScrape: true,
         fetchingScrape: true,
         invalidScrape: false,
+        scrapeUrl: action.url,
       }
     case RECEIVE_SCRAPE:
       return {
@@ -33,7 +35,7 @@ export const createReducer = (
         ...state,
         fetchingScrape: false,
         invalidScrape: true,
-        fromScrape: false
+        fromScrape: false,
       }
     default:
       return state

+ 3 - 9
recipes/src/containers/Recipes/Create/types.ts

@@ -13,30 +13,24 @@ export const SELECT_SUGGESTION = 'SELECT_SUGGESTION';
 
 interface ScrapeRecipeAction {
   type: typeof SCRAPE_RECIPE,
-  scrape: string,
-  fromScrape: boolean,
-  fetchingScrape: boolean,
-  invalidScrape: boolean,
+  url: string
 }
 
 interface ReceiveScrapeAction {
   type: typeof RECEIVE_SCRAPE,
-  fetchingScrape: boolean,
-  invalidScrape: boolean,
-  initialState: Recipe,
   data: Recipe,
 }
 
 interface InvalidScrapeAction {
   type: typeof INVALID_SCRAPE,
-  fetchingScrape: boolean,
-  invalidScrape: boolean,
+  error: any
 }
 
 export interface CreateState {
   data: Recipe|{},
   initialState: Recipe|{},
   fromScrape: boolean,
+  scrapeUrl: string|null,
   fetchingScrape: boolean,
   invalidScrape: boolean
 }