summaryrefslogtreecommitdiff
path: root/public/bundle.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2017-03-19 04:13:21 +0100
committerJules Laplace <jules@okfoc.us>2017-03-19 04:44:04 +0100
commitdc8baa6109b7cc8eac33ba32fdf0f52cfbabd0db (patch)
treef4c5069d9cc5ffb93e7a50699fe70b525aa80916 /public/bundle.js
parent34691ba687be4adefb12864e49d5c5a357e1a74b (diff)
destroy records
Diffstat (limited to 'public/bundle.js')
-rw-r--r--public/bundle.js85
1 files changed, 58 insertions, 27 deletions
diff --git a/public/bundle.js b/public/bundle.js
index 560da90..4725ea1 100644
--- a/public/bundle.js
+++ b/public/bundle.js
@@ -29740,6 +29740,7 @@ var MealList = function (_React$Component4) {
_this5.handleCreate = _this5.handleCreate.bind(_this5);
_this5.handleUpdate = _this5.handleUpdate.bind(_this5);
+ _this5.handleDelete = _this5.handleDelete.bind(_this5);
_this5.pickMeal = _this5.pickMeal.bind(_this5);
_client2.default.service('meals').find({
@@ -29749,7 +29750,6 @@ var MealList = function (_React$Component4) {
token: _client2.default.get('token')
}
}).then(function (data) {
- console.log(data);
_this5.setState(data);
}).catch(function (error) {
console.error(error);
@@ -29770,7 +29770,17 @@ var MealList = function (_React$Component4) {
key: 'handleUpdate',
value: function handleUpdate(meal) {
var meals = this.state.data.map(function (data, i) {
- return data.id == meal.id ? meal : data;
+ return data.id === meal.id ? meal : data;
+ }).sort(sortByDate);
+ this.setState({
+ data: meals
+ });
+ }
+ }, {
+ key: 'handleDelete',
+ value: function handleDelete(mealid) {
+ var meals = this.state.data.filter(function (data, i) {
+ return data.id !== mealid;
}).sort(sortByDate);
this.setState({
data: meals
@@ -29786,11 +29796,11 @@ var MealList = function (_React$Component4) {
value: function render() {
var _this6 = this;
- console.log(this.state.data);
var items = this.state.data.map(function (meal, i) {
return _react2.default.createElement(MealItem, { key: meal.id,
meal: meal,
- onClick: _this6.pickMeal });
+ onClick: _this6.pickMeal,
+ onDelete: _this6.handleDelete });
});
return _react2.default.createElement(
'div',
@@ -29824,21 +29834,41 @@ var MealItem = function (_React$Component5) {
function MealItem() {
_classCallCheck(this, MealItem);
- return _possibleConstructorReturn(this, (MealItem.__proto__ || Object.getPrototypeOf(MealItem)).apply(this, arguments));
+ var _this7 = _possibleConstructorReturn(this, (MealItem.__proto__ || Object.getPrototypeOf(MealItem)).call(this));
+
+ _this7.remove = _this7.remove.bind(_this7);
+ return _this7;
}
_createClass(MealItem, [{
+ key: 'remove',
+ value: function remove(e) {
+ var _this8 = this;
+
+ e.stopPropagation();
+ var mealid = this.props.meal.id;
+ var mealsService = _client2.default.service('meals');
+ var params = { query: { token: _client2.default.get('token') } };
+ mealsService.remove(mealid, params).then(function (result) {
+ _this8.props.onDelete(mealid);
+ }).catch(function (error) {
+ console.error(error);
+ });
+ }
+ }, {
key: 'render',
value: function render() {
- var _this8 = this;
+ var _this9 = this;
var meal = this.props.meal;
+ // const canEdit = this.props.meal.userid === this.props.currentUser.id ? 'canEdit' : ''
+ var canEdit = 'canEdit';
var date = parseDate(meal.date);
var time = parseTime(meal.time);
return _react2.default.createElement(
'div',
- { className: 'meal', onClick: function onClick() {
- return _this8.props.onClick(meal);
+ { className: 'meal ' + canEdit, onClick: function onClick() {
+ return _this9.props.onClick(meal);
} },
_react2.default.createElement(
'div',
@@ -29860,6 +29890,11 @@ var MealItem = function (_React$Component5) {
'div',
{ className: 'time' },
time
+ ),
+ _react2.default.createElement(
+ 'div',
+ { className: 'remove', onClick: this.remove },
+ 'x'
)
);
}
@@ -29874,9 +29909,9 @@ var MealForm = function (_React$Component6) {
function MealForm(props) {
_classCallCheck(this, MealForm);
- var _this9 = _possibleConstructorReturn(this, (MealForm.__proto__ || Object.getPrototypeOf(MealForm)).call(this));
+ var _this10 = _possibleConstructorReturn(this, (MealForm.__proto__ || Object.getPrototypeOf(MealForm)).call(this));
- _this9.state = {
+ _this10.state = {
id: '',
userid: props.user.id,
name: '',
@@ -29884,9 +29919,9 @@ var MealForm = function (_React$Component6) {
date: new Date(),
time: new Date()
};
- _this9.updateState = _this9.updateState.bind(_this9);
- _this9.handleSubmit = _this9.handleSubmit.bind(_this9);
- return _this9;
+ _this10.updateState = _this10.updateState.bind(_this10);
+ _this10.handleSubmit = _this10.handleSubmit.bind(_this10);
+ return _this10;
}
_createClass(MealForm, [{
@@ -29903,7 +29938,6 @@ var MealForm = function (_React$Component6) {
}, {
key: 'pick',
value: function pick(meal) {
- console.log(meal);
this.setState(meal);
}
}, {
@@ -29938,18 +29972,16 @@ var MealForm = function (_React$Component6) {
}, {
key: 'create',
value: function create() {
- var _this10 = this;
+ var _this11 = this;
var mealsService = _client2.default.service('meals');
var params = { query: { token: _client2.default.get('token') } };
-
mealsService.create(this.state, params).then(function (result) {
- console.log(result);
- _this10.props.onCreate(result);
- _this10.reset();
+ _this11.props.onCreate(result);
+ _this11.reset();
}).catch(function (error) {
console.error(error);
- _this10.setState({
+ _this11.setState({
error: error.toString()
});
});
@@ -29957,18 +29989,17 @@ var MealForm = function (_React$Component6) {
}, {
key: 'update',
value: function update() {
- var _this11 = this;
+ var _this12 = this;
var mealsService = _client2.default.service('meals');
var params = { query: { token: _client2.default.get('token') } };
mealsService.update(this.state.id, this.state, params).then(function (result) {
- console.log(result);
- _this11.props.onUpdate(result);
- _this11.reset();
+ _this12.props.onUpdate(result);
+ _this12.reset();
}).catch(function (error) {
console.error(error);
- _this11.setState({
+ _this12.setState({
error: error.toString()
});
});
@@ -29976,7 +30007,7 @@ var MealForm = function (_React$Component6) {
}, {
key: 'render',
value: function render() {
- var _this12 = this;
+ var _this13 = this;
var id = this.state.id;
var action = id ? 'update' : 'create';
@@ -29996,7 +30027,7 @@ var MealForm = function (_React$Component6) {
_react2.default.createElement(
'span',
{ className: 'clear', onClick: function onClick() {
- return _this12.reset();
+ return _this13.reset();
} },
'clear'
),