├── .babelrc
├── .editorconfig
├── .gitignore
├── .prettierrc
├── LICENSE.md
├── README.md
├── data
└── data.json
├── package.json
├── path.js
├── public
├── favicon.ico
├── index.html
└── manifest.json
├── src
├── App.js
├── App.test.js
├── Provider.js
├── components
│ ├── Dam.js
│ ├── Dam.test.js
│ ├── Dams.js
│ ├── Details.js
│ ├── Icon.js
│ ├── Loader.js
│ ├── Loading.js
│ ├── Menu.js
│ └── Transition.js
├── config.js
├── contexts
│ ├── DamsContext.js
│ └── LocationContext.js
├── index.js
├── pages
│ ├── About.js
│ └── Map.js
├── serviceWorker.js
└── setupTests.js
├── webpack.common.js
├── webpack.dev.js
├── webpack.prod.js
└── yarn.lock
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | [
4 | "@babel/preset-env",
5 | {
6 | "modules": false
7 | }
8 | ],
9 | "@babel/preset-react"
10 | ],
11 | "plugins": [
12 | "@babel/plugin-syntax-dynamic-import",
13 | [
14 | "import",
15 | {
16 | "libraryName": "antd",
17 | "style": true
18 | }
19 | ],
20 | "@babel/plugin-transform-spread",
21 | "@babel/plugin-proposal-object-rest-spread",
22 | "@babel/plugin-syntax-import-meta",
23 | "@babel/plugin-proposal-class-properties",
24 | "@babel/plugin-proposal-json-strings",
25 | "@babel/plugin-proposal-function-sent",
26 | "@babel/plugin-proposal-export-namespace-from",
27 | "@babel/plugin-proposal-numeric-separator",
28 | "@babel/plugin-proposal-throw-expressions",
29 | "@babel/plugin-proposal-export-default-from",
30 | "@babel/plugin-proposal-logical-assignment-operators",
31 | "@babel/plugin-proposal-optional-chaining",
32 | "@babel/plugin-proposal-nullish-coalescing-operator"
33 | ],
34 | "env": {
35 | "development": {
36 | "plugins": [
37 | "@babel/plugin-transform-modules-commonjs",
38 | [
39 | "styled-components",
40 | {
41 | "minify": false
42 | }
43 | ]
44 | ]
45 | },
46 | "test": {
47 | "plugins": ["@babel/plugin-transform-modules-commonjs"]
48 | },
49 | "production": {
50 | "plugins": [
51 | "transform-react-remove-prop-types",
52 | [
53 | "styled-components",
54 | {
55 | "displayName": false
56 | }
57 | ]
58 | ]
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | end_of_line = lf
6 | indent_size = 2
7 | indent_style = space
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # snapshots
9 | __snapshots__/
10 |
11 | # testing
12 | /coverage
13 |
14 | # production
15 | /build
16 |
17 | # misc
18 | .DS_Store
19 | .env.local
20 | .env.development.local
21 | .env.test.local
22 | .env.production.local
23 |
24 | npm-debug.log*
25 | yarn-debug.log*
26 | yarn-error.log*
27 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "useTabs": false,
3 | "printWidth": 80,
4 | "tabWidth": 2,
5 | "singleQuote": true,
6 | "trailingComma": "none",
7 | "jsxBracketSameLine": false,
8 | "semi": false,
9 | "bracketSpacing": true
10 | }
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Guilherme Bayer
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Barragens
2 |
3 | Projeto que tem como intuito tornar a informação que o governo disponibiliza com relação às barragens brasileiras, de fácil acesso e com uma experiência agradável.
4 |
5 | As informações relacionadas as barragens são totalmente obtidas da [Agência Nacional de Águas](http://www.snisb.gov.br/portal/snisb/mapas-tematicos-e-relatorios).
6 |
7 | ## Para desenvolvedores
8 |
9 | ### Instale as dependências
10 |
11 | ```sh
12 | yarn
13 | ```
14 |
15 | ### Rodando aplicação em desenvolvimento
16 |
17 | Primeiro, rode o comando abaixo apenas na primeira vez que fizer o clone da aplicação para gerar o diretório.
18 |
19 | ```sh
20 | yarn build
21 | ```
22 |
23 | Após o comando acima, só é necessário o comando abaixo.
24 |
25 | ```sh
26 | yarn start
27 | ```
28 |
29 | ## Dúvidas ou sugestões
30 |
31 | Você pode abrir uma [issue](https://github.com/guuibayer/barragens/issues/new) ou entrar no [Gitter](https://gitter.im/barragens/community#) do projeto.
32 |
33 | ## Contribuições
34 |
35 | Todas as tarefas dessa aplicação estão sendo mapeadas em nosso board, clique [aqui](https://github.com/guuibayer/barragens/projects/1) e confira.
36 |
37 | ## Licença
38 |
39 | [MIT © Guilherme Bayer](https://github.com/guuibayer/barragens/blob/master/LICENSE.md)
40 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "barragens",
3 | "version": "1.0.0",
4 | "private": true,
5 | "dependencies": {
6 | "antd": "^3.13.0",
7 | "leaflet": "^1.4.0",
8 | "leaflet.markercluster": "^1.4.1",
9 | "prop-types": "^15.6.2",
10 | "react": "^16.8.1",
11 | "react-dom": "^16.8.1",
12 | "react-ga": "^2.5.7",
13 | "react-leaflet": "^2.2.0",
14 | "react-leaflet-markercluster": "^2.0.0-rc3",
15 | "react-pose": "^4.0.7",
16 | "react-router": "^4.3.1",
17 | "react-router-dom": "^4.3.1",
18 | "styled-components": "^4.1.3",
19 | "uuid": "^3.3.2"
20 | },
21 | "scripts": {
22 | "start": "webpack-dev-server --open --config webpack.dev.js",
23 | "build": "webpack --config webpack.prod.js",
24 | "test": "jest"
25 | },
26 | "jest": {
27 | "snapshotSerializers": [
28 | "enzyme-to-json/serializer"
29 | ],
30 | "setupFiles": [
31 | "./src/setupTests.js"
32 | ],
33 | "moduleNameMapper": {
34 | ".+\\.(css|less|png|jpg|ttf|woff|woff2)$": "jest-transform-stub"
35 | }
36 | },
37 | "devDependencies": {
38 | "@babel/core": "^7.2.2",
39 | "@babel/plugin-proposal-class-properties": "^7.3.0",
40 | "@babel/plugin-proposal-export-default-from": "^7.2.0",
41 | "@babel/plugin-proposal-export-namespace-from": "^7.2.0",
42 | "@babel/plugin-proposal-function-sent": "^7.2.0",
43 | "@babel/plugin-proposal-json-strings": "^7.2.0",
44 | "@babel/plugin-proposal-logical-assignment-operators": "^7.2.0",
45 | "@babel/plugin-proposal-nullish-coalescing-operator": "^7.2.0",
46 | "@babel/plugin-proposal-numeric-separator": "^7.2.0",
47 | "@babel/plugin-proposal-object-rest-spread": "^7.3.1",
48 | "@babel/plugin-proposal-optional-chaining": "^7.2.0",
49 | "@babel/plugin-proposal-throw-expressions": "^7.2.0",
50 | "@babel/plugin-syntax-dynamic-import": "^7.2.0",
51 | "@babel/plugin-syntax-import-meta": "^7.2.0",
52 | "@babel/plugin-transform-modules-commonjs": "^7.2.0",
53 | "@babel/plugin-transform-spread": "^7.2.2",
54 | "@babel/preset-env": "^7.3.1",
55 | "@babel/preset-react": "^7.0.0",
56 | "@svgr/webpack": "^4.1.0",
57 | "babel-jest": "^24.0.0",
58 | "babel-loader": "^8.0.5",
59 | "babel-plugin-import": "^1.11.0",
60 | "babel-preset-es2015": "^6.24.1",
61 | "copy-webpack-plugin": "^4.6.0",
62 | "css-loader": "^2.1.0",
63 | "enzyme": "^3.8.0",
64 | "enzyme-adapter-react-16": "^1.8.0",
65 | "enzyme-to-json": "^3.3.5",
66 | "html-webpack-plugin": "^3.2.0",
67 | "jest": "^24.0.0",
68 | "jest-transform-stub": "^2.0.0",
69 | "less": "^3.9.0",
70 | "less-loader": "^4.1.0",
71 | "react-test-renderer": "^16.7.0",
72 | "style-loader": "^0.23.1",
73 | "uglifyjs-webpack-plugin": "^2.1.1",
74 | "webpack": "^4.29.0",
75 | "webpack-cli": "^3.2.1",
76 | "webpack-dev-server": "^3.1.14",
77 | "webpack-merge": "^4.2.1"
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/path.js:
--------------------------------------------------------------------------------
1 | const { join } = require('path')
2 |
3 | module.exports = {
4 | source: join(process.cwd(), `src`),
5 | build: join(process.cwd(), 'build'),
6 | public: join(process.cwd(), 'public'),
7 | data: join(process.cwd(), 'data/data.json')
8 | }
9 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iamgbayer/barragens/30a32eef1241764a00b0ccac38950b8ac5989854/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 |
12 |
16 |
17 |
18 |
22 |
23 |
27 |
28 |
32 |
33 | Barragens
34 |
35 |
36 |
37 |
38 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | }
10 | ],
11 | "start_url": ".",
12 | "display": "standalone",
13 | "theme_color": "#000000",
14 | "background_color": "#ffffff"
15 | }
16 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from 'styled-components'
3 | import { createGlobalStyle } from 'styled-components'
4 | import { Route, Switch, BrowserRouter } from 'react-router-dom'
5 | import ReactGA from 'react-ga'
6 |
7 | import { Menu } from './components/Menu'
8 | import { Map } from './pages/Map'
9 | import { About } from './pages/About'
10 | import { Provider } from './Provider'
11 |
12 | const GlobalStyle = createGlobalStyle`
13 | .leaflet-tile-pane {
14 | -webkit-filter: grayscale(100%);
15 | filter: grayscale(100%);
16 | }
17 | `
18 |
19 | const Container = styled.div`
20 | width: 100%;
21 | height: 100vh;
22 | display: flex;
23 | `
24 |
25 | ReactGA.initialize(process.env.REACT_APP_UA)
26 |
27 | export const App = () => (
28 |
29 | <>
30 |
31 |
32 |
33 |
41 |
42 | >
43 |
44 | )
45 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { shallow } from 'enzyme'
3 |
4 | import { App } from './App'
5 |
6 | it('renders without crashing', () => {
7 | const component = shallow()
8 | expect(component).toMatchSnapshot()
9 | })
10 |
--------------------------------------------------------------------------------
/src/Provider.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { LocationProvider } from './contexts/LocationContext'
3 | import { DamsProvider } from './contexts/DamsContext'
4 |
5 | export const Provider = props => (
6 |
7 | {props.children}
8 |
9 | )
10 |
--------------------------------------------------------------------------------
/src/components/Dam.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 | import { v4 } from 'uuid'
3 | import { Marker } from 'react-leaflet'
4 | import { PoseGroup } from 'react-pose'
5 |
6 | import { Icon } from './Icon'
7 | import { Details } from './Details'
8 |
9 | export function Dam(props) {
10 | const [isShowable, setIsShowable] = useState(false)
11 |
12 | const whenMarkerPressed = () => setIsShowable(!isShowable)
13 | const whenCloseable = () => setIsShowable(false)
14 |
15 | const { coords } = props.data
16 | const { lat, lng } = coords
17 |
18 | return (
19 | <>
20 |
21 | {isShowable && (
22 |
28 | )}
29 |
30 |
31 |
37 | >
38 | )
39 | }
40 |
--------------------------------------------------------------------------------
/src/components/Dam.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { shallow } from 'enzyme'
3 | import { Marker } from 'react-leaflet'
4 |
5 | import { Dam } from './Dam'
6 | import { Details } from './Details'
7 |
8 | const data = {
9 | coords: {
10 | lat: -13.5594465,
11 | lng: -46.7659922
12 | }
13 | }
14 |
15 | jest.mock('uuid', () => ({
16 | v4: jest.fn(() => '82f934ef-65ff-4539-a656-4fac1c9eea72')
17 | }))
18 |
19 | it('renders without crashing', () => {
20 | const component = shallow()
21 |
22 | expect(component).toMatchSnapshot()
23 | })
24 |
25 | it('test when marker pressed', () => {
26 | const component = shallow()
27 | component.find(Marker).simulate('click')
28 |
29 | expect(component.state().isShowable).toBe(true)
30 | })
31 |
32 | it('test should Details component rendered', () => {
33 | const component = shallow()
34 | component.setState({ isShowable: true })
35 |
36 | expect(component.find(Details).length).toEqual(1)
37 | })
38 |
39 | it('test when marker was closed', () => {
40 | const component = shallow()
41 | component.setState({ isShowable: true })
42 |
43 | const instance = component.instance()
44 | instance.whenCloseable()
45 |
46 | expect(component.state().isShowable).toBe(false)
47 | })
48 |
--------------------------------------------------------------------------------
/src/components/Dams.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import PropTypes from 'prop-types'
3 | import { v4 } from 'uuid'
4 |
5 | import { Dam } from './Dam'
6 |
7 | export const Dams = ({ data }) => {
8 | return (
9 | <>
10 | {data.map(dam => (
11 |
12 | ))}
13 | >
14 | )
15 | }
16 |
17 | Dams.propTypes = {
18 | data: PropTypes.array
19 | }
20 |
--------------------------------------------------------------------------------
/src/components/Details.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from 'styled-components'
3 | import PropTypes from 'prop-types'
4 | import ReactGA from 'react-ga'
5 | import { Icon } from 'antd'
6 |
7 | import config from '../config'
8 | import { Transition } from './Transition'
9 |
10 | const Container = styled(Transition)`
11 | width: calc(100% - 20px);
12 | height: 200px;
13 | display block;
14 | position: absolute;
15 | bottom: 10px;
16 | left: 10px;
17 | z-index: 999;
18 | border: 1px solid #e8e8e8;
19 | border-radius: 2px;
20 | background: #fff;
21 |
22 | h4 {
23 | font-size: 15px;
24 | margin-bottom: 0;
25 | color: rgba(0, 0, 0, 0.45);
26 | }
27 | `
28 |
29 | const Header = styled.div`
30 | background: #fafafa;
31 | padding: 12px 10px;
32 | border-bottom: 1px solid #e8e8e8;
33 | display: flex;
34 | justify-content: space-between;
35 | align-items: center;
36 | `
37 |
38 | const Body = styled.div`
39 | padding: 12px;
40 | display: flex;
41 | flex-wrap: wrap;
42 | flex-direction: row;
43 | `
44 |
45 | const Close = styled(Icon)`
46 | font-size: 20px;
47 | color: rgba(0, 0, 0, 0.45);
48 | transform: rotate(315deg);
49 | `
50 |
51 | const Item = styled.div`
52 | margin-bottom: 15px;
53 | flex: 50%;
54 |
55 | strong {
56 | margin-right: 5px;
57 | }
58 | `
59 |
60 | export const Details = ({ isShowable, data, whenCloseable, ...props }) => {
61 | const { name, state, risk, purpose, inspector, city, lng, lat } = data
62 |
63 | ReactGA.pageview(`${config.resources.dam}/${name}`)
64 |
65 | return (
66 |
67 |
71 |
72 | -
73 | Estado
74 | {state}
75 |
76 | -
77 | Cidade
78 | {city}
79 |
80 | -
81 | Orgão responsável
82 | {inspector}
83 |
84 | -
85 | Propósito da barragem
86 | {purpose}
87 |
88 | -
89 | Risco
90 | {risk}
91 |
92 | -
93 | Latitude
94 | {lat}
95 |
96 | -
97 | Longitude
98 | {lng}
99 |
100 |
101 |
102 | )
103 | }
104 |
105 | Details.propTypes = {
106 | data: PropTypes.shape({
107 | name: PropTypes.string,
108 | capacity: PropTypes.number,
109 | city: PropTypes.string,
110 | coords: PropTypes.shape({
111 | lat: PropTypes.number,
112 | lng: PropTypes.number
113 | }),
114 | dpa: PropTypes.string,
115 | inspector: PropTypes.string,
116 | purpose: PropTypes.string,
117 | risk: PropTypes.string,
118 | snisb: PropTypes.number,
119 | state: PropTypes.string
120 | })
121 | }
122 |
--------------------------------------------------------------------------------
/src/components/Icon.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOMServer from 'react-dom/server'
3 | import L from 'leaflet'
4 | import styled from 'styled-components'
5 |
6 | const Colorizable = styled.svg`
7 | circle {
8 | fill: rgba(110, 204, 57, 0.6);
9 | }
10 | `
11 |
12 | const Container = () => (
13 |
14 |
15 |
16 | )
17 |
18 | export const Icon = L.divIcon({
19 | html: ReactDOMServer.renderToString(),
20 | className: 'icon'
21 | })
22 |
--------------------------------------------------------------------------------
/src/components/Loader.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iamgbayer/barragens/30a32eef1241764a00b0ccac38950b8ac5989854/src/components/Loader.js
--------------------------------------------------------------------------------
/src/components/Loading.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from 'styled-components'
3 | import { Spin } from 'antd'
4 |
5 | const wasDataLoading = data => {
6 | console.log(data.length === 0)
7 | return data.length === 0
8 | }
9 |
10 | const Spineable = styled(Spin)`
11 | width: 100%;
12 |
13 | .ant-spin-nested-loading {
14 | width: 100%;
15 | }
16 | `
17 |
18 | export const Loading = ({ children, data }) => (
19 |
20 | {children}
21 |
22 | )
23 |
--------------------------------------------------------------------------------
/src/components/Menu.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from 'styled-components'
3 | import { Menu as Menuable, Icon } from 'antd'
4 | import { Link } from 'react-router-dom'
5 |
6 | const Navigation = styled(Menuable)`
7 | display: flex;
8 | justify-content: flex-end;
9 | height: 48px;
10 | `
11 |
12 | const Container = styled.div`
13 | display: flex;
14 | flex-direction: column;
15 | width: 100%;
16 | height: 100vh;
17 | `
18 |
19 | export const Menu = props => (
20 |
21 |
22 |
23 |
24 |
25 | Barragens
26 |
27 |
28 |
29 |
30 |
31 | Sobre
32 |
33 |
34 |
35 |
36 | {props.children}
37 |
38 | )
39 |
--------------------------------------------------------------------------------
/src/components/Transition.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import posed from 'react-pose'
3 |
4 | export const Transition = posed.div({
5 | enter: {
6 | y: 0,
7 | opacity: 1,
8 | delay: 300,
9 | transition: {
10 | y: { type: 'spring', stiffness: 1000, damping: 15 },
11 | default: { duration: 50 }
12 | }
13 | },
14 | exit: {
15 | y: 50,
16 | opacity: 0,
17 | transition: { duration: 150 }
18 | }
19 | })
20 |
--------------------------------------------------------------------------------
/src/config.js:
--------------------------------------------------------------------------------
1 | export default {
2 | resources: {
3 | about: '/about',
4 | dams: '/dams',
5 | dam: '/dams/dam'
6 | },
7 | JSON: 'data.json'
8 | }
9 |
--------------------------------------------------------------------------------
/src/contexts/DamsContext.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect } from 'react'
2 | import config from '../config'
3 |
4 | export const DamsContext = React.createContext()
5 |
6 | export function DamsProvider({ children }) {
7 | const [data, setData] = useState([])
8 |
9 | useEffect(() => {
10 | fetch(config.JSON)
11 | .then(data => data.json())
12 | .then(formatter)
13 | .then(setData)
14 | }, [])
15 |
16 | /**
17 | * @todo Anti corruption method
18 | * @param {object} data
19 | */
20 | const formatter = data => {
21 | const format = dam => ({
22 | height_above_foundation: dam['Altura Acima da Fundação (m)'],
23 | height_above_ground: dam['Altura Acima do Terreno (m)'],
24 | capacity: dam['Capacidade (hm3)'],
25 | risk: dam['Categoria de Risco'],
26 | dpa: dam['Classe de DPA'],
27 | snisb: dam['Código SNISB'],
28 | inspector: dam['Fiscalizador'],
29 | city: dam['Município'],
30 | name: dam['Nome da Barragem'],
31 | state: dam['UF'],
32 | purpose: dam['Uso Principal'],
33 | lng: dam['Longitude'],
34 | lat: dam['Latitude'],
35 | coords: {
36 | lat: dam['Latitude (Graus)'],
37 | lng: dam['Longitude (Graus)']
38 | }
39 | })
40 |
41 | return data.map(format)
42 | }
43 |
44 | return {children}
45 | }
46 |
--------------------------------------------------------------------------------
/src/contexts/LocationContext.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 |
3 | const defaultLocation = {
4 | lat: -13.5594465,
5 | lng: -46.7659922
6 | }
7 |
8 | export const LocationContext = React.createContext()
9 |
10 | export function LocationProvider({ children }) {
11 | const [location, setLocation] = useState(defaultLocation)
12 |
13 | return (
14 |
15 | {children}
16 |
17 | )
18 | }
19 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom'
3 | import { App } from './App'
4 | import * as serviceWorker from './serviceWorker'
5 |
6 | ReactDOM.render(, document.getElementById('root'))
7 |
8 | // If you want your app to work offline and load faster, you can change
9 | // unregister() to register() below. Note this comes with some pitfalls.
10 | // Learn more about service workers: http://bit.ly/CRA-PWA
11 | serviceWorker.unregister()
12 |
--------------------------------------------------------------------------------
/src/pages/About.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from 'styled-components'
3 | import ReactGA from 'react-ga'
4 | import config from '../config'
5 |
6 | const Title = styled.h1`
7 | text-align: center;
8 | color: #000;
9 | `
10 |
11 | const Description = styled.p`
12 | color: #000;
13 | text-align: center;
14 | width: 100%;
15 | max-width: 670px;
16 | margin: 0 auto;
17 | margin-bottom: 20px;
18 | `
19 |
20 | const Container = styled.div`
21 | width: 100%;
22 | max-width: 1024px;
23 | margin: 0 auto;
24 | margin-top: 45px;
25 |
26 | @media (max-width: 1024px) {
27 | padding: 0 15px;
28 | }
29 | `
30 |
31 | export const About = () => {
32 | ReactGA.pageview(config.resources.about)
33 |
34 | return (
35 |
36 | Sobre
37 |
38 |
39 | Projeto que tem como intuito tornar a informação que o governo
40 | disponibiliza com relação às barragens brasileiras, de fácil acesso e
41 | com uma experiência agradável.
42 |
43 |
44 |
45 | As informações relacionadas as barragens são totalmente obtidas da{' '}
46 |
50 | Agência Nacional de Águas
51 |
52 | , e não são apenas informações sobre barragens de minério e sim de
53 | vários propósitos, atualmente são mais de 5000 barragens cadastradas no{' '}
54 |
55 | SNISB - Sistema Nacional de Informações sobre Segurança de Barragens.
56 |
57 |
58 |
59 |
60 | Você também pode obter o código fonte do projeto{' '}
61 |
62 | aqui
63 |
64 | , além de sugerir novas ideias e apontar melhorias através das issues.
65 |
66 |
67 | )
68 | }
69 |
--------------------------------------------------------------------------------
/src/pages/Map.js:
--------------------------------------------------------------------------------
1 | import React, { useContext } from 'react'
2 | import styled from 'styled-components'
3 | import ReactGA from 'react-ga'
4 | import { Map as Mapeable, TileLayer } from 'react-leaflet'
5 | import MarkerClusterGroup from 'react-leaflet-markercluster'
6 |
7 | import config from '../config'
8 | import { LocationContext } from '../contexts/LocationContext'
9 | import { DamsContext } from '../contexts/DamsContext'
10 | import { Dams } from '../components/Dams'
11 |
12 | const Container = styled(Mapeable)`
13 | width: 100%;
14 | height: 100vh;
15 |
16 | .icon {
17 | border: none;
18 | background: transparent;
19 | }
20 | `
21 |
22 | export const Map = () => {
23 | ReactGA.pageview(config.resources.dams)
24 |
25 | const data = useContext(DamsContext)
26 | const { lat, lng } = useContext(LocationContext)
27 |
28 | return (
29 |
30 |
31 |
32 |
36 |
37 |
38 |
39 | )
40 | }
41 |
--------------------------------------------------------------------------------
/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read http://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.1/8 is considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit http://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See http://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl)
104 | .then(response => {
105 | // Ensure service worker exists, and that we really are getting a JS file.
106 | const contentType = response.headers.get('content-type');
107 | if (
108 | response.status === 404 ||
109 | (contentType != null && contentType.indexOf('javascript') === -1)
110 | ) {
111 | // No service worker found. Probably a different app. Reload the page.
112 | navigator.serviceWorker.ready.then(registration => {
113 | registration.unregister().then(() => {
114 | window.location.reload();
115 | });
116 | });
117 | } else {
118 | // Service worker found. Proceed as normal.
119 | registerValidSW(swUrl, config);
120 | }
121 | })
122 | .catch(() => {
123 | console.log(
124 | 'No internet connection found. App is running in offline mode.'
125 | );
126 | });
127 | }
128 |
129 | export function unregister() {
130 | if ('serviceWorker' in navigator) {
131 | navigator.serviceWorker.ready.then(registration => {
132 | registration.unregister();
133 | });
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/src/setupTests.js:
--------------------------------------------------------------------------------
1 | import { configure } from 'enzyme'
2 | import Adapter from 'enzyme-adapter-react-16'
3 |
4 | configure({ adapter: new Adapter() })
5 |
--------------------------------------------------------------------------------
/webpack.common.js:
--------------------------------------------------------------------------------
1 | const webpack = require('webpack')
2 |
3 | const PATH = require('./path')
4 |
5 | const HtmlWebpackPlugin = require('html-webpack-plugin')
6 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
7 |
8 | module.exports = {
9 | output: {
10 | path: PATH.build
11 | },
12 |
13 | resolve: {
14 | extensions: ['.js', '.less']
15 | },
16 |
17 | module: {
18 | rules: [
19 | {
20 | test: /\.js$/,
21 | exclude: /node_modules/,
22 | include: PATH.source,
23 | use: {
24 | loader: 'babel-loader'
25 | }
26 | },
27 | {
28 | test: /node_modules\/.*\.less$/,
29 | use: [
30 | { loader: 'style-loader' },
31 | { loader: 'css-loader' },
32 | {
33 | loader: 'less-loader',
34 | options: {
35 | javascriptEnabled: true,
36 | modifyVars: {
37 | '@primary-color': '#FF8764'
38 | }
39 | }
40 | }
41 | ]
42 | },
43 | {
44 | test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
45 | use: [
46 | {
47 | loader: 'babel-loader'
48 | },
49 | {
50 | loader: '@svgr/webpack',
51 | options: {
52 | babel: false,
53 | icon: true
54 | }
55 | }
56 | ]
57 | }
58 | ]
59 | },
60 |
61 | plugins: [
62 | new HtmlWebpackPlugin({
63 | template: `${PATH.public}/index.html`
64 | }),
65 | new webpack.EnvironmentPlugin({
66 | REACT_APP_UA: ''
67 | })
68 | ]
69 | }
70 |
--------------------------------------------------------------------------------
/webpack.dev.js:
--------------------------------------------------------------------------------
1 | const merge = require('webpack-merge')
2 | const common = require('./webpack.common.js')
3 |
4 | const PATH = require('./path')
5 |
6 | module.exports = merge(common, {
7 | mode: 'development',
8 | devtool: 'inline-source-map',
9 | devServer: {
10 | contentBase: PATH.build,
11 | publicPath: '/',
12 | historyApiFallback: true
13 | }
14 | })
15 |
--------------------------------------------------------------------------------
/webpack.prod.js:
--------------------------------------------------------------------------------
1 | const merge = require('webpack-merge')
2 | const common = require('./webpack.common.js')
3 | const path = require('./path')
4 |
5 | const CopyWebpackPlugin = require('copy-webpack-plugin')
6 |
7 | module.exports = merge(common, {
8 | mode: 'production',
9 | devtool: 'source-map',
10 |
11 | plugins: [
12 | new CopyWebpackPlugin([
13 | {
14 | from: path.data,
15 | to: path.build
16 | }
17 | ])
18 | ]
19 | })
20 |
--------------------------------------------------------------------------------