2017-06-08 05:25:47 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-01-08 12:44:42 +08:00
|
|
|
import { withTracker } from 'meteor/react-meteor-data';
|
2017-05-05 05:10:49 +08:00
|
|
|
import CursorService from './service';
|
|
|
|
import Cursor from './component';
|
|
|
|
|
|
|
|
|
2017-08-15 08:15:11 +08:00
|
|
|
class CursorContainer extends Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = {
|
|
|
|
labelBoxWidth: 0,
|
|
|
|
labelBoxHeight: 0,
|
|
|
|
};
|
|
|
|
this.setLabelBoxDimensions = this.setLabelBoxDimensions.bind(this);
|
2017-05-05 05:10:49 +08:00
|
|
|
}
|
2017-08-15 08:15:11 +08:00
|
|
|
|
|
|
|
setLabelBoxDimensions(labelBoxWidth, labelBoxHeight) {
|
|
|
|
this.setState({
|
|
|
|
labelBoxWidth,
|
|
|
|
labelBoxHeight,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { cursorX, cursorY } = this.props;
|
2017-09-06 09:36:15 +08:00
|
|
|
const { labelBoxWidth, labelBoxHeight } = this.state;
|
2017-08-15 08:15:11 +08:00
|
|
|
|
|
|
|
if (cursorX > 0 && cursorY > 0) {
|
|
|
|
return (
|
|
|
|
<Cursor
|
|
|
|
cursorX={cursorX}
|
|
|
|
cursorY={cursorY}
|
2017-09-06 09:36:15 +08:00
|
|
|
labelBoxWidth={labelBoxWidth}
|
|
|
|
labelBoxHeight={labelBoxHeight}
|
2017-08-15 08:15:11 +08:00
|
|
|
setLabelBoxDimensions={this.setLabelBoxDimensions}
|
|
|
|
{...this.props}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2017-07-29 08:29:40 +08:00
|
|
|
|
2017-05-05 05:10:49 +08:00
|
|
|
|
2018-01-08 12:44:42 +08:00
|
|
|
export default withTracker((params) => {
|
2017-08-15 08:15:11 +08:00
|
|
|
const { cursorId } = params;
|
2017-07-29 08:29:40 +08:00
|
|
|
|
2017-08-15 08:15:11 +08:00
|
|
|
const cursor = CursorService.getCurrentCursor(cursorId);
|
2017-05-05 05:10:49 +08:00
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
if (cursor) {
|
2018-01-08 12:44:42 +08:00
|
|
|
const { x: cursorX, y: cursorY, userName } = cursor;
|
|
|
|
return {
|
|
|
|
cursorX,
|
|
|
|
cursorY,
|
|
|
|
userName,
|
|
|
|
};
|
2017-05-05 05:10:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2018-01-08 12:44:42 +08:00
|
|
|
cursorX: -1,
|
|
|
|
cursorY: -1,
|
|
|
|
userName: '',
|
2017-05-05 05:10:49 +08:00
|
|
|
};
|
2018-01-08 12:44:42 +08:00
|
|
|
})(CursorContainer);
|
2017-05-05 05:10:49 +08:00
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
|
|
|
|
CursorContainer.propTypes = {
|
|
|
|
// Defines the 'x' coordinate for the cursor, in percentages of the slide's width
|
|
|
|
cursorX: PropTypes.number.isRequired,
|
|
|
|
|
|
|
|
// Defines the 'y' coordinate for the cursor, in percentages of the slide's height
|
|
|
|
cursorY: PropTypes.number.isRequired,
|
|
|
|
};
|