-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
connect app with api and add create task function #20
- Loading branch information
Showing
6 changed files
with
100 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
[{"id":1,"name":"Learn React","completed":false},{"id":2,"name":"Learn Vite","completed":false},{"id":3,"name":"Learn Node","completed":false},{"id":"10","text":"Prueba"},{"id":11,"text":"Prueba"}] | ||
[ | ||
{ "text": "Tarea Prueba", "id": "9691749823042075-1717951418737" }, | ||
{ "text": "Tarea 2", "id": "8822678026350037-1717951589854" }, | ||
{ "text": "Tarea 3", "id": "49480507403849905-1717951598149" }, | ||
{ "text": "Lorena es tonta del to", "id": "9158222028142664-1717951606748" } | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const logic = {} | ||
|
||
logic.createTask = (text, callback) => { | ||
const xhr = new XMLHttpRequest() | ||
|
||
xhr.onload = () => { | ||
|
||
if (xhr.status === 201) { | ||
|
||
callback(null) | ||
console.log("task inserted, seguimos Laiiifff!!!") | ||
return | ||
} | ||
|
||
const { error, message } = JSON.parse(xhr.responseText) | ||
|
||
callback({ error, message }) | ||
} | ||
|
||
xhr.open("POST", "http://localhost:3000/tasks") | ||
|
||
const body = { text } | ||
|
||
const json = JSON.stringify(body) | ||
|
||
xhr.setRequestHeader("Content-Type", "application/json") | ||
xhr.send(json) | ||
} | ||
|
||
export default logic |