Link to website: https://rilmxp-global-warming.netlify.app/
An environmental information website created with React that renders charts about global warming's key factors by fetching data from different APIs. It promotes awareness about human impact on nature following the UN's Climate Action goal.
HTTP requests for charts are made to Global Warming and Climate Change API at https://global-warming.org/api
To run the app on local sever:
- Clone repository
- Install dependencies:
npm install - Launch local server:
npm run dev
The website consists of seven different routes to components that represent "pages".
All data displayed inside the charts is fetched directly from the APIs.
All data displayed outside the charts is retrieved from a local file at src/data/contentData.js
Each factor page consists of a chart and a list of causes, effects, and improvements to be made("What you can do"), regarding that particular factor.
-
Home: A banner displaying a carousel of famous quotations regarding commitment to change, importance of education and climate change. An introductory summary of the current status of factors that have a deep impact on the environment.
-
Temperature: chart displaying celsius anomalies through the years.
-
Carbon dioxide: chart displaying carbon dioxide levels.
-
Methane: chart displaying methane levels.
-
Nitrous oxide: chart displaying nitrous oxide levels.
-
Polar ice: chart displaying ice land extent in million square kilometers.
-
Error Page: to be displayed whenever the user inserts invalid route information directly on the url.
- Brand/Logo link to Home.
- Links to all global warming factors.
- Horizonal inline display of links on wide screens. Vertical canvas on click of toggle button on narrow screens.
On page load, it retrieves data from local file at src/data/contentData.js to feed the Factors section.
-
Banner
- Main heading containing a responsive image and a carousel of quotations.
- Main heading containing a responsive image and a carousel of quotations.
-
Factors section
- Each factor consists of a summary of its current status and a button that links to its dedicated page.
- To be rendered through animation only when the element enters the viewport.
-
Chart
-
On page load, data will be fetched from its corresponding factor API and a chart will be rendered.
-
On data chart loading, a loader animation will be shown.
-
In cases of huge amount of data, the same has been reduced in favor of a nicer/cleaner display. As an example, temperature data has been reduced to 1 value every ten years from 1880 until 1980, and annually from 1981 to present.
-
Linear, Area and Bar charts have been used to represent the data recieved.
-
On hover, a tooltip will be displayed to provide an easier reading of data.
-
In case of Error, a feedback message will be displayed.
-
-
Facts Section
- They consist of a list of "Causes", "Effects", and "What you can do" guidelines.
- Data is dinamically retrieved from local file at src/data/contentData.js.
Whenever the user manually inserts invalid data on the url, they will be redirected to the error page which consists of a background picture (the same used for the banner), and a button to go back to home.
-
Application created with ViteJs.
-
State management.
- No global state context setup was necessary for this app.
- Charts state is managed internally by Recharts library.
- Animations state is managed internally by framer motion library.
- Asynchronous state is managed by React Query.
- Bootstrap's Navbar state has been manually modified to close canvas after clicking on links.
-
Components. They can be found inside the
featuresfolder with the exception of page components which are located in their dedicated folder namedpages. -
Folders and file structure.
-
Note on
public/imagesfolder. Given the fact that images are dinamically imported withinFactor.jsx, they have been placed inside thepublicfolder instead ofsrc. All other files and folders have been created insidesrcfolder -
featuresfolder has been divided into different categories to reduce clutter. Each folder has anindex.jswhich imports and exports in only one place all the components from that specific feature. As an example, chart components for each factor will be found in thechartsfolder and, navbar and footer in thelayoutfolder. -
features/configurationfolder contains different animation setups for page transitions.RoutesTransitionAnimationcontains allRoutecomponents. It configures them withuseLocationso Framer Motion can animate their transition. -
datafolder containscontentData.jsfile with static data to feedFactorsContainer.jsxandFactsContainer.jsxandTextCarousel.jsx(quotations). -
stylesfolder contains minimum common configuration sass files as most styles have been set using css modules. -
apifolder contains axios base configuration for async calls ongraphDataApiConfig.jsand functions to handle API responses for each chart ongraphDataResponseHandlers.js.
-
- Used for creation of charts.
- Used for HTTP requests. Its base configuration can be found in
graphDataApiConfig.jsinside theapifolder
- Used for asynchronous state management of HTTP requests.
- Used for fade-in of page transitions and charts, scale-in of factors, spring-in of facts, and elements' display on entereing the viewport.
-
A few sass partials have been created.
_config.scssfor basic global styles._custom-bootstrap-main.scssand_custom-bootstrap-maps.scssto modify some bootstrap defaults. And_exports.module.scsswhich is needed in chart components for <defs> and tooltip inline styles as per Recharts specifications since classes will simply not work. -
Apart from that, most of the styles have been defined in Css modules adjacent to each corresponding component.
-
React-Icons. Github, briefcase, lightbulb, thermometer and magnifying glass icons.
-
Nanoid. To create ids for react lists internal indexing.
-
React-router-dom. To route to different page-like components.
-
React Bootstrap. Used for navigation bar.
The responsive nature of each component has been set directly on their own css module. Depending on the component, breakpoints have been set at min-width: 700px, 900px, 1400px.
-
Responsive images:
- Banner: achieved by changing the url value from
background-imageproperty. - Factors: achieved by setting
srcSetattribute on the <img> tag.
- Banner: achieved by changing the url value from
-
Responsive elements:
- Chart page: width and height of
GraphContainerandFactsContainer. - Homepage: width of
FactorsContainerand layout of its elements from vertical to horizontal.
- Chart page: width and height of