From 436efad95d51cf5b87bf6db060adb15df2d65571 Mon Sep 17 00:00:00 2001 From: knod Date: Sun, 25 Nov 2018 10:20:01 -0500 Subject: [PATCH] Cleans code style of '/src/containers'. #1018 --- src/App.js | 6 +- src/containers/AboutPage.js | 26 ++-- src/containers/DevSwitch.js | 2 +- src/containers/HomePage.js | 8 +- src/containers/VisitPage.js | 166 +++++++++++++------------- src/test/containers/AboutPage.test.js | 2 +- src/test/containers/HomePage.test.js | 2 +- 7 files changed, 110 insertions(+), 102 deletions(-) diff --git a/src/App.js b/src/App.js index c2451e54..bb02d1d4 100644 --- a/src/App.js +++ b/src/App.js @@ -9,9 +9,9 @@ import { Helmet } from 'react-helmet'; import { Confirmer } from './utils/getUserConfirmation'; // CUSTOM COMPONENTS -import HomePage from './containers/HomePage'; -import AboutPage from './containers/AboutPage'; -import VisitPage from './containers/VisitPage'; +import { HomePage } from './containers/HomePage'; +import { AboutPage } from './containers/AboutPage'; +import { VisitPage } from './containers/VisitPage'; import Footer from './components/Footer'; import Header from './components/Header'; diff --git a/src/containers/AboutPage.js b/src/containers/AboutPage.js index c06f3d12..672bf000 100644 --- a/src/containers/AboutPage.js +++ b/src/containers/AboutPage.js @@ -1,46 +1,51 @@ import React from 'react'; +import { + Header, + Message, +} from 'semantic-ui-react'; -import { Header, Message } from 'semantic-ui-react'; +// PROJECT COMPONENTS import { ExternalLink } from '../components/ExternalLink'; import { PageLayout } from '../components/PageLayout'; + const AboutPage = ({ translations }) => { return (
+ className = { `ac-header` } + as = { `h1` }> { translations.i_aboutPageHeader }
-
{ translations.i_whatForHeader }
+
{ translations.i_whatForHeader }
{ translations.i_whatForImportantNote }

{ translations.i_whatFor }

-
{ translations.i_whyHeader }
+
{ translations.i_whyHeader }

{ translations.i_why1 }

{ translations.i_why2 }

-
{ translations.i_howToUseHeader }
+
{ translations.i_howToUseHeader }

{ translations.i_howToUse }

{ translations.i_howToUseNote } -
{ translations.i_whoMadeThisHeader }
+
{ translations.i_whoMadeThisHeader }

{ translations.i_whoMadeThis1 }

{ translations.i_whoMadeThis2 }

{ translations.i_whoMadeThis3 }

@@ -49,4 +54,5 @@ const AboutPage = ({ translations }) => { ); }; // Ends -export default AboutPage; + +export { AboutPage }; diff --git a/src/containers/DevSwitch.js b/src/containers/DevSwitch.js index 65b52eb0..71ba92cf 100644 --- a/src/containers/DevSwitch.js +++ b/src/containers/DevSwitch.js @@ -36,7 +36,7 @@ const DevSwitch = function ({ setDev, devProps, history }) { ); -}; // End +}; // Ends export { DevSwitch }; diff --git a/src/containers/HomePage.js b/src/containers/HomePage.js index d9979ac2..7801adf6 100644 --- a/src/containers/HomePage.js +++ b/src/containers/HomePage.js @@ -1,6 +1,7 @@ import React, { Component } from 'react'; import { Link } from 'react-router-dom'; + class HomePage extends Component { render() { return ( @@ -30,7 +31,8 @@ class HomePage extends Component { ); - } -} + }; +}; + -export default HomePage; +export { HomePage }; diff --git a/src/containers/VisitPage.js b/src/containers/VisitPage.js index 67f52ccb..f2df1a78 100644 --- a/src/containers/VisitPage.js +++ b/src/containers/VisitPage.js @@ -11,11 +11,9 @@ import { cloneDeep } from 'lodash'; import { convertForUpdate } from '../utils/convertForUpdate'; // Data -// import { clientList } from '../config/dummyClients'; import { CLIENT_DEFAULTS } from '../utils/CLIENT_DEFAULTS'; // Our Components -// import AlertSidebar from '../AlertSidebar' import BrowserLeaveListener from '../components/prompts/BrowserLeaveListener'; import ReactRouterLeaveListener from '../components/prompts/ReactRouterLeaveListener'; import ErrorListener from '../components/prompts/ErrorListener'; @@ -42,7 +40,7 @@ class VisitPage extends Component { promptData: { open: false, // Start as hidden message: `default`, - header: '', + header: ``, leaveText: `Leave`, callback: () => {}, }, @@ -51,15 +49,16 @@ class VisitPage extends Component { oldHousing: clientData.current.housing, userChanged: {}, translations: props.translations, - }; // end this.state {} - }; // End constructor() + }; // ends this.state {} + }; // Ends constructor() - componentDidMount() { + + componentDidMount = () => { this.didMount = true; - } + }; - resetClientIfOk = (shouldReset) => { + resetClientIfOk = (shouldReset) => { if (!shouldReset) { return; } @@ -72,10 +71,10 @@ class VisitPage extends Component { }); this.goToStep({ index: 0 }); - }; + }; // Ends resetClientIfOk() - askToResetClient = (promptData) => { + askToResetClient = (promptData) => { promptData = promptData || this.promptData; // If the user hasn't interacted with the form at all if (!this.state.isBlocking) { @@ -85,10 +84,10 @@ class VisitPage extends Component { // Otherwise, suggest the user submit feedback this.askForFeedback(this.resetClientIfOk, promptData); } - }; + }; // Ends askToResetClient() - askForFeedback = (callback, promptText) => { + askForFeedback = (callback, promptText) => { // When user exits feedback prompt somehow, // close it before finishing the callback. let closePrompt = (isOk) => { @@ -103,41 +102,42 @@ class VisitPage extends Component { callback: closePrompt, }, }); + }; // Ends askForFeedback() - }; openFeedback = () => { this.setState({ feedbackFormRequested: true }); }; + closeFeedback = () => { this.setState({ feedbackFormRequested: false }); }; - updateClientValue = ({ route, value, time }) => { + updateClientValue = ({ route, value, time }) => { let clone = cloneDeep(this.state.client), userChanged = { ...this.state.userChanged }, // only 1 deep - routeList = route.split('/'), + routeList = route.split(`/`), id = routeList[ 0 ], // `routeList` gets mutated newEvent = { time: time, route: routeList, value: value }; setNestedProperty(newEvent, clone, this.state.userChanged[ id ]); // Only set if the input was valid...? For now, always. // Also, userChanged should be only one step deep - if (time === 'future') { + if (time === `future`) { userChanged[ id ] = true; } // Hack for MVP (otherwise need dependency + history system) let oldHousing = this.state.oldHousing; - if (route === 'housing') { + if (route === `housing`) { // clone housing should be right now oldHousing = clone.current.housing; } - if (clone.current.benefits.includes('section8')) { - clone.current.housing = 'voucher'; + if (clone.current.benefits.includes(`section8`)) { + clone.current.housing = `voucher`; } else { // Restore housing to previous value clone.current.housing = oldHousing; @@ -155,23 +155,26 @@ class VisitPage extends Component { isBlocking: true, }; }); - }; // End onClientChange() + }; // Ends updateClientValue() + changeCurrent = (evnt, data) => { - data.time = 'current'; + data.time = `current`; let newData = convertForUpdate(data); this.updateClientValue(newData); }; + changeFuture = (evnt, data) => { - data.time = 'future'; + data.time = `future`; let newData = convertForUpdate(data); this.updateClientValue(newData); }; - // Implement once privacy and security are worked out + + // @todo Implement once privacy and security are worked out saveForm = (exitAfterSave) => { - alert('Form saved (not really, this is a placeholder).'); + alert(`Form saved (not really, this is a placeholder).`); if (exitAfterSave) { this.setState({ isBlocking: false, redirect: true }); } else { @@ -179,54 +182,57 @@ class VisitPage extends Component { } }; - scrollToTop = () => { + + scrollToTop () { document.body.scrollTop = 0; // For Safari document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE, and Opera }; + nextStep = () => { - const nextStepIndex = this.getCurrentStepIndex() + 1; - + const nextStepIndex = this.getCurrentStepIndex() + 1; if (nextStepIndex === STEP_VALS.length) { return; } - this.goToStep({ index: nextStepIndex }); }; - + + previousStep = () => { const prevStepIndex = this.getCurrentStepIndex() - 1; - if (prevStepIndex < 0) { return; } - this.goToStep({ index: prevStepIndex }); }; + goToStep = ({ key, index }) => { if (!key) { key = STEP_VALS[ index ].key; } - this.props.history.push(`${this.getPathPrefix()}/${key}`); this.scrollToTop(); }; + getPathPrefix = () => { return `/visit/${this.props.clientId}/${this.props.visitId}`; }; + getCurrentStepIndex = () => { return STEP_VALS.findIndex((step) => { return step.key === this.props.stepKey; }); }; + shouldConfirmLeave = ({ location }) => { return !location.pathname.startsWith(this.getPathPrefix()); }; + render() { if (!this.didMount || !this.props.stepKey) { return ( @@ -234,7 +240,7 @@ class VisitPage extends Component { ); } - let translations = this.state.translations, + let translations = this.state.translations, prevContent = null, nextContent = null, stepIndex = this.getCurrentStepIndex(), @@ -271,78 +277,74 @@ class VisitPage extends Component { right: nextContent, }; - const step = STEP_VALS[ stepIndex ]; - - const StepComponent = step.component; + let step = STEP_VALS[ stepIndex ], + StepComponent = step.component; return ( -
+
{/* = PROMPTS & PROMPT TRIGGERS = */} {/* - Sometimes visible - */} {/* Triggered by `ReactRouterLeaveListener`, *`ResetAnytime`, or `ErrorListener` */} + isBlocking = { this.state.isBlocking } + openFeedback = { this.openFeedback } /> {/* Triggered by `FeedbackPrompt` & `FeedbackAnytime` */} + isOpen = { this.state.feedbackFormRequested } + close = { this.closeFeedback } + data = { this.state.client } /> {/* - Never visible - */} + callback = { this.resetClientIfOk } + client = { this.state.client } + askForFeedback = { this.askForFeedback } /> {/* Browser nav - reload/back/unload. */} {/* React nav buttons (Home/About) */} + askForFeedback = { this.askForFeedback } + confirmer = { this.props.confirmer } + shouldRequestConfirmation = { this.shouldConfirmLeave } + isBlocking = { this.state.isBlocking } /> {/* = LINKS? = */} {/* We should probably remove this. If we want to * do this we might do this a different way at this * point. Perhaps a user's page should be a route * in VisitPage? */} - { this.state.redirect ? ( + { (this.state.redirect) ? ( ) : ( - false + null ) } {/* = SECTION = */} {/* `padding` here duplicates previous `` styling */} + id = { `cliff-effects-tool` } + className = { `flex-item flex-column` }> + id = { `form-nav` } + minWidth = { `874.5` }> + currentStepKey = { step.key } + goToStep = { this.goToStep } + translations = { this.state.translations.stepBar } /> -
+
+ navData = { navData } + saveForm = { this.saveForm } + askToResetClient = { this.askToResetClient } + openFeedback = { this.openFeedback } + client = { this.state.client } />
@@ -355,20 +357,18 @@ class VisitPage extends Component { - { - distrustConfirmed === false ? ( - - ) : ( - null - ) - } + { (distrustConfirmed === false) ? ( + + ) : ( + null + ) }
); - } -} + }; +}; // Ends -export default VisitPage; +export { VisitPage }; diff --git a/src/test/containers/AboutPage.test.js b/src/test/containers/AboutPage.test.js index 7323df26..34ea7bb0 100644 --- a/src/test/containers/AboutPage.test.js +++ b/src/test/containers/AboutPage.test.js @@ -1,7 +1,7 @@ import React from 'react'; import { mount } from 'enzyme'; -import AboutPage from '../../containers/AboutPage'; +import { AboutPage } from '../../containers/AboutPage'; import { translations } from '../helpers'; describe('', () => { diff --git a/src/test/containers/HomePage.test.js b/src/test/containers/HomePage.test.js index 4e0511e3..24f10209 100644 --- a/src/test/containers/HomePage.test.js +++ b/src/test/containers/HomePage.test.js @@ -1,7 +1,7 @@ import React from 'react'; import { mount } from 'enzyme'; -import HomePage from '../../containers/HomePage'; +import { HomePage } from '../../containers/HomePage'; import { withRouter } from '../helpers'; describe('', () => {