This commit is contained in:
Mo Bitar
2020-01-31 10:25:03 -06:00
parent 3c8c43ac7e
commit 05e5f311ad
4 changed files with 58 additions and 27 deletions

2
.gitignore vendored
View File

@@ -34,3 +34,5 @@ dump.rdb
# Ignore user uploads # Ignore user uploads
/public/uploads/* /public/uploads/*
!/public/uploads/.keep !/public/uploads/.keep
.vscode

View File

@@ -191,6 +191,7 @@ class TagsPanelCtrl extends PureCtrl {
content_type: 'Tag' content_type: 'Tag'
}); });
this.setState({ this.setState({
previousTag: this.state.selectedTag,
selectedTag: newTag, selectedTag: newTag,
editingTag: newTag, editingTag: newTag,
newTag: newTag newTag: newTag
@@ -206,24 +207,32 @@ class TagsPanelCtrl extends PureCtrl {
async saveTag($event, tag) { async saveTag($event, tag) {
$event.target.blur(); $event.target.blur();
await this.setState({ editingTag: null }); await this.setState({
editingTag: null
});
if (!tag.title || tag.title.length === 0) { if (!tag.title || tag.title.length === 0) {
if (this.editingOriginalName) { if (this.state.editingTag) {
tag.title = this.editingOriginalName; tag.title = this.editingOriginalName;
this.editingOriginalName = null; this.editingOriginalName = null;
} else { } else if(this.state.newTag) {
/** Newly created tag without content */
this.modelManager.removeItemLocally(tag); this.modelManager.removeItemLocally(tag);
this.setState({
selectedTag: this.state.previousTag
});
} }
this.setState({ newTag: null });
return; return;
} }
this.editingOriginalName = null;
const matchingTag = this.modelManager.findTag(tag.title); const matchingTag = this.modelManager.findTag(tag.title);
if (this.state.newTag === tag && matchingTag) { if (this.state.newTag === tag && matchingTag) {
this.alertManager.alert({ this.alertManager.alert({
text: "A tag with this name already exists." text: "A tag with this name already exists."
}); });
this.modelManager.removeItemLocally(tag); this.modelManager.removeItemLocally(tag);
this.setState({ newTag: null });
return; return;
} }
@@ -236,14 +245,12 @@ class TagsPanelCtrl extends PureCtrl {
}); });
} }
selectedRenameTag($event, tag) { async selectedRenameTag($event, tag) {
this.editingOriginalName = tag.title; this.editingOriginalName = tag.title;
this.setState({ await this.setState({
editingTag: tag editingTag: tag
}); });
this.$timeout(() => { document.getElementById('tag-' + tag.uuid).focus();
document.getElementById('tag-' + tag.uuid).focus();
});
} }
selectedDeleteTag(tag) { selectedDeleteTag(tag) {

View File

@@ -2185,8 +2185,8 @@ var Footer = function Footer() {
"use strict"; "use strict";
__webpack_require__.r(__webpack_exports__); __webpack_require__.r(__webpack_exports__);
/* harmony import */ var _abstract_pure_ctrl__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./abstract/pure_ctrl */ "./app/assets/javascripts/controllers/abstract/pure_ctrl.js"); /* harmony import */ var _abstract_pure_ctrl__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./abstract/pure_ctrl */ "./app/assets/javascripts/controllers/abstract/pure_ctrl.js");
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "PureCtrl", function() { return _abstract_pure_ctrl__WEBPACK_IMPORTED_MODULE_7__["PureCtrl"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "PureCtrl", function() { return _abstract_pure_ctrl__WEBPACK_IMPORTED_MODULE_0__["PureCtrl"]; });
/* harmony import */ var _editor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./editor */ "./app/assets/javascripts/controllers/editor.js"); /* harmony import */ var _editor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./editor */ "./app/assets/javascripts/controllers/editor.js");
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EditorPanel", function() { return _editor__WEBPACK_IMPORTED_MODULE_1__["EditorPanel"]; }); /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "EditorPanel", function() { return _editor__WEBPACK_IMPORTED_MODULE_1__["EditorPanel"]; });
@@ -4370,6 +4370,7 @@ function (_PureCtrl) {
content_type: 'Tag' content_type: 'Tag'
}); });
this.setState({ this.setState({
previousTag: this.state.selectedTag,
selectedTag: newTag, selectedTag: newTag,
editingTag: newTag, editingTag: newTag,
newTag: newTag newTag: newTag
@@ -4399,25 +4400,31 @@ function (_PureCtrl) {
case 3: case 3:
if (!(!tag.title || tag.title.length === 0)) { if (!(!tag.title || tag.title.length === 0)) {
_context3.next = 6; _context3.next = 7;
break; break;
} }
if (this.editingOriginalName) { if (this.state.editingTag) {
tag.title = this.editingOriginalName; tag.title = this.editingOriginalName;
this.editingOriginalName = null; this.editingOriginalName = null;
} else { } else if (this.state.newTag) {
/** Newly created tag without content */
this.modelManager.removeItemLocally(tag); this.modelManager.removeItemLocally(tag);
this.setState({
selectedTag: this.state.previousTag
});
} }
this.setState({
newTag: null
});
return _context3.abrupt("return"); return _context3.abrupt("return");
case 6: case 7:
this.editingOriginalName = null;
matchingTag = this.modelManager.findTag(tag.title); matchingTag = this.modelManager.findTag(tag.title);
if (!(this.state.newTag === tag && matchingTag)) { if (!(this.state.newTag === tag && matchingTag)) {
_context3.next = 11; _context3.next = 14;
break; break;
} }
@@ -4425,9 +4432,12 @@ function (_PureCtrl) {
text: "A tag with this name already exists." text: "A tag with this name already exists."
}); });
this.modelManager.removeItemLocally(tag); this.modelManager.removeItemLocally(tag);
this.setState({
newTag: null
});
return _context3.abrupt("return"); return _context3.abrupt("return");
case 11: case 14:
this.modelManager.setItemDirty(tag); this.modelManager.setItemDirty(tag);
this.syncManager.sync(); this.syncManager.sync();
this.modelManager.resortTag(tag); this.modelManager.resortTag(tag);
@@ -4436,7 +4446,7 @@ function (_PureCtrl) {
newTag: null newTag: null
}); });
case 16: case 19:
case "end": case "end":
return _context3.stop(); return _context3.stop();
} }
@@ -4446,13 +4456,25 @@ function (_PureCtrl) {
}, { }, {
key: "selectedRenameTag", key: "selectedRenameTag",
value: function selectedRenameTag($event, tag) { value: function selectedRenameTag($event, tag) {
this.editingOriginalName = tag.title; return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.async(function selectedRenameTag$(_context4) {
this.setState({ while (1) {
editingTag: tag switch (_context4.prev = _context4.next) {
}); case 0:
this.$timeout(function () { this.editingOriginalName = tag.title;
document.getElementById('tag-' + tag.uuid).focus(); _context4.next = 3;
}); return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.awrap(this.setState({
editingTag: tag
}));
case 3:
document.getElementById('tag-' + tag.uuid).focus();
case 4:
case "end":
return _context4.stop();
}
}
}, null, this);
} }
}, { }, {
key: "selectedDeleteTag", key: "selectedDeleteTag",

File diff suppressed because one or more lines are too long