Sha256: 727cb83500e4ea34329cc391dd9984157f7c838eb0f354e400e4164fb0041ca8

Contents?: true

Size: 1.96 KB

Versions: 4

Compression:

Stored size: 1.96 KB

Contents

class Lanes.Components.NetworkActivityOverlay extends Lanes.React.Component

    propTypes:
        model:   Lanes.PropTypes.Model
        message: React.PropTypes.string
        timeout: React.PropTypes.number
        visible: React.PropTypes.bool
        errorTimeout: React.PropTypes.number

    getDefaultProps: ->
        timeout: 30000, errorTimeout: 2000

    removeMessage: ->
        return unless @isMounted()
        @setState(isRequesting: false, hasError: false)

    clearTimeout: ->
        clearTimeout(@state.removeHandler) if @state.removeHandler

    installRemoval: (state) ->
        @clearTimeout()
        @setState(removeHandler: _.delay(@removeMessage,
            if state.hasError then @props.errorTimeout else @props.timeout
        ))

    listenNetworkEvents: true

    setDataState: (state) ->
        if state.hasError or state.isRequesting
            @installRemoval(state)
        else if not @state.hasError
            @removeMessage()
        @setState(state)

    render: ->
        return null unless @props.visible or @state.isRequesting or @state.hasError
        message = @props.message or (
            if @state.hasError
                errorMsg = @model.errorMessage
                if errorMsg and _.isString(errorMsg) then errorMsg else "Error"
            else if @state.isRequesting is 'GET'
                'Loading…'
            else if _.includes(['PATCH', 'POST', 'PUT'], @state.isRequesting)
                'Saving…'
            else if @state.isRequesting is 'DELETE'
                'Deleting…'
            else
                'Pending…'
        )
        icon = if @state.hasError then 'exclamation-circle' else 'spinner'
        classes = _.classnames 'overlay', {rounded: @props.roundedCorners}
        <div className={classes}>
            <div className="mask" />
            <div className="message">
                <LC.Icon type={icon} animated={not @state.hasError} />
                {message}
            </div>
        </div>

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lanes-0.5.6 client/lanes/components/shared/NetworkActivityOverlay.cjsx
lanes-0.5.5 client/lanes/components/shared/NetworkActivityOverlay.cjsx
lanes-0.5.0 client/lanes/components/shared/NetworkActivityOverlay.cjsx
lanes-0.4.0 client/lanes/components/shared/NetworkActivityOverlay.cjsx