From d3e3171efae87ef45cc5140a2692016a3de8d925 Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Fri, 2 Oct 2020 14:58:54 -0400 Subject: [PATCH] Clean up annual report jsx file, add comments for functions and constants --- src/views/annual-report/annual-report.jsx | 194 +++++++++++----------- 1 file changed, 98 insertions(+), 96 deletions(-) diff --git a/src/views/annual-report/annual-report.jsx b/src/views/annual-report/annual-report.jsx index 40dbf6e5c..a26f2617b 100644 --- a/src/views/annual-report/annual-report.jsx +++ b/src/views/annual-report/annual-report.jsx @@ -1,27 +1,27 @@ const bindAll = require('lodash.bindall'); const classNames = require('classnames'); +const React = require('react'); +const MediaQuery = require('react-responsive').default; const FormattedHTMLMessage = require('react-intl').FormattedHTMLMessage; const FormattedMessage = require('react-intl').FormattedMessage; const injectIntl = require('react-intl').injectIntl; const intlShape = require('react-intl').intlShape; -const React = require('react'); +const render = require('../../lib/render.jsx'); +const frameless = require('../../lib/frameless'); + +const Page = require('../../components/page/www/page.jsx'); const Button = require('../../components/forms/button.jsx'); const FlexRow = require('../../components/flex-row/flex-row.jsx'); const Comment = require('../../components/comment/comment.jsx'); -const People = require('./people.json'); -const PeopleGrid = require('../../components/people-grid/people-grid.jsx'); const WorldMap = require('../../components/world-map/world-map.jsx'); const CountryUsage = require('./country-usage.json'); - -const Page = require('../../components/page/www/page.jsx'); -const render = require('../../lib/render.jsx'); - -const MediaQuery = require('react-responsive').default; -const frameless = require('../../lib/frameless'); +const PeopleGrid = require('../../components/people-grid/people-grid.jsx'); +const People = require('./people.json'); require('./annual-report.scss'); +// Some constants used for the page subnav and section refs const SECTIONS = { message: 'message', mission: 'mission', @@ -46,6 +46,7 @@ const SECTION_NAMES = { donate: }; +// Constants used for world map data processing/formatting for use with Plotly const countryKeys = Object.keys(CountryUsage); const countryNames = countryKeys.map(key => CountryUsage[key].display); const countryData = countryKeys.map(key => CountryUsage[key].count); @@ -64,7 +65,7 @@ class AnnualReport extends React.Component { this.subnavRef = null; this.state = { - currentlyVisible: SECTIONS.message, + currentlyVisible: SECTIONS.message, // The currently visible section dropdownVisible: false }; @@ -90,8 +91,8 @@ class AnnualReport extends React.Component { // A generic handler for a subnav item that takes the name of the // section to scroll to (all lowercase) handleSubnavItemClick (sectionName) { - // Return a button click handler that scrolls to the - // correct section + // Return a button click handler that will close the dropdown if open + // and scrolls to the correct section return () => { this.setState({dropdownVisible: false}); this.scrollTo(this.sectionRefs[sectionName]); @@ -107,6 +108,8 @@ class AnnualReport extends React.Component { } } + // Generically create a ref for the given section, stored in + // this.sectionRefs setRef (sectionName) { return ref => (this.sectionRefs[sectionName] = ref); } @@ -115,6 +118,8 @@ class AnnualReport extends React.Component { this.subnavRef = ref; } + // Calculate the dimensions of a given section for use in figuring out + // which section is currently visible getDimensionsOfSection (sectionRef) { const {height} = sectionRef.getBoundingClientRect(); const offsetTop = sectionRef.offsetTop; @@ -127,6 +132,7 @@ class AnnualReport extends React.Component { }; } + // While scrolling, update the subnav to reflect the currently visible section handleScroll () { const subnavHeight = this.getDimensionsOfSection(this.subnavRef).height; // The additional 50 is to account for the main site nav height @@ -146,86 +152,90 @@ class AnnualReport extends React.Component { } } + // Click handler for responsive subnav dropdown handleDropDownClick () { this.setState({dropdownVisible: !this.state.dropdownVisible}); } render () { - const subnav = ( - - {SECTION_NAMES.message} - - - - - - - - - - - - - - - - - - - - - - - - - - ); - + // Element containing buttons to scroll to each of the sections in the + // annual report. The layout of this component will be different on + // different screen sizes (see below) + const subnav = + ( + + {SECTION_NAMES.message} + + + + + + + + + + + + + + + + + + + + + + + + + + ); return (
@@ -364,7 +374,6 @@ class AnnualReport extends React.Component {
{/*
@@ -372,7 +381,6 @@ class AnnualReport extends React.Component {
@@ -584,7 +592,6 @@ class AnnualReport extends React.Component {
@@ -698,7 +705,7 @@ class AnnualReport extends React.Component {
-
+
@@ -725,7 +732,6 @@ class AnnualReport extends React.Component {
{/*
@@ -733,7 +739,6 @@ class AnnualReport extends React.Component {
@@ -871,7 +876,6 @@ class AnnualReport extends React.Component {
@@ -1149,7 +1153,6 @@ class AnnualReport extends React.Component {