Skip to content

Commit 402c4d3

Browse files
feat(components): component selecting
1 parent 234b140 commit 402c4d3

File tree

17 files changed

+271
-11
lines changed

17 files changed

+271
-11
lines changed

src/actions/component.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @file component.js
3+
* Exports actions related to components.
4+
*/
5+
6+
import { put, takeLatest } from 'redux-saga/effects';
7+
8+
import { COMPONENT_SELECT } from '../constants';
9+
10+
/**
11+
* Sets the currently selected component.
12+
*
13+
* @param {object} payload - Payload for this saga action.
14+
* @param {string} payload.id - ID of the component that should be selected.
15+
*/
16+
export function* componentSelect({ id }) {
17+
yield put({
18+
type: `${COMPONENT_SELECT}_SUCCESS`,
19+
payload: {
20+
id
21+
}
22+
});
23+
}
24+
25+
export function* watchComponentActions() {
26+
yield takeLatest(COMPONENT_SELECT, componentSelect);
27+
}

src/actions/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import { all } from 'redux-saga/effects';
88
import { watchUserActions } from './user';
99
import { watchExperiencesActions } from './experiences';
1010
import { watchOpenExperienceActions } from './openExperience';
11+
import { watchComponentActions } from './component';
1112

1213
export default function* rootSaga() {
1314
yield all([
1415
watchUserActions(),
1516
watchExperiencesActions(),
16-
watchOpenExperienceActions()
17+
watchOpenExperienceActions(),
18+
watchComponentActions()
1719
]);
1820
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @file isExitable.js
3+
* AFrame component that allows for components to be selected for editing.
4+
*/
5+
6+
/* globals AFRAME */
7+
8+
import { COMPONENT_SELECT, MODE_COMPONENT_SELECTING } from '../../constants';
9+
import connectRedux from '../utils/connectRedux';
10+
import connectRouter from '../utils/connectRouter';
11+
12+
const isEditable = {
13+
multiple: true,
14+
clickHandler() {
15+
const id = this.el.getAttribute('id');
16+
const { dispatch } = this.props;
17+
const {
18+
match: {
19+
params: { editorMode }
20+
}
21+
} = this.router;
22+
23+
if (id && editorMode === MODE_COMPONENT_SELECTING) {
24+
dispatch({
25+
type: COMPONENT_SELECT,
26+
id
27+
});
28+
}
29+
},
30+
init() {
31+
this.el.addEventListener('click', this.clickHandler.bind(this));
32+
},
33+
remove() {
34+
this.el.removeEventListener('click', this.clickHandler.bind(this));
35+
}
36+
};
37+
38+
AFRAME.registerComponent(
39+
'is-editable',
40+
connectRedux(state => ({
41+
experience: state.openExperience.item
42+
}))(
43+
connectRouter(
44+
isEditable,
45+
'/experience/vreditor/:experienceSlug/:sceneSlug/:editorMode?'
46+
)
47+
)
48+
);

src/aframe/components/spawnDialogs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const spawnDialogs = {
6565
const e = document.createElement('a-entity');
6666
e.setAttribute('id', component.id);
6767
e.setAttribute('look-at', '#camera');
68+
e.setAttribute('is-editable', true);
6869
e.setAttribute('position', { x, y, z });
6970
e.setAttribute('dialog-popup', {
7071
title,

src/aframe/entities/scene.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require('../components/spawnSky');
1414
require('../components/spawnLinks');
1515
require('../components/spawnDialogs');
1616
require('../components/navLink');
17+
require('../components/isEditable');
1718

1819
export default () => (
1920
<a-scene
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @file ComponentForm.container.js
3+
* Exports a redux-connected ComponentForm component.
4+
*/
5+
6+
import { connect } from 'react-redux';
7+
8+
import ComponentForm from './ComponentForm';
9+
10+
const mapDispatchToProps = dispatch => ({
11+
dispatch
12+
});
13+
14+
const mapState = ({ user, openExperience }) => ({
15+
user,
16+
experience: openExperience
17+
});
18+
19+
export default connect(mapState, mapDispatchToProps)(ComponentForm);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @file ComponentForm.js
3+
* Exports a component that allows users to operate on scene components.
4+
*/
5+
6+
import React from 'react';
7+
import PropTypes from 'prop-types';
8+
import { withFormik } from 'formik';
9+
import { withStyles } from '@material-ui/core';
10+
11+
import ComponentFormStyles from './ComponentForm.style';
12+
13+
const ComponentForm = ({ id }) => <form>{id}</form>;
14+
15+
ComponentForm.propTypes = {
16+
id: PropTypes.string.isRequired
17+
};
18+
19+
const FormikComponentForm = withFormik({
20+
displayName: 'ComponentForm',
21+
enableReinitialize: true
22+
})(ComponentForm);
23+
24+
export default withStyles(ComponentFormStyles)(FormikComponentForm);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @file ComponentForm.style.js
3+
* Exports ComponentForm component styles.
4+
*/
5+
6+
export default () => ({});

src/components/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import App from './App/App';
77
import LoginForm from './LoginForm/LoginForm.container';
88
import ExperienceForm from './ExperienceForm/ExperienceForm.container';
99
import SceneForm from './SceneForm/SceneForm.container';
10+
import ComponentForm from './ComponentForm/ComponentForm.container';
1011
import Loading from './Loading/Loading';
1112
import Message from './Message/Message';
1213
import SceneCards from './SceneCards/SceneCards.container';
@@ -20,5 +21,6 @@ export {
2021
Message,
2122
SceneCards,
2223
ToolsMenu,
23-
SceneForm
24+
SceneForm,
25+
ComponentForm
2426
};

src/constants/component.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @file component.js
3+
* Exports component-related constants.
4+
*/
5+
6+
export const COMPONENT_SELECT = 'COMPONENT_SELECT';

0 commit comments

Comments
 (0)