From fc05245f3f0232d857898c53b669ec01e0ae8a65 Mon Sep 17 00:00:00 2001 From: dalemcgrew Date: Wed, 11 Sep 2024 13:02:06 -0700 Subject: [PATCH] Added ChallengeInviteFriendsTopNavigation. Improved Challenges option in footer. New FooterMainWeVote id. --- .../ChallengeInviteFriendsTopNavigation.jsx | 123 ++++++++++++++++++ .../pages/Challenge/ChallengeHomePage.jsx | 3 + src/js/components/Navigation/FooterBar.jsx | 1 + .../Navigation/FooterMainWeVote.jsx | 8 +- 4 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 src/js/common/components/Navigation/ChallengeInviteFriendsTopNavigation.jsx diff --git a/src/js/common/components/Navigation/ChallengeInviteFriendsTopNavigation.jsx b/src/js/common/components/Navigation/ChallengeInviteFriendsTopNavigation.jsx new file mode 100644 index 000000000..edcf32e12 --- /dev/null +++ b/src/js/common/components/Navigation/ChallengeInviteFriendsTopNavigation.jsx @@ -0,0 +1,123 @@ +import { AppBar, Tab, Tabs, Toolbar } from '@mui/material'; +import { createTheme, StyledEngineProvider, ThemeProvider } from '@mui/material/styles'; +import makeStyles from '@mui/styles/makeStyles'; +import React from 'react'; +import { useHistory } from 'react-router-dom'; +import { renderLog } from '../../utils/logging'; +import { endsWith } from '../../utils/startsWith'; +import stringContains from '../../utils/stringContains'; + + +// TODO: Mar 23, 2022, makeStyles is legacy in MUI 5, replace instance with styled-components or sx if there are issues +const useStyles = makeStyles((theme) => ({ + appBarRoot: { + borderBottom: 0, + boxShadow: 'none', + [theme.breakpoints.up('sm')]: { + borderBottom: '1px solid #ddd', + }, + }, + root: { + flexGrow: 1, + backgroundColor: theme.palette.background.paper, + }, + toolbarRoot: { + minHeight: 48, + }, +})); + + +export default function ChallengeInviteFriendsTopNavigation (incomingVariables) { + const [value, setValue] = React.useState(0); + const classes = useStyles(); + const history = useHistory(); + + const defaultTheme = createTheme(); + + const theme = createTheme({ + typography: { + button: { + textTransform: 'none', + }, + }, + components: { + MuiButtonBase: { + root: { + '&:hover': { + color: '#4371cc', + }, + }, + }, + MuiTab: { + root: { + minWidth: 0, + [defaultTheme.breakpoints.up('xs')]: { + minWidth: 0, + }, + }, + }, + }, + }); + + const { challengeSEOFriendlyPath, challengeWeVoteId } = incomingVariables; + // console.log('ChallengeInviteFriendsTopNavigation incomingVariables:', incomingVariables); + // console.log('ChallengeInviteFriendsTopNavigation challengeSEOFriendlyPath:', challengeSEOFriendlyPath); + const handleChange = (event, newValue) => { + setValue(newValue); + }; + + const { location: { pathname } } = window; + if (endsWith('/about', pathname) && value !== 1) { + // console.log('Render ChallengeInviteFriendsTopNavigation, initial value set to 1'); + setValue(1); + } else if (endsWith('/leaderboard', pathname) && value !== 2) { + // console.log('Render ChallengeInviteFriendsTopNavigation, initial value set to 2'); + setValue(2); + } else if (endsWith('/friends', pathname) && value !== 3) { + // console.log('Render ChallengeInviteFriendsTopNavigation, initial value set to 3'); + setValue(3); + } else if (stringContains('/+/', pathname) && value !== 0 && value !== 1 && value !== 2) { + // console.log('Render ChallengeInviteFriendsTopNavigation, initial value set to 0'); + setValue(0); + } + + let aboutUrl; + let leaderboardUrl; + let friendsUrl; + if (challengeSEOFriendlyPath) { + aboutUrl = `/${challengeSEOFriendlyPath}/+/`; + leaderboardUrl = `/${challengeSEOFriendlyPath}/+/leaderboard`; + friendsUrl = `/${challengeSEOFriendlyPath}/+/friends`; + } else { + aboutUrl = `/+/${challengeWeVoteId}`; + leaderboardUrl = `/+/${challengeWeVoteId}/leaderboard`; + friendsUrl = `/+/${challengeWeVoteId}/friends`; + } + + // console.log('ChallengeInviteFriendsTopNavigation, aboutUrl:', aboutUrl); + // console.log('ChallengeInviteFriendsTopNavigation, leaderboardUrl:', leaderboardUrl); + // console.log('ChallengeInviteFriendsTopNavigation, friendsUrl:', friendsUrl); + + renderLog('ChallengeInviteFriendsTopNavigation functional component'); + return ( +
+ + + + + + history.push(aboutUrl)} /> + history.push(leaderboardUrl)} /> + history.push(friendsUrl)} /> + + + + + +
+ ); +} diff --git a/src/js/common/pages/Challenge/ChallengeHomePage.jsx b/src/js/common/pages/Challenge/ChallengeHomePage.jsx index 435ac8d8c..874a5b4b2 100644 --- a/src/js/common/pages/Challenge/ChallengeHomePage.jsx +++ b/src/js/common/pages/Challenge/ChallengeHomePage.jsx @@ -7,6 +7,7 @@ import React, { Component, Suspense } from 'react'; import { Helmet } from 'react-helmet-async'; import { Link } from 'react-router-dom'; import styled from 'styled-components'; +import ChallengeInviteFriendsTopNavigation from '../../components/Navigation/ChallengeInviteFriendsTopNavigation'; import DesignTokenColors from '../../components/Style/DesignTokenColors'; import { PageContentContainer } from '../../../components/Style/pageLayoutStyles'; import webAppConfig from '../../../config'; @@ -585,6 +586,7 @@ class ChallengeHomePage extends Component { useVerticalCard voterWeVoteId={voterWeVoteId} /> + ==== MOBILE {challengeDataFound && ( @@ -715,6 +717,7 @@ class ChallengeHomePage extends Component { /> + }> - Donate + + Donate + )}