Skip to content

Commit

Permalink
Enhancements to todo app
Browse files Browse the repository at this point in the history
  • Loading branch information
robtweed committed Aug 7, 2023
1 parent 834ba83 commit 6410c55
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/todo/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
}
};

golgi.logging = true;
//golgi.logging = true;

await golgi.renderAssembly('root', 'body', context);

Expand Down
6 changes: 3 additions & 3 deletions examples/todo/js/components/todo/todo-footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ button {
<ul class="filters">
<li>
<a href="#/all" golgi:prop="allSelector" class="selected" golgi:on_click="showAll">All</a>
<a href="#" golgi:prop="allSelector" class="selected" golgi:on_click="showAll">All</a>
</li>
<li>
<a href="#/active" golgi:prop="activeSelector" golgi:on_click="showActive">Active</a>
<a href="#" golgi:prop="activeSelector" golgi:on_click="showActive">Active</a>
</li>
<li>
<a href="#/completed" golgi:prop="completedSelector" golgi:on_click="showCompleted">Completed</a>
<a href="#" golgi:prop="completedSelector" golgi:on_click="showCompleted">Completed</a>
</li>
</ul>
Expand Down
11 changes: 7 additions & 4 deletions examples/todo/js/components/todo/todo-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ input:placeholder-shown {
}

async addTodo() {
let id = this.context.createTodo(this.input.value);
let itemComponent = await this.context.mainComponent.addItem(id, this.input.value, false);
this.context.registerItemComponent(id, itemComponent);
this.input.value = '';
let value = this.input.value.trim();
if (value !== '') {
let id = this.context.createTodo(value);
let itemComponent = await this.context.mainComponent.addItem(id, value, false);
this.context.registerItemComponent(id, itemComponent);
this.input.value = '';
}
}

});
Expand Down
23 changes: 20 additions & 3 deletions examples/todo/js/components/todo/todo-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ input[type='text']:not(.edit) {
<label golgi:on_dblclick="editingOn">golgi:bind=value</label>
<button class="destroy" golgi:on_click="destroy"></button>
</div>
<input type="text" class="edit hidden" golgi:prop="editField" value="golgi:bind=value" golgi:on_blur="editingOff" golgi:on_change="editingOff" />
<input type="text" class="edit hidden" golgi:prop="editField" value="golgi:bind=value" golgi:on_blur="editingOff" golgi:on_keydown="testForEnd" />
</li>
`;
Expand Down Expand Up @@ -252,23 +252,40 @@ input[type='text']:not(.edit) {

editingOn() {

this.originalValue = this.editField.value;

// turn on the edit field

this.viewDiv.classList.add('hidden');
this.editField.classList.remove('hidden');
this.editField.focus();
}

testForEnd(e) {
if (e.key === 'Escape') {
this.editField.value = this.originalValue;
}
if (e.key === 'Escape' || e.key === 'Enter') {
this.editingOff();
}
}

editingOff() {

// turn off the edit field and transfer the new value to the UI and todos object

let text = this.editField.value.trim();
if (text === '') {
this.destroy();
return;
}

this.viewDiv.classList.remove('hidden');
this.editField.classList.add('hidden');
this.modifyState({
value: this.editField.value
value: text
});
this.context.editTodo(this.todoId, this.editField.value);
this.context.editTodo(this.todoId, text);
}

destroy() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "golgi",
"version": "1.4.4",
"version": "1.4.6",
"description": "Dynamically-loading WebComponent Assembly Framework",
"main": "/src/golgi.mjs",
"browser": "/src/golgi.min.js",
Expand Down

0 comments on commit 6410c55

Please sign in to comment.