Skip to content

Commit

Permalink
fix(webchat): reduced size of bundle by 1mb
Browse files Browse the repository at this point in the history
  • Loading branch information
slvnperron committed Mar 6, 2019
1 parent 2c53ab5 commit fbbc861
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
14 changes: 6 additions & 8 deletions modules/channel-web/src/views/lite/main.jsx
Expand Up @@ -3,19 +3,17 @@
import React from 'react'
import classnames from 'classnames'

// import { Emoji } from 'emoji-mart'

import addMilliseconds from 'date-fns/add_milliseconds'
import isBefore from 'date-fns/is_before'
import queryString from 'query-string'
import moment from 'moment'
import ms from 'ms'

import Convo from './convo'
import Side from './side'

import style from './style.scss'
import _ from 'lodash'

const _values = obj => Object.keys(obj).map(x => obj[x])

if (!window.location.origin) {
window.location.origin =
Expand Down Expand Up @@ -61,7 +59,7 @@ export default class Web extends React.Component {
const { config } = JSON.parse(decodeURIComponent(options || '{}'))

if (config.overrides) {
for (const override of _.values(config.overrides)) {
for (const override of _values(config.overrides)) {
this.props.bp.loadModuleView(override.module, true)
}
}
Expand Down Expand Up @@ -300,7 +298,7 @@ export default class Web extends React.Component {
this.handleSendData({
type: 'visit',
text: 'User visit',
timezone: moment().utcOffset() / 60
timezone: new Date().getTimezoneOffset() / 60
}).catch(this.checkForExpiredExternalToken)
})
}
Expand All @@ -322,8 +320,8 @@ export default class Web extends React.Component {

let conversationIdToFetch = convoId || currentConversationId
if (conversations.length > 0 && !conversationIdToFetch) {
const lifeTimeMargin = moment().subtract(ms(this.state.recentConversationLifetime), 'ms')
if (moment(conversations[0].last_heard_on).isBefore(lifeTimeMargin) && this.state.startNewConvoOnTimeout) {
const lifeTimeMargin = Date.now() - ms(this.state.recentConversationLifetime)
if (new Date(conversations[0].last_heard_on).getTime() < lifeTimeMargin && this.state.startNewConvoOnTimeout) {
return
}
conversationIdToFetch = conversations[0].id
Expand Down
7 changes: 5 additions & 2 deletions modules/channel-web/src/views/lite/messages/index.jsx
Expand Up @@ -14,7 +14,6 @@ import CarouselMessage from './carousel'

import style from './style.scss'
import Form from './form'
import _ from 'lodash'

const TIME_BETWEEN_DATES = 10 // 10 minutes

Expand Down Expand Up @@ -312,9 +311,13 @@ class Message extends Component {

const InjectedModuleView = this.props.bp.getModuleInjector()

const messageDataProps = { ...this.props.data.message_data }
delete messageDataProps.module
delete messageDataProps.component

const props = {
onSendData: this.props.onSendData,
..._.omit(this.props.data.message_data, 'module', 'component')
...messageDataProps
}

return (
Expand Down
9 changes: 8 additions & 1 deletion yarn.lock
Expand Up @@ -1130,7 +1130,7 @@ bluebird-global@^1.0.1:
resolved "https://registry.yarnpkg.com/bluebird-global/-/bluebird-global-1.0.1.tgz#147c174f4e3a19740e80d992ea70ec3dc51d0d95"
integrity sha512-llTREi0V3EUM150DKdMLlXN/X2QsQ/hWJDiaGnivqeDwE32I0dmivYLU9/VvhotTzvvbv7OiM6zjVXYJ2dCmKQ==

bluebird@^3.5.3:
bluebird@^3.3.3, bluebird@^3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7"
integrity sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw==
Expand Down Expand Up @@ -7172,6 +7172,13 @@ redis@^2.8.0, redis@~2.8.0:
redis-commands "^1.2.0"
redis-parser "^2.6.0"

redlock@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/redlock/-/redlock-3.1.2.tgz#27c82534da8548027aa8d61084a08078ae74ed36"
integrity sha512-CKXhOvLd4In5QOfbcF0GIcSsa+pL9JPZd+eKeMk/Sydxh93NUNtwQMTIKFqwPu3PjEgDStwYFJTurVzNA33pZw==
dependencies:
bluebird "^3.3.3"

reflect-metadata@^0.1.12:
version "0.1.12"
resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.12.tgz#311bf0c6b63cd782f228a81abe146a2bfa9c56f2"
Expand Down

0 comments on commit fbbc861

Please sign in to comment.