1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

withTracker HOC formatting

This commit is contained in:
Matthias Kretschmann 2019-04-08 19:54:18 +02:00
parent 18267a1a18
commit 6ac4440897
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 29 additions and 19 deletions

View File

@ -72,4 +72,9 @@ export const faucetPort = process.env.REACT_APP_FAUCET_PORT || 443
// export const faucetHost = 'localhost'
// export const faucetPort = 3001
export const verbose = true
export const verbose = true
//
// APP CONFIG
//
export const analyticsId = 'UA-60614729-11'

View File

@ -252,7 +252,7 @@ class Publish extends Component<{}, PublishState> {
ReactGA.event({
category: 'Publish',
action: 'registerAsset-start'
});
})
this.setState({
publishingError: '',
isPublishing: true

View File

@ -1,15 +1,19 @@
import React, { Component } from 'react'
import React, { PureComponent } from 'react'
import ReactGA from 'react-ga'
import { analyticsId } from './config/config'
interface TrackerProps {
location: any
location: Location
}
ReactGA.initialize('UA-60614729-11', {testMode: process.env.NODE_ENV === 'test'})
ReactGA.initialize(analyticsId, {
testMode: process.env.NODE_ENV === 'test'
})
export default function withTracker(WrappedComponent: any, options: any = {}) {
const trackPage = (page: any) => {
options.isWeb3 = (window.web3 !== undefined)
const trackPage = (page: string) => {
options.isWeb3 = window.web3 !== undefined
ReactGA.set({
page,
...options
@ -17,25 +21,26 @@ export default function withTracker(WrappedComponent: any, options: any = {}) {
ReactGA.pageview(page)
}
const HOC = class extends Component<TrackerProps, {}> {
componentDidMount() {
const page = this.props.location.pathname + this.props.location.search
return class HOC extends PureComponent<TrackerProps, {}> {
public componentDidMount() {
const page =
this.props.location.pathname + this.props.location.search
trackPage(page)
}
componentWillReceiveProps(nextProps: any) {
const currentPage = this.props.location.pathname;
const nextPage = nextProps.location.pathname;
public componentWillReceiveProps(nextProps: any) {
const currentPage = this.props.location.pathname
const nextPage = nextProps.location.pathname
if (currentPage !== nextPage) {
trackPage(nextProps.location.pathname + nextProps.location.search);
trackPage(
nextProps.location.pathname + nextProps.location.search
)
}
}
render() {
public render() {
return <WrappedComponent {...this.props} />
}
}
return HOC
}
}