Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
simple-todo-app
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
Ajmal.S
simple-todo-app
Commits
f49e25cb
Commit
f49e25cb
authored
Mar 15, 2022
by
Ajmal.S
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correctins
parent
5ccaa161
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
56 deletions
+48
-56
db.json
db.json
+12
-6
App.js
src/App.js
+4
-29
Form.js
src/components/Form.js
+31
-20
Students.js
src/components/Students.js
+1
-1
No files found.
db.json
View file @
f49e25cb
{
"students"
:
[
{
"
text"
:
"aruny
"
,
"
mark"
:
"100
"
,
"id"
:
1
"
mark"
:
"45
"
,
"
text"
:
"1
"
,
"id"
:
4
},
{
"text"
:
"partha"
,
"mark"
:
"997"
,
"id"
:
2
"mark"
:
"90"
,
"text"
:
"2"
,
"id"
:
5
},
{
"mark"
:
"95"
,
"text"
:
"3"
,
"id"
:
6
}
]
}
\ No newline at end of file
src/App.js
View file @
f49e25cb
...
...
@@ -8,10 +8,6 @@ export const valueContext = React.createContext();
function
App
()
{
const
[
studentsData
,
setStudentsData
]
=
useState
([]);
const
[
text
,
setText
]
=
useState
();
const
[
mark
,
setMark
]
=
useState
();
const
[
editId
,
setEdit
]
=
useState
();
const
[
editMode
,
setEditMode
]
=
useState
(
false
);
const
fetchStudents
=
async
()
=>
{
const
response
=
await
fetch
(
'http://localhost:5000/students'
);
...
...
@@ -25,7 +21,7 @@ function App() {
setStudentsData
(
data
);
}
setStudents
();
},
[
editMode
])
},
[])
const
addStudent
=
async
(
data
)
=>
{
...
...
@@ -41,35 +37,14 @@ function App() {
}
}
const
updateStudent
=
async
(
id
)
=>
{
let
item
=
{
text
,
mark
}
const
response
=
await
fetch
(
`http://localhost:5000/students/
${
id
}
`
,
{
method
:
'PUT'
,
headers
:
{
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
},
body
:
JSON
.
stringify
(
item
)
})
const
data
=
await
response
.
json
();
}
const
handleEditChange
=
(
id
,
text
,
mark
)
=>
{
setEditMode
(
true
);
setEdit
(
id
);
setMark
(
mark
);
setText
(
text
);
};
return
(
<
div
className
=
"c-container"
>
<
valueContext
.
Provider
value
=
"Students Mark List
"
>
<
valueContext
.
Provider
value
=
"Students Mark List"
>
<
Header
/>
<
/valueContext.Provider
>
<
Form
editId
=
{
editId
}
setEdit
=
{
setEdit
}
text
=
{
text
}
setText
=
{
setText
}
mark
=
{
mark
}
setMark
=
{
setMark
}
onAdd
=
{
addStudent
}
onEdit
=
{
updateStudent
}
editMode
=
{
editMode
}
/
>
<
Form
onAdd
=
{
addStudent
}
/
>
{
studentsData
.
map
((
data
,
index
)
=>
(
<
Students
key
=
{
data
.
id
}
index
=
{
index
}
id
=
{
data
.
id
}
marks
=
{
data
.
mark
}
onAdd
=
{
addStudent
}
onDelete
=
{
deleteStudent
}
handleEditChange
=
{
handleEditChange
}
>
{
data
.
text
}
<
/Students
>
<
Students
key
=
{
data
.
id
}
index
=
{
index
}
id
=
{
data
.
id
}
marks
=
{
data
.
mark
}
onAdd
=
{
addStudent
}
onDelete
=
{
deleteStudent
}
>
{
data
.
text
}
<
/Students
>
))}
<
/div
>
);
...
...
src/components/Form.js
View file @
f49e25cb
import
React
from
'react'
;
import
PropTypes
from
'prop-types'
;
import
'../../src/index.css'
import
React
,
{
useState
}
from
'react'
;
export
const
Form
=
({
onAdd
,
editId
,
text
,
setText
,
mark
,
setMark
,
onEdit
,
editMode
})
=>
{
const
Form
=
({
onAdd
})
=>
{
const
[
text
,
setText
]
=
useState
();
const
[
mark
,
setMark
]
=
useState
();
const
[
editId
,
setEdit
]
=
useState
();
const
[
editMode
,
setEditMode
]
=
useState
(
false
);
const
handleSubmit
=
(
e
)
=>
{
e
.
preventDefault
()
...
...
@@ -24,8 +27,28 @@ export const Form = ({ onAdd, editId, text, setText, mark, setMark, onEdit, edit
setMark
(
''
);
}
const
handleEditChange
=
(
id
,
children
,
marks
)
=>
{
setEditMode
(
true
);
setEdit
(
id
);
setMark
(
marks
);
setText
(
children
);
};
const
updateStudent
=
async
(
id
)
=>
{
let
item
=
{
text
,
mark
}
const
response
=
await
fetch
(
`http://localhost:5000/students/
${
id
}
`
,
{
method
:
'PUT'
,
headers
:
{
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
},
body
:
JSON
.
stringify
(
item
)
})
const
data
=
await
response
.
json
();
}
return
(
<
form
className
=
'add-form'
onSubmit
=
{
!
editMode
?
handleSubmit
:
()
=>
onEdi
t
(
editId
)}
>
<
form
className
=
'add-form'
onSubmit
=
{
!
editMode
?
handleSubmit
:
()
=>
updateStuden
t
(
editId
)}
>
<
div
className
=
'form-ctrl'
>
<
label
>
Student
Name
<
/label
>
<
input
type
=
'text'
placeholder
=
'Name'
value
=
{
text
}
onChange
=
{(
e
)
=>
setText
(
e
.
target
.
value
)}
/
>
...
...
@@ -35,22 +58,10 @@ export const Form = ({ onAdd, editId, text, setText, mark, setMark, onEdit, edit
<
input
type
=
'number'
placeholder
=
'Mark'
value
=
{
mark
}
onChange
=
{(
e
)
=>
setMark
(
e
.
target
.
value
)}
/
>
<
/div
>
{
!
editMode
?
<
input
type
=
'submit'
value
=
'Save'
className
=
'button button-block'
><
/input>
:
<
input
type
=
'submit'
value
=
'Update'
className
=
'button button-block'
><
/input>
}
<
/form
>
<
input
type
=
'submit'
value
=
'Save'
className
=
'button button-block'
><
/input>
:
<
input
type
=
'submit'
value
=
'Update'
className
=
'button button-block'
><
/input>
}
<
/form
>
)
}
Form
.
propTypes
=
{
editMode
:
PropTypes
.
bool
,
handleSubmit
:
PropTypes
.
func
,
onEdit
:
PropTypes
.
func
,
editId
:
PropTypes
.
string
,
text
:
PropTypes
.
string
,
mark
:
PropTypes
.
string
,
// setText: PropTypes.func,
// setMark: PropTypes.func,
onAdd
:
PropTypes
.
func
};
export
default
Form
src/components/Students.js
View file @
f49e25cb
...
...
@@ -11,7 +11,7 @@ const Students = ({ children, marks, id, index, onDelete, handleEditChange }) =>
<
div
><
small
className
=
{
`
${
marks
>=
35
?
'pass'
:
'fail'
}
`
}
>
({
marks
>=
35
?
'P'
:
'F'
})
<
/small></
div
>
<
div
style
=
{{
display
:
'flex'
}}
>
<
div
><
MdOutlineModeEditOutline
onClick
=
{()
=>
handleEditChange
(
id
,
children
,
marks
)}
/></
div
>
<
div
style
=
{{
marginLeft
:
'10px'
}}
><
ImBin
onClick
=
{()
=>
(
onDelete
(
id
))}
/></
div
>
<
div
style
=
{{
marginLeft
:
'10px'
}}
><
ImBin
onClick
=
{()
=>
(
onDelete
(
id
))}
/></
div
>
<
/div
>
<
/div
>
)
...
...
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