mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2024-12-26 22:30:44 -05:00
refactor: modular
This commit is contained in:
parent
482e2c4d1d
commit
c3184ad970
6 changed files with 147 additions and 87 deletions
|
@ -1,15 +1,42 @@
|
||||||
import GeneralInfo from "./components/generalInfo";
|
import GeneralInfoForm from "./components/generalInfoForm";
|
||||||
import EducationInfo from "./components/educationInfo";
|
import GeneralInfoDisplay from "./components/generalInfoDisplay";
|
||||||
import Experience from "./components/experience";
|
import EducationInfoDisplay from "./components/educationInfoDisplay";
|
||||||
|
import EducationInfoForm from "./components/educationInfoForm";
|
||||||
|
import ExperienceForm from "./components/experienceForm";
|
||||||
import "./App.css";
|
import "./App.css";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
const [basicInfo, setBasicInfo] = useState({
|
||||||
|
firstName: "",
|
||||||
|
lastName: "",
|
||||||
|
phone: "",
|
||||||
|
email: "",
|
||||||
|
});
|
||||||
|
const [educationInfo, setEducationInfo] = useState([]);
|
||||||
|
const [editEducation, setEditEducation] = useState(null);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="container">
|
||||||
<GeneralInfo />
|
<div className="form">
|
||||||
<EducationInfo />
|
<GeneralInfoForm setBasicInfo={setBasicInfo} basicInfo={basicInfo} />
|
||||||
<Experience />
|
<EducationInfoForm
|
||||||
</>
|
educationInfo={educationInfo}
|
||||||
|
setEducationInfo={setEducationInfo}
|
||||||
|
setEditEducation={setEditEducation}
|
||||||
|
editEducation={editEducation}
|
||||||
|
/>
|
||||||
|
<ExperienceForm />
|
||||||
|
</div>
|
||||||
|
<div className="resume">
|
||||||
|
<GeneralInfoDisplay basicInfo={basicInfo} />
|
||||||
|
<EducationInfoDisplay
|
||||||
|
educationInfo={educationInfo}
|
||||||
|
setEditEducation={setEditEducation}
|
||||||
|
setEducationInfo={setEducationInfo}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
54
cv-project/src/components/educationInfoDisplay.jsx
Normal file
54
cv-project/src/components/educationInfoDisplay.jsx
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
export default function EducationInfoDisplay(props) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{props.educationInfo.length <= 0 ? (
|
||||||
|
<>
|
||||||
|
<p>Add your Education info</p>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<EducationDisplay
|
||||||
|
educationInfo={props.educationInfo}
|
||||||
|
setEducationInfo={props.setEducationInfo}
|
||||||
|
setEditEducation={props.setEditEducation}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function EducationDisplay(props) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{props.educationInfo.map((item) => {
|
||||||
|
return (
|
||||||
|
<div key={item.schoolName} className="education-info">
|
||||||
|
<h2>School: {item.schoolName}</h2>
|
||||||
|
<p>
|
||||||
|
Graduation Date: {item.graduationDate + " "}
|
||||||
|
Field of Study: {item.fieldOfStudy}
|
||||||
|
<button onClick={() => props.setEditEducation(item)}>edit</button>
|
||||||
|
<button
|
||||||
|
onClick={() =>
|
||||||
|
deleteEducationItem(
|
||||||
|
props.educationInfo,
|
||||||
|
item.schoolName,
|
||||||
|
props.setEducationInfo,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
remove
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteEducationItem(educationInfo, item, setEducationInfo) {
|
||||||
|
const filteredSchools = educationInfo.filter(
|
||||||
|
(school) => school.schoolName !== item,
|
||||||
|
);
|
||||||
|
setEducationInfo(filteredSchools);
|
||||||
|
}
|
|
@ -1,29 +1,12 @@
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
export default function EducationInfo() {
|
export default function EducationInfoForm(props) {
|
||||||
const [schools, setSchools] = useState([]);
|
// const [schools, setSchools] = useState([]);
|
||||||
const [educationItemActive, setEducationItemActive] = useState(false);
|
const [educationItemActive, setEducationItemActive] = useState(false);
|
||||||
const [editSchool, setEditSchool] = useState(null);
|
// const [editSchool, setEditSchool] = useState(null);
|
||||||
|
|
||||||
const mainDivStyle = {
|
|
||||||
display: "flex",
|
|
||||||
justifyContent: "space-between",
|
|
||||||
flexDirection: "row-reverse",
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="education-info section" style={mainDivStyle}>
|
<div className="education-info section">
|
||||||
{schools.length <= 0 ? (
|
|
||||||
<>
|
|
||||||
<p>Add your Education info</p>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<EducationDisplay
|
|
||||||
schools={schools}
|
|
||||||
setSchools={setSchools}
|
|
||||||
setEditSchool={setEditSchool}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<div>
|
<div>
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
@ -35,46 +18,21 @@ export default function EducationInfo() {
|
||||||
|
|
||||||
<EducationForm
|
<EducationForm
|
||||||
isActive={educationItemActive}
|
isActive={educationItemActive}
|
||||||
schools={schools}
|
educationInfo={props.educationInfo}
|
||||||
setSchools={setSchools}
|
setEducationInfo={props.setEducationInfo}
|
||||||
editSchool={editSchool}
|
editSchool={props.editEducation}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function EducationDisplay(props) {
|
function EducationForm({
|
||||||
return (
|
isActive,
|
||||||
<div>
|
educationInfo,
|
||||||
{props.schools.map((item) => {
|
setEducationInfo,
|
||||||
return (
|
editSchool,
|
||||||
<div key={item.schoolName} className="education-info">
|
}) {
|
||||||
<h2>School: {item.schoolName}</h2>
|
|
||||||
<p>
|
|
||||||
Graduation Date: {item.graduationDate + " "}
|
|
||||||
Field of Study: {item.fieldOfStudy}
|
|
||||||
<button onClick={() => props.setEditSchool(item)}>edit</button>
|
|
||||||
<button
|
|
||||||
onClick={() =>
|
|
||||||
deleteEducationItem(
|
|
||||||
props.schools,
|
|
||||||
item.schoolName,
|
|
||||||
props.setSchools,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
remove
|
|
||||||
</button>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function EducationForm({ isActive, schools, setSchools, editSchool }) {
|
|
||||||
const [graduationDate, setGraduationDate] = useState("");
|
const [graduationDate, setGraduationDate] = useState("");
|
||||||
const [schoolName, setSchoolName] = useState("");
|
const [schoolName, setSchoolName] = useState("");
|
||||||
const [fieldOfStudy, setFieldOfStudy] = useState("");
|
const [fieldOfStudy, setFieldOfStudy] = useState("");
|
||||||
|
@ -92,7 +50,9 @@ function EducationForm({ isActive, schools, setSchools, editSchool }) {
|
||||||
}, [editSchool]);
|
}, [editSchool]);
|
||||||
|
|
||||||
let schoolId = editSchool
|
let schoolId = editSchool
|
||||||
? schools.findIndex((school) => school.schoolName === editSchool.schoolName)
|
? educationInfo.findIndex(
|
||||||
|
(school) => school.schoolName === editSchool.schoolName,
|
||||||
|
)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
const contactFormStyle = {
|
const contactFormStyle = {
|
||||||
|
@ -128,17 +88,17 @@ function EducationForm({ isActive, schools, setSchools, editSchool }) {
|
||||||
type="submit"
|
type="submit"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const updatedSchools = [...schools];
|
const updatedSchools = [...educationInfo];
|
||||||
if (schoolId !== -1 && schoolId !== null) {
|
if (schoolId !== -1 && schoolId !== null) {
|
||||||
updatedSchools[schoolId] = {
|
updatedSchools[schoolId] = {
|
||||||
schoolName: schoolName,
|
schoolName: schoolName,
|
||||||
graduationDate: graduationDate,
|
graduationDate: graduationDate,
|
||||||
fieldOfStudy: fieldOfStudy,
|
fieldOfStudy: fieldOfStudy,
|
||||||
};
|
};
|
||||||
setSchools(updatedSchools);
|
setEducationInfo(updatedSchools);
|
||||||
} else {
|
} else {
|
||||||
setSchools([
|
setEducationInfo([
|
||||||
...schools,
|
...educationInfo,
|
||||||
{
|
{
|
||||||
schoolName: schoolName,
|
schoolName: schoolName,
|
||||||
fieldOfStudy: fieldOfStudy,
|
fieldOfStudy: fieldOfStudy,
|
||||||
|
@ -170,10 +130,3 @@ function EducationForm({ isActive, schools, setSchools, editSchool }) {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteEducationItem(schools, item, setSchools) {
|
|
||||||
const filteredSchools = schools.filter(
|
|
||||||
(school) => school.schoolName !== item,
|
|
||||||
);
|
|
||||||
setSchools(filteredSchools);
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
export default function Experience() {
|
export default function ExperienceForm() {
|
||||||
const [jobs, setJobs] = useState([]);
|
const [jobs, setJobs] = useState([]);
|
||||||
const [showJobForm, setShowJobForm] = useState(false);
|
const [showJobForm, setShowJobForm] = useState(false);
|
||||||
|
|
18
cv-project/src/components/generalInfoDisplay.jsx
Normal file
18
cv-project/src/components/generalInfoDisplay.jsx
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
export default function GeneralInfoDisplay(props) {
|
||||||
|
const basicInfo = props.basicInfo;
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{
|
||||||
|
basicInfo ?
|
||||||
|
(
|
||||||
|
<div className="basic-info" >
|
||||||
|
<h1>{basicInfo.firstName + " " + basicInfo.lastName}</h1>
|
||||||
|
<p>{basicInfo.email}</p>
|
||||||
|
<p>{basicInfo.phone}</p>
|
||||||
|
</div>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
export default function GeneralInfo() {
|
export default function GeneralInfoForm(props) {
|
||||||
const [firstName, setFirstName] = useState("");
|
const [firstName, setFirstName] = useState("");
|
||||||
const [lastName, setLastName] = useState("");
|
const [lastName, setLastName] = useState("");
|
||||||
const [phone, setPhone] = useState("");
|
const [phone, setPhone] = useState("");
|
||||||
|
@ -26,35 +26,43 @@ export default function GeneralInfo() {
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="First Name"
|
placeholder="First Name"
|
||||||
value={firstName}
|
value={firstName}
|
||||||
onChange={(e) => setFirstName(e.target.value)}
|
onChange={(e) => {
|
||||||
|
setFirstName(e.target.value)
|
||||||
|
props.setBasicInfo({ ...props.basicInfo, firstName: e.target.value })
|
||||||
|
}
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Last Name"
|
placeholder="Last Name"
|
||||||
value={lastName}
|
value={lastName}
|
||||||
onChange={(e) => setLastName(e.target.value)}
|
onChange={(e) => {
|
||||||
/>
|
setLastName(e.target.value)
|
||||||
|
props.setBasicInfo({ ...props.basicInfo, lastName: e.target.value })
|
||||||
|
}} />
|
||||||
<input
|
<input
|
||||||
type="email"
|
type="email"
|
||||||
placeholder="Email"
|
placeholder="Email"
|
||||||
value={email}
|
value={email}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
onChange={(e) => {
|
||||||
|
setEmail(e.target.value)
|
||||||
|
props.setBasicInfo({ ...props.basicInfo, email: e.target.value })
|
||||||
|
}
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Phone Number"
|
placeholder="Phone Number"
|
||||||
value={phone}
|
value={phone}
|
||||||
onChange={(e) => setPhone(e.target.value)}
|
onChange={(e) => {
|
||||||
|
setPhone(e.target.value)
|
||||||
|
props.setBasicInfo({ ...props.basicInfo, phone: e.target.value })
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="contact-info">
|
|
||||||
<h1>{firstName + " " + lastName}</h1>
|
|
||||||
<p>{email}</p>
|
|
||||||
<p>{phone}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
Loading…
Reference in a new issue