{"size": 2120, "ext": "js", "max_stars_repo_path": "app/packages/dashboard/client/ui/ActiveUserPositions.js", "max_stars_repo_name": "learning-layers/LD-Meteor", "max_stars_repo_stars_event_min_datetime": "2016-04-24T18:53:11.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-06T11:17:48.000Z", "max_issues_repo_path": "app/packages/dashboard/client/ui/ActiveUserPositions.js", "max_issues_repo_name": "learning-layers/LD-Meteor", "max_issues_repo_issues_event_min_datetime": "2016-04-24T16:08:58.000Z", "max_issues_repo_issues_event_max_datetime": "2016-12-05T20:32:10.000Z", "max_forks_repo_path": "app/packages/dashboard/client/ui/ActiveUserPositions.js", "max_forks_repo_name": "learning-layers/LD-Meteor", "max_forks_repo_forks_event_min_datetime": "2021-03-02T01:01:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-02T01:01:16.000Z"}
{"max_stars_count": 3, "max_issues_count": 35, "max_forks_count": 1, "avg_line_length": 34.1935483871, "max_line_length": 175, "alphanum_fraction": 0.6103773585}
import React, { Component } from 'react'
import { Meteor } from 'meteor/meteor'
import { compose } from 'react-komposer'
import { UserPositions } from '../../lib/collections'
import { Documents } from '../../../document/lib/collections'
import { Tracker } from 'meteor/tracker'

function getTrackerLoader (reactiveMapper) {
  return (props, onData, env) => {
    let trackerCleanup = null
    const handler = Tracker.nonreactive(() => {
      return Tracker.autorun(() => {
        // assign the custom clean-up function.
        trackerCleanup = reactiveMapper(props, onData, env)
      })
    })

    return () => {
      if (typeof trackerCleanup === 'function') trackerCleanup()
      return handler.stop()
    }
  }
}

function onPropsChange (props, onData) {
  let handle = Meteor.subscribe('activeUserPositions')
  if (handle.ready()) {
    const userPositions = UserPositions.find({}).fetch()
    onData(null, { userPositions })
  }
}

class ActiveUserPositions extends Component {
  render () {
    const { userPositions } = this.props
    return <div id='active-user-positions'>
      <div className='table-responsive'>
        <table className='table table-striped table-bordered table-condensed'>
          <thead>
            <tr>
              <th key='user-pos-userinfo'>User</th>
              <th key='user-pos-type'>Type: Title</th>
            </tr>
          </thead>
          <tbody>
            {userPositions.map(function (userPosition) {
              const user = Meteor.users.findOne({_id: userPosition.userId})
              const document = Documents.findOne({_id: userPosition.elementId})
              return <tr key={'user-pos-' + userPosition._id}>
                <td>{user.profile ? user.profile.name : userPosition.userId}</td>
                <td><a href={'/document/' + userPosition.elementId}><span className='glyphicon glyphicon-file' /> {document ? document.title : userPosition.elementId}</a></td>
              </tr>
            })}
          </tbody>
        </table>
      </div>
    </div>
  }
}

export default compose(getTrackerLoader(onPropsChange))(ActiveUserPositions)
