]> infiniteadaptability.org Git - workouts/commitdiff
tested with live data
authorAlex-Laptop <[email protected]>
Sun, 7 Apr 2019 02:38:34 +0000 (19:38 -0700)
committerAlex-Laptop <[email protected]>
Sun, 7 Apr 2019 02:38:34 +0000 (19:38 -0700)
src/classes/workout.js
src/components/main/main.js
src/components/manage.row/manage.row.js
src/components/manage/manage.component.js
src/components/manage/manage.css
src/components/manage/manage.js
src/components/recent/recent.component.js
src/components/recent/recent.css
src/components/recent/recent.js
src/reducers/view.js

index 4f0447764babe930fbb5fb7d8b2fb2703ff16f76..66e241241a9e3b708483244c3dc8db55b584f01c 100644 (file)
@@ -81,7 +81,12 @@ export default class workout {
                throw new Error("Not implemented");
        }
        get last_done() {
-               return this.datesDone.slice(0,1);
+               let res = this.datesDone.slice(0,1);
+               if(res.length==0) {
+                       return "";
+               } else {
+                       return res[0];
+               }
        }
        remove(date) {
                for(let i=0;i<this.datesDone.length;i++) {
index eac8cbdec82933fcc620445a6a1cbd4ab1d3b215..e6dd15a803fd3cb02e95008268248651d273c21c 100644 (file)
@@ -3,7 +3,7 @@ import {connect} from 'react-redux';
 import Main from './main.component.js';
 
 import {constants} from '../../constants.js';
-const {CHANGE_VIEW} = constants;
+const {CHANGE_VIEW,SORT_VIEW} = constants;
 
 const mapStateToParentProps = (state) => {
        const {workouts} = state;
@@ -27,6 +27,11 @@ const mapDispatchToProps = (dispatch,ownProps) => {
                                workouts:ownProps.workouts,
                                view
                        });
+                       dispatch({
+                               type:SORT_VIEW,
+                               key:(view=="manage")?"last_done":"date",
+                               shift:false
+                       });
                }
        };
 };
index afc7419a6a446a3e35359f996d805cbb5ca71809..31792f16cf349b9474820dcd261ab42a6f872c74 100644 (file)
@@ -33,15 +33,10 @@ export default class manageRow extends React.Component {
                        "description",
                        "done"
                ].map((field) => {
-                       let val;
                        if(field=="done") {
                                return createElement("td",{key:"cell-"+field},
                                        createElement("input",{type:"button",value:"Completed",onClick:this.completeWorkout})
                                );
-                       } else if(data[field] === void(0)) {
-                               return createElement("td",{key:"cell-attr-"+field,onClick:this.toggleAttribute.bind(this,field)},
-                                       (data.attributes[field])?"Yes":"No"
-                               );
                        } else if(field=="name") {
                                return createElement("td",{key:"cell-"+field},
                                        createElement("input",{defaultValue:data[field],onBlur:this.changeName})
@@ -50,8 +45,12 @@ export default class manageRow extends React.Component {
                                return createElement("td",{key:"cell-"+field},
                                        createElement("textarea",{value:data[field],onChange:this.changeDescription})
                                );
+                       } else if((field=="times_done")||(field=="last_done")) {
+                               return createElement("td",{key:"cell-"+field},data[field]);
                        } else {
-                               return createElement("td",{key:"cell-"+field},val);
+                               return createElement("td",{key:"cell-attr-"+field,onClick:this.toggleAttribute.bind(this,field)},
+                                       (data[field])?"Yes":"No"
+                               );
                        }
                });
                return createElement("tr",null,
index 3281bc0c19ecc7ac7490df50fe04ad2f8077036c..2a94464bc767f2331d82636719b489b1434f1295 100644 (file)
@@ -35,14 +35,14 @@ export default class Manage extends React.Component {
                ].map((x) => {
                        return createElement("th",{key:"head-"+x,onClick:this.handleSort.bind(this,x)},x);
                });
-               const rows = Object.keys(workouts).map((i) => {
+               const rows = workouts.map((i) => {
                        return createElement(manageRow,{
-                               key:"row-"+i,
-                               data:workouts[i],
-                               complete:() => completeWorkout(i),
-                               description:(val) => changeDescription(i,val),
-                               name:(val) => changeName(i,val),
-                               toggle:(attr) => toggleAttribute(i,attr)
+                               key:"row-"+i.name,
+                               data:i,
+                               complete:() => completeWorkout(i.name),
+                               description:(val) => changeDescription(i.name,val),
+                               name:(val) => changeName(i.name,val),
+                               toggle:(attr) => toggleAttribute(i.name,attr)
                        });
                });
                return createElement("div",{className:style.container},
index b0f2cb7fe53cae7fd8a8bb2a34e0834ed959eb90..c6d7d766ac28ad7fd40a18713facdc33fa68c61b 100644 (file)
@@ -1,5 +1,7 @@
 :local(.container) {
-
+       width:100%;
+       height:100%;
+       overflow:scroll;
 }
 
 :local(.container) > input {
index 0741a1b9c4dab75e5b1fa9de6ba393a49753bcb1..5d8f1962863e59626848532068727d424711aad1 100644 (file)
@@ -6,9 +6,8 @@ import {constants} from '../../constants.js';
 const {ADD_WORKOUT,CHANGE_ATTRIBUTE,CHANGE_WORKOUT_DESCRIPTION,CHANGE_WORKOUT_NAME,NEW_WORKOUT,SORT_VIEW} = constants;
 
 const mapStateToProps = (state) => {
-       const {workouts} = state;
        return {
-               workouts
+               workouts:state.view.data
        };
 };
 
index 85c92642c900eba54f6b5f2cb0cd8ddcb87cd0b7..e756a849349574ca94be6cbfddc4c05344444999 100644 (file)
@@ -3,10 +3,17 @@ import style from './recent.css';
 import recentRow from '../recent.row/recent.row.js';
 
 export default class Recent extends React.Component {
+       constructor(props) {
+               super(props);
+               this.handleSort = this.handleSort.bind(this);
+       }
+       handleSort(key,event) {
+               this.props.handleSort(key,event.shiftKey);
+       }
        render() {
-               const {data,handleDateChange} = this.props;
-               const headers = ["workout name","date"].map((x) => {
-                       return createElement("th",{key:"head-"+x},x);
+               const {data,handleDateChange,handleSort} = this.props;
+               const headers = ["name","date"].map((x) => {
+                       return createElement("th",{key:"head-"+x,onClick:this.handleSort.bind(this,x)},x);
                });
                const rows = data.map((i) => {
                        return createElement(recentRow,{
index 1f1752be1b425370c825f752f8e4798b6e29ff71..ea30953b9f6608699057cdcd68e3dae1293badba 100644 (file)
@@ -1,5 +1,7 @@
 :local(.container) {
-
+       width:100%;
+       height:100%;
+       overflow:scroll;
 }
 
 :local(.table) {
index 68c89acea4d3812dc70db908542a5af50a1356bb..1ce502af9d447d67927a0aebe56194e39b948e7d 100644 (file)
@@ -3,11 +3,11 @@ import {connect} from 'react-redux';
 import Recent from './recent.component.js';
 
 import {constants} from '../../constants.js';
-const {CHANGE_WORKOUT_DATE} = constants;
+const {CHANGE_WORKOUT_DATE,SORT_VIEW} = constants;
 
 const mapStateToProps = (state) => {
        return {
-               data:state.view.data
+               data:state.view.data.slice(0,100)
        };
 }
 
@@ -20,6 +20,13 @@ const mapDispatchToProps = (dispatch) => {
                                old,
                                new:date
                        });
+               },
+               handleSort:(key) => {
+                       dispatch({
+                               type:SORT_VIEW,
+                               key,
+                               shift:false
+                       });
                }
        };
 }
index 0c16fd2aac6cab9c2882697aa9a69a6088abbe74..3e503c4d3c37065d5d797080db51b7f9f4d86126 100644 (file)
@@ -19,8 +19,8 @@ const generateDaysAgo = (workouts) => {
        const daysAgo = {...defaultDaysAgo};
        const now = new Date();
        for(let i in workouts) {
-               const last = workouts[i].last_done[0];
-               if(last === void(0)) {
+               const last = workouts[i].last_done;
+               if(last === "") {
                        continue;
                }
                let lastDate = new Date(last);
@@ -52,25 +52,25 @@ export default function view(state = defaultState,action) {
                        }
                        switch(action.view) {
                                case "manage":
-                                       console.log('manage');
                                        const newStateManageView = {
                                                ...state,
                                                view:"manage"
                                        };
                                        newStateManageView.data = [];
-                                       for(let i=0;i<action.workouts.length;i++) {
-                                               newStateManageView.data.push({
-                                                       attributes:actions.workouts[i].attributes,
-                                                       name:actions.workouts[i].name,
-                                                       last_done:actions.workouts[i].last_done,
-                                                       description:actions.workouts[i].description
-                                               });
+                                       for(let i in action.workouts) {
+                                               let toPush = {};
+                                               for(let j in DEFAULT_ATTRIBUTES) {
+                                                       toPush[j] = action.workouts[i].attributes[j];
+                                               }
+                                               toPush.name = action.workouts[i].name;
+                                               toPush.times_done = action.workouts[i].times_done;
+                                               toPush.last_done = action.workouts[i].last_done;
+                                               toPush.description = action.workouts[i].description;
+                                               newStateManageView.data.push(toPush);
                                        }
                                        newStateManageView.daysAgo = generateDaysAgo(action.workouts);
-                                       console.log(JSON.stringify(newStateManageView.data));
                                        return newStateManageView;
                                case "recent":
-                                       console.log('recent');
                                        const newStateRecentView = {
                                                ...state,
                                                view:"recent"
@@ -85,12 +85,12 @@ export default function view(state = defaultState,action) {
                                                }
                                        }
                                        newStateRecentView.daysAgo = generateDaysAgo(action.workouts);
-                                       console.log(JSON.stringify(newStateRecentView.data));
                                        return newStateRecentView;
                                default:
                                        return state;
                        }
                case SORT_VIEW:
+                       console.log(SORT_VIEW);
                        if(action.key === void(0)) {
                                return state;
                        }
@@ -115,11 +115,8 @@ export default function view(state = defaultState,action) {
                        }
                        newStateAfterSort.sortKey = newSortKey;
                        newStateAfterSort.sortOrder = newSortOrder;
-                       console.log(state.data);
-                       console.log(newStateAfterSort.data);
                        newStateAfterSort.data.sort((a,b) => {
                                for(let i=0;i<newSortKey.length;i++) {
-                                       console.log(a[newSortKey[i]],b[newSortKey[i]]);
                                        if(a[newSortKey[i]]<b[newSortKey[i]]) {
                                                return (newSortOrder[i]=="asc")?-1:1;
                                        } else if(a[newSortKey[i]]>b[newSortKey[i]]) {