Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
Todo-Storybook
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Madhankumar
Todo-Storybook
Commits
7bc8167f
Commit
7bc8167f
authored
Sep 18, 2023
by
Madhankumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
app context
parent
64719727
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
114 additions
and
94 deletions
+114
-94
db.json
db.json
+8
-1
App.js
src/App.js
+10
-88
index.js
src/appcontext/index.js
+86
-0
index.js
src/index.js
+3
-0
api.js
src/lib/api.js
+7
-5
No files found.
db.json
View file @
7bc8167f
...
...
@@ -8,9 +8,15 @@
},
{
"sId"
:
1
,
"title"
:
"helloxxsxsxsxsxsxsxsxsxsxsxsxsxssssssssssssssssssssxssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"
,
"title"
:
"helloxxsxsxsxsxsxsxsxsxsxsxsxsxssssssssssssssssssssxssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
adddadsdsdsadasasasadasaadadadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaavrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrryyyyy
"
,
"isCompleted"
:
false
,
"id"
:
2
},
{
"sId"
:
1
,
"title"
:
"bbb"
,
"isCompleted"
:
true
,
"id"
:
6
}
]
}
\ No newline at end of file
src/App.js
View file @
7bc8167f
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useEffect
}
from
"react"
;
import
"./App.css"
;
import
Layout
from
"./components/base/layout"
;
import
Form
from
"./components/top-level/form"
;
import
Tasks
from
"./components/top-level/tasks"
;
import
{
addTodo
,
getTodo
,
updateRemainder
,
updateTitle
,
deleteTodo
,
}
from
"./lib/api"
;
import
{
useAppContext
}
from
"./appcontext/index"
;
function
App
()
{
const
[
task
,
setTask
]
=
useState
([]);
const
addtask
=
async
(
data
)
=>
{
const
todoData
=
await
addTodo
(
data
);
setTask
([...
task
,
todoData
]);
};
const
gettask
=
async
()
=>
{
const
todoData
=
await
getTodo
();
setTask
(
todoData
);
};
const
updateremainder
=
async
(
id
)
=>
{
const
todoData
=
await
updateRemainder
(
id
);
setTask
(
task
.
map
((
e
)
=>
e
.
id
===
todoData
.
id
?
{
...
e
,
isCompleted
:
todoData
.
isCompleted
}
:
e
)
);
};
const
updatetitle
=
async
(
data
)
=>
{
const
todoData
=
await
updateTitle
(
data
);
setTask
(
task
.
map
((
e
)
=>
(
e
.
id
===
todoData
.
id
?
todoData
:
e
)));
};
const
deletetask
=
async
(
id
)
=>
{
await
deleteTodo
(
id
);
setTask
(
task
.
filter
((
e
)
=>
e
.
id
!==
id
));
};
// const getTask = async () => {
// const taskData = await fetch("http://192.168.1.91:5000/task");
// const response = await taskData.json();
// setTask(response);
// };
// const getTaskById = async (id) => {
// const tasktracker = await fetch(`http://192.168.1.91:5000/task/${id}`);
// const response = await tasktracker.json();
// return response;
// };
// const remainder = async (id) => {
// const toogle = await getTaskById(id);
// const result = { ...toogle, isCompleted: !toogle.isCompleted };
// const res = await fetch(`http://192.168.1.91:5000/task/${id}`, {
// method: "PUT",
// headers: { "Content-type": "application/json" },
// body: JSON.stringify(result),
// });
// const data = await res.json();
// setTask(
// task.map((e) =>
// e.id === data.id ? { ...e, isCompleted: data.isCompleted } : e
// )
// );
// };
// const editTask = async (datas) => {
// console.log(datas);
// const response = await fetch(`http://192.168.1.91:5000/task/${datas.id}`, {
// method: "PATCH",
// headers: { "Content-type": "application/json" },
// body: JSON.stringify({ title: datas.title }),
// });
// const data = await response.json();
// setTask(task.map((e) => (e.id === data.id ? data : e)));
// };
// const deleteTask = async (id) => {
// await fetch(`http://192.168.1.91:5000/task/${id}`, {
// method: "DELETE",
// });
// setTask(task.filter((e) => e.id !== id));
// };
const
{
task
,
addTask
,
updateremainder
,
getTask
,
deleteTask
,
updatetitle
}
=
useAppContext
();
useEffect
(()
=>
{
get
t
ask
();
get
T
ask
();
},
[]);
console
.
log
(
"okpp"
,
task
);
return
(
<
div
className
=
"App"
>
<
Layout
count
=
{
task
.
filter
((
e
)
=>
!
e
.
isCompleted
).
length
}
>
{
task
.
length
>
0
?
(
<
Layout
count
=
{
task
?
.
filter
((
e
)
=>
!
e
.
isCompleted
).
length
}
>
{
task
?
.
length
>
0
?
(
<
Tasks
tasklist
=
{
task
}
onEdit
=
{
updatetitle
}
remainder
=
{
updateremainder
}
deleted
=
{
delete
t
ask
}
deleted
=
{
delete
T
ask
}
/
>
)
:
(
<
h3
>
No
task
<
/h3
>
)}
<
Form
onSubmit
=
{
add
t
ask
}
/
>
<
Form
onSubmit
=
{
add
T
ask
}
/
>
<
/Layout
>
<
/div
>
);
...
...
src/appcontext/index.js
0 → 100644
View file @
7bc8167f
import
React
,
{
createContext
,
useContext
,
useState
}
from
"react"
;
import
{
addTodo
,
getTodo
,
getTodoById
,
updateRemainder
,
updateTitle
,
deleteTodo
,
}
from
"../lib/api"
;
export
const
TodoContext
=
createContext
();
export
const
useAppContext
=
()
=>
useContext
(
TodoContext
);
export
function
TodoProvider
({
children
,
...
props
})
{
const
[
task
,
setTask
]
=
useState
([]);
//POST METHOD
async
function
addTask
(
data
)
{
try
{
const
taskData
=
await
addTodo
(
data
);
setTask
([...
task
,
taskData
]);
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
}
//PATCH METHOD
async
function
updateremainder
(
id
)
{
try
{
console
.
log
(
"llll"
,
id
);
const
response
=
await
updateRemainder
(
id
);
setTask
(
response
);
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
}
async
function
updatetitle
(
data
)
{
try
{
const
result
=
await
updateTitle
(
data
);
setTask
([...
task
,
result
]);
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
}
//GET METHOD
async
function
getTask
()
{
try
{
const
taskData
=
await
getTodo
();
setTask
(
taskData
);
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
}
async
function
getTaskById
(
id
)
{
try
{
const
response
=
await
getTodoById
(
id
);
setTask
(
response
);
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
}
//DELETE METHOD
async
function
deleteTask
(
id
)
{
try
{
const
taskData
=
await
deleteTodo
(
id
);
setTask
(
taskData
);
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
}
const
value
=
{
task
,
addTask
,
updateremainder
,
getTask
,
getTaskById
,
deleteTask
,
updatetitle
,
};
return
(
<
TodoContext
.
Provider
value
=
{
value
}
{...
props
}
>
{
children
}
<
/TodoContext.Provider
>
);
}
src/index.js
View file @
7bc8167f
...
...
@@ -3,11 +3,14 @@ import ReactDOM from "react-dom/client";
import
"./index.css"
;
import
App
from
"./App"
;
import
reportWebVitals
from
"./reportWebVitals"
;
import
{
TodoProvider
}
from
"./appcontext"
;
const
root
=
ReactDOM
.
createRoot
(
document
.
getElementById
(
"root"
));
root
.
render
(
// <React.StrictMode>
<
TodoProvider
>
<
App
/>
<
/TodoProvider
>
// </React.StrictMode>
);
...
...
src/lib/api.js
View file @
7bc8167f
...
...
@@ -25,7 +25,7 @@ export async function updateRemainder(id) {
headers
:
{
"Content-type"
:
"application/json"
},
body
:
JSON
.
stringify
(
result
),
});
const
resultData
=
await
updateresponse
.
json
();
const
resultData
=
await
getTodo
();
return
resultData
;
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
...
...
@@ -38,9 +38,8 @@ export async function updateTitle(data) {
headers
:
{
"Content-type"
:
"application/json"
},
body
:
JSON
.
stringify
({
title
:
data
.
title
}),
});
const
result
=
await
response
.
json
();
return
result
;
const
resultData
=
await
getTodo
();
return
resultData
;
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
...
...
@@ -51,6 +50,7 @@ export async function getTodo() {
try
{
const
response
=
await
fetch
(
url
);
const
result
=
await
response
.
json
();
return
result
;
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
...
...
@@ -69,9 +69,11 @@ export async function getTodoById(id) {
//DELETE METHOD
export
async
function
deleteTodo
(
id
)
{
try
{
return
await
fetch
(
url
+
`/
${
id
}
`
,
{
await
fetch
(
url
+
`/
${
id
}
`
,
{
method
:
"DELETE"
,
});
const
resultData
=
await
getTodo
();
return
resultData
;
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment