From aa59c574410584fcd0600045e7c6bfd9dcf1c046 Mon Sep 17 00:00:00 2001 From: resistance-is-futile Date: Thu, 6 Sep 2018 15:15:26 -0700 Subject: [PATCH 1/4] Working on the migration of the console to redux --- app/actions/actiontypes.js | 6 ++ app/api/core.js | 4 +- app/components/Terminal/TerminalConsole.js | 120 ++++++++++----------- app/images/world-light.jpg | Bin 4508915 -> 4508911 bytes app/reducers/index.js | 4 +- 5 files changed, 71 insertions(+), 63 deletions(-) diff --git a/app/actions/actiontypes.js b/app/actions/actiontypes.js index 96f0b516c..7620a4bf6 100644 --- a/app/actions/actiontypes.js +++ b/app/actions/actiontypes.js @@ -117,3 +117,9 @@ export const SET_MOUSE_POSITION = "SET_MOUSE_POSITION"; export const TOGGLE_CREATE_ADDRESS = "TOGGLE_CREATE_ADDRESS"; export const SET_HIGHEST_PEER_BLOCK = "SET_HIGHEST_PEER_BLOCK"; export const SET_SYNC_STATUS = "SET_SYNC_STATUS"; + + +// Terminal +export const SET_COMMAND_LIST = "SET_COMMAND_LIST"; +export const PRINT_TO_CONSOLE = "PRINT_TO_CONSOLE"; +export const RESET_MY_CONSOLE = "RESET_MY_CONSOLE"; diff --git a/app/api/core.js b/app/api/core.js index f719fcc44..09ab2740a 100644 --- a/app/api/core.js +++ b/app/api/core.js @@ -2,7 +2,7 @@ const log = require("electron-log"); const statusdelay = 1000; var user = "rpcserver"; -var password = require('crypto').randomBytes(64).toString('hex'); +var password = null; var host = "http://127.0.0.1:9336"; var coreprocess = null; @@ -26,7 +26,7 @@ function SetCoreParameters(settings) } else { user = "rpcserver"; - password = require('crypto').randomBytes(32).toString('hex'); + password = (password==null)?require('crypto').randomBytes(32).toString('hex'):password; host = "http://127.0.0.1:9336"; } diff --git a/app/components/Terminal/TerminalConsole.js b/app/components/Terminal/TerminalConsole.js index d61f28988..a2b894993 100644 --- a/app/components/Terminal/TerminalConsole.js +++ b/app/components/Terminal/TerminalConsole.js @@ -4,52 +4,41 @@ import styles from "./style.css"; import { timingSafeEqual } from "crypto"; import * as RPC from "../../script/rpc"; -export default class TerminalConsole extends Component { - constructor(props){ - super(props); - this.state = { - //vars go here - consoleoutput: [], - currentInput: "", - inputfield: null, - commandList:[], - autoComplete:[], - testnum: 99999 - } - } +// Added to migrate to Redux +import * as TYPE from "../../actions/actiontypes"; +import { connect } from "react-redux"; + +const mapStateToProps = state => { + return { ...state.terminal, ...state.common }; +}; + +const mapDispatchToProps = dispatch => ({ + setCommandList: (commandList) => dispatch({type:TYPE.SET_COMMAND_LIST , payload: commandList}), + printToConsole: (consoleOutput) => dispatch({type:TYPE.PRINT_TO_CONSOLE , payload: consoleOutput}), + resetMyConsole: () => dispatch({type:TYPE.RESET_MY_CONSOLE}) +}); +class TerminalConsole extends Component { componentDidMount(){ RPC.PROMISE("help", []).then(payload => { let CommandList = payload.split('\n'); console.log(CommandList); - this.setState( - { - commandList:CommandList - } - ); - }); - } - - /// Reset Nexus RPC Console - /// Clean out the consoleoutput state - resetnexusrpcconsole() - { - this.setState({ - consoleoutput:[] + this.props.setCommandList(CommandList); }); } /// Process Output /// Process the consoleoutput and return JSX + // Called in the renderer so processing what gets put on screen stays here. processOutput() { - if ( this.state.inputfield != null) + if ( this.props.inputfield != null) { - this.state.inputfield.focus(); + this.props.inputfield.focus(); } let num = 0; - return this.state.consoleoutput.map((i) => + return this.props.consoleoutput.map((i) => { num++; return ( @@ -66,29 +55,27 @@ export default class TerminalConsole extends Component { processInput() { /// If Nothing Then just exit - if (this.state.currentInput == "") + if (this.props.currentInput == "") { return; } /// This is not a RPC command, so catch this input and clear the console - if (this.state.currentInput.toLowerCase() == "clear" ) + if (this.props.currentInput.toLowerCase() == "clear" ) { - this.resetnexusrpcconsole(); - this.state.inputfield.value = ""; + this.props.resetMyConsole(); + this.props.inputfield.value = ""; return; } /// remove the command inputed - this.state.inputfield.value = ""; + this.props.inputfield.value = ""; /// Get the old console output so we can concat on it. - let tempConsoleOutput = [...this.state.consoleoutput]; + // let tempConsoleOutput = [...this.props.consoleOutput]; /// Split the input so that we can get the command and the arguments. THIS MIGHT BE AN ISSUE as I am just checking the US keyboard space - let splitInput = this.state.currentInput.split(" "); - - let preSanatized = splitInput[0]; + let splitInput = this.props.currentInput.split(" "); - preSanatized = preSanatized.replace(/[^a-zA-Z0-9]/g, ""); + let preSanatized = splitInput[0].replace(/[^a-zA-Z0-9]/g, ""); splitInput[0] = preSanatized; @@ -111,12 +98,12 @@ export default class TerminalConsole extends Component { RPC.PROMISE(splitInput[0], RPCArguments).then(payload => { /// If a single object is given back, output it - if(typeof payload === "string" || typeof payload === "number" ) { - if (typeof payload === "string"){ + if(typeof payload === "string" || typeof payload === "number") { + if(typeof payload === "string") { let temppayload = payload; /// If we find there are end line characters then we need to make these line breaks temppayload.split('\n').map((item, key) => { - return tempConsoleOutput.push({item}
); + return tempConsoleOutput.push(item); }) } else @@ -128,7 +115,6 @@ export default class TerminalConsole extends Component { else { for (let outputObject in payload) { - //ddd.push(aaa + ": " + payload[aaa]); if (typeof payload[outputObject] === "object") { tempConsoleOutput.push(outputObject + ": " ); @@ -148,27 +134,28 @@ export default class TerminalConsole extends Component { } } - /// Set the state to have this tempconsoleoutput - this.setState( - { - consoleoutput: tempConsoleOutput, - currentInput:"" - } - ); }).catch( error => { /// If there is an error then return that error message and place it in the output. - - tempConsoleOutput.push(error); - this.setState( - { - consoleoutput: tempConsoleOutput, - currentInput:"" - }); + this.props.printToConsole(error); + // tempConsoleOutput.push(error); + // this.setState( + // { + // consoleOutput: tempConsoleOutput, + // currentInput:"" + // }); } ); } - + recallPreviousCommand() { + // history of at least 10 commands that were entered. + } + recallNextCommandOrClear() { + // terminates back to what the user typed last as a state 0. + } + autoFillAutoComplete() { + // it could check to see if its looking for any addresses, check the clipboard for an address... + } /// Set Input Field /// Sets up the input field so we can reference it later setInputFeild = (e) => @@ -187,6 +174,15 @@ export default class TerminalConsole extends Component { if (e.key === 'Enter') { this.processInput(); } + if (e.key === 'ArrowUp') { + this.recallPreviousCommand(); + } + if (e.key === 'ArrowDown') { + this.recallNextCommandOrClear(); + } + if (e.key === 'ArrowRight') { + this.autoFillAutoComplete(); + } } /// Handle arrow key press @@ -346,10 +342,14 @@ export default class TerminalConsole extends Component { - + ); } } +export default connect( + mapStateToProps, + mapDispatchToProps +)(TerminalConsole); \ No newline at end of file diff --git a/app/images/world-light.jpg b/app/images/world-light.jpg index 90acbc773245f1075923b1e9c50cb482fac6983c..f1038e4371f02ef19c56856020ef911c0c9e0f37 100644 GIT binary patch delta 279 zcmWN=OKt%H9KhiiYD%fL4D~3=s225pjQ8shUATXBl#qlaB2kISk!TW^#JBFN(8;H-bR=<%!%iWMQy9n~i!+=f zhYRFUz$LD5jT;nELK!A1sG^2C8fc=0Hg0j}`l_?};g6?vagPT)qK7B+F~HFEG;6V@ iH607jPDY|QbBH`fT>|9 Date: Fri, 7 Sep 2018 07:31:26 -0700 Subject: [PATCH 2/4] Fixing binaries gitattribute for png --- .gitattributes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index c3fa1079c..2c1ceb062 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,4 +2,4 @@ *.mmdb binary *.ico binary *.icns binary -*.mmbd binary \ No newline at end of file +*.png binary \ No newline at end of file From 7486361f2c3d471ee55c3feb76cf6850072b3473 Mon Sep 17 00:00:00 2001 From: resistance-is-futile Date: Fri, 7 Sep 2018 08:03:21 -0700 Subject: [PATCH 3/4] Tracking terminal reducers --- app/reducers/terminal.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 app/reducers/terminal.js diff --git a/app/reducers/terminal.js b/app/reducers/terminal.js new file mode 100644 index 000000000..a95822ba9 --- /dev/null +++ b/app/reducers/terminal.js @@ -0,0 +1,39 @@ +import * as TYPE from "../actions/actiontypes"; + +// These be props! On with the show. +const initialState = { + //vars go here + consoleOutput: [], + currentInput: "", + inputfield: null, + commandList:[], + autoComplete:[], + testnum: 99999, + commandHistory:[] +}; + +export default (state = initialState, action) => { + switch (action.type) { + case TYPE.SET_COMMAND_LIST: + return { + ...state, + commandList: [...action.payload] + }; + case TYPE.PRINT_TO_CONSOLE: + var payloadCopy = action.payload; + for(var i; i < state.consoleOutput.length; i++) { + payloadCopy.push(state.consoleOutput[i]); + } + return { + ...state, + consoleOutput: payloadCopy + }; + case TYPE.RESET_MY_CONSOLE: + return { + ...state, + consoleOutput : [] + }; + default: + return state; + } +}; From a93a4a80b63731b27cc376269ca1c75c4ef417a0 Mon Sep 17 00:00:00 2001 From: resistance-is-futile Date: Mon, 10 Sep 2018 12:31:13 -0700 Subject: [PATCH 4/4] Console history working --- app/actions/actiontypes.js | 9 + app/api/core.js | 2 +- app/components/Header/index.js | 2 +- app/components/Terminal/TerminalConsole.js | 252 +++++++-------------- app/images/world-light.jpg | Bin 4508911 -> 4508915 bytes app/reducers/terminal.js | 78 ++++++- package-lock.json | 28 +-- 7 files changed, 174 insertions(+), 197 deletions(-) diff --git a/app/actions/actiontypes.js b/app/actions/actiontypes.js index 7620a4bf6..5a91c27f4 100644 --- a/app/actions/actiontypes.js +++ b/app/actions/actiontypes.js @@ -123,3 +123,12 @@ export const SET_SYNC_STATUS = "SET_SYNC_STATUS"; export const SET_COMMAND_LIST = "SET_COMMAND_LIST"; export const PRINT_TO_CONSOLE = "PRINT_TO_CONSOLE"; export const RESET_MY_CONSOLE = "RESET_MY_CONSOLE"; +export const RECALL_PREVIOUS_COMMAND = "RECALL_PREVIOUS_COMMAND"; +export const ON_INPUT_FIELD_CHANGE = "ON_INPUT_FIELD_CHANGE"; +export const SET_INPUT_FEILD = "SET_INPUT_FEILD"; +export const ON_AUTO_COMPLETE_CLICK = "ON_AUTO_COMPLETE_CLICK"; +export const RETURN_AUTO_COMPLETE = "RETURN_AUTO_COMPLETE"; +export const REMOVE_AUTO_COMPLETE_DIV = "REMOVE_AUTO_COMPLETE_DIV"; +export const HANDLE_KEYBOARD_INPUT = "HANDLE_KEYBOARD_INPUT"; +export const RECALL_NEXT_COMMAND_OR_CLEAR = "RECALL_NEXT_COMMAND_OR_CLEAR"; +export const ADD_TO_HISTORY = "ADD_TO_HISTORY"; diff --git a/app/api/core.js b/app/api/core.js index 09ab2740a..08b30717d 100644 --- a/app/api/core.js +++ b/app/api/core.js @@ -127,7 +127,7 @@ class Core extends EventEmitter { super(); } get user() { return user;} - get password() { return password;} + get password() { return "password";} get host() { return host;} get event() { return eventEmitter;} get process() { return coreprocess;} diff --git a/app/components/Header/index.js b/app/components/Header/index.js index d743e4c51..1350cf100 100644 --- a/app/components/Header/index.js +++ b/app/components/Header/index.js @@ -267,7 +267,7 @@ class Header extends Component { alt="Nexus Logo" /> - + {/* */}
); diff --git a/app/components/Terminal/TerminalConsole.js b/app/components/Terminal/TerminalConsole.js index a2b894993..d4c65196e 100644 --- a/app/components/Terminal/TerminalConsole.js +++ b/app/components/Terminal/TerminalConsole.js @@ -8,6 +8,7 @@ import * as RPC from "../../script/rpc"; import * as TYPE from "../../actions/actiontypes"; import { connect } from "react-redux"; +let currentHistoryIndex = -1; const mapStateToProps = state => { return { ...state.terminal, ...state.common }; }; @@ -15,7 +16,16 @@ const mapStateToProps = state => { const mapDispatchToProps = dispatch => ({ setCommandList: (commandList) => dispatch({type:TYPE.SET_COMMAND_LIST , payload: commandList}), printToConsole: (consoleOutput) => dispatch({type:TYPE.PRINT_TO_CONSOLE , payload: consoleOutput}), - resetMyConsole: () => dispatch({type:TYPE.RESET_MY_CONSOLE}) + resetMyConsole: () => dispatch({type:TYPE.RESET_MY_CONSOLE}), + onInputfieldChange: (consoleInput) => dispatch({type:TYPE.ON_INPUT_FIELD_CHANGE, payload: consoleInput}), + setInputFeild: (input) => dispatch({type:TYPE.SET_INPUT_FEILD, payload: input}), + onAutoCompleteClick: (inItem) => dispatch({type:TYPE.ON_AUTO_COMPLETE_CLICK, payload: inItem}), + returnAutocomplete: (currentInput) => dispatch({type:TYPE.RETURN_AUTO_COMPLETE, payload: currentInput}), + // removeAutoCompleteDiv: () => dispatch({type:TYPE.REMOVE_AUTO_COMPLETE_DIV}), + recallPreviousCommand: (currentCommandItem) => dispatch({type:TYPE.RECALL_PREVIOUS_COMMAND, payload: currentCommandItem}), + recallNextCommandOrClear: (currentCommandItem) => dispatch({type:TYPE.RECALL_NEXT_COMMAND_OR_CLEAR, payload: currentCommandItem}), + addToHistory: (currentCommandItem) => dispatch({type:TYPE.ADD_TO_HISTORY, payload: currentCommandItem}) + // handleKeyboardInput: (key) => dispatch({type:TYPE.HANDLE_KEYBOARD_INPUT, payload: key}) }); class TerminalConsole extends Component { @@ -33,17 +43,17 @@ class TerminalConsole extends Component { // Called in the renderer so processing what gets put on screen stays here. processOutput() { - if ( this.props.inputfield != null) + // if ( this.props.currentInput != null) + // { + // this.props.currentInput.focus(); + // } + // let num = 0; + return this.props.consoleOutput.map((item, key) => { - this.props.inputfield.focus(); - } - let num = 0; - return this.props.consoleoutput.map((i) => - { - num++; + // num++; return ( -
- {i} +
+ {item}
) }); @@ -63,14 +73,13 @@ class TerminalConsole extends Component { if (this.props.currentInput.toLowerCase() == "clear" ) { this.props.resetMyConsole(); - this.props.inputfield.value = ""; + this.props.setInputFeild(""); return; } /// remove the command inputed - this.props.inputfield.value = ""; /// Get the old console output so we can concat on it. - // let tempConsoleOutput = [...this.props.consoleOutput]; + let tempConsoleOutput = [...this.props.consoleOutput]; /// Split the input so that we can get the command and the arguments. THIS MIGHT BE AN ISSUE as I am just checking the US keyboard space let splitInput = this.props.currentInput.split(" "); @@ -81,6 +90,8 @@ class TerminalConsole extends Component { /// this is the argument array let RPCArguments = []; + this.props.addToHistory(splitInput[0]); + this.props.setInputFeild(""); /// Get all the words after the first one and place them into the RPCargs array @@ -105,10 +116,14 @@ class TerminalConsole extends Component { temppayload.split('\n').map((item, key) => { return tempConsoleOutput.push(item); }) + // this is so that you have tha data available to display on the screen + this.props.printToConsole(tempConsoleOutput); } else { tempConsoleOutput.push(payload); + // this is so that you have tha data available to display on the screen + this.props.printToConsole(tempConsoleOutput); } } /// If it is a object with multi variables then output them on each line @@ -118,9 +133,13 @@ class TerminalConsole extends Component { if (typeof payload[outputObject] === "object") { tempConsoleOutput.push(outputObject + ": " ); + // this is so that you have tha data available to display on the screen + // this.props.printToConsole(tempConsoleOutput); } else{ tempConsoleOutput.push(outputObject + ": " + payload[outputObject]); + // this is so that you have tha data available to display on the screen + // this.props.printToConsole(tempConsoleOutput); } //If it is a object then we need to display ever var on a new line. @@ -130,9 +149,13 @@ class TerminalConsole extends Component { /// Probably need to do this in css but I add a tab to make it look cleaner tempConsoleOutput.push('       ' + interalres + ":" + payload[outputObject][interalres]); } + // this is so that you have tha data available to display on the screen + // this.props.printToConsole(tempConsoleOutput); } } + this.props.printToConsole(tempConsoleOutput); + } }).catch( error => { @@ -147,180 +170,55 @@ class TerminalConsole extends Component { } ); } - recallPreviousCommand() { - // history of at least 10 commands that were entered. - } - recallNextCommandOrClear() { - // terminates back to what the user typed last as a state 0. - } - autoFillAutoComplete() { - // it could check to see if its looking for any addresses, check the clipboard for an address... - } - /// Set Input Field - /// Sets up the input field so we can reference it later - setInputFeild = (e) => - { - this.setState( - { - inputfield:e - } - ) - } - ///Handle Enter Key Press - /// Handles what happens when the user presses the enter key - handleEnterKeyPress = (e) => { + ///Handle enter key being presssed. + handleKeyboardInput = (e) => { if (e.key === 'Enter') { + console.log("enter key pressed"); this.processInput(); - } - if (e.key === 'ArrowUp') { - this.recallPreviousCommand(); - } - if (e.key === 'ArrowDown') { - this.recallNextCommandOrClear(); - } - if (e.key === 'ArrowRight') { - this.autoFillAutoComplete(); + currentHistoryIndex = -1; } } - /// Handle arrow key press - /// Handles what happens when the user presses arrow keys for the auto complete - handleAutocompleteArrowKeyPress = (e) => { - ///NOT WORKING COME BACK TO THIS - - - /* - console.log(this.state.currentInput); - console.log(e.target.value); - - let pdpdpdp = this.state.testnum; - - if (pdpdpdp == 9999) - { - pdpdpdp = -1; - } - - if (e.key === 'ArrowDown') - { - pdpdpdp++; - } - - if (e.key === 'ArrowUp') - { - pdpdpdp--; - } - if (e.target.value == "") - { - pdpdpdp = 9999; - } - - let tempcommand = this.state.autoComplete[pdpdpdp] - - if ( tempcommand != null) - { - console.log(tempcommand.props.children[0]); - e.target.value = tempcommand.props.children[0]; - this.setState( - { - testnum:-1 - } - ) + handleKeyboardArrows = (e) => { + // e.preventDefault(); + // this.props.setInputFeild("arrows being pressed"); + if (e.key === 'ArrowUp') { + currentHistoryIndex++; + console.log("ArrowUp key pressed"); + if(this.props.commandHistory[currentHistoryIndex]){ + this.props.setInputFeild(this.props.commandHistory[currentHistoryIndex]); + } + else { + this.props.setInputFeild(""); + currentHistoryIndex = -1; + } } - - - - this.setState( - { - testnum:pdpdpdp + else if (e.key === 'ArrowDown') { + currentHistoryIndex--; + if(currentHistoryIndex <= -1){ + currentHistoryIndex = -1; + this.props.setInputFeild(""); } - , () => {console.log(this.state.testnum)}); - - */ - } - - /// On Input Field Change - /// What happens when the value of the inputfield changes - onInputfieldChange = (e) => - { - this.inputfield = e.target; - this.setState( - { - currentInput: e.target.value - }, () => this.returnAutocomplete() ); - - } - - /// On Auto Complete Click - /// What happens when you click on an auto complete link - onAutoCompleteClick(inItem) - { - const inputRef = this.state.inputfield; - inputRef.value = inItem; - //inputRef.focus(); - this.setState( - { - currentInput:inItem, - autoComplete: [] + else { + this.props.setInputFeild(this.props.commandHistory[currentHistoryIndex]); } - ); + console.log("ArrowDown key pressed"); + } + else if (e.key === 'ArrowRight') { + console.log("ArrowRight key pressed"); + } } /// Return Auto Complete - /// Returns the list of commands that should be displayed for the auto complete section - returnAutocomplete() + autoComplete() { - - - const CommandList = this.state.commandList; - const CurrentInput = this.state.currentInput; - let tempCompandList = []; - - ///Just incase - if (CurrentInput == "") - { - this.setState( - { - autoComplete: [] - } - ); - return; - } - - - CommandList.forEach(element => { - if ( element.startsWith(CurrentInput)) - { - tempCompandList.push(element); - } + return this.props.filteredCmdList.map((item, key) => { + return ( this.onAutoCompleteClick(item)}>{item}
); }); - let tempAutoComplete = []; - tempCompandList.map((item, key) => { - return tempAutoComplete.push( this.onAutoCompleteClick(item)}>{item}
); - }) - - - - this.setState( - { - autoComplete: tempAutoComplete - } - ); - } - - /// Remove Auto Complete Div - /// Removes all divs from the array - removeAutoCompleteDiv = (e) => - { - this.setState( - { - autoComplete: [] - } - ); } - render() { return ( @@ -329,11 +227,21 @@ class TerminalConsole extends Component {
- + this.props.onInputfieldChange(e.target.value)} + onKeyPress={(e) => this.handleKeyboardInput(e)} + onKeyDown={(e) => this.handleKeyboardArrows(e)} + // onBlur={this.props.removeAutoCompleteDiv()} + />
- {this.state.autoComplete}
+ {this.autoComplete()}
diff --git a/app/images/world-light.jpg b/app/images/world-light.jpg index f1038e4371f02ef19c56856020ef911c0c9e0f37..90acbc773245f1075923b1e9c50cb482fac6983c 100644 GIT binary patch delta 287 zcmWm8J5B;&7=__*b6`+#KoPtE!yN?`f$^8ype};K%}{)a3m_q}nN^s~9;UEx0nP#_ zFrk}@m*Oc-@)l?NwF>XBl#qlaB2kISk!TW^#JBFN(8;H-bR=<%!%iWMQy9n~i!+=f zhYRFUz$LD5jT;nELK!A1sG^2C8fc=0Hg0j}`l_?};g6?vagPT)qK7B+F~HFEG;6V@ iH607jPDY|QbBH`fT>|9 { @@ -19,6 +20,7 @@ export default (state = initialState, action) => { ...state, commandList: [...action.payload] }; + break; case TYPE.PRINT_TO_CONSOLE: var payloadCopy = action.payload; for(var i; i < state.consoleOutput.length; i++) { @@ -28,12 +30,84 @@ export default (state = initialState, action) => { ...state, consoleOutput: payloadCopy }; + break; case TYPE.RESET_MY_CONSOLE: return { ...state, consoleOutput : [] }; + break; + case TYPE.ON_INPUT_FIELD_CHANGE: + return { + ...state, + currentInput: action.payload + }; + break; + case TYPE.SET_INPUT_FEILD: + return { + ...state, + currentInput : action.payload + }; + break; + case TYPE.ON_AUTO_COMPLETE_CLICK: + return { + ...state, + currentInput : action.payload, + autoComplete : [] + }; + break; + case TYPE.RETURN_AUTO_COMPLETE: + // foreach commandlist starts with current input push into string aray + // needs commandlist, a copy of the ones that go into it, and a returned array of commandlist that is less. + let filteredCmdListTmp = []; + for(var i = 0; i < commandList.length; i++) { + if(commandList[i].indexOf(action.payload) != -1) { + filteredCmdList.push(commandList[i]); + } + } + return { + ...state, + filteredCmdList : filteredCmdListTmp + }; + break; + case TYPE.REMOVE_AUTO_COMPLETE_DIV: + return { + ...state, + currentInput : action.payload + }; + break; + case TYPE.RECALL_PREVIOUS_COMMAND: + return { + ...state, + commandHistory : action.payload + }; + break; + case TYPE.RECALL_NEXT_COMMAND_OR_CLEAR: + return { + ...state, + currentInput : action.payload + }; + break; + case TYPE.ADD_TO_HISTORY: + return { + ...state, + commandHistory : [...state.commandHistory, action.payload] + }; + break; + default: return state; } }; + +// export const SET_COMMAND_LIST = "SET_COMMAND_LIST"; +// export const PRINT_TO_CONSOLE = "PRINT_TO_CONSOLE"; +// export const RESET_MY_CONSOLE = "RESET_MY_CONSOLE"; +// export const RECALL_PREVIOUS_COMMAND = "RECALL_PREVIOUS_COMMAND"; +// export const ON_INPUT_FIELD_CHANGE = "ON_INPUT_FIELD_CHANGE"; +// export const SET_INPUT_FEILD = "SET_INPUT_FEILD"; +// export const ON_AUTO_COMPLETE_CLICK = "ON_AUTO_COMPLETE_CLICK"; +// export const RETURN_AUTO_COMPLETE = "RETURN_AUTO_COMPLETE"; +// export const REMOVE_AUTO_COMPLETE_DIV = "REMOVE_AUTO_COMPLETE_DIV"; +// export const HANDLE_KEYBOARD_INPUT = "HANDLE_KEYBOARD_INPUT"; +// export const RECALL_NEXT_COMMAND_OR_CLEAR = "RECALL_NEXT_COMMAND_OR_CLEAR"; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 447f92a49..e4e80a7fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7273,14 +7273,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -7295,20 +7293,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -7425,8 +7420,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -7438,7 +7432,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -7453,7 +7446,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -7461,14 +7453,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -7487,7 +7477,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -7568,8 +7557,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -7581,7 +7569,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -7703,7 +7690,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",