From 1dcd4f2d686f2a8f3a9ebcd6511d5b23404cb820 Mon Sep 17 00:00:00 2001 From: Brian Hurst Date: Tue, 21 Apr 2020 13:01:01 -0400 Subject: [PATCH 1/2] Add public path to router --- config/webpack/webpack.shared.js | 2 +- src/browser-history.js | 4 ++-- src/components/about-page/index.js | 2 +- .../__snapshots__/app.component.test.js.snap | 22 ++----------------- src/components/app/app.component.js | 7 ++---- src/components/footer/footer.container.js | 9 +++----- src/components/menu/menu.container.js | 11 ++++------ .../mobile-menu-control.container.js | 4 ++-- src/utils/other.js | 2 ++ styles/theme/_uswds-theme-general.scss | 2 +- styles/theme/_uswds-theme-typography.scss | 2 +- 11 files changed, 21 insertions(+), 46 deletions(-) diff --git a/config/webpack/webpack.shared.js b/config/webpack/webpack.shared.js index 5b77bf27..71e3b18e 100644 --- a/config/webpack/webpack.shared.js +++ b/config/webpack/webpack.shared.js @@ -243,7 +243,7 @@ module.exports = { appleStartup: false }, inject: true, - prefix: '/assets/img/favicons', + prefix: join(PUBLIC_PATH, '/assets/img/favicons'), output: './assets/img/favicons/', config: { favicons: true, diff --git a/src/browser-history.js b/src/browser-history.js index bec071e1..7bef9a73 100644 --- a/src/browser-history.js +++ b/src/browser-history.js @@ -1,5 +1,5 @@ import { createBrowserHistory } from 'history' -const history = createBrowserHistory() +const history = createBrowserHistory({ basename: PUBLIC_PATH }) -export default history \ No newline at end of file +export default history diff --git a/src/components/about-page/index.js b/src/components/about-page/index.js index 5f336548..f5367587 100644 --- a/src/components/about-page/index.js +++ b/src/components/about-page/index.js @@ -19,7 +19,7 @@ import Resources from './resources.component' import MeasuringCode from './measuring-code.component' import Licensing from './licensing.component' -const abouturl = `${PUBLIC_PATH}about` +const abouturl = `/about` const links = [ { diff --git a/src/components/app/__snapshots__/app.component.test.js.snap b/src/components/app/__snapshots__/app.component.test.js.snap index 333cf2dc..e1335a19 100644 --- a/src/components/app/__snapshots__/app.component.test.js.snap +++ b/src/components/app/__snapshots__/app.component.test.js.snap @@ -30,25 +30,7 @@ exports[`components - App render should render correctly 1`] = ` isDark={true} /> - + -` +`; diff --git a/src/components/app/app.component.js b/src/components/app/app.component.js index 346c1e06..b23b7980 100644 --- a/src/components/app/app.component.js +++ b/src/components/app/app.component.js @@ -14,7 +14,7 @@ import Menu from 'components/menu' import Footer from 'components/footer' import OfficialBanner from 'components/official-banner' import PrivacyPolicy from 'components/privacy-policy' -import { refreshView } from 'utils/other' +import { refreshView, isHomepage } from 'utils/other' export default class AppComponent extends Component { componentDidMount() { @@ -25,15 +25,12 @@ export default class AppComponent extends Component { } render() { - const location = window.location - const isHomepage = location.pathname === '/' - return (
{isHomepage ? : } - + diff --git a/src/components/footer/footer.container.js b/src/components/footer/footer.container.js index 8f7d88aa..25bd2733 100644 --- a/src/components/footer/footer.container.js +++ b/src/components/footer/footer.container.js @@ -1,16 +1,13 @@ /* global PUBLIC_PATH */ import { connect } from 'react-redux' -import { getConfigValue } from 'utils/other' +import { getConfigValue, isHomepage } from 'utils/other' import Footer from './footer.component' -export const mapStateToProps = ({ router }) => { - const onHomePage = router.location.pathname === PUBLIC_PATH - return { +export const mapStateToProps = ({ router }) => ({ color: 'white', links: getConfigValue('content.footer.links'), logos: getConfigValue('content.footer.logos'), socials: getConfigValue('content.footer.socials') - } -} +}) export default connect(mapStateToProps)(Footer) diff --git a/src/components/menu/menu.container.js b/src/components/menu/menu.container.js index f729bac9..5af9aa8c 100644 --- a/src/components/menu/menu.container.js +++ b/src/components/menu/menu.container.js @@ -2,22 +2,19 @@ import { withRouter } from 'react-router-dom' import { connect } from 'react-redux' -import { getConfigValue } from 'utils/other' +import { getConfigValue, isHomepage } from 'utils/other' import toggleSearchDropdown from 'actions/toggle-search-dropdown' import MenuComponent from './menu.component' -export const mapStateToProps = ({ router, searchDropdown }) => { - const onHomePage = router.location.pathname === PUBLIC_PATH - return { +export const mapStateToProps = ({ router, searchDropdown }) => ({ color: 'white', logoDark: getConfigValue('content.header.logos.dark'), logoLight: getConfigValue('content.header.logos.light'), menu: getConfigValue('content.header.menu'), - onHomePage, + onHomePage: isHomepage, searchDropdown, siteTitle: getConfigValue('title') - } -} +}) export const mapDispatchToProps = dispatch => ({ toggleSearchDropdown: () => dispatch(toggleSearchDropdown()) diff --git a/src/components/mobile-menu-control/mobile-menu-control.container.js b/src/components/mobile-menu-control/mobile-menu-control.container.js index 9563b7b6..46b5c0bd 100644 --- a/src/components/mobile-menu-control/mobile-menu-control.container.js +++ b/src/components/mobile-menu-control/mobile-menu-control.container.js @@ -3,11 +3,11 @@ import { connect } from 'react-redux' import hideMobileMenu from 'actions/hide-mobile-menu' import showMobileMenu from 'actions/show-mobile-menu' import toggleMobileMenu from 'actions/toggle-mobile-menu' +import { refreshView, isHomepage } from 'utils/other' import MobileMenuControlComponent from './mobile-menu-control.component' export const mapStateToProps = ({ displayMobileMenu, router }) => { - const onHomePage = router.location.pathname === PUBLIC_PATH - const color = onHomePage ? 'white' : 'dark' + const color = isHomepage ? 'white' : 'dark' return { color, displayMobileMenu diff --git a/src/utils/other.js b/src/utils/other.js index 6f5d2c44..a54914ff 100644 --- a/src/utils/other.js +++ b/src/utils/other.js @@ -263,3 +263,5 @@ export function prettify(text) { match => `
${match.replace(/[A-Za-z]{1,25}/, name => `${name}`)}` ) } + +export const isHomepage = window.location.pathname === PUBLIC_PATH diff --git a/styles/theme/_uswds-theme-general.scss b/styles/theme/_uswds-theme-general.scss index 7d43bfc1..53e4f1d1 100644 --- a/styles/theme/_uswds-theme-general.scss +++ b/styles/theme/_uswds-theme-general.scss @@ -25,7 +25,7 @@ Relative image file path ---------------------------------------- */ -$theme-image-path: "/uswds/img"; +$theme-image-path: "./uswds/img"; /* ---------------------------------------- diff --git a/styles/theme/_uswds-theme-typography.scss b/styles/theme/_uswds-theme-typography.scss index 4bb86430..bc9718be 100644 --- a/styles/theme/_uswds-theme-typography.scss +++ b/styles/theme/_uswds-theme-typography.scss @@ -77,7 +77,7 @@ Relative font file path ---------------------------------------- */ -$theme-font-path: "/uswds/fonts"; +$theme-font-path: "./uswds/fonts"; /* ---------------------------------------- From 36133020b1697741968fe4e55fc0acd323ab2612 Mon Sep 17 00:00:00 2001 From: Brian Hurst Date: Mon, 27 Apr 2020 17:05:46 -0400 Subject: [PATCH 2/2] Update snapshots --- src/components/menu/__snapshots__/menu.container.test.js.snap | 4 ++-- .../__snapshots__/mobile-menu-control.container.test.js.snap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/menu/__snapshots__/menu.container.test.js.snap b/src/components/menu/__snapshots__/menu.container.test.js.snap index 903a0eb8..b1f76a03 100644 --- a/src/components/menu/__snapshots__/menu.container.test.js.snap +++ b/src/components/menu/__snapshots__/menu.container.test.js.snap @@ -95,8 +95,8 @@ Object { "name": "SOCIAL", }, ], - "onHomePage": false, + "onHomePage": true, "searchDropdown": "test-search-dropdown", "siteTitle": "code.gov", } -` +`; diff --git a/src/components/mobile-menu-control/__snapshots__/mobile-menu-control.container.test.js.snap b/src/components/mobile-menu-control/__snapshots__/mobile-menu-control.container.test.js.snap index b8e23507..b6a320ed 100644 --- a/src/components/mobile-menu-control/__snapshots__/mobile-menu-control.container.test.js.snap +++ b/src/components/mobile-menu-control/__snapshots__/mobile-menu-control.container.test.js.snap @@ -2,7 +2,7 @@ exports[`containers - MobileMenuControl mapStateToProps should return the correct properties 1`] = ` Object { - "color": "dark", + "color": "white", "displayMobileMenu": true, } -` +`;