Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add past big-party redirects #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions conferences/big-party-v/schedule.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { styles } from './schedule.styles'
import { Fragment } from 'react'

const DATA: ScheduleItemModel[] = [
{
Expand Down Expand Up @@ -176,15 +177,15 @@ const ScheduleItem = (props: ScheduleItemModel) => {

{speakerBios.map((item, idx) => {
return (
<>
<Fragment key={item.fullName}>
<SpeakerLink
key={item.fullName}
link={item.link}
fullName={item.fullName}
company={item.company}
/>
{isMultiple ? <br /> : null}
</>
</Fragment>
)
})}
<div className="ap-m-agenda-item-description-text">{speakerTalk}</div>
Expand Down
1 change: 1 addition & 0 deletions globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ declare namespace JSX {
'amp-analytics': AMP.AmpAnalytics
'amp-sidebar': AMP.AmpSidebar
'amp-lightbox': AMP.AmpLightBox
'amp-script': AMP.AmpScript
}
}

Expand Down
5 changes: 5 additions & 0 deletions pages/big-party-i/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { redirectTo } from '../../shared'

export default redirectTo(
'https://www.eventbrite.com/e/ngbigparty-tickets-18241722483'
)
3 changes: 3 additions & 0 deletions pages/big-party-ii/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { redirectTo } from '../../shared'

export default redirectTo('https://www.ngparty.cz/ngBigParty-II')
3 changes: 3 additions & 0 deletions pages/big-party-iii/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { redirectTo } from '../../shared'

export default redirectTo('https://www.meetup.com/ngParty/events/231965205/')
10 changes: 10 additions & 0 deletions shared/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +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'
49 changes: 49 additions & 0 deletions shared/external-redirect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, { useEffect } from 'react'
import { NextPageContext } from 'next'
import Head from 'next/head'
import { useRouter } 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 (
<>
<Head>
<meta http-equiv="refresh" content={`0;url=${redirectUrl}`} />
</Head>
<p>Redirecting...</p>
</>
)
}

return Redirect
}

export const redirectTo = (redirectUrl: string, { external = true } = {}) => {
const Redirect = () => {
const router = useRouter()

useEffect(() => {
if (external) {
window.location.href = redirectUrl
return
}
router.push(redirectUrl)
}, [])

return React.createElement('div', null, 'Redirecting...')
}

return Redirect
}

function serverRedirect(res: NextPageContext['res'], redirectUrl: string) {
if (res) {
res.writeHead(302, { Location: redirectUrl })
res.end()
}
}
2 changes: 2 additions & 0 deletions shared/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './data'
export * from './external-redirect'
export * from './environment'
28 changes: 19 additions & 9 deletions typings/amp.d.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
}
Expand All @@ -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
}
}