From 82fdf537d92e6f8e22b884ca33022ad7c8e42d0a Mon Sep 17 00:00:00 2001 From: yudjinn Date: Thu, 27 Aug 2020 12:19:53 -0600 Subject: [PATCH 1/2] Working Put, Delete, and Get for workouts --- .gitignore | 1 + onefit/db.sqlite3 | Bin 192512 -> 192512 bytes onefit/frontend/src/actions/types.js | 2 + onefit/frontend/src/actions/workouts.js | 30 +- .../frontend/src/components/workouts/Form.js | 67 +- .../src/components/workouts/Workouts.js | 20 +- onefit/frontend/src/index.js | 2 +- onefit/frontend/src/reducers/workouts.js | 14 +- onefit/frontend/static/frontend/index.css | 218 +++ onefit/frontend/static/frontend/main.js | 1682 ++++++++++++++++- onefit/frontend/templates/frontend/index.html | 2 + .../users/__pycache__/__init__.cpython-37.pyc | Bin 141 -> 137 bytes onefit/users/__pycache__/admin.cpython-37.pyc | Bin 255 -> 343 bytes onefit/users/__pycache__/apps.cpython-37.pyc | Bin 498 -> 494 bytes onefit/users/__pycache__/forms.cpython-37.pyc | Bin 1423 -> 1419 bytes .../users/__pycache__/models.cpython-37.pyc | Bin 1038 -> 1174 bytes .../users/__pycache__/signals.cpython-37.pyc | Bin 696 -> 692 bytes onefit/users/__pycache__/views.cpython-37.pyc | Bin 1280 -> 1559 bytes .../__pycache__/0001_initial.cpython-37.pyc | Bin 906 -> 902 bytes .../__pycache__/__init__.cpython-37.pyc | Bin 152 -> 148 bytes .../migrations/0011_auto_20200827_1149.py | 18 + onefit/workouts/models.py | 2 +- package-lock.json | 129 +- package.json | 2 + 24 files changed, 2165 insertions(+), 24 deletions(-) create mode 100644 onefit/frontend/static/frontend/index.css create mode 100644 onefit/workouts/migrations/0011_auto_20200827_1149.py diff --git a/.gitignore b/.gitignore index 9afaae2..53b7b13 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .venv .pyenv secret_settings.py +.vscode node_modules diff --git a/onefit/db.sqlite3 b/onefit/db.sqlite3 index 326ec89264d17a358b8fbe22c0f3c1b32e19242f..c38806181596ffb1c93aa7b71a7af795a09cfe72 100644 GIT binary patch delta 453 zcmZp8z}@hGdxEr}4Fdy%J`n2wF%uB4pQvNZYQvys{b6Iu0)A!%4vxv}0`^QC9Ge3L z4zN4eDX=ogT055K7iH&{mJ}Np7#hYWmX_ql8yOfG7+4sY#~T`&Sb{jZ1{S(T<_d;} zRwkBK#uj=e7G?%UMw>k(%ETEtChymGU{q)_*k-`U_JQjP1OHe4SN!++uWT1oU^>UI z#KFZZ$(Wy)nwD9@j$pDOn5>H)C~OO0Vsqf~X5hcdzmmU--+QxQf;E4=E(a@vqpT#d z3oNV*%&km~^ehc63=9nNvlA;zGE(y(#_O_UQ*LTyWTa|rk}*FoH7&D*1;J!S zFqt@+B{?Aq7Clhd7Qn>jz~#@te}#Vqe+|Ds&}eUBO?Vv z3o9d2D+5D4Q&VFz1Eb*7aea&EKAMifNuI0RI(XD*ylh diff --git a/onefit/frontend/src/actions/types.js b/onefit/frontend/src/actions/types.js index 9b7c5f3..d232ce1 100644 --- a/onefit/frontend/src/actions/types.js +++ b/onefit/frontend/src/actions/types.js @@ -1 +1,3 @@ export const GET_WORKOUTS = "GET_WORKOUTS"; +export const DELETE_WORKOUT = "DELETE_WORKOUT"; +export const ADD_WORKOUT = "ADD_WORKOUT"; diff --git a/onefit/frontend/src/actions/workouts.js b/onefit/frontend/src/actions/workouts.js index c0d9e6d..58b63c6 100644 --- a/onefit/frontend/src/actions/workouts.js +++ b/onefit/frontend/src/actions/workouts.js @@ -1,11 +1,11 @@ import axios from "axios"; -import { GET_WORKOUTS } from "./types"; +import { GET_WORKOUTS, DELETE_WORKOUT, ADD_WORKOUT } from "./types"; // GET WORKOUTS export const getWorkouts = () => (dispatch) => { axios - .get("/api/workouts/") + .get(`/api/workouts/`) .then((res) => { dispatch({ type: GET_WORKOUTS, @@ -14,3 +14,29 @@ export const getWorkouts = () => (dispatch) => { }) .catch((err) => console.log(err)); }; + +// DELETE WORKOUT +export const deleteWorkout = (id) => (dispatch) => { + axios + .delete(`/api/workouts/${id}/`) + .then((res) => { + dispatch({ + type: DELETE_WORKOUT, + payload: id, + }); + }) + .catch((err) => console.log(err)); +}; + +// ADD WORKOUT +export const addWorkout = (workout) => (dispatch) => { + axios + .post(`/api/workouts/`, workout) + .then((res) => { + dispatch({ + type: ADD_WORKOUT, + payload: res.data, + }); + }) + .catch((err) => console.log(err)); +}; diff --git a/onefit/frontend/src/components/workouts/Form.js b/onefit/frontend/src/components/workouts/Form.js index 05a3cfa..665aa6f 100644 --- a/onefit/frontend/src/components/workouts/Form.js +++ b/onefit/frontend/src/components/workouts/Form.js @@ -1,13 +1,74 @@ import React, { Component } from "react"; +import DateTime from "react-datetime"; +import moment from "moment"; +import { connect } from "react-redux"; +import PropTypes from "prop-types"; +import { addWorkout } from "../../actions/workouts"; export class Form extends Component { + state = { + user_name: "", + date: moment(), + notes: "", + }; + + static propTypes = { + addWorkout: PropTypes.func.isRequired, + }; + + onChange = (e) => this.setState({ [e.target.name]: e.target.value }); + + onSubmit = (e) => { + e.preventDefault(); + const { user_name, date, notes } = this.state; + const workout = { user_name, date, notes }; + this.props.addWorkout(workout); + }; + render() { + const { user_name, date, notes } = this.state; return ( -
-

Add Workout Form

+
+

Add Workout

+
+
+ + +
+
+ + +
+
+ +