Skip to content

Commit

Permalink
fix: handle Discord button on scroll (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-ziv authored May 24, 2022
1 parent 775035c commit 5fdce7e
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 31 deletions.
10 changes: 4 additions & 6 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {Navigate, Route, Routes, useLocation} from 'react-router-dom';
import {Navigate, Route, Routes} from 'react-router-dom';

import styles from './App.module.scss';
import {TrackEvent} from './analytics';
Expand All @@ -15,11 +15,9 @@ import {openInNewTab} from './utils';
export const App = () => {
const [trackDiscordClick] = useTracking(TrackEvent.DISCORD_TAB_CLICK);
const {DISCORD_LINK_URL} = useConstants();
const {isAcceptTerms} = useApp();
const {pathname} = useLocation();
const {isAcceptTerms, isScrollActive} = useApp();
const {isLoggedIn} = useLogin();
const liquidityProviders = useLiquidityProviders();
const isBridgeRoute = !['/terms', '/faq'].includes(pathname);

const onDiscordClick = () => {
trackDiscordClick();
Expand All @@ -29,7 +27,7 @@ export const App = () => {
return (
<div className={styles.app}>
<Header />
<StyledBackground withLightAccent={isBridgeRoute}>
<StyledBackground withLightAccent={isScrollActive}>
<Routes>
<Route
element={
Expand All @@ -45,7 +43,7 @@ export const App = () => {
<Route element={<Navigate replace to="/" />} path="*" />
</Routes>
</StyledBackground>
{isBridgeRoute && <SideButton icon={<DiscordIcon />} onClick={onDiscordClick} />}
<SideButton icon={<DiscordIcon />} onClick={onDiscordClick} />
<Footer />
</div>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/UI/BurgerMenu/BurgerMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {useBurgerMenuTranslation} from '../../../hooks';
import {useApp} from '../../../providers/AppProvider';
import {toClasses} from '../../../utils';
import {BurgerMenuItem} from '../BurgerMenuItem/BurgerMenuItem';
import {Menu} from '../Menu/Menu';
import styles from './BurgerMenu.module.scss';

export const BurgerMenu = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/UI/BurgerMenu/BurgerMenu.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ $burger-symbol-size-2: 27px;
}

.burgerMenu {
margin: 5px;
z-index: 1000;
margin: 5px #{$--scroll-width}px 5px 5px;
z-index: 100000;
position: absolute;
transition: 0.3s ease-in-out;
padding: 15px 60px 15px 10px;
Expand Down
2 changes: 1 addition & 1 deletion src/components/UI/Menu/Menu.module.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.menu {
opacity: 0;
max-height: 100%;
transition: all 0.4s ease-in-out;
transition: all 0.3s ease-in-out;

&.show {
opacity: 1;
Expand Down
29 changes: 16 additions & 13 deletions src/components/UI/MultiChoiceMenu/MultiChoiceMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
import React from 'react';

import {toClasses} from '../../../utils';
import {Menu} from '../Menu/Menu';
import {MultiChoiceErrorMessage} from '../MultiChoiceErrorMessage/MultiChoiceErrorMessage';
import {MultiChoiceItem} from '../MultiChoiceItem/MultiChoiceItem';
import styles from './MultiChoiceMenu.module.scss';
Expand All @@ -23,20 +24,22 @@ export const MultiChoiceMenu = ({title, description, choices, error, footer}) =>
};

return (
<div className={toClasses(styles.multiChoiceMenu, 'center')}>
<div className={styles.content}>
<div className={styles.title}>{title}</div>
{description && <p>{description}</p>}
<div className={styles.container}>{renderChoiceItems()}</div>
{error && <MultiChoiceErrorMessage message={error.message} />}
<Menu>
<div className={toClasses(styles.multiChoiceMenu, 'center')}>
<div className={styles.content}>
<div className={styles.title}>{title}</div>
{description && <p>{description}</p>}
<div className={styles.container}>{renderChoiceItems()}</div>
{error && <MultiChoiceErrorMessage message={error.message} />}
</div>
{footer && (
<>
<div className={styles.separator} />
{footer}
</>
)}
</div>
{footer && (
<>
<div className={styles.separator} />
{footer}
</>
)}
</div>
</Menu>
);
};

Expand Down
13 changes: 12 additions & 1 deletion src/components/UI/SideButton/SideButton.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import PropTypes from 'prop-types';
import React from 'react';

import {useVars} from '../../../hooks';
import {useApp} from '../../../providers/AppProvider';
import styles from './SideButton.module.scss';

export const SideButton = ({icon, onClick}) => {
const {isScrollActive} = useApp();
const {scrollWidth} = useVars();

return (
<div className={styles.sideButton} onClick={onClick}>
<div
style={{
right: isScrollActive ? `${scrollWidth}px` : 0
}}
className={styles.sideButton}
onClick={onClick}
>
{icon}
</div>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/UI/SideButton/SideButton.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
align-items: center;
justify-content: center;
cursor: pointer;
transition: 0.3s ease-in-out;
}
1 change: 1 addition & 0 deletions src/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './useAccountChange';
export * from './useIsMaxTotalBalanceExceeded';
export * from './useMaxTotalBalance';
export * from './useMaxDeposit';
export * from './useVars';
5 changes: 5 additions & 0 deletions src/hooks/useVars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {useMemo} from 'react';

import vars from '../styles/variables.module.scss';

export const useVars = () => useMemo(() => vars, []);
2 changes: 2 additions & 0 deletions src/providers/AppProvider/AppProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const AppProvider = ({children}) => {
const [state, dispatch] = useReducer(reducer, initialState);
const {pathname} = useLocation();
const navigate = useNavigate();
const isScrollActive = ['/terms', '/faq'].includes(pathname);

const navigateToRoute = route => {
pathname !== route && navigate(route);
Expand Down Expand Up @@ -40,6 +41,7 @@ export const AppProvider = ({children}) => {

const value = {
...state,
isScrollActive,
navigateToRoute,
acceptTerms,
login,
Expand Down
1 change: 1 addition & 0 deletions src/providers/AppProvider/app-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {initialState} from './app-reducer';

export const AppContext = createContext({
...initialState,
isScrollActive: false,
navigateToRoute: () => {},
acceptTerms: () => {},
login: () => {},
Expand Down
14 changes: 6 additions & 8 deletions src/routes/Liquidity/Liquidity.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import {Menu, MultiChoiceMenu} from '../../components/UI';
import {MultiChoiceMenu} from '../../components/UI';
import {useLiquidityProviders, useLiquidityTranslation} from '../../hooks';
import {openInNewTab} from '../../utils';

Expand All @@ -20,12 +20,10 @@ export const Liquidity = () => {
};

return (
<Menu>
<MultiChoiceMenu
choices={mapLiquidityProviders()}
description={descriptionTxt}
title={titleTxt}
/>
</Menu>
<MultiChoiceMenu
choices={mapLiquidityProviders()}
description={descriptionTxt}
title={titleTxt}
/>
);
};
2 changes: 2 additions & 0 deletions src/styles/variables.module.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
$--header-height: 80;
$--footer-height: 50;
$--scroll-width: 7;
$--main-offset: $--header-height + $--footer-height + 2;

:export {
mainOffset: $--main-offset;
scrollWidth: $--scroll-width;
}

0 comments on commit 5fdce7e

Please sign in to comment.