Skip to content

Commit e9e6428

Browse files
committed
refactor: refactor components
1 parent 8999aff commit e9e6428

16 files changed

+189
-172
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040
]
4141
},
4242
"devDependencies": {
43+
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
4344
"@eslint/js": "^9.17.0",
4445
"eslint": "^9.17.0",
4546
"eslint-config-react-app": "^7.0.1",
4647
"eslint-plugin-react": "^7.37.3",
4748
"globals": "^15.14.0"
4849
}
49-
}
50+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/App.css

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/App.js

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,63 @@
11
import React, { useState } from 'react'
22
import { Header, TextArea, ChartPlot, Footer } from './components'
33
import { preparDataChart } from '../src/util/TreadUserInput'
4-
import './App.css'
4+
import { ErrorContainer } from './styles'
55

66
export default function App() {
77

8+
const [value, setValue] = useState('')
89
const [chartProperties, setChartProperties] = useState({
9-
value: '',
1010
categories: null,
1111
series: null,
1212
})
13+
const [showError, setShowError] = useState(false)
14+
const [showChart, setShowChart] = useState(false)
1315

1416
const handleClick = () => {
15-
let temp = chartProperties.value !== null ? preparDataChart(chartProperties.value) : false
1617

17-
if (temp !== false) {
18+
setChartProperties({
19+
categories: null,
20+
series: null,
21+
})
22+
23+
setShowChart(false)
24+
setShowError(false)
25+
26+
const temp = value !== null ? preparDataChart(value) : false
27+
28+
if (temp !== false && temp?.series && temp?.series?.length > 0) {
1829
setChartProperties({
1930
categories: temp.categories,
2031
series: temp.series,
21-
value: '',
2232
})
33+
setShowChart(true)
34+
} else {
35+
setShowError(true)
2336
}
24-
}
2537

26-
const handleChange = (event) => {
27-
setChartProperties((prevState) => ({
28-
...prevState,
29-
value: event.target.value
30-
}))
38+
setValue('')
3139
}
3240

41+
const { categories, series } = chartProperties
3342

3443
return (
35-
<div className="app">
44+
<div>
3645
<Header />
3746
<TextArea
38-
value={chartProperties.value}
39-
handleChange={handleChange}
47+
value={value}
48+
handleChange={(event) => setValue(event.target.value)}
4049
/>
41-
{chartProperties.categories !== null && chartProperties.series !== null ? (
50+
{!!showChart && (
4251
<ChartPlot
43-
categories={chartProperties.categories}
44-
series={chartProperties.series}
52+
categories={categories}
53+
series={series}
4554
/>
46-
) : (
47-
<React.Fragment />
4855
)}
56+
57+
{!!showError && (
58+
<ErrorContainer>Opps... Dados de entrada inválidos</ErrorContainer>
59+
)}
60+
4961
<Footer handleClick={handleClick} />
5062
</div>
5163
)

src/GlobalStyle.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { createGlobalStyle } from 'styled-components'
2+
const GlobalStyle = createGlobalStyle`
3+
body {
4+
margin: 0;
5+
padding: 0;
6+
}
7+
8+
/* scrollbar style */
9+
::-webkit-scrollbar {
10+
width: 10px;
11+
}
12+
13+
::-webkit-scrollbar-track {
14+
background: rgb(10, 18, 42);
15+
}
16+
17+
::-webkit-scrollbar-thumb {
18+
background: rgb(102, 102, 102);
19+
border-radius: 10px;
20+
}
21+
22+
::-webkit-scrollbar-thumb:hover {
23+
background: rgb(102, 102, 102);
24+
}
25+
26+
/* import google fonts */
27+
@font-face {
28+
font-family: "Source Sans Pro";
29+
font-style: normal;
30+
font-weight: 400;
31+
src: url("./fonts/source-sans-pro-v11-latin-regular.eot");
32+
/* IE9 Compat Modes */
33+
src: local("Source Sans Pro Regular"), local("SourceSansPro-Regular"),
34+
url("/fonts/source-sans-pro-v11-latin-regular.eot?#iefix") format("embedded-opentype"),
35+
url("/fonts/source-sans-pro-v11-latin-regular.woff2") format("woff2"),
36+
url("/fonts/source-sans-pro-v11-latin-regular.woff") format("woff"),
37+
url("/fonts/source-sans-pro-v11-latin-regular.ttf") format("truetype"),
38+
url("/fonts/source-sans-pro-v11-latin-regular.svg#SourceSansPro") format("svg");
39+
}
40+
`
41+
42+
export default GlobalStyle

src/components/Footer/Footer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import { Button, Container } from './styles'
33

4-
export function Footer(handleClick) {
4+
export function Footer({ handleClick }) {
55
return (
66
<Container>
77
<Button

0 commit comments

Comments
 (0)