extract strings from Language Tab

This commit is contained in:
Amruth Pillai
2020-03-30 02:31:55 +05:30
parent fe6df1b9b3
commit a373c463b4
4 changed files with 54 additions and 67 deletions

View File

@ -31,7 +31,7 @@ const LeftSidebar = () => {
const { state, dispatch } = context;
const { data } = state;
const [currentTab, setCurrentTab] = useState('Skills');
const [currentTab, setCurrentTab] = useState('Languages');
const onChange = (key, value) => {
dispatch({
type: 'on_input',

View File

@ -1,4 +1,5 @@
import React, { useState, useEffect, useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { v4 as uuidv4 } from 'uuid';
import set from 'lodash/set';
@ -6,10 +7,13 @@ import TextField from '../../../shared/TextField';
import AppContext from '../../../context/AppContext';
import Checkbox from '../../../shared/Checkbox';
import Counter from '../../../shared/Counter';
import { addItem, deleteItem, moveItemUp, moveItemDown } from '../../../utils';
import { addItem } from '../../../utils';
import ItemActions from '../../../shared/ItemActions';
import AddItemButton from '../../../shared/AddItemButton';
import ItemHeading from '../../../shared/ItemHeading';
const LanguagesTab = ({ data, onChange }) => {
const { t } = useTranslation('app');
const context = useContext(AppContext);
const { dispatch } = context;
@ -43,7 +47,7 @@ const LanguagesTab = ({ data, onChange }) => {
</div>
<div className="col-span-5">
<TextField
placeholder="Heading"
placeholder={t('heading.placeholder')}
value={data.languages.heading}
onChange={v => onChange('data.languages.heading', v)}
/>
@ -64,13 +68,37 @@ const LanguagesTab = ({ data, onChange }) => {
/>
))}
<AddItem dispatch={dispatch} />
<AddItem heading={data.languages.heading} dispatch={dispatch} />
</>
)
);
};
const AddItem = ({ dispatch }) => {
const Form = ({ item, onChange, identifier = '' }) => {
const { t } = useTranslation('leftSidebar');
return (
<div>
<TextField
className="mb-6"
label={t('languages.key.label')}
placeholder={t('languages.key.placeholder')}
value={item.key}
onChange={v => onChange(`${identifier}key`, v)}
/>
<Counter
className="mb-6"
label={t('languages.rating.label')}
value={item.value}
onDecrement={() => item.value > 1 && onChange(`${identifier}value`, item.value - 1)}
onIncrement={() => item.value < 5 && onChange(`${identifier}value`, item.value + 1)}
/>
</div>
);
};
const AddItem = ({ heading, dispatch }) => {
const [isOpen, setOpen] = useState(false);
const [item, setItem] = useState({
id: uuidv4(),
@ -98,41 +126,12 @@ const AddItem = ({ dispatch }) => {
return (
<div className="my-4 border border-gray-200 rounded p-5">
<div
className="flex justify-between items-center cursor-pointer"
onClick={() => setOpen(!isOpen)}
>
<h6 className="text-sm font-medium">Add Language</h6>
<i className="material-icons">{isOpen ? 'expand_less' : 'expand_more'}</i>
</div>
<ItemHeading heading={heading} setOpen={setOpen} isOpen={isOpen} />
<div className={`mt-6 ${isOpen ? 'block' : 'hidden'}`}>
<TextField
label="Key"
className="mb-6"
placeholder="Dothraki"
value={item.key}
onChange={v => onChange('key', v)}
/>
<Form item={item} onChange={onChange} />
<Counter
label="Rating"
className="mb-6"
value={item.value}
onDecrement={() => item.value > 1 && onChange('value', item.value - 1)}
onIncrement={() => item.value < 5 && onChange('value', item.value + 1)}
/>
<button
type="button"
onClick={onSubmit}
className="bg-gray-600 hover:bg-gray-700 text-white text-sm font-medium py-2 px-5 rounded"
>
<div className="flex items-center">
<i className="material-icons mr-2 font-bold text-base">add</i>
<span className="text-sm">Add</span>
</div>
</button>
<AddItemButton onSubmit={onSubmit} />
</div>
</div>
);
@ -140,46 +139,23 @@ const AddItem = ({ dispatch }) => {
const Item = ({ item, index, onChange, dispatch, first, last }) => {
const [isOpen, setOpen] = useState(false);
const identifier = `data.languages.items[${index}]`;
const identifier = `data.languages.items[${index}].`;
return (
<div className="my-4 border border-gray-200 rounded p-5">
<div
className="flex justify-between items-center cursor-pointer"
onClick={() => setOpen(!isOpen)}
>
<h6 className="text-sm font-medium">{item.key}</h6>
<i className="material-icons">{isOpen ? 'expand_less' : 'expand_more'}</i>
</div>
<ItemHeading title={item.key} setOpen={setOpen} isOpen={isOpen} />
<div className={`mt-6 ${isOpen ? 'block' : 'hidden'}`}>
<TextField
label="Name"
className="mb-6"
placeholder="Dothraki"
value={item.key}
onChange={v => onChange(`${identifier}.key`, v)}
/>
<Counter
label="Rating"
className="mb-6"
value={item.value}
onDecrement={() => item.value > 1 && onChange(`${identifier}.value`, item.value - 1)}
onIncrement={() => item.value < 5 && onChange(`${identifier}.value`, item.value + 1)}
/>
<Form item={item} onChange={onChange} identifier={identifier} />
<ItemActions
dispatch={dispatch}
first={first}
identifier={identifier}
item={item}
last={last}
onChange={onChange}
type="languages"
identifier={identifier}
dispatch={dispatch}
deleteItem={deleteItem}
first={first}
moveItemUp={moveItemUp}
last={last}
moveItemDown={moveItemDown}
/>
</div>
</div>

View File

@ -5,6 +5,7 @@ import education from './education.json';
import awards from './awards.json';
import certifications from './certifications.json';
import skills from './skills.json';
import languages from './languages.json';
export default {
profile,
@ -14,4 +15,5 @@ export default {
awards,
certifications,
skills,
languages,
};

View File

@ -0,0 +1,9 @@
{
"key": {
"label": "Key",
"placeholder": "Dothraki"
},
"rating": {
"label": "Rating"
}
}