Skip to content

Recipe project#2

Open
FVenneri wants to merge 31 commits into
masterfrom
recipe-project
Open

Recipe project#2
FVenneri wants to merge 31 commits into
masterfrom
recipe-project

Conversation

@FVenneri

@FVenneri FVenneri commented Jul 6, 2020

Copy link
Copy Markdown
Owner

FE for Django API:

  • CRUD for Recipes/Ingredients/Tags APIs
  • Handled login
  • Manual styling with styled-components
  • Few basic unit tests (very few)

Francesco Venneri added 30 commits June 26, 2020 11:40
Comment thread recipe-hooks-project/src/App.css Outdated
@@ -0,0 +1,44 @@
/*.App {*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our projects we would block a PR leaving commented code 😄

jest.mock("axios");

afterEach(() => {
cleanup()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to do this anymore, testing-library automatically invokes cleanup after each test now

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know that!

@@ -0,0 +1,134 @@
import React from "react";
import {cleanup, fireEvent, render} from "@testing-library/react";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add waitForElement to the imports from this file (and remove it from @testing-library/dom)

expect(container.querySelector("input[name=email]")).toBeInTheDocument();
});

// test("an user can logout", () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't leave commented code, not even for tests 😉

margin-top: 50px;
`;

const Image = styled.img.attrs(props => ({

@giuband giuband Jul 8, 2020

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the .attrs(props => ({ ...props }) part, it can just be

styled.img`max-width: 70;`

Comment thread recipe-hooks-project/src/Ingredients.js Outdated
addingIngredient
? <form onSubmit={handleNewIngredientCreation}>
<Input type="text" id="ingredientInput" value={newIngredient} onChange={handleNewIngredientChange}/>
<Button primary onClick={handleNewIngredientCreation}><span>Create</span></Button>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably wouldn't need that inner span node

return (
<Route
render={() =>
token !== null

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably token !== null is a bit too strict, could just be token ? <>{/* private */}</> : <>{/* public */}</>

import RecipeDetails from "./RecipeDetails";
import {AuthContext} from "./contexts/AuthenticationProvider";

export function PrivateRoutes() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file is called PrivateRoutes but it actually contains the public too, why not calling it just Routes?

Comment thread recipe-hooks-project/src/Profile.js Outdated
}

async function modifyUser(password, name) {
if ((name === "" || name === undefined) && (password === "" || password === undefined))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(name === "" || name === undefined) => (!name) (same for password)

Comment thread recipe-hooks-project/src/Recipes.js Outdated
}

async function fetchTags() {
console.log("Fetching tags for: [" + token + "]");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI in our web apps it won't be possible to ship code calling console.log (I've seen it being used quite a lot in this project)

Comment thread recipe-hooks-project/src/Recipes.js Outdated
return (
<option key={i} value={item.id}>{item.name}</option>
)
}, this)}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the this argument here, because:

Comment thread recipe-hooks-project/src/Register.js Outdated
}
}

const renderRedirect = () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't put this as a function, I'd just add the if inside the body of the functional component:

if (redirect) return <Redirect />
return (
  <>
    <Container />
  </>
)

background: white;
font-weight: 400;
border: 2px solid red;
-webkit-box-sizing: border-box;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

styled-components will automatically apply autoprefixer to your styles, no need to prefix them on your own

@giuband giuband left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a bunch of comments on what wouldn't have been approved on web or any other FE project of ours, if you have any doubts or questions feel free to reach me out on slack

return (
<>
{renderRedirect()}
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit uncommon to leave a redirect inside the body, I would just put a separate if before this return.

if (redirect) return <Redirect to="/app" />

return (
  <>
    <Container />
  </>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants