From: Alex-Laptop Date: Sun, 7 Apr 2019 02:38:34 +0000 (-0700) Subject: tested with live data X-Git-Tag: v1.0.0~82 X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=d59d15c7f2326f3df781426c3f6ede2f32f95b0b;p=workouts tested with live data --- diff --git a/src/classes/workout.js b/src/classes/workout.js index 4f04477..66e2412 100644 --- a/src/classes/workout.js +++ b/src/classes/workout.js @@ -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 { 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 + }); } }; }; diff --git a/src/components/manage.row/manage.row.js b/src/components/manage.row/manage.row.js index afc7419..31792f1 100644 --- a/src/components/manage.row/manage.row.js +++ b/src/components/manage.row/manage.row.js @@ -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, diff --git a/src/components/manage/manage.component.js b/src/components/manage/manage.component.js index 3281bc0..2a94464 100644 --- a/src/components/manage/manage.component.js +++ b/src/components/manage/manage.component.js @@ -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}, diff --git a/src/components/manage/manage.css b/src/components/manage/manage.css index b0f2cb7..c6d7d76 100644 --- a/src/components/manage/manage.css +++ b/src/components/manage/manage.css @@ -1,5 +1,7 @@ :local(.container) { - + width:100%; + height:100%; + overflow:scroll; } :local(.container) > input { diff --git a/src/components/manage/manage.js b/src/components/manage/manage.js index 0741a1b..5d8f196 100644 --- a/src/components/manage/manage.js +++ b/src/components/manage/manage.js @@ -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 }; }; diff --git a/src/components/recent/recent.component.js b/src/components/recent/recent.component.js index 85c9264..e756a84 100644 --- a/src/components/recent/recent.component.js +++ b/src/components/recent/recent.component.js @@ -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,{ diff --git a/src/components/recent/recent.css b/src/components/recent/recent.css index 1f1752b..ea30953 100644 --- a/src/components/recent/recent.css +++ b/src/components/recent/recent.css @@ -1,5 +1,7 @@ :local(.container) { - + width:100%; + height:100%; + overflow:scroll; } :local(.table) { diff --git a/src/components/recent/recent.js b/src/components/recent/recent.js index 68c89ac..1ce502a 100644 --- a/src/components/recent/recent.js +++ b/src/components/recent/recent.js @@ -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 + }); } }; } diff --git a/src/reducers/view.js b/src/reducers/view.js index 0c16fd2..3e503c4 100644 --- a/src/reducers/view.js +++ b/src/reducers/view.js @@ -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 { for(let i=0;ib[newSortKey[i]]) {