Skip to content

Commit

Permalink
Add educationHook to wrap education functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cvfavano committed Sep 12, 2024
1 parent ec44429 commit b1105d7
Showing 1 changed file with 59 additions and 63 deletions.
122 changes: 59 additions & 63 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,80 +13,77 @@ import Data from './Data.jsx'
function useCrudEducation () {
const [education, setEducation] = useState([Data.education])
const [educationForm, setEducationForm] = useState(Data.education)



const createEducation = () => {
const newId = uuid();
const newEducation = {
id: newId,
name:'Update School/University',
major: 'Update Major',
location:'Update City',
date: ''
const createEducation = () => {
const newId = uuid();
const newEducation = {
id: newId,
name:'Update School/University',
major: 'Update Major',
location:'Update City',
date: ''
}

setEducation(previousState => ([
...previousState,
newEducation
]))
setEducationForm(newEducation)
}

setEducation(previousState => ([
...previousState,
newEducation
]))
setEducationForm(newEducation)
}

const readEducation = (id) => {
const readEducation = (id) => {

let educationToUpdate = education.filter(school => {
if(school.id === id)
return school

})
setEducationForm(educationToUpdate[0])
}
let educationToUpdate = education.filter(school => {
if(school.id === id)
return school
})
setEducationForm(educationToUpdate[0])
}

const updateEducationForm = (event, id) => {
const updateEducationForm = (event, id) => {

const {name, value} = event.target
const {name, value} = event.target

const updatedEducation = education.map(school => {

if (school.id === id)
return( {...school, [name]: value})

else
return school;
})
const updatedEducation = education.map(school => {

setEducation(updatedEducation)

setEducationForm(prevEducationForm => ({
...prevEducationForm,
[name]: value
if (school.id === id)
return( {...school, [name]: value})
else
return school;
})
)
}

const deleteEducation = (id) => {

setEducation(updatedEducation)

setEducationForm(prevEducationForm => ({
...prevEducationForm,
[name]: value
})
)
}

let filteredEducation = education.filter((school => school.id !== id ));
const deleteEducation = (id) => {

setEducation(filteredEducation)
setEducationForm(filteredEducation.at(-1))
}
let filteredEducation = education.filter((school => school.id !== id ));

if(education.length === 0 ){

const newId = uuid();
const newEducation = {
id: newId,
name:'Update School/University',
major: 'Update Major',
location:'Update City',
date: ''
setEducation(filteredEducation)
setEducationForm(filteredEducation.at(-1))
}

setEducation([newEducation])
setEducationForm(newEducation)
}
if(education.length === 0 ){

const newId = uuid();
const newEducation = {
id: newId,
name:'Update School/University',
major: 'Update Major',
location:'Update City',
date: ''
}

setEducation([newEducation])
setEducationForm(newEducation)
}
return {education, educationForm, createEducation, readEducation, updateEducationForm, deleteEducation}
}

Expand Down Expand Up @@ -168,12 +165,11 @@ function useCrudExperience () {
return { experience, workForm, createWorkExperience, readExperience, updateWorkExperience, deleteExperience }
}
function App() {
const {education, educationForm, createEducation, readEducation, updateEducationForm, deleteEducation} = useCrudEducation()
const { experience, workForm, createWorkExperience, readExperience, updateWorkExperience, deleteExperience} = useCrudExperience()
//TODO, toggle edit mode
//const [showButtons, setButtons] = useState(true);
const [personalInfo, setPersonalInfo] = useState(Data.personalInfo)
const [education, setEducation] = useState([Data.education])
const [educationForm, setEducationForm] = useState(Data.education)

const updatePersonalInfo = (event) => {

Expand Down

0 comments on commit b1105d7

Please sign in to comment.