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