|
@@ -1,42 +1,43 @@
|
|
|
import React from 'react';
|
|
import React from 'react';
|
|
|
import Navbar from 'components/Navbar';
|
|
import Navbar from 'components/Navbar';
|
|
|
-import Input from 'components/Input';
|
|
|
|
|
import RecipeForm from 'components/RecipeForm';
|
|
import RecipeForm from 'components/RecipeForm';
|
|
|
|
|
|
|
|
import './styles.scss';
|
|
import './styles.scss';
|
|
|
|
|
|
|
|
-import Recipe, { SubRecipe, Author, Details, _recipe, _subRecipe, _ingredient, Ingredient, DBRecipe } from 'types/recipes';
|
|
|
|
|
|
|
+import { _recipe, _subRecipe, _ingredient, Ingredient, DBRecipe } from 'types/recipes';
|
|
|
import { getRecipeById, updateRecipe } from '../services';
|
|
import { getRecipeById, updateRecipe } from '../services';
|
|
|
import { RouteComponentProps } from 'react-router';
|
|
import { RouteComponentProps } from 'react-router';
|
|
|
|
|
+import Spinner from 'components/Spinner';
|
|
|
|
|
|
|
|
interface EditRecipeProps extends RouteComponentProps<{id: string}> {
|
|
interface EditRecipeProps extends RouteComponentProps<{id: string}> {
|
|
|
-
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
interface EditRecipeState {
|
|
interface EditRecipeState {
|
|
|
form: DBRecipe,
|
|
form: DBRecipe,
|
|
|
|
|
+ loadingRecipe: boolean,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
class EditRecipe extends React.Component<EditRecipeProps, EditRecipeState> {
|
|
class EditRecipe extends React.Component<EditRecipeProps, EditRecipeState> {
|
|
|
constructor(props: EditRecipeProps) {
|
|
constructor(props: EditRecipeProps) {
|
|
|
super(props);
|
|
super(props);
|
|
|
- this.state = {
|
|
|
|
|
|
|
+ this.state = {
|
|
|
form: {
|
|
form: {
|
|
|
..._recipe,
|
|
..._recipe,
|
|
|
_id: '',
|
|
_id: '',
|
|
|
- }
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ loadingRecipe: true,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
componentDidMount = () => {
|
|
componentDidMount = () => {
|
|
|
- getRecipeById(this.props.match.params.id).then(recipe => this.setState({ form: recipe }))
|
|
|
|
|
|
|
+ getRecipeById(this.props.match.params.id).then(recipe =>
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ form: recipe,
|
|
|
|
|
+ loadingRecipe: false,
|
|
|
|
|
+ }))
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- updateOriginal = (ingredient: Ingredient): string => (`
|
|
|
|
|
- ${ingredient.quantity} ${ingredient.unit||''} ${ingredient.unit && 'of'} ${ingredient.name}
|
|
|
|
|
- `);
|
|
|
|
|
-
|
|
|
|
|
saveRecipe = (recipe: DBRecipe) => {
|
|
saveRecipe = (recipe: DBRecipe) => {
|
|
|
updateRecipe(recipe)
|
|
updateRecipe(recipe)
|
|
|
.then((response: any) => {
|
|
.then((response: any) => {
|
|
@@ -53,11 +54,12 @@ class EditRecipe extends React.Component<EditRecipeProps, EditRecipeState> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- const { form } = this.state;
|
|
|
|
|
|
|
+ const { form, loadingRecipe } = this.state;
|
|
|
return (
|
|
return (
|
|
|
<div>
|
|
<div>
|
|
|
|
|
+ { loadingRecipe && (<Spinner/>)}
|
|
|
<Navbar
|
|
<Navbar
|
|
|
- title="Create a recipe"
|
|
|
|
|
|
|
+ title="Edit recipe"
|
|
|
/>
|
|
/>
|
|
|
|
|
|
|
|
<div className="cbk-create-recipe">
|
|
<div className="cbk-create-recipe">
|