Skip to content

Commit

Permalink
feat: update sequence position in the chart (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoMercy235 committed Mar 21, 2020
1 parent 51691d5 commit 43cc4a9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Graph } from 'react-d3-graph';

import { Card, CardContent } from '@material-ui/core';
import {
generateRandomPosition,
getNewGraph,
optionToLink,
seqToNode
Expand Down Expand Up @@ -39,10 +40,11 @@ class WriteStoryComponent extends Component {
name: `test-${new Date().getTime()}`,
content: 'test',
story: story._id,
...generateRandomPosition(),
});
socket.emit(
SocketEvents.NewSequenceRequest,
SequenceModel.forApi(seq, ['story']),
SequenceModel.forApi(seq, ['story', 'x', 'y']),
);
};

Expand All @@ -51,6 +53,7 @@ class WriteStoryComponent extends Component {
story,
onEditSequence,
onEditOption,
onUpdateSeqPosition,
} = this.props;
const { nodes, links } = this.state;
const data = {
Expand Down Expand Up @@ -102,6 +105,7 @@ class WriteStoryComponent extends Component {
}}
onClickNode={onEditSequence}
onClickLink={onEditOption}
onNodePositionChange={onUpdateSeqPosition}
/>
</CardContent>
</Card>
Expand All @@ -117,6 +121,7 @@ WriteStoryComponent.propTypes = {

onEditSequence: PropTypes.func.isRequired,
onEditOption: PropTypes.func.isRequired,
onUpdateSeqPosition: PropTypes.func.isRequired,
};

export default WriteStoryComponent;
8 changes: 8 additions & 0 deletions src/admin/story-view/view/containers/WriteStoryContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ class WriteStoryContainer extends Component {
console.log(optionId);
};

onUpdateSeqPosition = (seqId, x, y) => {
socket.emit(
SocketEvents.UpdateSequenceRequest,
{ _id: seqId, x, y },
);
};

render() {
const {
storyViewStore: {
Expand All @@ -81,6 +88,7 @@ class WriteStoryContainer extends Component {
options={allStoryOptions}
onEditSequence={this.onEditSequence}
onEditOption={this.onEditOption}
onUpdateSeqPosition={this.onUpdateSeqPosition}
/>
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/infrastructure/models/SequenceModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export class SequenceModel extends BaseModel {
hasScenePic = false;
content = '';
isEnding = false;
x = 0;
y = 0;
@observable options = [];

constructor(metadata) {
Expand Down
6 changes: 5 additions & 1 deletion src/shared/utils/graphUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ export const generateRandomPosition = () => {
};

export const seqToNode = story => seq => {
const position = seq.x && seq.y
? { x: seq.x, y: seq.y }
: generateRandomPosition();

return {
id: seq._id,
...generateRandomPosition(),
...position,
size: GRAPH_NODE_SIZE,
name: seq.name,
...(story.startSeq === seq._id && {
Expand Down

0 comments on commit 43cc4a9

Please sign in to comment.