Commit 3cf242ab by Syed Abdul Rahman

changes in cors handling

parent c96c5244
{ {
"todos": [ "todos": [
{ {
"id": "5250", "id": "a904",
"title": "qwer", "title": "Buy groceries tomorrow",
"completed": false "completed": false
}, },
{ {
"id": "aeb0", "id": "a175",
"title": "qwre", "title": "Travel to head office",
"completed": false "completed": false
}, },
{ {
"id": "7e99", "id": "2753",
"title": "qwer", "title": "Get phone from head office",
"completed": false
},
{
"id": "4dca",
"title": "qwer",
"completed": false
},
{
"id": "2c46",
"title": "qwre",
"completed": false
},
{
"id": "224e",
"title": "qwer",
"completed": false
},
{
"id": "023a",
"title": "qre",
"completed": false
},
{
"id": "91d5",
"title": "qwer",
"completed": false "completed": false
} }
] ]
......
...@@ -17,7 +17,11 @@ function App() { ...@@ -17,7 +17,11 @@ function App() {
}, []) }, [])
const fetchTodos = async () => { const fetchTodos = async () => {
const response = await fetch('http://localhost:3000/todos'); const response = await fetch('http://localhost:3000/todos', {
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) { if (!response.ok) {
console.log("Error fetching data") console.log("Error fetching data")
} }
...@@ -43,7 +47,7 @@ function App() { ...@@ -43,7 +47,7 @@ function App() {
} }
} }
const toggleTodo = async (todoItem: any,e: any) => { const toggleTodo = async (todoItem: any, e: any) => {
e.stopPropagation() e.stopPropagation()
console.log(todoItem, "todoItem.completed") console.log(todoItem, "todoItem.completed")
await fetch(`http://localhost:3000/todos/${todoItem.id}`, { await fetch(`http://localhost:3000/todos/${todoItem.id}`, {
...@@ -81,10 +85,10 @@ function App() { ...@@ -81,10 +85,10 @@ function App() {
const onEditCancel = (e: any) => { const onEditCancel = (e: any) => {
setEditingTodoId(null); setEditingTodoId(null);
setEditableTitle(''); setEditableTitle('');
e.stopPropagation() e.stopPropagation()
} }
const onSaveEdit = async(e: any, todoId: any) => { const onSaveEdit = async (e: any, todoId: any) => {
e.stopPropagation(); e.stopPropagation();
await fetch(`http://localhost:3000/todos/${todoId}`, { await fetch(`http://localhost:3000/todos/${todoId}`, {
method: 'PATCH', method: 'PATCH',
...@@ -109,8 +113,8 @@ function App() { ...@@ -109,8 +113,8 @@ function App() {
<Fragment key={ele.id}> <Fragment key={ele.id}>
<div className='checklist-item'> <div className='checklist-item'>
<div className='checklist-item__content' onClick={() => editTodo(ele.id)}> <div className='checklist-item__content' onClick={() => editTodo(ele.id)}>
<input type='checkbox' checked={ele.completed} className='custom-checkbox' onClick={(e) => e.stopPropagation()} onChange={(e) => toggleTodo(ele,e)} /> <input type='checkbox' checked={ele.completed} className='custom-checkbox' onClick={(e) => e.stopPropagation()} onChange={(e) => toggleTodo(ele, e)} />
{editingTodoId === ele.id ? ( {editingTodoId === ele.id ? (
<input type='text' value={editableTitle} className='checklist-item__editable-input' onChange={(e) => setEditableTitle(e.target.value)} /> <input type='text' value={editableTitle} className='checklist-item__editable-input' onChange={(e) => setEditableTitle(e.target.value)} />
) : ( ) : (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment