frontend code refactoring
This commit is contained in:
@@ -18,7 +18,7 @@ class App extends Component {
|
||||
constructor(props){
|
||||
super(props);
|
||||
|
||||
this.state={_id:'5a5016e775becaef2015da10',
|
||||
this.state={_id:'5a232fb86ce046c749739455',
|
||||
skillID:'',
|
||||
skillName:'',
|
||||
invocationName:'Saburly',
|
||||
@@ -30,8 +30,8 @@ class App extends Component {
|
||||
waiting: false
|
||||
};
|
||||
|
||||
getSkill(this.state._id).then(l=> l.text()).then(result=>{
|
||||
let jResult = JSON.parse(result)[0];
|
||||
getSkill(this.state._id).then(l=>l.json()).then(result=>{
|
||||
let jResult = result[0];
|
||||
if (jResult===undefined) return;
|
||||
this.setState({ skillID:jResult.skillID,skillName:jResult.skillName, invocationName: jResult.invocationName,
|
||||
invocationAnswer: jResult.invocationAnswer,
|
||||
@@ -51,6 +51,26 @@ class App extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
let rightPanel;
|
||||
switch (this.state.selectedIndex) {
|
||||
case LAUNCH_REQUEST_SELECTED_INDEX:
|
||||
rightPanel = <LaunchRequest invocationName={this.state.invocationName}
|
||||
invocationAnswer={this.state.invocationAnswer}
|
||||
onSaveClick={this.handleSaveLaunchRequestClick}
|
||||
waiting={this.state.waiting}/> ;
|
||||
break;
|
||||
case CONTACT_SELECTED_INDEX:
|
||||
rightPanel = <Contact contactEmail={this.state.contactEmail}
|
||||
onSaveEmailClick={this.handleSaveEmailClick}
|
||||
waiting={this.state.waiting}/> ;
|
||||
break;
|
||||
default:
|
||||
rightPanel = <IntentDetails selectedIntent={this.state.selectedIntent}
|
||||
onDeleteIntentClick={this.handleDeleteIntentClick}
|
||||
onSaveIntentClick={this.handleSaveIntentClick}
|
||||
waiting={this.state.waiting}/>;
|
||||
}
|
||||
|
||||
return(
|
||||
<div className="App">
|
||||
<Popup/>
|
||||
@@ -63,37 +83,9 @@ class App extends Component {
|
||||
onIntentClick={this.handleIntentClick}
|
||||
onAddIntentClick={this.handleAddIntentClick}
|
||||
selectedIndex={this.state.selectedIndex}
|
||||
waiting={this.state.waiting}>
|
||||
</IntentList>
|
||||
{(
|
||||
()=>{
|
||||
if (this.state.selectedIndex===LAUNCH_REQUEST_SELECTED_INDEX){
|
||||
return (
|
||||
<LaunchRequest invocationName={this.state.invocationName}
|
||||
invocationAnswer={this.state.invocationAnswer}
|
||||
onSaveClick={this.handleSaveLaunchRequestClick}
|
||||
waiting={this.state.waiting}>
|
||||
</LaunchRequest>
|
||||
);
|
||||
}else if (this.state.selectedIndex===CONTACT_SELECTED_INDEX){
|
||||
return (
|
||||
<Contact
|
||||
contactEmail={this.state.contactEmail}
|
||||
onSaveEmailClick={this.handleSaveEmailClick}
|
||||
waiting={this.state.waiting}>
|
||||
</Contact>
|
||||
);
|
||||
}else{
|
||||
return(
|
||||
<IntentDetails selectedIntent={this.state.selectedIntent}
|
||||
onDeleteIntentClick={this.handleDeleteIntentClick}
|
||||
onSaveIntentClick={this.handleSaveIntentClick}
|
||||
waiting={this.state.waiting}>
|
||||
</IntentDetails>
|
||||
);
|
||||
}
|
||||
}
|
||||
)()}
|
||||
waiting={this.state.waiting}/>
|
||||
|
||||
{rightPanel}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -179,10 +171,9 @@ class App extends Component {
|
||||
|
||||
sendSkill(newAllIntents, showPopUp, resolveState, rejectState, newName, newAnswer, email, updateOnAmazon){
|
||||
return new Promise((resolve,reject)=>{
|
||||
updateSkill(this.createSkill(newAllIntents,newName,newAnswer,email,updateOnAmazon)).then(l=>l.text()).then(result=>{
|
||||
let jResult = JSON.parse(result);
|
||||
if (jResult.result !== RESULT_CODES.OK){
|
||||
console.log(jResult.result);
|
||||
updateSkill(this.createSkill(newAllIntents,newName,newAnswer,email,updateOnAmazon)).then(l=>l.json()).then(result=>{
|
||||
if (result.result !== RESULT_CODES.OK){
|
||||
console.log(result.result);
|
||||
if (showPopUp) Popup.alert('Model was not saved. Please try again');
|
||||
this.setState(rejectState);
|
||||
//reject('Error code : ' + jResult.result);
|
||||
|
||||
Reference in New Issue
Block a user