Passed the data from the whiteboard-toolbar to the whiteboard-overlay

This commit is contained in:
Oleksandr Zhurbenko 2017-05-02 17:05:41 -07:00
parent f415390673
commit 2c01a6ae5a
6 changed files with 94 additions and 31 deletions

View File

@ -17,8 +17,6 @@ export default class WhiteboardOverlay extends React.Component {
currentShapeId: undefined, currentShapeId: undefined,
count: 0, count: 0,
toolSelected: "Pencil",
}; };
this.mouseDownHandler = this.mouseDownHandler.bind(this); this.mouseDownHandler = this.mouseDownHandler.bind(this);
@ -29,9 +27,11 @@ export default class WhiteboardOverlay extends React.Component {
//main mouse down handler //main mouse down handler
//calls a mouseDown<AnnotationName> handler based on the tool selected //calls a mouseDown<AnnotationName> handler based on the tool selected
mouseDownHandler(event) { mouseDownHandler(event) {
window.addEventListener('mouseup', this.mouseUpHandler); if(this.props.drawSettings.tool) {
window.addEventListener('mousemove', this.mouseMoveHandler, true); window.addEventListener('mouseup', this.mouseUpHandler);
this["mouseDown" +this.state.toolSelected](event); window.addEventListener('mousemove', this.mouseMoveHandler, true);
this["mouseDown" + this.props.drawSettings.tool](event);
}
} }
//main mouse up handler //main mouse up handler
@ -39,13 +39,13 @@ export default class WhiteboardOverlay extends React.Component {
mouseUpHandler(event) { mouseUpHandler(event) {
window.removeEventListener('mouseup', this.mouseUpHandler); window.removeEventListener('mouseup', this.mouseUpHandler);
window.removeEventListener('mousemove', this.mouseMoveHandler, true); window.removeEventListener('mousemove', this.mouseMoveHandler, true);
this["mouseUp" + this.state.toolSelected](event); this["mouseUp" + this.props.drawSettings.tool](event);
} }
//main mouse move handler //main mouse move handler
//calls a mouseMove<AnnotationName> handler based on the tool selected //calls a mouseMove<AnnotationName> handler based on the tool selected
mouseMoveHandler(event) { mouseMoveHandler(event) {
this["mouseMove" + this.state.toolSelected](event); this["mouseMove" + this.props.drawSettings.tool](event);
} }
mouseDownLine(event) { mouseDownLine(event) {
@ -125,7 +125,7 @@ export default class WhiteboardOverlay extends React.Component {
transformedSvgPoint.x = transformedSvgPoint.x / this.props.slideWidth * 100; transformedSvgPoint.x = transformedSvgPoint.x / this.props.slideWidth * 100;
transformedSvgPoint.y = transformedSvgPoint.y / this.props.slideHeight * 100; transformedSvgPoint.y = transformedSvgPoint.y / this.props.slideHeight * 100;
this["handleDraw" + this.state.toolSelected](this.state.initialCoordinates, transformedSvgPoint, "DRAW_UPDATE", this.state.currentShapeId); this["handleDraw" + this.props.drawSettings.tool](this.state.initialCoordinates, transformedSvgPoint, "DRAW_UPDATE", this.state.currentShapeId);
} }
mouseUpLine(event) { mouseUpLine(event) {
@ -164,7 +164,7 @@ export default class WhiteboardOverlay extends React.Component {
transformedSvgPoint.x = transformedSvgPoint.x / this.props.slideWidth * 100; transformedSvgPoint.x = transformedSvgPoint.x / this.props.slideWidth * 100;
transformedSvgPoint.y = transformedSvgPoint.y / this.props.slideHeight * 100; transformedSvgPoint.y = transformedSvgPoint.y / this.props.slideHeight * 100;
this["handleDraw" + this.state.toolSelected](this.state.initialCoordinates, transformedSvgPoint, "DRAW_END", this.state.currentShapeId); this["handleDraw" + this.props.drawSettings.tool](this.state.initialCoordinates, transformedSvgPoint, "DRAW_END", this.state.currentShapeId);
this.setState({ this.setState({
initialCoordinates: { initialCoordinates: {
x: undefined, x: undefined,
@ -232,17 +232,17 @@ export default class WhiteboardOverlay extends React.Component {
} }
render() { render() {
let toolSelected = this.state.toolSelected; let tool = this.props.drawSettings.tool;
return ( return (
<div <div
className={ className={
cx( cx(
toolSelected == "Pencil" ? styles.pencil : '', tool == "Pencil" ? styles.pencil : '',
toolSelected == "Triangle" ? styles.triangle : '', tool == "Triangle" ? styles.triangle : '',
toolSelected == "Rectangle" ? styles.rectangle : '', tool == "Rectangle" ? styles.rectangle : '',
toolSelected == "Ellipse" ? styles.ellipse : '', tool == "Ellipse" ? styles.ellipse : '',
toolSelected == "Line" ? styles.line : '', tool == "Line" ? styles.line : '',
toolSelected == "Text" ? styles.text : '' tool == "Text" ? styles.text : ''
) )
} }
style={{ width: '100%', height: '100%' }} style={{ width: '100%', height: '100%' }}

View File

@ -17,4 +17,5 @@ class WhiteboardOverlayContainer extends React.Component {
export default createContainer(() => ({ export default createContainer(() => ({
sendAnnotation: WhiteboardOverlayService.sendAnnotation, sendAnnotation: WhiteboardOverlayService.sendAnnotation,
drawSettings: WhiteboardOverlayService.getWhiteboardToolbarValues(),
}), WhiteboardOverlayContainer); }), WhiteboardOverlayContainer);

View File

@ -1,9 +1,19 @@
import { callServer } from '/imports/ui/services/api/index.js'; import { callServer } from '/imports/ui/services/api/index.js';
import Storage from '/imports/ui/services/storage/session';
const sendAnnotation = (annotation) => { const sendAnnotation = (annotation) => {
callServer('sendAnnotation', annotation); callServer('sendAnnotation', annotation);
}; };
const getWhiteboardToolbarValues = () => {
return {
tool: Storage.getItem('whiteboardAnnotationTool'),
thickness: Storage.getItem('whiteboardAnnotationThickness'),
color: Storage.getItem('whiteboardAnnotationColor'),
};
};
export default { export default {
sendAnnotation, sendAnnotation,
getWhiteboardToolbarValues,
}; };

View File

@ -8,10 +8,21 @@ export default class WhiteboardToolbar extends Component {
super(props); super(props);
this.state = { this.state = {
//a variable to control which list is currently open
currentSubmenuOpen: '', currentSubmenuOpen: '',
annotationSelected: 'hand',
//variables to keep current selected draw settings
annotationSelected: {
icon: 'hand',
sessionValue: 'Hand',
},
thicknessSelected: 6, thicknessSelected: 6,
colorSelected: '#000000', colorSelected: '#000000',
//lists of tools/thickness/colors are not direct children of main toolbar buttons
//and we want the list to close when onBlur fires at the main toolbar button
//(click anywhere on the screen) thus we have to control the blur manually by disabling it
//when you hover over the buttons in the list and enabling when the mouse leaves the list
onBlurEnabled: true, onBlurEnabled: true,
}; };
@ -26,6 +37,13 @@ export default class WhiteboardToolbar extends Component {
this.enableOnBlur = this.enableOnBlur.bind(this); this.enableOnBlur = this.enableOnBlur.bind(this);
} }
componentWillMount() {
//setting default or resetting current drawing settings in the session
const { annotationSelected, thicknessSelected, colorSelected } = this.state;
this.props.setWhiteboardToolbarValues(annotationSelected.sessionValue, thicknessSelected, colorSelected);
}
componentDidMount() { componentDidMount() {
//to let the whiteboard know that the presentation area's size has changed //to let the whiteboard know that the presentation area's size has changed
window.dispatchEvent(new Event('resize')); window.dispatchEvent(new Event('resize'));
@ -36,12 +54,14 @@ export default class WhiteboardToolbar extends Component {
window.dispatchEvent(new Event('resize')); window.dispatchEvent(new Event('resize'));
} }
//open a submenu
displaySubMenu(listName) { displaySubMenu(listName) {
this.setState({ this.setState({
currentSubmenuOpen: this.state.currentSubmenuOpen == listName ? '' : listName, currentSubmenuOpen: this.state.currentSubmenuOpen == listName ? '' : listName,
}); });
} }
//close a current submenu (fires onBlur only, when you click anywhere on the screen)
closeSubMenu() { closeSubMenu() {
if(this.state.onBlurEnabled) { if(this.state.onBlurEnabled) {
this.setState({ this.setState({
@ -50,15 +70,22 @@ export default class WhiteboardToolbar extends Component {
} }
} }
//undo annotation
handleUndo() { handleUndo() {
this.props.undoAnnotation(); this.props.undoAnnotation();
} }
//clear all annotations
handleClearAll() { handleClearAll() {
this.props.clearWhiteboard(); this.props.clearWhiteboard();
} }
//changes a current selected annotation both in the state and in the session
//and closes the annotation list
handleAnnotationChange(annotation) { handleAnnotationChange(annotation) {
const { thicknessSelected, colorSelected } = this.state;
this.props.setWhiteboardToolbarValues(annotation.sessionValue, thicknessSelected, colorSelected);
this.setState({ this.setState({
annotationSelected: annotation, annotationSelected: annotation,
onBlurEnabled: true, onBlurEnabled: true,
@ -66,15 +93,24 @@ export default class WhiteboardToolbar extends Component {
}); });
} }
handleThicknessChange(radius) { //changes a current selected thickness both in the state and in the session
//and closes the thickness list
handleThicknessChange(thickness) {
const { annotationSelected, colorSelected } = this.state;
this.props.setWhiteboardToolbarValues(annotationSelected.sessionValue, thickness, colorSelected);
this.setState({ this.setState({
thicknessSelected: radius, thicknessSelected: thickness,
onBlurEnabled: true, onBlurEnabled: true,
currentSubmenuOpen: '', currentSubmenuOpen: '',
}); });
} }
//changes a current selected color both in the state and in the session
//and closes the color list
handleColorChange(color) { handleColorChange(color) {
const { annotationSelected, thicknessSelected } = this.state;
this.props.setWhiteboardToolbarValues(annotationSelected.sessionValue, thicknessSelected, color);
this.setState({ this.setState({
colorSelected: color, colorSelected: color,
onBlurEnabled: true, onBlurEnabled: true,
@ -82,12 +118,14 @@ export default class WhiteboardToolbar extends Component {
}); });
} }
//disabling onBlur flag when mouse is over the items in the lists
disableOnBlur() { disableOnBlur() {
this.setState({ this.setState({
onBlurEnabled: false, onBlurEnabled: false,
}); });
} }
//enabling the onBlur flag when the mouse leaving the lists
enableOnBlur() { enableOnBlur() {
this.setState({ this.setState({
onBlurEnabled: true, onBlurEnabled: true,
@ -98,22 +136,19 @@ export default class WhiteboardToolbar extends Component {
return ( return (
<div className={cx(styles.annotationList, styles.toolbarList)}> <div className={cx(styles.annotationList, styles.toolbarList)}>
{ this.props.annotations? this.props.annotations.map((annotation) => { this.props.annotations? this.props.annotations.map((annotation, index) =>
<Button <Button
label="Annotation" label="Annotation"
hideLabel={true} hideLabel={true}
color={'default'} color={'default'}
icon={annotation} icon={annotation.icon}
size={'md'} size={'md'}
className={cx(styles.toolbarListButton, this.state.annotationSelected == annotation ? styles.selectedListButton : '')} className={cx(styles.toolbarListButton, this.state.annotationSelected.sessionValue == annotation.sessionValue ? styles.selectedListButton : '')}
onClick={this.handleAnnotationChange.bind(null, annotation)} onClick={this.handleAnnotationChange.bind(null, annotation)}
onMouseEnter={this.disableOnBlur} onMouseEnter={this.disableOnBlur}
onMouseLeave={this.enableOnBlur} onMouseLeave={this.enableOnBlur}
key={annotation} key={index}
role="button" role="button"
aria-labelledby={`${annotation}Label`}
aria-describedby={`${annotation}Descrip`}
/> />
) : null} ) : null}
</div> </div>
@ -189,11 +224,11 @@ export default class WhiteboardToolbar extends Component {
hideLabel={true} hideLabel={true}
role="button" role="button"
color={'default'} color={'default'}
icon={this.state.annotationSelected} icon={this.state.annotationSelected.icon}
size={'md'} size={'md'}
onClick={this.displaySubMenu.bind(null, "annotationList")} onClick={this.displaySubMenu.bind(null, "annotationList")}
onBlur={this.closeSubMenu} onBlur={this.closeSubMenu}
className={styles.toolbarButton} className={cx(styles.toolbarButton, this.state.currentSubmenuOpen == "annotationList" ? '' : styles.notActive)}
/> />
{this.state.currentSubmenuOpen == "annotationList" ? {this.state.currentSubmenuOpen == "annotationList" ?
this.renderAnnotationList() this.renderAnnotationList()
@ -208,7 +243,7 @@ export default class WhiteboardToolbar extends Component {
size={'md'} size={'md'}
onClick={this.displaySubMenu.bind(null, "thicknessList")} onClick={this.displaySubMenu.bind(null, "thicknessList")}
onBlur={this.closeSubMenu} onBlur={this.closeSubMenu}
className={styles.toolbarButton} className={cx(styles.toolbarButton, this.state.currentSubmenuOpen == "thicknessList" ? '' : styles.notActive)}
customSvgIcon={ customSvgIcon={
<svg className={styles.customSvgIcon} shapeRendering="geometricPrecision"> <svg className={styles.customSvgIcon} shapeRendering="geometricPrecision">
<circle shapeRendering="geometricPrecision" cx="50%" cy="50%" r={this.state.thicknessSelected} fill={this.state.colorSelected} stroke="black" strokeWidth="1"/> <circle shapeRendering="geometricPrecision" cx="50%" cy="50%" r={this.state.thicknessSelected} fill={this.state.colorSelected} stroke="black" strokeWidth="1"/>
@ -228,7 +263,7 @@ export default class WhiteboardToolbar extends Component {
size={'md'} size={'md'}
onClick={this.displaySubMenu.bind(null, "colorList")} onClick={this.displaySubMenu.bind(null, "colorList")}
onBlur={this.closeSubMenu} onBlur={this.closeSubMenu}
className={styles.toolbarButton} className={cx(styles.toolbarButton, this.state.currentSubmenuOpen == "colorList" ? '' : styles.notActive)}
customSvgIcon={ customSvgIcon={
<svg className={styles.customSvgIcon}> <svg className={styles.customSvgIcon}>
<rect x="25%" y="25%" width="50%" height="50%" fill={this.state.colorSelected} stroke="black" strokeWidth="1"/> <rect x="25%" y="25%" width="50%" height="50%" fill={this.state.colorSelected} stroke="black" strokeWidth="1"/>
@ -275,7 +310,15 @@ const defaultProps = {
'#00FFFF', '#0088FF', '#0000FF', '#8800FF', '#FF00FF', '#C0C0C0' '#00FFFF', '#0088FF', '#0000FF', '#8800FF', '#FF00FF', '#C0C0C0'
], ],
thicknessRadiuses: [14, 12, 10, 8, 6, 4, 2], thicknessRadiuses: [14, 12, 10, 8, 6, 4, 2],
annotations: ['text_tool', 'linte_tool', 'circle_tool', 'triangle_tool', 'rectangle_tool', 'pen_tool', 'hand'], annotations: [
{icon: 'text_tool', sessionValue: "Text"},
{icon: 'linte_tool', sessionValue:"Line"},
{icon: 'circle_tool', sessionValue: "Ellipse"},
{icon: 'triangle_tool', sessionValue: "Triangle"},
{icon: 'rectangle_tool', sessionValue: "Rectangle"},
{icon: 'pen_tool', sessionValue: "Pencil"},
{icon: 'hand', sessionValue: "Hand"}
],
}; };
WhiteboardToolbar.defaultProps = defaultProps; WhiteboardToolbar.defaultProps = defaultProps;

View File

@ -18,4 +18,5 @@ class WhiteboardToolbarContainer extends React.Component {
export default createContainer(() => ({ export default createContainer(() => ({
undoAnnotation: WhiteboardToolbarService.undoAnnotation, undoAnnotation: WhiteboardToolbarService.undoAnnotation,
clearWhiteboard: WhiteboardToolbarService.clearWhiteboard, clearWhiteboard: WhiteboardToolbarService.clearWhiteboard,
setWhiteboardToolbarValues: WhiteboardToolbarService.setWhiteboardToolbarValues,
}), WhiteboardToolbarContainer); }), WhiteboardToolbarContainer);

View File

@ -1,4 +1,5 @@
import { callServer } from '/imports/ui/services/api/index.js'; import { callServer } from '/imports/ui/services/api/index.js';
import Storage from '/imports/ui/services/storage/session';
const undoAnnotation = () => { const undoAnnotation = () => {
callServer('undoAnnotation'); callServer('undoAnnotation');
@ -8,7 +9,14 @@ const clearWhiteboard = () => {
callServer('clearWhiteboard'); callServer('clearWhiteboard');
}; };
const setWhiteboardToolbarValues = (tool, thickness, color) => {
Storage.setItem('whiteboardAnnotationTool', tool);
Storage.setItem('whiteboardAnnotationThickness', thickness);
Storage.setItem('whiteboardAnnotationColor', color);
};
export default { export default {
undoAnnotation, undoAnnotation,
clearWhiteboard, clearWhiteboard,
setWhiteboardToolbarValues,
}; };