diff --git a/ui/analytics.js b/ui/analytics.js index d39364f70..eaf66ae2a 100644 --- a/ui/analytics.js +++ b/ui/analytics.js @@ -21,6 +21,7 @@ ElectronCookies.enable({ // @endif type Analytics = { + error: string => void, pageView: string => void, setUser: Object => void, toggle: (boolean, ?boolean) => void, @@ -44,6 +45,11 @@ type LogPublishParams = { let analyticsEnabled: boolean = true; const analytics: Analytics = { + error: message => { + if (analyticsEnabled) { + Lbryio.call('event', 'desktop_error', { error_message: message }); + } + }, pageView: path => { if (analyticsEnabled) { ReactGA.pageview(path, [SECOND_TRACKER_NAME]); diff --git a/ui/component/errorBoundary/view.jsx b/ui/component/errorBoundary/view.jsx index 3b2df1d58..3b80bc231 100644 --- a/ui/component/errorBoundary/view.jsx +++ b/ui/component/errorBoundary/view.jsx @@ -1,12 +1,12 @@ // @flow import type { Node } from 'react'; -import { Lbryio } from 'lbryinc'; import React, { Fragment } from 'react'; import Yrbl from 'component/yrbl'; import Button from 'component/button'; import { withRouter } from 'react-router'; import Native from 'native'; import { Lbry } from 'lbry-redux'; +import analytics from 'analytics'; type Props = { children: Node, @@ -38,7 +38,8 @@ class ErrorBoundary extends React.Component { errorMessage += 'lbry.tv\n'; errorMessage += `page: ${window.location.pathname + window.location.search}\n`; errorMessage += error.stack; - this.log(errorMessage); + analytics.error(errorMessage); + // @endif // @if TARGET='app' Native.getAppVersionInfo().then(({ localVersion }) => { @@ -47,19 +48,12 @@ class ErrorBoundary extends React.Component { errorMessage += `sdk version: ${sdkVersion}\n`; errorMessage += `page: ${window.location.href.split('.html')[1]}\n`; errorMessage += `${error.stack}`; - this.log(errorMessage); + analytics.error(errorMessage); }); }); // @endif } - log(message) { - declare var app: { env: string }; - if (app.env === 'production') { - Lbryio.call('event', 'desktop_error', { error_message: message }); - } - } - refresh() { const { history } = this.props; // use history.replace instead of history.push so the user can't click back to the errored page diff --git a/ui/component/publishAdditionalOptions/index.js b/ui/component/publishAdditionalOptions/index.js index fa963ea73..708a61c27 100644 --- a/ui/component/publishAdditionalOptions/index.js +++ b/ui/component/publishAdditionalOptions/index.js @@ -1,5 +1,5 @@ import { connect } from 'react-redux'; -import { selectPublishFormValues, doUpdatePublishForm } from 'lbry-redux'; +import { selectPublishFormValues, doUpdatePublishForm, doToast } from 'lbry-redux'; import PublishPage from './view'; const select = state => ({ @@ -8,6 +8,7 @@ const select = state => ({ const perform = dispatch => ({ updatePublishForm: value => dispatch(doUpdatePublishForm(value)), + showToast: message => dispatch(doToast({ isError: true, message })), }); export default connect( diff --git a/ui/component/publishAdditionalOptions/license-type.jsx b/ui/component/publishAdditionalOptions/license-type.jsx index 79f08d289..7cf424ce9 100644 --- a/ui/component/publishAdditionalOptions/license-type.jsx +++ b/ui/component/publishAdditionalOptions/license-type.jsx @@ -2,6 +2,7 @@ import * as React from 'react'; import { FormField } from 'component/common/form'; import { CC_LICENSES, LEGACY_CC_LICENSES, COPYRIGHT, OTHER, PUBLIC_DOMAIN, NONE } from 'constants/licenses'; +import analytics from 'analytics'; type Props = { licenseType: ?string, @@ -10,6 +11,7 @@ type Props = { handleLicenseChange: (string, string) => void, handleLicenseDescriptionChange: (SyntheticInputEvent<*>) => void, handleLicenseUrlChange: (SyntheticInputEvent<*>) => void, + showToast: string => void, }; class LicenseType extends React.PureComponent { @@ -20,15 +22,26 @@ class LicenseType extends React.PureComponent { } handleLicenseOnChange(event: SyntheticInputEvent<*>) { - const { handleLicenseChange } = this.props; + const { handleLicenseChange, showToast } = this.props; // $FlowFixMe const { options, selectedIndex } = event.target; - const selectedOption = options[selectedIndex]; - const licenseType = selectedOption.value; - const licenseUrl = selectedOption.getAttribute('data-url'); + if (options !== null) { + const selectedOption = options[selectedIndex]; + const licenseType = selectedOption.value; + const licenseUrl = selectedOption.getAttribute('data-url'); - handleLicenseChange(licenseType, licenseUrl); + handleLicenseChange(licenseType, licenseUrl); + } else { + // There were users where this options were null for some reason + // This will at least make it so the app doesn't crash + // Hopefully this helps figure it out + analytics.error('Error changing the publish license\n' + JSON.stringify(this.props)); + + showToast( + __('There was an error updating the license type. If it continues to happen send an email to help@lbry.com.') + ); + } } render() { diff --git a/ui/component/publishAdditionalOptions/view.jsx b/ui/component/publishAdditionalOptions/view.jsx index 0985f258f..cfb1ce304 100644 --- a/ui/component/publishAdditionalOptions/view.jsx +++ b/ui/component/publishAdditionalOptions/view.jsx @@ -15,10 +15,11 @@ type Props = { licenseUrl: ?string, disabled: boolean, updatePublishForm: ({}) => void, + showToast: string => void, }; function PublishAdvanced(props: Props) { - const { language, name, licenseType, otherLicenseDescription, licenseUrl, updatePublishForm } = props; + const { language, name, licenseType, otherLicenseDescription, licenseUrl, updatePublishForm, showToast } = props; const [hideSection, setHideSection] = usePersistedState('publish-advanced-options', true); function toggleHideSection() { @@ -66,6 +67,7 @@ function PublishAdvanced(props: Props) {