From 1de3aaa523ce64b31f47ab49e99e0e917d6486d0 Mon Sep 17 00:00:00 2001 From: Amruth Pillai Date: Fri, 27 Mar 2020 16:41:54 +0530 Subject: [PATCH] more organization, added references and languages --- src/components/LeftSidebar/LeftSidebar.js | 10 +- src/components/LeftSidebar/tabs/Awards.js | 46 +-- .../LeftSidebar/tabs/Certifications.js | 46 +-- src/components/LeftSidebar/tabs/Education.js | 46 +-- src/components/LeftSidebar/tabs/Extras.js | 46 +-- src/components/LeftSidebar/tabs/Languages.js | 212 ++++++++++++++ src/components/LeftSidebar/tabs/References.js | 268 ++++++++++++++++++ src/components/LeftSidebar/tabs/Skills.js | 26 +- src/components/LeftSidebar/tabs/Work.js | 46 +-- src/context/AppContext.js | 12 + src/index.css | 22 +- src/shared/Counter.js | 35 +++ src/shared/TextField.js | 12 +- src/utils/index.js | 52 +++- 14 files changed, 659 insertions(+), 220 deletions(-) create mode 100644 src/components/LeftSidebar/tabs/Languages.js create mode 100644 src/components/LeftSidebar/tabs/References.js create mode 100644 src/shared/Counter.js diff --git a/src/components/LeftSidebar/LeftSidebar.js b/src/components/LeftSidebar/LeftSidebar.js index e6498664..9fdbf6c7 100644 --- a/src/components/LeftSidebar/LeftSidebar.js +++ b/src/components/LeftSidebar/LeftSidebar.js @@ -10,6 +10,8 @@ import AwardsTab from './tabs/Awards'; import CertificationsTab from './tabs/Certifications'; import SkillsTab from './tabs/Skills'; import ExtrasTab from './tabs/Extras'; +import LanguagesTab from './tabs/Languages'; +import ReferencesTab from './tabs/References'; const tabs = [ 'Profile', @@ -19,6 +21,8 @@ const tabs = [ 'Awards', 'Certifications', 'Skills', + 'Languages', + 'References', 'Extras', ]; @@ -27,7 +31,7 @@ const LeftSidebar = () => { const { state, dispatch } = context; const { data } = state; - const [currentTab, setCurrentTab] = useState('Profile'); + const [currentTab, setCurrentTab] = useState('Languages'); const onChange = (key, value) => { dispatch({ type: 'on_input', @@ -56,6 +60,10 @@ const LeftSidebar = () => { return ; case 'Skills': return ; + case 'Languages': + return ; + case 'References': + return ; case 'Extras': return ; default: diff --git a/src/components/LeftSidebar/tabs/Awards.js b/src/components/LeftSidebar/tabs/Awards.js index 07e80b7e..85606fa3 100644 --- a/src/components/LeftSidebar/tabs/Awards.js +++ b/src/components/LeftSidebar/tabs/Awards.js @@ -6,6 +6,7 @@ import TextField from '../../../shared/TextField'; import AppContext from '../../../context/AppContext'; import Checkbox from '../../../shared/Checkbox'; import TextArea from '../../../shared/TextArea'; +import { addItem, deleteItem, moveItemUp, moveItemDown } from '../../../utils'; const AwardsTab = ({ data, onChange }) => { const context = useContext(AppContext); @@ -59,16 +60,10 @@ const AddItem = ({ dispatch }) => { const onChange = (key, value) => setItem(set({ ...item }, key, value)); - const addItem = () => { + const onSubmit = () => { if (item.title === '') return; - dispatch({ - type: 'add_item', - payload: { - key: 'awards', - value: item, - }, - }); + addItem(dispatch, 'awards', item); setItem({ id: uuidv4(), @@ -116,7 +111,7 @@ const AddItem = ({ dispatch }) => { + + + ); +}; + +const Item = ({ item, index, onChange, dispatch, first, last }) => { + const [isOpen, setOpen] = useState(false); + const identifier = `data.languages.items[${index}]`; + + return ( +
+
setOpen(!isOpen)} + > +
{item.key}
+ {isOpen ? 'expand_less' : 'expand_more'} +
+ +
+ onChange(`${identifier}.key`, v)} + /> + + item.value > 1 && onChange(`${identifier}.value`, item.value - 1)} + onIncrement={() => item.value < 5 && onChange(`${identifier}.value`, item.value + 1)} + /> + +
+ + +
+ {!first && ( + + )} + + {!last && ( + + )} +
+
+
+
+ ); +}; + +export default LanguagesTab; diff --git a/src/components/LeftSidebar/tabs/References.js b/src/components/LeftSidebar/tabs/References.js new file mode 100644 index 00000000..ec1749e2 --- /dev/null +++ b/src/components/LeftSidebar/tabs/References.js @@ -0,0 +1,268 @@ +import React, { useState, useEffect, useContext } from 'react'; +import { v4 as uuidv4 } from 'uuid'; +import set from 'lodash/set'; + +import TextField from '../../../shared/TextField'; +import TextArea from '../../../shared/TextArea'; +import AppContext from '../../../context/AppContext'; +import Checkbox from '../../../shared/Checkbox'; +import { addItem, deleteItem, moveItemUp, moveItemDown } from '../../../utils'; + +const ReferencesTab = ({ data, onChange }) => { + const context = useContext(AppContext); + const { dispatch } = context; + + useEffect(() => { + if (!('references' in data)) { + dispatch({ + type: 'migrate_section', + payload: { + key: 'references', + value: { + enable: false, + heading: 'References', + items: [], + }, + }, + }); + + dispatch({ type: 'save_data' }); + } + }, [data, dispatch]); + + return ( + 'references' in data && ( + <> +
+
+ onChange('data.references.enable', v)} + /> +
+
+ onChange('data.references.heading', v)} + /> +
+
+ +
+ + {data.references.items.map((x, index) => ( + + ))} + + + + ) + ); +}; + +const AddItem = ({ dispatch }) => { + const [isOpen, setOpen] = useState(false); + const [item, setItem] = useState({ + id: uuidv4(), + name: '', + position: '', + phone: '', + email: '', + description: '', + }); + + const onChange = (key, value) => setItem(set({ ...item }, key, value)); + + const onSubmit = () => { + if (item.name === '' || item.position === '') return; + + addItem(dispatch, 'references', item); + + setItem({ + id: uuidv4(), + name: '', + position: '', + phone: '', + email: '', + description: '', + }); + + setOpen(false); + }; + + return ( +
+
setOpen(!isOpen)} + > +
Add Reference
+ {isOpen ? 'expand_less' : 'expand_more'} +
+ +
+ onChange('name', v)} + /> + + onChange('position', v)} + /> + + onChange('phone', v)} + /> + + onChange('email', v)} + /> + +