-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1039 from Aiswarika/exercise-tracker
Added exercise tracker.
- Loading branch information
Showing
13 changed files
with
394 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.App { | ||
text-align: center; | ||
} | ||
|
||
.App-logo { | ||
height: 40vmin; | ||
pointer-events: none; | ||
} | ||
|
||
@media (prefers-reduced-motion: no-preference) { | ||
.App-logo { | ||
animation: App-logo-spin infinite 20s linear; | ||
} | ||
} | ||
|
||
.App-header { | ||
background-color: #282c34; | ||
min-height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: calc(10px + 2vmin); | ||
color: white; | ||
} | ||
|
||
.App-link { | ||
color: #61dafb; | ||
} | ||
|
||
@keyframes App-logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import { BrowserRouter as Router, Route} from "react-router-dom"; | ||
import "bootstrap/dist/css/bootstrap.min.css"; | ||
|
||
import Navbar from "./components/navbar.component"; | ||
import ExercisesList from "./components/exercises-list.component"; | ||
import EditExercise from "./components/edit-exercise.component"; | ||
import CreateExercise from "./components/create-exercise.component"; | ||
import CreateUser from "./components/create-user.component"; | ||
|
||
function App() { | ||
return ( | ||
<Router> | ||
<div className="container"> | ||
<Navbar /> | ||
<br/> | ||
<Route path="/" exact component={ExercisesList} /> | ||
<Route path="/edit/:id" component={EditExercise} /> | ||
<Route path="/create" component={CreateExercise} /> | ||
<Route path="/user" component={CreateUser} /> | ||
</div> | ||
</Router> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Exercise Tracker using Javascript | ||
|
||
# Introduction | ||
|
||
This is a MERN exercise tracker which tracks your daily exercising schedules. | ||
|
||
# Third-Party Libraries Required : | ||
|
||
React - https://www.javatpoint.com/react-installation | ||
Node - https://phoenixnap.com/kb/install-node-js-npm-on-windows | ||
|
||
## Steps to try this | ||
|
||
1. Clone/Download this repository | ||
|
||
``` | ||
git clone clone_path | ||
``` | ||
|
||
## How to use it: | ||
|
||
After Cloning a repository | ||
|
||
1. Open the Exercise Tracker folder | ||
|
||
2. Run index.html file. | ||
|
||
# Output | ||
|
||
## Input Image | ||
|
||
<img src="images/img (3).jpg"> | ||
<img src="images/img (4).jpg"> | ||
|
||
## Output Image | ||
|
||
<img src="images/img (1).jpg"> | ||
<img src="images/img (4).jpg"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import React, { Component } from 'react'; | ||
import axios from 'axios'; | ||
import DatePicker from 'react-datepicker'; | ||
import "react-datepicker/dist/react-datepicker.css"; | ||
|
||
|
||
export default class CreateExercises extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.onChangeUsername = this.onChangeUsername.bind(this); | ||
this.onChangeDescription = this.onChangeDescription.bind(this); | ||
this.onChangeDuration = this.onChangeDuration.bind(this); | ||
this.onChangeDate = this.onChangeDate.bind(this); | ||
this.onSubmit = this.onSubmit.bind(this); | ||
|
||
this.state = { | ||
username: '', | ||
description: '', | ||
duration: 0, | ||
date: new Date(), | ||
users: [] | ||
} | ||
} | ||
|
||
componentDidMount() { | ||
axios.get('http://localhost:5000/users/') | ||
.then(response => { | ||
if (response.data.length > 0) { | ||
this.setState({ | ||
users: response.data.map(user => user.username), | ||
username: response.data[0].username | ||
}) | ||
} | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
}) | ||
|
||
} | ||
|
||
onChangeUsername(e) { | ||
this.setState({ | ||
username: e.target.value | ||
}); | ||
} | ||
|
||
onChangeDescription(e) { | ||
this.setState({ | ||
description: e.target.value | ||
}); | ||
} | ||
|
||
onChangeDuration(e) { | ||
this.setState({ | ||
duration: e.target.value | ||
}); | ||
} | ||
|
||
onChangeDate(date) { | ||
this.setState({ | ||
date: date | ||
}); | ||
} | ||
|
||
onSubmit(e) { | ||
e.preventDefault(); | ||
|
||
const exercise = { | ||
username: this.state.username, | ||
description: this.state.description, | ||
duration: this.state.duration, | ||
date: this.state.date | ||
} | ||
|
||
console.log(exercise); | ||
|
||
axios.post('http://localhost:5000/exercises/add', exercise) | ||
.then(res => console.log(res.data)); | ||
|
||
window.location = '/'; | ||
} | ||
|
||
|
||
render() { | ||
return ( | ||
<div> | ||
<h3>Create New Exercise Log</h3> | ||
<form onSubmit={this.onSubmit}> | ||
<div className="form-group"> | ||
<label>Username: </label> | ||
<select ref="userInput" | ||
required | ||
className="form-control" | ||
value={this.state.username} | ||
onChange={this.onChangeUsername}> | ||
{ | ||
this.state.users.map(function(user) { | ||
return <option | ||
key={user} | ||
value={user}>{user} | ||
</option>; | ||
}) | ||
} | ||
</select> | ||
</div> | ||
<div className="form-group"> | ||
<label>Description: </label> | ||
<input type="text" | ||
required | ||
className="form-control" | ||
value={this.state.description} | ||
onChange={this.onChangeDescription} | ||
/> | ||
</div> | ||
<div className="form-group"> | ||
<label>Duration (in minutes): </label> | ||
<input | ||
type="text" | ||
className="form-control" | ||
value={this.state.duration} | ||
onChange={this.onChangeDuration} | ||
/> | ||
</div> | ||
<div className="form-group"> | ||
<label>Date: </label> | ||
<div> | ||
<DatePicker | ||
selected={this.state.date} | ||
onChange={this.onChangeDate} | ||
/> | ||
</div> | ||
</div> | ||
|
||
<div className="form-group"> | ||
<input type="submit" value="Create Exercise Log" className="btn btn-primary" /> | ||
</div> | ||
</form> | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { Component } from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import axios from 'axios'; | ||
|
||
const Exercise = props => ( | ||
<tr> | ||
<td>{props.exercise.username}</td> | ||
<td>{props.exercise.description}</td> | ||
<td>{props.exercise.duration}</td> | ||
<td>{props.exercise.date.substring(0,10)}</td> | ||
<td> | ||
<Link to={"/edit/"+props.exercise._id}>edit</Link> | <a href="#" onClick={() => { props.deleteExercise(props.exercise._id) }}>delete</a> | ||
</td> | ||
</tr> | ||
) | ||
|
||
|
||
export default class ExercisesList extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.deleteExercise = this.deleteExercise.bind(this) | ||
|
||
this.state = {exercises: []}; | ||
} | ||
|
||
componentDidMount() { | ||
axios.get('http://localhost:5000/exercises/') | ||
.then(response => { | ||
this.setState({ exercises: response.data }) | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
}) | ||
} | ||
|
||
deleteExercise(id) { | ||
axios.delete('http://localhost:5000/exercises/'+id) | ||
.then(response => { console.log(response.data)}); | ||
|
||
this.setState({ | ||
exercises: this.state.exercises.filter(el => el._id !== id) | ||
}) | ||
} | ||
|
||
exerciseList() { | ||
return this.state.exercises.map(currentexercise => { | ||
return <Exercise exercise={currentexercise} deleteExercise={this.deleteExercise} key={currentexercise._id}/>; | ||
}) | ||
} | ||
|
||
|
||
|
||
|
||
render() { | ||
return ( | ||
<div> | ||
<h3>Logged Exercises</h3> | ||
<table className="table"> | ||
<thead className="thead-light"> | ||
<tr> | ||
<th>Username</th> | ||
<th>Description</th> | ||
<th>Duration</th> | ||
<th>Date</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{ this.exerciseList() } | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
) | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
body { | ||
margin: 0; | ||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', | ||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', | ||
sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
} | ||
|
||
code { | ||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', | ||
monospace; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
<meta | ||
name="description" | ||
content="Web site created using create-react-app" | ||
/> | ||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> | ||
|
||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
|
||
<title>Exercise Tracker</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import App from './App'; | ||
|
||
ReactDOM.render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
document.getElementById('root') | ||
); |
Oops, something went wrong.