Skip to content
Snippets Groups Projects
Commit 78f48dd3 authored by Paul Kaplan's avatar Paul Kaplan
Browse files

Use container for selector to handle behavioral callbacks

parent a8c373a3
No related branches found
No related tags found
No related merge requests found
const React = require('react'); const React = require('react');
const SpriteSelectorItem = require('../sprite-selector-item/sprite-selector-item.jsx'); const SpriteSelectorItem = require('../../containers/sprite-selector-item.jsx');
const Box = require('../box/box.jsx'); const Box = require('../box/box.jsx');
const styles = require('./selector.css'); const styles = require('./selector.css');
...@@ -23,24 +24,18 @@ const Selector = props => { ...@@ -23,24 +24,18 @@ const Selector = props => {
{newText} {newText}
</Box> </Box>
<Box className={styles.listArea}> <Box className={styles.listArea}>
{items.map((item, index) => { {items.map((item, index) => (
const _onItemClick = () => onItemClick(item); <SpriteSelectorItem
const _onDeleteClick = e => { className={styles.listItem}
e.stopPropagation(); costumeURL={item.image}
onDeleteClick(item); id={index}
}; key={`asset-${index}`}
return ( name={item.name}
<SpriteSelectorItem selected={index === selectedItemIndex}
className={styles.listItem} onClick={onItemClick}
costumeURL={item.image} onDeleteButtonClick={onDeleteClick}
key={`asset-${index}`} />
name={item.name} ))}
selected={index === selectedItemIndex}
onClick={_onItemClick}
onDeleteButtonClick={_onDeleteClick}
/>
);
})}
</Box> </Box>
</Box> </Box>
); );
......
...@@ -21,22 +21,21 @@ class CostumeTab extends React.Component { ...@@ -21,22 +21,21 @@ class CostumeTab extends React.Component {
this.state = {selectedCostumeIndex: 0}; this.state = {selectedCostumeIndex: 0};
} }
handleSelectCostume (item) { handleSelectCostume (costumeIndex) {
this.setState({selectedCostumeIndex: this.props.vm.editingTarget.getCostumeIndexByName(item.name)}); this.setState({selectedCostumeIndex: costumeIndex});
} }
handleDeleteCostume (item) { handleDeleteCostume (costumeIndex) {
// @todo the VM should handle all of this logic // @todo the VM should handle all of this logic
const {editingTarget} = this.props.vm; const {editingTarget} = this.props.vm;
const i = editingTarget.getCostumeIndexByName(item.name);
if (i === editingTarget.currentCostume) { if (costumeIndex === editingTarget.currentCostume) {
editingTarget.setCostume(i - 1); editingTarget.setCostume(costumeIndex - 1);
} }
editingTarget.sprite.costumes = editingTarget.sprite.costumes editingTarget.sprite.costumes = editingTarget.sprite.costumes
.slice(0, i) .slice(0, costumeIndex)
.concat(editingTarget.sprite.costumes.slice(i + 1)); .concat(editingTarget.sprite.costumes.slice(costumeIndex + 1));
this.props.vm.emitTargetsUpdate(); this.props.vm.emitTargetsUpdate();
// @todo not sure if this is getting redrawn correctly // @todo not sure if this is getting redrawn correctly
this.props.vm.runtime.requestRedraw(); this.props.vm.runtime.requestRedraw();
......
...@@ -16,38 +16,24 @@ class SoundTab extends React.Component { ...@@ -16,38 +16,24 @@ class SoundTab extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
bindAll(this, [ bindAll(this, [
'getSoundIndexByName',
'handleSelectSound', 'handleSelectSound',
'handleDeleteSound' 'handleDeleteSound'
]); ]);
this.state = {selectedSoundIndex: 0}; this.state = {selectedSoundIndex: 0};
} }
getSoundIndexByName (name) { handleSelectSound (soundIndex) {
// @todo should be in VM const sound = this.props.vm.editingTarget.sprite.sounds[soundIndex];
let i = -1;
this.props.vm.editingTarget.sprite.sounds.forEach((sound, soundIndex) => {
if (sound.name === name) {
i = soundIndex;
}
});
return i;
}
handleSelectSound (item) {
const selectedSoundIndex = this.getSoundIndexByName(item.name);
const sound = this.props.vm.editingTarget.sprite.sounds[selectedSoundIndex];
this.props.vm.editingTarget.audioPlayer.playSound(sound.md5); this.props.vm.editingTarget.audioPlayer.playSound(sound.md5);
this.setState({selectedSoundIndex}); this.setState({selectedSoundIndex: soundIndex});
} }
handleDeleteSound (item) { handleDeleteSound (soundIndex) {
// @todo the VM should handle all of this logic // @todo the VM should handle all of this logic
const {editingTarget} = this.props.vm; const {editingTarget} = this.props.vm;
const i = this.getSoundIndexByName(item.name);
editingTarget.sprite.sounds = editingTarget.sprite.sounds editingTarget.sprite.sounds = editingTarget.sprite.sounds
.slice(0, i) .slice(0, soundIndex)
.concat(editingTarget.sprite.sounds.slice(i + 1)); .concat(editingTarget.sprite.sounds.slice(soundIndex + 1));
this.props.vm.emitTargetsUpdate(); this.props.vm.emitTargetsUpdate();
this.props.vm.runtime.requestRedraw(); this.props.vm.runtime.requestRedraw();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment