OSDN Git Service

clean & add the dissmiss function
authorZhiting Lin <zlin035@uottawa.ca>
Mon, 7 May 2018 09:00:58 +0000 (17:00 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Mon, 7 May 2018 09:00:58 +0000 (17:00 +0800)
src/features/app/components/Navigation/Navigation.jsx
src/features/tutorial/components/Tutorial.jsx
src/features/tutorial/components/TutorialForm/TutorialForm.jsx
src/features/tutorial/components/TutorialHeader/TutorialHeader.jsx
src/features/tutorial/components/TutorialInfo/TutorialInfo.jsx
src/features/tutorial/reducers.js

index 972fdec..a6b6629 100644 (file)
@@ -61,12 +61,6 @@ class Navigation extends React.Component {
             </Link>
           </li>
           }
-          <li>
-            <a href='#' onClick={this.openTutorial}>
-              {navIcon('tutorial', styles)}
-              {lang === 'zh' ? '教程' : 'Tutorial'}
-            </a>
-          </li>
         </ul>
 
         { this.props.showNavAdvance && <ul className={styles.navigation}>
@@ -118,7 +112,6 @@ export default connect(
     }
   },
   (dispatch) => ({
-    openTutorial: () => dispatch({type: 'OPEN_TUTORIAL'}),
     setLang: (event) => {
       dispatch({
         type: 'UPDATE_CORE_LANGUAGE',
index 6fe3da3..a23725f 100644 (file)
@@ -1,41 +1,22 @@
 import React from 'react'
 import TutorialInfo from './TutorialInfo/TutorialInfo'
 import TutorialForm from './TutorialForm/TutorialForm'
-import TutorialModal from './TutorialModal/TutorialModal'
 
 const components = {
   TutorialInfo,
   TutorialForm
-  // TutorialModal
 }
 
 class Tutorial extends React.Component {
   render() {
-    // const userInput = this.props.tutorial.userInputs
-    //
     const tutorialOpen = !this.props.tutorial.location.isVisited
-    //
-    // const tutorialRoute = this.props.currentStep['route']
     const tutorialTypes = this.props.types
     const TutorialComponent = components[this.props.content['component']]
-    // const TutorialComponent = components[0]
-
 
     return (
       <div>
-            {/*{tutorialOpen && (tutorialTypes.includes(this.props.currentStep['component'])) &&*/}
-            {/*tutorialOpen &&*/}
-              {/*<TutorialComponent*/}
-                {/*// userInput={userInput}*/}
-                {/*// {...this.props.currentStep}*/}
-                {/*// handleNext={() => this.props.showNextStep(tutorialRoute)}*/}
-                {/*{...this.props.content}*/}
-              {/*/>}*/}
         {tutorialOpen && (tutorialTypes.includes(this.props.content['component'])) &&
           <TutorialComponent
-          // userInput={userInput}
-          // {...this.props.currentStep}
-          // handleNext={() => this.props.showNextStep(tutorialRoute)}
             {...this.props.content}
           />}
       </div>
@@ -43,20 +24,13 @@ class Tutorial extends React.Component {
   }
 }
 
-import { actions } from 'features/tutorial'
 import { connect } from 'react-redux'
 
 const mapStateToProps = (state) => ({
-  // currentStep: state.tutorial.currentStep,
   content: state.tutorial.content,
   tutorial: state.tutorial
 })
 
-const mapDispatchToProps = ( dispatch ) => ({
-  showNextStep: (route) => dispatch(actions.tutorialNextStep(route))
-})
-
 export default connect(
-  mapStateToProps,
-  mapDispatchToProps
+  mapStateToProps
 )(Tutorial)
index 4639d1e..7ba796c 100644 (file)
@@ -3,8 +3,6 @@ import styles from './TutorialForm.scss'
 
 class TutorialForm extends React.Component {
   render() {
-    const userInput = this.props.userInput
-
     return (
       <div className={styles.container}>
         <div className={`${styles.tutorialContainer} ${styles.fixedTutorial}`}>
@@ -15,13 +13,6 @@ class TutorialForm extends React.Component {
             <table className={styles.listItemContainer}>
               {this.props.content['steps'].map(function (contentLine, i){
                 let title = contentLine['title']
-                if (contentLine['type']) {
-                  let replacement = userInput[contentLine['type']]
-                  if ('index' in contentLine){
-                    replacement = replacement[contentLine['index']]
-                  }
-                  title = contentLine['title'].replace('STRING', replacement['alias'])
-                }
                 let rows = [
                   <tr key={`item-title-${i}`}>
                     <td className={styles.listBullet}>{i+1}</td>
@@ -34,24 +25,7 @@ class TutorialForm extends React.Component {
                     let description = descriptionLine
                     if (description['line']) { description = description['line'] }
 
-                    if (descriptionLine['type']) {
-                      let replacement = userInput[descriptionLine['type']] || descriptionLine['type']
-                      if ('index' in descriptionLine){
-                        replacement = replacement[descriptionLine['index']]
-                      }
-
-                      if (replacement.hasOwnProperty('alias')) {
-                        replacement = replacement['alias'] || ''
-                      }
-
-                      description.split('STRING').forEach( (item, k, arr) => {
-                        descriptionResult.push(item)
-                        let replacementText = k < arr.length - 1 && <span key={`item-input-${j}-${k}`} className={styles.userInputData}>"{replacement}"</span>
-                        descriptionResult.push(replacementText)
-                      })
-                    } else {
-                      descriptionResult.push(description)
-                    }
+                    descriptionResult.push(description)
                   })
                   rows.push(<tr key={`item-description-${i}`} className={styles.listItemDescription}>
                     <td></td>
index 9ce6d16..70479ac 100644 (file)
@@ -1,5 +1,4 @@
 import React from 'react'
-import { Link } from 'react-router'
 import styles from './TutorialHeader.scss'
 
 class TutorialHeader extends React.Component {
@@ -16,32 +15,18 @@ class TutorialHeader extends React.Component {
   }
 
   render() {
-    // if(!this.props.tutorial.isShowing || this.props.currentStep.component == 'TutorialModal'){
-    // if(!this.props.isVisited){
-    //   return (
-    //     <div>
-    //       {this.props.children}
-    //     </div>
-    //   )
-    // }
-    // else {
-      return (
-        !this.props.isVisited && <div className={`${styles.main} ${!this.props.isVisited && styles.collapsed}`} ref={element => this.tutorialContainer = element}>
-          <div className={styles.header}>
-            {this.props.content && this.props.content.title }
-            <div className={styles.skip}>
-              {/*{!this.props.showTutorial && <Link to={this.props.tutorial.route}>*/}
-                {/*Resume tutorial*/}
-              {/*</Link>}*/}
-              {!this.props.isVisited &&
-              <a onClick={this.props.dismissTutorial}>close</a>}
-              {/*<a onClick={this.props.dismissTutorial}>{this.props.currentStep.dismiss || 'End tutorial'}</a>*/}
-            </div>
+    return (
+      !this.props.isVisited && <div className={`${styles.main} ${!this.props.isVisited && styles.collapsed}`} ref={element => this.tutorialContainer = element}>
+        <div className={styles.header}>
+          {this.props.content && this.props.content.title }
+          <div className={styles.skip}>
+            {!this.props.isVisited &&
+            <a onClick={this.props.dismissTutorial}>close</a>}
           </div>
-          {!this.props.isVisited && this.props.children}
         </div>
-      )
-    // }
+        {!this.props.isVisited && this.props.children}
+      </div>
+    )
   }
 }
 
@@ -51,10 +36,7 @@ const mapStateToProps = (state) => ({
   visitedLocation: state.tutorial.location.visited,
   isVisited: state.tutorial.location.isVisited,
   content: state.tutorial.content,
-
   tutorial: state.tutorial,
-  currentStep: state.tutorial.currentStep,
-  showTutorial: state.routing.locationBeforeTransitions.pathname.includes(state.tutorial.route)
 })
 
 const mapDispatchToProps = ( dispatch ) => ({
index 7008bb5..ea07226 100644 (file)
@@ -10,13 +10,6 @@ class TutorialInfo extends React.Component {
       objectImage = require(`images/empty/${this.props.image}.svg`)
     } catch (err) { /* do nothing */ }
 
-    // const userInput = this.props.userInput
-    // const nextButton = <Link to={this.props.route} className={styles.nextWrapper}>
-    //     <button key='showNext' className={`btn ${styles.next}`} onClick={this.props.handleNext}>
-    //       Next: {this.props.button}
-    //     </button>
-    //   </Link>
-
     return (
       <div>
         <div className={styles.container}>
@@ -37,18 +30,9 @@ class TutorialInfo extends React.Component {
                   <tbody>{list}</tbody>
                 </table>
               }
-              if (contentLine['type']){
-                let replacement = userInput[contentLine['type']]
-                if ('index' in contentLine){
-                  replacement = replacement[contentLine['index']]
-                }
-                str = str.replace('STRING', replacement['alias'])
-              }
-
               return <p key={i}>{str}</p>
             })}
           </div>
-          {/*{nextButton}*/}
         </div>
     </div>
     )
index 3b1c07d..eb2fa3c 100644 (file)
@@ -1,4 +1,3 @@
-import steps from './steps.json'
 import introduction from './introduction.json'
 
 export const location = (state = { visited: [], isVisited: false }, action) => {
@@ -12,57 +11,16 @@ export const location = (state = { visited: [], isVisited: false }, action) => {
       return{ ...state, isVisited:true }
     }
   }
-  return state
-}
-
-// export const step = (state = 0, action) => {
-//   if (action.type == 'TUTORIAL_NEXT_STEP') return state + 1
-//   if (action.type == 'UPDATE_TUTORIAL' && steps[state].objectType == action.object) {
-//     return state + 1
-//   }
-//   if (action.type == 'DISMISS_TUTORIAL') return 0
-//   return state
-// }
+  if (action.type == 'DISMISS_TUTORIAL')   return{ ...state, isVisited:true }
 
-export const isShowing = (state = true, action) => {
-  if (action.type == 'DISMISS_TUTORIAL') return false
-  if (action.type == 'OPEN_TUTORIAL') return true
   return state
 }
 
-// export const route = (currentStep) => (state = 'transactions', action) => {
-//   if (action.type == 'TUTORIAL_NEXT_STEP') return action.route
-//   if (action.type == 'UPDATE_TUTORIAL' && currentStep.objectType == action.object) {
-//     return action.object + 's'
-//   }
-//   if (action.type == 'DISMISS_TUTORIAL') return 'transactions'
-//   return state
-// }
-//
-// export const userInputs = (currentStep) => (state = { accounts: [] }, action) => {
-//   if (action.type == 'UPDATE_TUTORIAL' && currentStep.objectType == action.object) {
-//     if (action.object == 'key') return { ...state, key: action.data }
-//     if (action.object == 'asset') return { ...state, asset: action.data }
-//     if (action.object == 'account') {
-//       return { ...state, accounts: [...state.accounts, action.data] }
-//     }
-//     return state
-//   }
-//   if (action.type == 'DISMISS_TUTORIAL') return { accounts: [] }
-//   return state
-// }
-
 export default (state = {}, action) => {
   const newState = {
-    // step: step(state.step, action),
-    // isShowing: isShowing(state.isShowing, action),
     location: location(state.location, action)
   }
 
   newState.content = introduction[newState.location.visited[0]]
-  // newState.currentStep = steps[newState.step]
-  // // newState.userInputs = userInputs(newState.currentStep)(state.userInputs, action)
-  // newState.route = route(newState.currentStep)(state.route, action)
-
   return newState
 }