-.nyc_output/**
\ No newline at end of file
+.nyc_output/**
+workouts.json
\ No newline at end of file
this.datesDone = [];
this.name = "New Workout";
this.description = "";
+ if(typeof toClone == "object") {
+ if(toClone.attributes !== void(0)) {
+ for(let i in toClone.attributes) {
+ if(toClone.attributes[i] === true) {
+ try {
+ this.toggleAttribute(i);
+ } catch(err) {
+
+ }
+ }
+ }
+ }
+ if(toClone.datesDone !== void(0)) {
+ try {
+ this.add(toClone.datesDone);
+ } catch(err) {
+
+ }
+ }
+ if(toClone.name !== void(0)) {
+ try {
+ this.setName(toClone.name);
+ } catch(err) {
+
+ }
+ }
+ if(toClone.description !== void(0)) {
+ try {
+ this.changeDescription(toClone.description);
+ } catch(err) {
+
+ }
+ }
+ }
}
}
add(dates) { // add new workout to datesDone
export default class Main extends React.Component {
constructor(props) {
super(props);
+ this.save = this.save.bind(this);
this.switchView = this.switchView.bind(this);
+ this.handleKeyPress = this.handleKeyPress.bind(this);
+ }
+ componentDidMount() {
+ document.addEventListener('keydown',this.handleKeyPress);
+ }
+ componentWillUnmount() {
+ document.removeEventListener('keydown',this.handleKeyPress);
+ }
+ handleKeyPress(event) {
+ if(event.ctrlKey) {
+ if(event.key=="s") {
+ this.save();
+ event.preventDefault();
+ }
+ }
+ }
+ save() {
+ const {workouts,save} = this.props;
+ save(workouts);
}
switchView(type) {
this.props.switchView(type);
}
render() {
- const props = this.props;
- const otherView = (props.view=="manage")?"recent":"manage";
+ const {view} = this.props;
+ const otherView = (view=="manage")?"recent":"manage";
return createElement("div",{className:style.container},
createElement("div",{className:style.headerContainer},
createElement(header,null)
createElement("div",{className:style.viewContainer},
createElement(daysAgo,null),
createElement("input",{type:"button",onClick:this.switchView.bind(this,otherView),value:otherView}),
- (props.view=="manage")?createElement(manage,null):createElement(recent,null)
+ createElement("input",{type:"button",onClick:this.save,value:"Save Workouts"}),
+ (view=="manage")?createElement(manage,null):createElement(recent,null)
)
);
}
import {main} from 'components/main/main.js';
-window.workoutsInit = (anchor) => {
+import workout from 'classes/workout.js';
+
+import data from '../workouts.json';
+
+const defaultSaveFunction = (data) => {
+ const content = JSON.stringify(data);
+ var a = document.createElement('a');
+ var blob = new Blob([content], {'type':'application/octet-stream'});
+ a.href = window.URL.createObjectURL(blob);
+ a.download = 'workouts.json';
+ document.body.appendChild(a);
+ a.click();
+ setTimeout(() => {
+ document.body.removeChild(a);
+ window.URL.revokeObjectURL(blob);
+ }, 0);
+};
+
+window.workoutsInit = (anchor,saveCb) => {
if(!(anchor instanceof HTMLElement)) {
throw new Error("Invalid anchor");
}
- const store = createStore(reducers,{});
+ // Import data into store
+ if((data !== void(0))&&(typeof data =="object")) {
+ for(let i in data) {
+ data[i] = new workout(data[i]);
+ }
+ }
+ const store = createStore(reducers,{workouts:data});
+ if(typeof saveCb != "function") {
+ saveCb = defaultSaveFunction;
+ }
render(
createElement(Provider,{store},
- createElement(main,null)
+ createElement(main,{save:saveCb})
),
anchor
);