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
6581c9f4
Commit
6581c9f4
authored
Sep 19, 2023
by
Madhankumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update api changes
parent
3fc39fc9
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
58 additions
and
125 deletions
+58
-125
db.json
db.json
+6
-2
App.js
src/App.js
+7
-13
index.js
src/app-context/index.js
+21
-46
index.js
src/components/top-level/form/index.js
+1
-7
index.js
src/components/top-level/task/index.js
+5
-5
index.js
src/components/top-level/tasks/index.js
+5
-10
index.js
src/index.js
+1
-1
api.js
src/lib/api.js
+12
-41
No files found.
db.json
View file @
6581c9f4
{
"task"
:
[
{
"sId"
:
1
,
"title"
:
"rhrhrhrytyty"
,
"isCompleted"
:
true
,
"id"
:
1
},
{
"sId"
:
1
,
"title"
:
"helloxxsxsxsxsxsxsxsxsxsxsxsxsxssssssssssssssssssssxssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssadddadsdsdsadasasasadasaadadadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaavrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrryyyyy"
,
"isCompleted"
:
false
,
"id"
:
2
},
{
"title"
:
"hello"
,
"isCompleted"
:
false
,
"id"
:
3
}
]
}
\ No newline at end of file
src/App.js
View file @
6581c9f4
...
...
@@ -3,29 +3,23 @@ import "./App.css";
import
Layout
from
"./components/base/layout"
;
import
Form
from
"./components/top-level/form"
;
import
Tasks
from
"./components/top-level/tasks"
;
import
{
useAppContext
}
from
"./appcontext/index"
;
import
{
useAppContext
}
from
"./app
-
context/index"
;
function
App
()
{
const
{
task
,
addTask
,
updateremainder
,
getTask
,
deleteTask
,
updatetitle
}
=
useAppContext
();
const
{
todo
,
addTodo
,
getTodos
,
deleteTodo
,
updateTodo
}
=
useAppContext
();
useEffect
(()
=>
{
getT
ask
();
getT
odos
();
},
[]);
return
(
<
div
className
=
"App"
>
<
Layout
count
=
{
task
?.
filter
((
e
)
=>
!
e
.
isCompleted
).
length
}
>
{
task
?.
length
>
0
?
(
<
Tasks
tasklist
=
{
task
}
onEdit
=
{
updatetitle
}
remainder
=
{
updateremainder
}
deleted
=
{
deleteTask
}
/
>
<
Layout
count
=
{
todo
?.
filter
((
e
)
=>
!
e
.
isCompleted
).
length
}
>
{
todo
?.
length
>
0
?
(
<
Tasks
tasks
=
{
todo
}
onChange
=
{
updateTodo
}
onDelete
=
{
deleteTodo
}
/
>
)
:
(
<
h3
>
No
task
<
/h3
>
)}
<
Form
onSubmit
=
{
addT
ask
}
/
>
<
Form
onSubmit
=
{
addT
odo
}
/
>
<
/Layout
>
<
/div
>
);
...
...
src/appcontext/index.js
→
src/app
-
context/index.js
View file @
6581c9f4
import
React
,
{
createContext
,
useContext
,
useState
}
from
"react"
;
import
{
addTodo
,
getTodo
,
getTodoById
,
updateRemainder
,
updateTitle
,
deleteTodo
,
}
from
"../lib/api"
;
import
*
as
api
from
"../lib/api"
;
export
const
TodoContext
=
createContext
();
export
const
useAppContext
=
()
=>
useContext
(
TodoContext
);
export
function
TodoProvider
({
children
})
{
const
[
t
ask
,
setTask
]
=
useState
([]);
const
[
t
odo
,
setTodo
]
=
useState
([]);
//POST METHOD
async
function
addT
ask
(
data
)
{
async
function
addT
odo
({
title
}
)
{
try
{
const
taskData
=
await
addTodo
(
data
);
setTask
([...
task
,
taskData
]);
//default isCompleted is false
const
response
=
await
api
.
addTodo
({
title
,
isCompleted
:
false
});
setTodo
([...
todo
,
response
]);
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
}
//
PATCH
METHOD
async
function
update
remainder
(
id
)
{
//
UPDATE
METHOD
async
function
update
Todo
(
item
)
{
try
{
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
]);
const
response
=
await
api
.
updateTodo
(
item
);
setTodo
(
response
);
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
}
//GET METHOD
async
function
getT
ask
()
{
async
function
getT
odos
()
{
try
{
const
taskData
=
await
getTodo
();
setT
ask
(
taskData
);
const
response
=
await
api
.
getTodos
();
setT
odo
(
response
);
}
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
deleteT
ask
(
id
)
{
async
function
deleteT
odo
(
id
)
{
try
{
const
taskData
=
await
deleteTodo
(
id
);
setT
ask
(
taskData
);
const
response
=
await
api
.
deleteTodo
(
id
);
setT
odo
(
response
);
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
}
const
value
=
{
task
,
addTask
,
updateremainder
,
getTask
,
getTaskById
,
deleteTask
,
updatetitle
,
todo
,
addTodo
,
getTodos
,
deleteTodo
,
updateTodo
,
};
return
<
TodoContext
.
Provider
value
=
{
value
}
>
{
children
}
<
/TodoContext.Provider>
;
}
src/components/top-level/form/index.js
View file @
6581c9f4
...
...
@@ -5,15 +5,9 @@ import "./form.css";
function
Form
({
onSubmit
})
{
const
[
title
,
setTitle
]
=
useState
(
""
);
let
[
count
,
setCount
]
=
useState
(
0
);
const
handleSubmit
=
(
e
)
=>
{
e
.
preventDefault
();
let
len
=
count
+
1
;
setCount
(
len
);
const
data
=
JSON
.
parse
(
JSON
.
stringify
({
sId
:
len
,
title
,
isCompleted
:
false
})
);
onSubmit
(
data
);
onSubmit
({
title
});
//setTitle("");
};
...
...
src/components/top-level/task/index.js
View file @
6581c9f4
...
...
@@ -9,7 +9,7 @@ import {
useCallback
,
}
from
"react"
;
function
Task
({
id
,
title
,
isCompleted
,
onDelete
,
onChange
,
onEdit
})
{
function
Task
({
id
=
1
,
title
,
isCompleted
,
onChange
,
onDelete
})
{
const
[
debouncetitle
,
setDebounceTitle
]
=
useState
(
title
);
const
[
ischeck
,
setIsCheck
]
=
useState
(
isCompleted
);
const
textarea_ref
=
useRef
(
null
);
...
...
@@ -25,7 +25,7 @@ function Task({ id, title, isCompleted, onDelete, onChange, onEdit }) {
};
const
handleChange
=
useCallback
(()
=>
{
setIsCheck
(
!
ischeck
);
onChange
({
id
,
isCompleted
:
ischeck
?
true
:
false
});
onChange
({
id
,
isCompleted
:
!
ischeck
});
},
[
ischeck
]);
const
handleContent
=
(
e
)
=>
{
...
...
@@ -41,7 +41,7 @@ function Task({ id, title, isCompleted, onDelete, onChange, onEdit }) {
useEffect
(()
=>
{
const
handler
=
setTimeout
(()
=>
{
if
(
textarea_ref
.
current
.
value
!=
title
)
{
on
Edit
({
id
,
title
:
debouncetitle
});
on
Change
({
id
,
title
:
debouncetitle
});
}
},
2000
);
...
...
@@ -65,11 +65,11 @@ function Task({ id, title, isCompleted, onDelete, onChange, onEdit }) {
<
textarea
ref
=
{
textarea_ref
}
className
=
{
`
${
is
Completed
?
"strike-through"
:
""
}
`
}
className
=
{
`
${
is
check
?
"strike-through"
:
""
}
`
}
contentEditable
=
{
true
}
value
=
{
debouncetitle
}
onChange
=
{
handleContent
}
disabled
=
{
is
Completed
}
disabled
=
{
is
check
}
><
/textarea
>
<
/div
>
<
FaTimesCircle
className
=
"fa-close"
onClick
=
{
handleDelete
}
/
>
...
...
src/components/top-level/tasks/index.js
View file @
6581c9f4
import
"./tasks.css"
;
import
Task
from
"../task"
;
function
Tasks
({
tasklist
,
deleted
,
remainder
,
onEdit
})
{
const
handleChange
=
(
id
)
=>
{
remainder
(
id
);
};
function
Tasks
({
tasks
,
onDelete
,
onChange
})
{
return
(
<
div
className
=
"tasklist"
>
{
task
list
.
length
>
0
&&
task
list
.
map
(({
id
,
title
,
isCompleted
})
=>
(
{
task
s
.
length
>
0
&&
task
s
.
map
(({
id
,
title
,
isCompleted
})
=>
(
<
Task
key
=
{
id
}
id
=
{
id
}
title
=
{
title
}
isCompleted
=
{
isCompleted
}
onEdit
=
{
onEdit
}
onChange
=
{()
=>
handleChange
(
id
)}
onDelete
=
{()
=>
deleted
(
id
)}
onChange
=
{
onChange
}
onDelete
=
{()
=>
onDelete
(
id
)}
/
>
))}
<
/div
>
...
...
src/index.js
View file @
6581c9f4
...
...
@@ -3,7 +3,7 @@ import ReactDOM from "react-dom/client";
import
"./index.css"
;
import
App
from
"./App"
;
import
reportWebVitals
from
"./reportWebVitals"
;
import
{
TodoProvider
}
from
"./appcontext"
;
import
{
TodoProvider
}
from
"./app
-
context"
;
const
root
=
ReactDOM
.
createRoot
(
document
.
getElementById
(
"root"
));
root
.
render
(
...
...
src/lib/api.js
View file @
6581c9f4
const
url
=
"http://192.168.1.91:5000/task"
;
//POST METHOD
export
async
function
addTodo
(
data
)
{
export
async
function
addTodo
(
todo
)
{
try
{
const
response
=
await
fetch
(
url
,
{
method
:
"POST"
,
headers
:
{
"Content-type"
:
"application/json"
},
body
:
JSON
.
stringify
(
data
),
body
:
JSON
.
stringify
(
todo
),
});
const
result
=
await
response
.
json
();
return
result
;
return
response
.
json
();
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
}
//PATCH METHOD
export
async
function
update
Remainder
(
id
)
{
export
async
function
update
Todo
({
id
,
...
todo
}
)
{
try
{
const
response
=
await
getTodoById
(
id
);
const
result
=
{
...
response
,
isCompleted
:
!
response
.
isCompleted
};
const
updateresponse
=
await
fetch
(
url
+
`/
${
id
}
`
,
{
method
:
"PUT"
,
headers
:
{
"Content-type"
:
"application/json"
},
body
:
JSON
.
stringify
(
result
),
});
const
resultData
=
await
getTodo
();
return
resultData
;
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
}
export
async
function
updateTitle
(
data
)
{
try
{
const
response
=
await
fetch
(
url
+
`/
${
data
.
id
}
`
,
{
await
fetch
(
url
+
`/
${
id
}
`
,
{
method
:
"PATCH"
,
headers
:
{
"Content-type"
:
"application/json"
},
body
:
JSON
.
stringify
({
title
:
data
.
title
}),
body
:
JSON
.
stringify
({
...
todo
}),
});
const
res
ultData
=
await
getTodo
();
return
res
ultData
;
const
res
ponse
=
await
getTodos
();
return
res
ponse
;
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
}
//GET METHOD
export
async
function
getTodo
()
{
export
async
function
getTodo
s
()
{
try
{
const
response
=
await
fetch
(
url
);
const
result
=
await
response
.
json
();
return
result
;
return
await
fetch
(
url
).
then
((
data
)
=>
data
.
json
());
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
}
export
async
function
getTodoById
(
id
)
{
try
{
const
response
=
await
fetch
(
url
+
`/
${
id
}
`
);
const
result
=
await
response
.
json
();
return
result
;
}
catch
(
err
)
{
console
.
log
(
err
.
message
);
}
}
//DELETE METHOD
export
async
function
deleteTodo
(
id
)
{
try
{
await
fetch
(
url
+
`/
${
id
}
`
,
{
method
:
"DELETE"
,
});
const
res
ultData
=
await
getTodo
();
return
res
ultData
;
const
res
ponse
=
await
getTodos
();
return
res
ponse
;
}
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