From fa34a40c17f81dd2346caabc5b5b9bfa57fcdf80 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Fri, 27 Dec 2019 23:11:11 +0100 Subject: [PATCH 1/4] feat(shared): add redirectTo hoc and apply it for old big-party conf --- pages/big-party-i/index.tsx | 5 +++++ pages/big-party-ii/index.tsx | 3 +++ pages/big-party-iii/index.tsx | 3 +++ shared/external-redirect.ts | 25 +++++++++++++++++++++++++ shared/index.ts | 1 + 5 files changed, 37 insertions(+) create mode 100644 pages/big-party-i/index.tsx create mode 100644 pages/big-party-ii/index.tsx create mode 100644 pages/big-party-iii/index.tsx create mode 100644 shared/external-redirect.ts diff --git a/pages/big-party-i/index.tsx b/pages/big-party-i/index.tsx new file mode 100644 index 0000000..d342683 --- /dev/null +++ b/pages/big-party-i/index.tsx @@ -0,0 +1,5 @@ +import { redirectTo } from '../../shared' + +export default redirectTo( + 'https://www.eventbrite.com/e/ngbigparty-tickets-18241722483' +) diff --git a/pages/big-party-ii/index.tsx b/pages/big-party-ii/index.tsx new file mode 100644 index 0000000..51151ce --- /dev/null +++ b/pages/big-party-ii/index.tsx @@ -0,0 +1,3 @@ +import { redirectTo } from '../../shared' + +export default redirectTo('https://www.ngparty.cz/ngBigParty-II') diff --git a/pages/big-party-iii/index.tsx b/pages/big-party-iii/index.tsx new file mode 100644 index 0000000..5aff3ab --- /dev/null +++ b/pages/big-party-iii/index.tsx @@ -0,0 +1,3 @@ +import { redirectTo } from '../../shared' + +export default redirectTo('https://www.meetup.com/ngParty/events/231965205/') diff --git a/shared/external-redirect.ts b/shared/external-redirect.ts new file mode 100644 index 0000000..96fee38 --- /dev/null +++ b/shared/external-redirect.ts @@ -0,0 +1,25 @@ +import React from 'react' +import { + NextApiRequest, + NextApiResponse, + NextPage, + NextPageContext, +} from 'next' +import Router from 'next/router' + +export const redirectTo = (redirectUrl: string) => { + const Redirect = () => { + return React.createElement('div', null, 'redirecting...') + } + Redirect.getInitialProps = async ({ res }: NextPageContext) => { + if (res) { + res.writeHead(302, { Location: redirectUrl }) + res.end() + return + } + + Router.push(redirectUrl) + } + + return Redirect +} diff --git a/shared/index.ts b/shared/index.ts index 7f16534..b22f808 100644 --- a/shared/index.ts +++ b/shared/index.ts @@ -1 +1,2 @@ export * from './data' +export * from './external-redirect' From e307d190ef23d8179e6205a933053b0a981505db Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Sun, 29 Dec 2019 12:39:31 +0100 Subject: [PATCH 2/4] fixup! feat(shared): add redirectTo hoc and apply it for old big-party conf --- globals.d.ts | 1 + pages/big-party-ii/index.tsx | 4 ++- pages/big-party-iii/index.tsx | 4 ++- shared/environment.ts | 1 + shared/external-redirect.ts | 25 ----------------- shared/external-redirect.tsx | 52 +++++++++++++++++++++++++++++++++++ shared/index.ts | 1 + typings/amp.d.ts | 28 +++++++++++++------ 8 files changed, 80 insertions(+), 36 deletions(-) create mode 100644 shared/environment.ts delete mode 100644 shared/external-redirect.ts create mode 100644 shared/external-redirect.tsx diff --git a/globals.d.ts b/globals.d.ts index 9ccfe06..ab3fd94 100644 --- a/globals.d.ts +++ b/globals.d.ts @@ -5,6 +5,7 @@ declare namespace JSX { 'amp-analytics': AMP.AmpAnalytics 'amp-sidebar': AMP.AmpSidebar 'amp-lightbox': AMP.AmpLightBox + 'amp-script': AMP.AmpScript } } diff --git a/pages/big-party-ii/index.tsx b/pages/big-party-ii/index.tsx index 51151ce..ce88d96 100644 --- a/pages/big-party-ii/index.tsx +++ b/pages/big-party-ii/index.tsx @@ -1,3 +1,5 @@ import { redirectTo } from '../../shared' -export default redirectTo('https://www.ngparty.cz/ngBigParty-II') +export default redirectTo('https://www.ngparty.cz/ngBigParty-II', { + external: true, +}) diff --git a/pages/big-party-iii/index.tsx b/pages/big-party-iii/index.tsx index 5aff3ab..85cc2c2 100644 --- a/pages/big-party-iii/index.tsx +++ b/pages/big-party-iii/index.tsx @@ -1,3 +1,5 @@ import { redirectTo } from '../../shared' -export default redirectTo('https://www.meetup.com/ngParty/events/231965205/') +export default redirectTo('https://www.meetup.com/ngParty/events/231965205/', { + external: true, +}) diff --git a/shared/environment.ts b/shared/environment.ts new file mode 100644 index 0000000..9c6e0dd --- /dev/null +++ b/shared/environment.ts @@ -0,0 +1 @@ +export const isClient = typeof window !== 'undefined' diff --git a/shared/external-redirect.ts b/shared/external-redirect.ts deleted file mode 100644 index 96fee38..0000000 --- a/shared/external-redirect.ts +++ /dev/null @@ -1,25 +0,0 @@ -import React from 'react' -import { - NextApiRequest, - NextApiResponse, - NextPage, - NextPageContext, -} from 'next' -import Router from 'next/router' - -export const redirectTo = (redirectUrl: string) => { - const Redirect = () => { - return React.createElement('div', null, 'redirecting...') - } - Redirect.getInitialProps = async ({ res }: NextPageContext) => { - if (res) { - res.writeHead(302, { Location: redirectUrl }) - res.end() - return - } - - Router.push(redirectUrl) - } - - return Redirect -} diff --git a/shared/external-redirect.tsx b/shared/external-redirect.tsx new file mode 100644 index 0000000..3fc51c9 --- /dev/null +++ b/shared/external-redirect.tsx @@ -0,0 +1,52 @@ +import React from 'react' +import { NextPageContext } from 'next' +import Head from 'next/head' +import Router from 'next/router' + +/** + * @experimental + * + * NOTE: this doesn't work as `http-equiv="refresh"` is forbidden within AMP + */ +export const ampRedirectTo = (redirectUrl: string) => { + const Redirect = () => { + return ( + <> + + + +

Redirecting...

+ + ) + } + + return Redirect +} + +/** + * NOTE: + * 1. This doesn't work with `next export` as getInitialProps work only with node served app + * 2. `Router.push` is unable to push external urls + */ +export const redirectTo = (redirectUrl: string, { external = false } = {}) => { + const Redirect = () => { + return React.createElement('div', null, 'redirecting...') + } + Redirect.getInitialProps = async ({ res }: NextPageContext) => { + if (res) { + res.writeHead(302, { Location: redirectUrl }) + res.end() + return {} + } + + if (external) { + window.location.href = redirectUrl + } else { + Router.push(redirectUrl) + } + + return {} + } + + return Redirect +} diff --git a/shared/index.ts b/shared/index.ts index b22f808..a8c2ffa 100644 --- a/shared/index.ts +++ b/shared/index.ts @@ -1,2 +1,3 @@ export * from './data' export * from './external-redirect' +export * from './environment' diff --git a/typings/amp.d.ts b/typings/amp.d.ts index 4496aa7..1b80e57 100644 --- a/typings/amp.d.ts +++ b/typings/amp.d.ts @@ -1,4 +1,13 @@ declare namespace AMP { + type Layouts = + | 'responsive' + | 'fixed' + | 'fill' + | 'fixed-height' + | 'flex-item' + | 'container' + | 'nodisplay' + | 'intrinsic' interface AmpBaseElement extends JSX.IntrinsicAttributes {} interface AmpLightBox extends AmpBaseElement { @@ -18,15 +27,7 @@ declare namespace AMP { src?: string width?: string height?: string - layout?: - | 'responsive' - | 'fixed' - | 'fill' - | 'fixed-height' - | 'flex-item' - | 'container' - | 'nodisplay' - | 'intrinsic' + layout?: Layouts className?: string children?: React.ReactNode } @@ -42,4 +43,13 @@ declare namespace AMP { children?: React.ReactNode } interface AmpAnalytics extends AmpBaseElement {} + + interface AmpScript { + width?: string + height?: string + script?: string + src?: string + layout?: Layouts + children?: React.ReactNode + } } From 62015960c6c2ffca33a665e8aad3b0c9973b9819 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Sun, 29 Dec 2019 13:18:45 +0100 Subject: [PATCH 3/4] fixup! feat(shared): add redirectTo hoc and apply it for old big-party conf --- pages/big-party-ii/index.tsx | 4 +--- pages/big-party-iii/index.tsx | 4 +--- shared/environment.ts | 9 ++++++++ shared/external-redirect.tsx | 41 ++++++++++++++++------------------- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/pages/big-party-ii/index.tsx b/pages/big-party-ii/index.tsx index ce88d96..51151ce 100644 --- a/pages/big-party-ii/index.tsx +++ b/pages/big-party-ii/index.tsx @@ -1,5 +1,3 @@ import { redirectTo } from '../../shared' -export default redirectTo('https://www.ngparty.cz/ngBigParty-II', { - external: true, -}) +export default redirectTo('https://www.ngparty.cz/ngBigParty-II') diff --git a/pages/big-party-iii/index.tsx b/pages/big-party-iii/index.tsx index 85cc2c2..5aff3ab 100644 --- a/pages/big-party-iii/index.tsx +++ b/pages/big-party-iii/index.tsx @@ -1,5 +1,3 @@ import { redirectTo } from '../../shared' -export default redirectTo('https://www.meetup.com/ngParty/events/231965205/', { - external: true, -}) +export default redirectTo('https://www.meetup.com/ngParty/events/231965205/') diff --git a/shared/environment.ts b/shared/environment.ts index 9c6e0dd..44ce80e 100644 --- a/shared/environment.ts +++ b/shared/environment.ts @@ -1 +1,10 @@ +import { NextPageContext } from 'next' + export const isClient = typeof window !== 'undefined' + +/** + * + * helper for getInitialProps, if you need to use it with `next export` + */ +export const isStaticExport = (ctx: NextPageContext) => + typeof ctx.res!.writeHead !== 'function' diff --git a/shared/external-redirect.tsx b/shared/external-redirect.tsx index 3fc51c9..8f44d85 100644 --- a/shared/external-redirect.tsx +++ b/shared/external-redirect.tsx @@ -1,7 +1,7 @@ -import React from 'react' +import React, { useEffect } from 'react' import { NextPageContext } from 'next' import Head from 'next/head' -import Router from 'next/router' +import { useRouter } from 'next/router' /** * @experimental @@ -23,30 +23,27 @@ export const ampRedirectTo = (redirectUrl: string) => { return Redirect } -/** - * NOTE: - * 1. This doesn't work with `next export` as getInitialProps work only with node served app - * 2. `Router.push` is unable to push external urls - */ -export const redirectTo = (redirectUrl: string, { external = false } = {}) => { +export const redirectTo = (redirectUrl: string, { external = true } = {}) => { const Redirect = () => { - return React.createElement('div', null, 'redirecting...') - } - Redirect.getInitialProps = async ({ res }: NextPageContext) => { - if (res) { - res.writeHead(302, { Location: redirectUrl }) - res.end() - return {} - } + const router = useRouter() - if (external) { - window.location.href = redirectUrl - } else { - Router.push(redirectUrl) - } + useEffect(() => { + if (external) { + window.location.href = redirectUrl + return + } + router.push(redirectUrl) + }, []) - return {} + return React.createElement('div', null, 'Redirecting...') } return Redirect } + +function serverRedirect(res: NextPageContext['res'], redirectUrl: string) { + if (res) { + res.writeHead(302, { Location: redirectUrl }) + res.end() + } +} From 8e02c8d63eb49cdedeb2d2736ed0937221003274 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Sun, 29 Dec 2019 13:20:43 +0100 Subject: [PATCH 4/4] fix(big-v): add keys on fragment list --- conferences/big-party-v/schedule.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/conferences/big-party-v/schedule.tsx b/conferences/big-party-v/schedule.tsx index 009ef2a..345207a 100644 --- a/conferences/big-party-v/schedule.tsx +++ b/conferences/big-party-v/schedule.tsx @@ -1,4 +1,5 @@ import { styles } from './schedule.styles' +import { Fragment } from 'react' const DATA: ScheduleItemModel[] = [ { @@ -176,7 +177,7 @@ const ScheduleItem = (props: ScheduleItemModel) => { {speakerBios.map((item, idx) => { return ( - <> + { company={item.company} /> {isMultiple ?
: null} - +
) })}
{speakerTalk}