Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
TodoList
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
Sakilesh J
TodoList
Commits
cce9c357
Commit
cce9c357
authored
Jan 24, 2024
by
Sakilesh J
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
task todo
parent
bd59e00a
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
77 additions
and
15 deletions
+77
-15
App.css
src/App.css
+43
-1
Todo.tsx
src/Components/Todo.tsx
+4
-4
Item.tsx
src/Components/TodoList/Item.tsx
+11
-3
List.tsx
src/Components/TodoList/List.tsx
+2
-2
Todos.tsx
src/Context Api/Todos.tsx
+16
-5
types.dt.ts
src/types.dt.ts
+1
-0
No files found.
src/App.css
View file @
cce9c357
...
...
@@ -36,17 +36,19 @@ img {
.item
{
min-width
:
100%
;
height
:
50px
;
border
:
2px
solid
black
;
display
:
flex
;
justify-content
:
space-between
;
align-items
:
center
;
padding
:
2rem
.8rem
;
box-shadow
:
4px
4px
2px
rgba
(
0
,
0
,
0
,
.05
);
background
:
white
;
}
.item
.item-content
{
font-size
:
20px
;
padding
:
0px
10px
;
text-transform
:
capitalize
;
background-color
:
transparent
;
}
.item
.item-content
>*
{
...
...
@@ -62,3 +64,42 @@ img {
width
:
20px
;
height
:
20px
;
}
.todo-name
{
outline
:
none
;
border
:
none
;
padding
:
0rem
0
;
font-size
:
20px
;
background-color
:
white
;
}
.todo-name
:focus
{
border
:
none
;
}
.input-item
{
width
:
100%
;
background-color
:
white
;
padding
:
1.7rem
;
box-shadow
:
4px
4px
2px
rgba
(
0
,
0
,
0
,
.05
);
}
.input-item
form
>
input
{
padding
:
.3rem
1rem
;
border
:
.5px
solid
black
;
background-color
:
white
;
width
:
70%
;
border-radius
:
2px
;
}
.input-item
form
>
button
{
border
:
none
;
padding
:
.4rem
.6rem
;
width
:
20%
;
color
:
white
;
border-radius
:
3px
;
background-color
:
black
;
margin-inline-start
:
10%
;
box-shadow
:
4px
4px
2px
rgba
(
0
,
0
,
0
,
.05
);
font-weight
:
600
;
}
\ No newline at end of file
src/Components/Todo.tsx
View file @
cce9c357
import
React
,
{
useContext
,
useState
}
from
'react'
import
React
,
{
useContext
,
use
Effect
,
use
State
}
from
'react'
import
{
todo
}
from
'../types.dt'
import
TodoCount
from
'./TodoCount'
import
List
from
'./TodoList/List'
...
...
@@ -6,12 +6,12 @@ import { Provider } from '../Context Api/Todos'
import
TodoCreate
from
'./TodoCreate'
const
Todo
=
()
=>
{
const
[
Todos
,
setTodos
]
=
useState
<
todo
[]
>
([])
const
{
state
,
handleCreate
,
handleDelete
}
=
useContext
(
Provider
)
console
.
log
(
handleCreate
)
const
{
state
,
handleCreate
,
handleDelete
,
handleUpdate
}
=
useContext
(
Provider
)
return
(
<>
<
TodoCount
count=
{
state
.
length
}
/>
<
List
Todo=
{
state
}
handleDelete=
{
handleDelete
}
/>
<
List
Todo=
{
state
}
handleDelete=
{
handleDelete
}
handleUpdate=
{
handleUpdate
}
/>
<
TodoCreate
handleCreate=
{
handleCreate
}
/>
</>
)
...
...
src/Components/TodoList/Item.tsx
View file @
cce9c357
...
...
@@ -7,17 +7,25 @@ import { Provider } from "../../Context Api/Todos";
interface
item
extends
todo
{
index
:
Number
,
handleDelete
?:
()
=>
void
handleUpdate
:
()
=>
void
}
const
Item
=
({
name
,
index
,
completed
,
handleDelete
}:
item
)
=>
{
const
Item
=
({
name
,
index
,
completed
,
handleDelete
,
handleUpdate
}:
item
)
=>
{
const
handleClick
=
(
e
:
React
.
ChangeEvent
<
HTMLImageElement
>
)
=>
{
// console.log(index)
handleDelete
({
index
})
}
const
handleChange
=
(
e
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
handleUpdate
({
name
:
e
.
target
.
value
,
index
})
}
const
handleTick
=
()
=>
{
console
.
log
(
"handletick"
)
handleUpdate
({
index
})
}
return
(
<
div
className=
"item"
>
<
div
className=
'item-content'
>
<
input
type=
'checkbox'
id=
{
`item-${index}`
}
/>
<
label
htmlFor=
{
`item-${index}`
}
>
{
name
}
</
label
>
<
input
type=
'checkbox'
id=
{
`item-${index}`
}
defaultChecked=
{
completed
}
onChange=
{
handleTick
}
/>
<
input
className=
"todo-name"
defaultValue=
{
name
}
type=
"text"
placeholder=
"Enter the Name of the List"
onChange=
{
handleChange
}
/
>
</
div
>
<
div
className=
'actions'
>
{
...
...
src/Components/TodoList/List.tsx
View file @
cce9c357
...
...
@@ -2,13 +2,13 @@ import React from 'react'
import
{
todo
}
from
'../../types.dt'
import
Item
from
'./Item'
const
List
=
({
Todo
,
handleDelete
}:
{
Todo
:
todo
[],
handleDele
te
:
()
=>
void
})
=>
{
const
List
=
({
Todo
,
handleDelete
,
handleUpdate
}:
{
Todo
:
todo
[],
handleDelete
:
()
=>
void
,
handleUpda
te
:
()
=>
void
})
=>
{
return
(
<>
{
Todo
.
map
((
item
,
index
)
=>
{
return
(
<
Item
{
...
item
}
index=
{
index
}
key=
{
index
}
handleDelete=
{
handleDelete
}
/>
<
Item
{
...
item
}
index=
{
index
}
key=
{
index
}
handleDelete=
{
handleDelete
}
handleUpdate=
{
handleUpdate
}
/>
)
})
}
...
...
src/Context Api/Todos.tsx
View file @
cce9c357
...
...
@@ -7,11 +7,19 @@ const Todos = ({ children }: {
const
reducer
=
(
state
:
todo
[],
action
:
action
)
=>
{
switch
(
action
.
type
)
{
case
'Create'
:
console
.
log
(
action
)
return
[...
state
,
{
name
:
action
.
name
,
completed
:
false
}]
// console.log(action)
const
set
=
new
Set
([...
state
,
{
id
:
state
.
length
+
1
,
name
:
action
.
name
,
completed
:
false
}])
const
newstate
=
Array
.
from
(
set
)
return
newstate
;
case
"Update"
:
state
[
action
.
index
].
name
=
action
.
name
return
state
if
(
action
.
name
)
{
state
[
action
.
index
].
name
=
action
.
name
;
}
else
{
state
[
action
.
index
].
completed
=
!
state
[
action
.
index
].
completed
;
}
return
[...
state
];
case
"Delete"
:
return
state
.
filter
((
data
,
i
)
=>
{
return
action
.
index
!==
i
...
...
@@ -22,13 +30,15 @@ const Todos = ({ children }: {
}
const
initialValues
:
todo
[]
=
[{
id
:
1
,
name
:
'Eren Yeager'
,
completed
:
false
,
},
{
id
:
2
,
name
:
"Hange Zoe"
,
completed
:
false
}]
const
[
state
,
dispatch
]
=
useReducer
(
reducer
,
initialValues
)
const
[
state
,
dispatch
]
=
useReducer
<
todo
[]
>
(
reducer
,
initialValues
)
const
handleCreate
=
(
data
:
params
):
void
=>
{
// console.log({ ...data }, "handleCreate")
...
...
@@ -40,6 +50,7 @@ const Todos = ({ children }: {
const
handleDelete
=
(
data
:
params
)
=>
{
dispatch
({
type
:
"Delete"
,
...
data
})
}
console
.
log
(
state
)
return
(
<
Provider
.
Provider
value=
{
{
state
,
handleCreate
,
handleDelete
,
handleUpdate
}
}
>
{
children
}
...
...
src/types.dt.ts
View file @
cce9c357
export
interface
todo
{
id
:
Number
,
name
:
String
,
completed
:
Boolean
}
...
...
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