refactor: jsx => tsx (next.js)

pull/313/head
amio 2019-10-04 21:44:20 +08:00
rodzic 08af45e2fe
commit ebbb97923e
7 zmienionych plików z 27 dodań i 13 usunięć

Wyświetl plik

@ -5,7 +5,7 @@ const DEFAULT_SIZE = 42
interface BuilderBarProps {
placeholder: string;
badgeURL: string;
host: string;
host?: string;
onChange: (value: string) => void;
onFocus: () => void;
onBlur: () => void;

Wyświetl plik

@ -1,10 +1,16 @@
import badgeList from '../static/.meta/badges.json'
const examples = [...badgeList.live, ...badgeList.static].reduce((accu, curr) => {
return accu.concat(Object.entries(curr.examples))
}, [])
return (accu as any).concat(Object.entries(curr.examples))
}, [] as [string, string][])
export default function BuilderHelper ({ badgeURL, onSelect }) {
interface BuilderHelperProps {
host?: string;
badgeURL: string;
onSelect: (value: string) => void;
}
export default function BuilderHelper ({ badgeURL, onSelect }: BuilderHelperProps) {
if (badgeURL.length < 2) {
return <div className='helper' />
}

Wyświetl plik

@ -1,6 +1,6 @@
import icons from 'badgen-icons'
export default function HomeIntro ({ isFlat }) {
export default function HomeIntro ({ isFlat = false }) {
return (
<div>
<pre>{explainCode(isFlat)}</pre>

Wyświetl plik

@ -1,11 +1,17 @@
import React from 'react'
import App, { Container } from 'next/app'
import App from 'next/app'
import Head from 'next/head'
declare global {
interface Window {
dataLayer: Array<any>;
}
}
export default class MyApp extends App {
componentDidMount () {
window.dataLayer = window.dataLayer || []
function gtag () { window.dataLayer.push(arguments) }
function gtag (...args) { window.dataLayer.push(args) }
gtag('js', new Date())
gtag('config', 'UA-4646421-14')
}
@ -14,7 +20,7 @@ export default class MyApp extends App {
const { Component, pageProps } = this.props
return (
<Container>
<>
<Head>
<title>Badgen - Fast badge generating service</title>
<link rel='icon' type='image/png' href='/static/favicon.png' />
@ -33,7 +39,7 @@ export default class MyApp extends App {
a { text-decoration: none }
`}
</style>
</Container>
</>
)
}
}

Wyświetl plik

@ -22,7 +22,7 @@ export default class BuilderPage extends React.Component {
handleSelect = exampleURL => this.setState({ badgeURL: exampleURL })
componentDidMount () {
const forceHost = new URL(window.location).searchParams.get('host')
const forceHost = new URL(window.location.href).searchParams.get('host')
this.setState({
host: (forceHost || window.location.origin) + '/',
badgeURL: window.location.hash.replace(/^#/, ''),

Wyświetl plik

@ -12,7 +12,7 @@ const Index = () => {
const badges = examples[tab]
useEffect(() => {
const forceHost = new URL(window.location).searchParams.get('host')
const forceHost = new URL(window.location.href).searchParams.get('host')
setHost((forceHost || window.location.origin) + '/')
})

Wyświetl plik

@ -5,7 +5,7 @@
"allowJs": true,
"skipLibCheck": true,
"jsx": "preserve",
"target": "esnext",
"target": "es2017",
"module": "esnext",
"moduleResolution": "node",
"esModuleInterop": true,
@ -24,7 +24,9 @@
"include": [
"index.ts",
"endpoints",
"types"
"components",
"pages",
"static"
],
"exclude": [
"node_modules"