From ef985ae0626b463e3b785357df834d04fc8cedc4 Mon Sep 17 00:00:00 2001 From: Konrad Zapotoczny Date: Fri, 29 Oct 2021 14:46:01 +0200 Subject: [PATCH 1/5] TabContent component created, changed the way tabs work --- task-01/src/App.js | 16 ++++------ task-01/src/containers/ClassForm.js | 6 ++-- task-01/src/containers/Form.js | 4 +-- task-01/src/containers/NavBar.js | 2 +- task-01/src/containers/Static.js | 4 +-- task-01/src/containers/TabContent.js | 15 ++++++++++ task-01/src/containers/Tabs.js | 45 +++++++--------------------- 7 files changed, 38 insertions(+), 54 deletions(-) create mode 100644 task-01/src/containers/TabContent.js diff --git a/task-01/src/App.js b/task-01/src/App.js index c8a2968..dec8e30 100644 --- a/task-01/src/App.js +++ b/task-01/src/App.js @@ -1,25 +1,19 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { LanguageProvider } from './libs/language'; import './App.css'; import ErrorBoundary from './components/ErrorBoundary'; import NavBar from './containers/NavBar'; -import Form from './containers/Form'; -import Static from './containers/Static'; -import ClassForm from './containers/ClassForm'; +import TabContent from './containers/TabContent'; function App() { - const [tabContentClassName, setTabContentClassName] = useState({form: "tab-content active", static: "tab-content", classForm: "tab-content"}); + const [activeTab, setActiveTab] = useState("form"); return (
- -
-
- - -
+ +
diff --git a/task-01/src/containers/ClassForm.js b/task-01/src/containers/ClassForm.js index 90fba24..7a4aa7b 100644 --- a/task-01/src/containers/ClassForm.js +++ b/task-01/src/containers/ClassForm.js @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import { deleteContactData as deleteContactData, submitContact } from '../libs/dataFlow'; +import { deleteContactData, submitContact } from '../libs/dataFlow'; import { Text, Input, TextArea } from '../libs/language'; import './ClassForm.css'; @@ -33,7 +33,7 @@ export default class ClassForm extends Component { } render() { - return ( + return (this.props.isactive ? (
@@ -44,7 +44,7 @@ export default class ClassForm extends Component {
-
+ ) : null ) } } diff --git a/task-01/src/containers/Form.js b/task-01/src/containers/Form.js index a0a361a..f708088 100644 --- a/task-01/src/containers/Form.js +++ b/task-01/src/containers/Form.js @@ -30,7 +30,7 @@ export default function Form(props){ dispatch(action); } - return ( isloading ?
Loading...
: ( + return ( props.isactive ? (isloading ?
Loading...
: (
@@ -54,7 +54,7 @@ export default function Form(props){
- )) + )) : null) diff --git a/task-01/src/containers/NavBar.js b/task-01/src/containers/NavBar.js index f67de0d..53f79d5 100644 --- a/task-01/src/containers/NavBar.js +++ b/task-01/src/containers/NavBar.js @@ -6,7 +6,7 @@ import "./NavBar.css"; export default function NavBar(props){ return (
- +
) diff --git a/task-01/src/containers/Static.js b/task-01/src/containers/Static.js index ae7d0b5..806794d 100644 --- a/task-01/src/containers/Static.js +++ b/task-01/src/containers/Static.js @@ -9,11 +9,11 @@ function Static(props) { arr.push(text); } - return ( + return ( props.isactive ? (


{Object.entries(arr).map(([id,text]) => )} -
+ ) : null ) } diff --git a/task-01/src/containers/TabContent.js b/task-01/src/containers/TabContent.js new file mode 100644 index 0000000..d9f060e --- /dev/null +++ b/task-01/src/containers/TabContent.js @@ -0,0 +1,15 @@ +import React, { useState } from 'react' +import Form from "./Form"; +import Static from "./Static"; +import ClassForm from "./ClassForm"; +import '../App.css' + +export default function TabContent(props) { + return ( +
+ + + +
+ ) +} diff --git a/task-01/src/containers/Tabs.js b/task-01/src/containers/Tabs.js index 7ce914e..a71f94e 100644 --- a/task-01/src/containers/Tabs.js +++ b/task-01/src/containers/Tabs.js @@ -1,52 +1,27 @@ -import React, { useState, useEffect } from 'react'; +import React from 'react'; import './Tabs.css'; -function onClick(id, setActive) { - setActive(id); -} function Tab(props) { + + function onClick(e) { + props.setActiveTab(e.target.id); + } + return ( -
onClick(props.id, props.setActive)}> - {props.name} +
+ {props.id}
) } export default function Tabs(props) { - const [active, setActive] = useState("form"); - const [className, setClassName] = useState({ form: "tab active", static: "tab", classForm: "tab" }); - const setTabContentClassName = props.setTabContentClassName; - - useEffect(() => { - switch (active) { - case "form": - setClassName({ form: "tab active", static: "tab", classForm: "tab" }); - setTabContentClassName({ form: "tab-content active", static: "tab-content", classForm: "tab-content" }); - break; - case "static": - setClassName({ form: "tab", static: "tab active", classForm: "tab" }); - setTabContentClassName({ form: "tab-content", static: "tab-content active", classForm: "tab-content" }); - break; - case "classForm": - setClassName({ form: "tab", static: "tab", classForm: "tab active" }); - setTabContentClassName({ form: "tab-content", static: "tab-content", classForm: "tab-content active" }); - break; - default: - setClassName({ form: "tab active", static: "tab", classForm: "tab" }); - setTabContentClassName({ form: "tab-content active", static: "tab-content", classForm: "tab-content" }); - } - }, [active, setTabContentClassName]) - const tabList = { - form: { name: "form", className: "tab active" }, - static: { name: "static", className: "tab" }, - classForm: { name: "classForm", className: "tab" } - } + const TAB_ID = ["form", "static", "classForm"]; return (
- {Object.entries(tabList).map(([id, obj]) => )} + {TAB_ID.map(id => )}
) } \ No newline at end of file From a5c72b2e872eef35d6f4cf50a5b7d6e260d34c73 Mon Sep 17 00:00:00 2001 From: Konrad Zapotoczny Date: Fri, 29 Oct 2021 14:51:54 +0200 Subject: [PATCH 2/5] fixed console warnings --- task-01/src/App.js | 2 +- task-01/src/containers/TabContent.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/task-01/src/App.js b/task-01/src/App.js index dec8e30..fdc2a75 100644 --- a/task-01/src/App.js +++ b/task-01/src/App.js @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useState } from 'react'; import { LanguageProvider } from './libs/language'; import './App.css'; import ErrorBoundary from './components/ErrorBoundary'; diff --git a/task-01/src/containers/TabContent.js b/task-01/src/containers/TabContent.js index d9f060e..1105bca 100644 --- a/task-01/src/containers/TabContent.js +++ b/task-01/src/containers/TabContent.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React from 'react' import Form from "./Form"; import Static from "./Static"; import ClassForm from "./ClassForm"; @@ -7,9 +7,9 @@ import '../App.css' export default function TabContent(props) { return (
- - - + + +
) } From b2f107b322cb27e3f44811721f0fe021169ce105 Mon Sep 17 00:00:00 2001 From: Konrad Zapotoczny Date: Fri, 29 Oct 2021 15:31:45 +0200 Subject: [PATCH 3/5] fixed accessibility warnings, removed useless props passing --- task-01/src/App.js | 2 +- task-01/src/components/LanguageSelector.js | 1 + task-01/src/containers/ClassForm.js | 26 +++++++++------------- task-01/src/containers/Form.js | 12 +++++----- task-01/src/containers/Static.js | 4 ++-- task-01/src/containers/TabContent.js | 9 ++++---- task-01/src/containers/Tabs.js | 4 ++-- 7 files changed, 27 insertions(+), 31 deletions(-) diff --git a/task-01/src/App.js b/task-01/src/App.js index fdc2a75..79e1fb5 100644 --- a/task-01/src/App.js +++ b/task-01/src/App.js @@ -13,7 +13,7 @@ function App() { - +
diff --git a/task-01/src/components/LanguageSelector.js b/task-01/src/components/LanguageSelector.js index 5a130d1..06cc1ff 100644 --- a/task-01/src/components/LanguageSelector.js +++ b/task-01/src/components/LanguageSelector.js @@ -13,6 +13,7 @@ export default function LanguageSelector(props){

-
-