Skip to content

Commit

Permalink
add cursors to editor #29
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenhao committed Aug 24, 2018
1 parent f01ee23 commit 0fe7989
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default class Editor extends Component {
this.setState({
selected,
});
this.props.onUpdateCursor(selected);
}

handleChangeDirection = () => {
Expand Down Expand Up @@ -235,6 +236,7 @@ export default class Editor extends Component {
ref='grid'
size={this.props.size}
grid={this.props.grid}
cursors={this.props.cursors}
selected={selected}
direction={direction}
onSetSelected={this.handleSetSelected}
Expand Down
18 changes: 17 additions & 1 deletion src/pages/Composition.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export default class Composition extends Component {
return `Compose: ${info.title}`;
}

get otherCursors() {
return _.filter(this.composition.cursors, ({id}) => (
id !== this.user.id
));
}

handlePressEnter = (el) => {
if (el === this.chat) {
this.game && this.game.focus();
Expand Down Expand Up @@ -166,6 +172,12 @@ export default class Composition extends Component {
downloadBlob(byteArray, 'download.puz');
}

handleUpdateCursor = (selected) => {
const { r, c } = selected;
const { id, color } = this.user;
this.compositionModel.updateCursor(r, c, id, color);
}

getCellSize() {
return 30 * 15 / this.composition.grid[0].length;
}
Expand All @@ -181,17 +193,21 @@ export default class Composition extends Component {
const gridObject = makeGridFromComposition(this.composition.grid);
const grid = gridObject.grid;
const clues = makeClues(this.composition.clues, grid);
const cursors = this.otherCursors;

return (
<Editor
ref={c => {this.editor = c;}}
size={this.getCellSize()}
grid={grid}
clues={clues}
cursors={cursors}
onUpdateGrid={this.handleUpdateGrid}
onUpdateClue={this.handleUpdateClue}
onUpdateCursor={this.handleUpdateCursor}
onChange={this.handleChange}
onFlipColor={this.handleFlipColor}
myColor={this.color}
myColor={this.user.color}
onUnfocus={this.handleUnfocusEditor}
/>
);
Expand Down

0 comments on commit 0fe7989

Please sign in to comment.