Giter VIP home page Giter VIP logo

hyf-react-week4-excercise's Introduction

Hack Your Future - React Week 4 - exercise

The goal of this exercise is to make a multipage todo app. You are provided with a boilerplate, it is up to you to fill in the blanks.

Setup

Project consist out 2 parts out of a backend and frontend.

  • backend can be found in the server directory
  • frontend can be found in the app directory

Install dependencies for both with npm.

cd app
npm install
cd server
npm install

The server uses nodemon to run it's code. Nodemon allows for automatic restarting of the node process when changes occur. Install it globably with:

npm install -g nodemon

Database configuration

The backend uses a mongodb database. But the specific instance of this database is not configured. You will need to configure a connection url for this database.

Obtain a connection url from the instructor or use your own if so desired. Create a file name .env in the server directory.

Now add a new line to it.

CONNECTION_URL=<url_goes_here>

Add a second line to it with as value your name (without any special characters or spaces). This will be your personal database for this exercise.

DATABASE_NAME=<your_name_goes_here>

Now run npm run init from withing the server directory, to seed your database and test if the connection is working.

Available Scripts

Backend

npm start

Starts the backend server on http://localhost:3001.

Frontend

There are more scripts as the frontend is initialized with create-react-app but for this exercise only the useful set is listed.

npm start

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.

Runs the the api at http://localhost:3001.

The page will reload if you make edits and the server will restart. You will also see any lint errors in the console.

Exercise

  1. Implement the resolve button
  • Implement the editTodo in api.js.
  • On click call function
  • If successful refresh the list by fetching it again and updating the state
  1. In the navigation make sure the active page is indicated with a color.
  1. Split up the list by category
  • Remove the overview Route and add 2 new routes to /work and to /private.
  • Instead of component define a render property on the Route.
  • The render property should be implemented with a function that returns the TodoList
  • The TodoList should be returned with a prop categoryand the value being either work or private depending on the route.
  • See https://reacttraining.com/react-router/web/api/Route/render-func for an example.
  • In TodoLisst filter the todos that do not match the category.
    • In the render function, this.state.todos should be filtered with .filter
    • Keep the todos that match this.props.category
  1. Implement the edit button

When the user clicks edit they are redirected to a page with a prefilled form where they can change the description.

  • Add a function onEditClick in the TodoList
  • Add a prop onEditClick to <TodoItem /> in TodoList and set the value to this.onEditClick
  • In TodoList.onEditClick set the id that is passed a first argument to the function to a state variable called editingTodoId with this.setState
  • Import Redirect from react-router-dom in TodoList.js
  • In the render method of TodoList add an if (this.state.editingTodoId) { return <Redirect to={/todos/${this.state.editingTodoId} /> }
  • Copy the TodoForm.js to a file component called EditForm.js.
  • Rename all occurences of TodoForm to EditForm in EditForm.js
  • Add a Route to /todos/:id in TodoNavigation, EditForm will be the component for this route.
  • Implement the getTodo function in api.js
    • This should be a GET fetch to /todos/:id, :id needs to filled in by the argument of the function.
  • In componentDidMount of EditForm you need to call the newly implemented getTodo with the id from the route.
    • make sure the you import the Api from ./api.js in EditForm.js
    • Call the static function getTodo on Api with the id of the todo
    • Check the documentation on how to get the id from the route it is something react-router-dom supports https://reacttraining.com/react-router/web/example/url-params
    • Set the result of the call to a state variable called todo
  • Set the form input values with data from this.state.todo
  • On submit instead of calling Api.addTodo call Api.editTodo.

hyf-react-week4-excercise's People

Contributors

toinne avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.