From 6c01051b9aa40a0ebd000386183201150a700774 Mon Sep 17 00:00:00 2001 From: Mehrdad Rafiee Date: Mon, 20 Nov 2023 23:20:07 -0800 Subject: [PATCH 1/3] convert App/ directory to use TypeScript --- src/components/App/{App.jsx => App.tsx} | 144 ++++++++++-------- .../App/{AppLogo.jsx => AppLogo.tsx} | 17 +-- src/components/App/{index.js => index.ts} | 0 .../App/{muiTheme.js => muiTheme.ts} | 0 4 files changed, 92 insertions(+), 69 deletions(-) rename src/components/App/{App.jsx => App.tsx} (73%) rename src/components/App/{AppLogo.jsx => AppLogo.tsx} (75%) rename src/components/App/{index.js => index.ts} (100%) rename src/components/App/{muiTheme.js => muiTheme.ts} (100%) diff --git a/src/components/App/App.jsx b/src/components/App/App.tsx similarity index 73% rename from src/components/App/App.jsx rename to src/components/App/App.tsx index 264108e60e..7c8be4d2fc 100644 --- a/src/components/App/App.jsx +++ b/src/components/App/App.tsx @@ -1,3 +1,4 @@ +// @ts-nocheck import darkBaseTheme from 'material-ui/styles/baseThemes/darkBaseTheme'; import getMuiTheme from 'material-ui/styles/getMuiTheme'; import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'; @@ -6,8 +7,7 @@ import Helmet from 'react-helmet'; import { connect } from 'react-redux'; import { Route, Switch, withRouter } from 'react-router-dom'; import styled from 'styled-components'; - -import Combos from './../Combos/Combos'; +import Combos from '../Combos/Combos'; import Api from '../Api'; import Subscription from '../Subscription'; import constants from '../constants'; @@ -33,7 +33,26 @@ import GlobalStyle from './GlobalStyle'; import muiTheme from './muiTheme'; import config from '../../config'; -const StyledDiv = styled.div` +interface AppStylesProps { + open?: boolean; + location: { + pathname?: string; + }; +} + +interface Back2TopStylesProps { + open?: boolean; + location: { + pathname: string; + }; +} + +interface AppProps { + location: { [key: string]: string } + strings: { [key: string]: string } +} + +const StyledDiv = styled.div` transition: ${constants.normalTransition}; position: relative; display: flex; @@ -41,49 +60,51 @@ const StyledDiv = styled.div` height: 100%; left: ${(props) => (props.open ? '256px' : '0px')}; margin-top: 0px; + background-image: ${(props) => props.location.pathname === '/' - ? 'url("/assets/images/home-background.png")' + ? `url("/assets/images/home-background.png")` : ''}; background-position: center top -56px; background-repeat: ${(props) => props.location.pathname === '/' ? 'no-repeat' : ''}; +`; - #back2Top { - position: fixed; - left: auto; - right: 0px; - top: auto; - bottom: 20px; - outline: none; - color: rgb(196, 196, 196); - text-align: center; - outline: none; - border: none; - background-color: rgba(0, 0, 0, 0.3); - width: 40px; - font-size: 14px; - border-radius: 2px; - cursor: pointer; - z-index: 999999; - opacity: 0; - display: block; - pointer-events: none; - -webkit-transform: translate3d(0, 0, 0); - padding: 3px; - transition: opacity 0.3s ease-in-out; - - & #back2TopTxt { - font-size: 10px; - line-height: 12px; - text-align: center; - margin-bottom: 3px; - } - } - #back2Top:hover { +const Back2Top = styled.button` + position: fixed; + left: auto; + right: 0px; + top: auto; + bottom: 20px; + outline: none; + color: rgb(196, 196, 196); + text-align: center; + outline: none; + border: none; + background-color: rgba(0, 0, 0, 0.3); + width: 40px; + font-size: 14px; + border-radius: 2px; + cursor: pointer; + z-index: 999999; + opacity: 0; + display: block; + pointer-events: none; + -webkit-transform: translate3d(0, 0, 0); + padding: 3px; + transition: opacity 0.3s ease-in-out; + + &:hover { background-color: rgb(26, 108, 239); } + + #back2TopTxt { + font-size: 10px; + line-height: 12px; + text-align: center; + margin-bottom: 3px; + } `; const StyledBodyDiv = styled.div` @@ -100,33 +121,36 @@ const AdBannerDiv = styled.div` text-align: center; margin-bottom: 5px; - & img { + img { margin-top: 10px; max-width: 100%; } `; -const App = (props) => { - const { strings, location } = props; +declare let window: Window & { adsbygoogle: any } - const back2Top = React.useRef(); +const App = (props: AppProps) => { + const { strings, location } = props; + const back2Top = React.useRef(); React.useEffect(() => { const handleScroll = () => { let wait = false; const { current } = back2Top; - if (!wait) { + + if (!wait && current) { if ( document.body.scrollTop > 1000 || document.documentElement.scrollTop > 1000 ) { - current.style.opacity = 1; + current.style.opacity = '1'; current.style.pointerEvents = 'auto'; } else { - current.style.opacity = 0; + current.style.opacity = '0'; current.style.pointerEvents = 'none'; } } + setTimeout(() => { wait = !wait; }, 300); @@ -137,7 +161,7 @@ const App = (props) => { return () => { window.removeEventListener('scroll', handleScroll); }; - }); + }, []); React.useLayoutEffect(() => { window.scrollTo(0, 0); @@ -152,7 +176,7 @@ const App = (props) => { }, []); return ( - + {/* muiTheme types are missing here */} { />
- - {includeAds && config.VITE_ENABLE_ADSENSE && ( - )} - + + {includeAds && config.VITE_ENABLE_ADSENSE && ( + )} + @@ -214,15 +238,15 @@ const App = (props) => { {includeAds && config.VITE_ENABLE_ADSENSE && ( )}