-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
224 additions
and
871 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import db from '../state/store'; | ||
|
||
/** ******************************* | ||
* Client & Server db Sync actions | ||
*/ | ||
export function formSubmission(event, _id: string, flipEdit?): void { | ||
let title: string = | ||
event.currentTarget.id === 'todoForm' | ||
? event.currentTarget.elements.todoInput.value | ||
: event.currentTarget.value; | ||
|
||
event.preventDefault(); | ||
|
||
// If adding an empty todo, just return out. | ||
if (!_id && !title) { | ||
return; | ||
} else if (_id && title.length) { | ||
// Was this an edit? | ||
// Fire action on db | ||
db.get(_id).then((doc) => { | ||
db.put({ | ||
...doc, | ||
title | ||
}).then((response) => { | ||
console.log('Todo has been updated'); | ||
}); | ||
}); | ||
} else if (_id && !title) { | ||
// If provided id, but title is empty delete item | ||
// Fire action on db | ||
db.get(_id).then((doc) => { | ||
db.put({ | ||
...doc, | ||
_deleted: true | ||
}).then((response) => { | ||
console.log('Todo has been deleted'); | ||
}); | ||
}); | ||
} else { | ||
// This was a new item | ||
// Fire action on db | ||
db.put({ | ||
_id: new Date().toJSON(), | ||
completed: false, | ||
title: title | ||
}).then((response) => { | ||
console.log('Todo has been saved'); | ||
}); | ||
event.currentTarget.elements.todoInput.value = ''; | ||
} | ||
} | ||
export function completeTodo(event, _id: string): void { | ||
event.preventDefault(); | ||
// Fire action on db | ||
db.get(_id).then((doc: any) => { | ||
db.put({ | ||
...doc, | ||
completed: !doc.completed | ||
}).then((response) => { | ||
console.log('Todo has been completed'); | ||
}); | ||
}); | ||
} | ||
export function deleteTodo(event, _id: string): void { | ||
event.preventDefault(); | ||
// Fire action on db | ||
db.get(_id).then((doc) => { | ||
db.put({ | ||
...doc, | ||
_deleted: true | ||
}).then((response) => { | ||
console.log('Todo has been deleted'); | ||
}); | ||
}); | ||
} | ||
export function completeAll(event, todos): void { | ||
// Fire action on db | ||
return; | ||
} | ||
export function clearCompleted(event, todos): void { | ||
// Fire action on db | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.