Skip to content

Commit 355e02b

Browse files
authored
Merge pull request #2292 from Plant-for-the-Planet-org/develop
Release Facelift WebApp
2 parents ce21ec1 + f78ffaa commit 355e02b

File tree

256 files changed

+12020
-5737
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

256 files changed

+12020
-5737
lines changed

.eslintrc.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ module.exports = {
44
browser: true,
55
es2020: true,
66
},
7-
extends: ['eslint:recommended', 'plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended', 'plugin:react/recommended', 'plugin:storybook/recommended'],
7+
extends: [
8+
'eslint:recommended',
9+
'plugin:@typescript-eslint/eslint-recommended',
10+
'plugin:@typescript-eslint/recommended',
11+
'plugin:react/recommended',
12+
'plugin:storybook/recommended',
13+
],
814
parser: '@typescript-eslint/parser',
915
parserOptions: {
1016
ecmaFeatures: {
@@ -47,6 +53,7 @@ module.exports = {
4753
'import/extensions': 'off',
4854
'import/no-unresolved': 'off',
4955
'react/jsx-no-literals': 'off',
56+
'@typescript-eslint/consistent-type-imports': 'warn',
5057
'@typescript-eslint/ban-types': 'off',
5158
'@typescript-eslint/no-empty-interface': 'off',
5259
'@typescript-eslint/no-empty-function': 'off',

package-lock.json

Lines changed: 2120 additions & 2784 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"prepare": "node ./husky-prepare.js"
2525
},
2626
"validate-branch-name": {
27-
"pattern": "^(main|develop){1}$|^(feature|hotfix)/[a-z0-9-_]+$",
27+
"pattern": "^(main|develop){1}$|^(feature|hotfix|projects-redesign)/[a-z0-9-_]+$",
2828
"errorMsg": "Invalid branch name. \n 1.Branch names can contain lowercase characters, numbers, hyphen and underscore. \n 2.Except for 'main' and 'develop', branch names must begin with 'feature/' or 'hotfix/' "
2929
},
3030
"engines": {
@@ -133,6 +133,7 @@
133133
"styled-jsx": "^5.0.0",
134134
"supercluster": "^8.0.1",
135135
"superjson": "^1.12.3",
136+
"swiper": "^11.1.14",
136137
"uuid": "^8.3.2",
137138
"vizzuality-components": "^3.0.3",
138139
"xlsx": "^0.18.5",

pages/_app.tsx

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { CacheProvider, EmotionCache } from '@emotion/react';
33
import createEmotionCache from '../src/createEmotionCache';
44
import 'mapbox-gl/dist/mapbox-gl.css';
55
import 'mapbox-gl-compare/dist/mapbox-gl-compare.css';
6-
import React from 'react';
6+
import React, { ReactElement, ReactNode, useMemo } from 'react';
77
import TagManager from 'react-gtm-module';
88
import Router from 'next/router';
9-
import App, { AppProps, AppContext, AppInitialProps } from 'next/app';
9+
import App, { AppContext, AppInitialProps, AppProps } from 'next/app';
1010
import { Auth0Provider } from '@auth0/auth0-react';
11+
// NOTE - needs to be removed when old projects code is removed
1112
import '../src/features/projects/styles/MapPopup.scss';
1213
import '../src/theme/global.scss';
14+
// NOTE - needs to be removed when old projects code is removed
1315
import './../src/features/projects/styles/Projects.scss';
1416
import './../src/features/common/Layout/Navbar/Navbar.scss';
1517
import ThemeProvider from '../src/theme/themeContext';
@@ -32,6 +34,7 @@ import QueryParamsProvider from '../src/features/common/Layout/QueryParamsContex
3234
import { PlanetCashProvider } from '../src/features/common/Layout/PlanetCashContext';
3335
import { PayoutsProvider } from '../src/features/common/Layout/PayoutsContext';
3436
import { trpc } from '../src/utils/trpc';
37+
// NOTE - needs to be removed when old projects code is removed
3538
import MapHolder from '../src/features/projects/components/maps/MapHolder';
3639
import { TenantProvider } from '../src/features/common/Layout/TenantContext';
3740
import { CurrencyProvider } from '../src/features/common/Layout/CurrencyContext';
@@ -41,9 +44,9 @@ import {
4144
getTenantSlug,
4245
} from '../src/utils/multiTenancy/helpers';
4346
import { Tenant } from '@planet-sdk/common/build/types/tenant';
44-
import { NextIntlClientProvider } from 'next-intl';
45-
46-
type AppOwnProps = { tenantConfig: Tenant };
47+
import { AbstractIntlMessages, NextIntlClientProvider } from 'next-intl';
48+
import { NextPage } from 'next';
49+
import { SetState } from '../src/features/common/types/common';
4750

4851
const VideoContainer = dynamic(
4952
() => import('../src/features/common/LandingVideo'),
@@ -107,15 +110,40 @@ const onRedirectCallback = (appState: any) => {
107110
// Client-side cache, shared for the whole session of the user in the browser.
108111
const clientSideEmotionCache = createEmotionCache();
109112

110-
export interface MyAppProps extends AppProps {
113+
export type NextPageWithLayout<P = PageComponentProps, IP = P> = NextPage<
114+
P,
115+
IP
116+
> & {
117+
getLayout?: (
118+
page: ReactElement,
119+
pageComponentProps: PageComponentProps
120+
) => ReactNode;
121+
};
122+
123+
type AppPropsWithLayout = Omit<AppProps, 'pageProps'> & {
124+
Component: NextPageWithLayout;
111125
emotionCache?: EmotionCache;
112-
}
126+
pageProps: PageProps;
127+
};
128+
129+
export type PageProps = {
130+
tenantConfig: Tenant;
131+
messages?: AbstractIntlMessages;
132+
[key: string]: any;
133+
};
134+
135+
export type PageComponentProps = {
136+
pageProps: PageProps;
137+
currencyCode: string;
138+
setCurrencyCode: SetState<string>;
139+
isMobile: boolean;
140+
};
113141

114142
const PlanetWeb = ({
115143
Component,
116144
pageProps,
117145
emotionCache = clientSideEmotionCache,
118-
}: MyAppProps & AppOwnProps) => {
146+
}: AppPropsWithLayout) => {
119147
const router = useRouter();
120148
const [isMap, setIsMap] = React.useState(false);
121149
const [currencyCode, setCurrencyCode] = React.useState('');
@@ -140,14 +168,7 @@ const PlanetWeb = ({
140168
}, []);
141169

142170
React.useEffect(() => {
143-
if (
144-
router.pathname === '/' ||
145-
router.pathname === '/[p]' ||
146-
router.pathname === '/[p]/[id]' ||
147-
router.pathname === '/sites/[slug]/[locale]' ||
148-
router.pathname === '/sites/[slug]/[locale]/[p]' ||
149-
router.pathname === '/sites/[slug]/[locale]/[p]/[id]'
150-
) {
171+
if (router.pathname.includes('projects-archive')) {
151172
setIsMap(true);
152173
} else {
153174
setIsMap(false);
@@ -164,10 +185,16 @@ const PlanetWeb = ({
164185
setBrowserCompatible(browserNotCompatible());
165186
}, []);
166187

167-
const ProjectProps = {
188+
const isMobile = useMemo(() => {
189+
if (typeof window === 'undefined') return false;
190+
return window.innerWidth < 481;
191+
}, [typeof window !== 'undefined' && window.innerWidth]);
192+
193+
const pageComponentProps = {
168194
pageProps,
169195
currencyCode,
170196
setCurrencyCode,
197+
isMobile,
171198
};
172199

173200
const [showVideo, setshowVideo] = React.useState(true);
@@ -180,11 +207,7 @@ const PlanetWeb = ({
180207
const [localShowVideo, setLocalShowVideo] = React.useState(false);
181208

182209
React.useEffect(() => {
183-
if (
184-
router.pathname === '/' ||
185-
router.pathname === '/sites/[slug]' ||
186-
router.pathname === '/sites/[slug]/[locale]'
187-
) {
210+
if (router.pathname.endsWith('projects-archive')) {
188211
if (typeof window !== 'undefined') {
189212
if (localStorage.getItem('showVideo')) {
190213
if (localStorage.getItem('showVideo') === 'true') {
@@ -206,6 +229,12 @@ const PlanetWeb = ({
206229
setshowVideo(localShowVideo);
207230
}, [localShowVideo]);
208231

232+
const getLayout = Component.getLayout ?? ((page) => page);
233+
const pageContent = getLayout(
234+
<Component {...pageComponentProps} />,
235+
pageComponentProps
236+
);
237+
209238
if (browserCompatible) {
210239
return <BrowserNotSupported />;
211240
} else {
@@ -273,7 +302,7 @@ const PlanetWeb = ({
273302
setshowVideo={setshowVideo}
274303
/>
275304
) : null}
276-
<Component {...ProjectProps} />
305+
{pageContent}
277306
</AnalyticsProvider>
278307
</BulkCodeProvider>
279308
</ProjectPropsProvider>
@@ -300,7 +329,7 @@ const PlanetWeb = ({
300329

301330
PlanetWeb.getInitialProps = async (
302331
context: AppContext
303-
): Promise<AppOwnProps & AppInitialProps> => {
332+
): Promise<AppInitialProps & { pageProps: PageProps }> => {
304333
const ctx = await App.getInitialProps(context);
305334

306335
const _tenantSlug = await getTenantSlug(
@@ -311,12 +340,13 @@ PlanetWeb.getInitialProps = async (
311340

312341
const tenantConfig = await getTenantConfig(tenantSlug);
313342

314-
const pageProps = {
315-
...ctx.pageProps,
316-
tenantConfig,
343+
return {
344+
...ctx,
345+
pageProps: {
346+
...ctx.pageProps,
347+
tenantConfig,
348+
},
317349
};
318-
319-
return { ...ctx, pageProps } as AppOwnProps & AppInitialProps;
320350
};
321351

322352
export default trpc.withTRPC(PlanetWeb);

pages/_document.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@ class MyDocument extends Document {
2525
return (
2626
<Html lang="en">
2727
<Head>
28-
<link rel="dns-prefetch" href="https://www.plant-for-the-planet.org/" />
28+
<link
29+
rel="dns-prefetch"
30+
href="https://www.plant-for-the-planet.org/"
31+
/>
2932
<link
3033
rel="preconnect"
3134
href="https://fonts.googleapis.com/"
3235
crossOrigin="true"
3336
/>
37+
<link
38+
rel="preload"
39+
as="image"
40+
href="/assets/images/project-contribution-default-landscape.png"
41+
/>
3442
{/* Commented code below to avoid inserting emotion css <style> tags above global/module scss */}
3543
{/* <meta name="emotion-insertion-point" content="" /> */}
3644
{this.props.styles}

0 commit comments

Comments
 (0)