Quellcode durchsuchen

Fix broken image when editing a recipe

Tatiana Inama vor 6 Jahren
Ursprung
Commit
900a422673

+ 3 - 3
recipes/src/components/ImageUploader/index.tsx

@@ -18,7 +18,7 @@ export const ImageUploader: React.FunctionComponent<ImageUploaderProps> = ({ ini
     image: ''
   });
 
-  const isBase64 = (file: string): boolean => !!file.indexOf('base64');
+  const isBase64 = (file: string): boolean => file.indexOf('base64') !== -1;
 
   const fileInput: React.RefObject<HTMLInputElement> = useRef(null);
 
@@ -41,8 +41,8 @@ export const ImageUploader: React.FunctionComponent<ImageUploaderProps> = ({ ini
   useEffect(() => {
     if(initialValue) {
       setFile({
-        image: isBase64(initialValue) ? initialValue : `${API}/${initialValue}`,
-        name: ''
+        name: '',
+        image: isBase64(initialValue) ? initialValue : `${API}/${initialValue}`
       })
     }
   }, [initialValue])

+ 4 - 5
recipes/src/containers/Recipes/Edit/index.tsx

@@ -30,13 +30,12 @@ class EditRecipe extends React.Component<EditRecipeProps, EditRecipeState> {
   }
 
   componentDidMount = () => {
-    getRecipeById(this.props.match.params.id).then(recipe => 
+    getRecipeById(this.props.match.params.id).then(recipe => {
       this.setState({
         form: recipe,
-      }, () => {
-        this.setState({ loadingRecipe: false })
-      }))
-
+        loadingRecipe: false
+      });
+    });
   }
 
   saveRecipe = (recipe: DBRecipe) => {