| @@ -0,0 +1,48 @@ | ||
| 'use strict'; | ||
|
|
||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
|
|
||
| var _react = require('react'); | ||
|
|
||
| var _react2 = _interopRequireDefault(_react); | ||
|
|
||
| var _dataRow = require('./dataRow'); | ||
|
|
||
| var _dataRow2 = _interopRequireDefault(_dataRow); | ||
|
|
||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
|
||
| var DataDiv = function DataDiv(props) { | ||
| var mergedArray = Object.keys(props.objectToDisplay).concat(props.hiddenProps); | ||
| mergedArray.sort(); | ||
| var dataRows = []; | ||
| for (var i = 0; i < mergedArray.length; i++) { | ||
| if (mergedArray[i] != mergedArray[i + 1]) { | ||
| if (props.positionedProps.indexOf(mergedArray[i]) < 0) { | ||
| dataRows.push(_react2.default.createElement(_dataRow2.default, { key: mergedArray[i], name: mergedArray[i], value: props.objectToDisplay[mergedArray[i]] })); | ||
| } | ||
| } else { | ||
| i++; | ||
| } | ||
| } | ||
| for (var x = props.positionedProps.length - 1; x > -1; x--) { | ||
| if (props.hiddenProps.indexOf(props.positionedProps[x]) < 0) { | ||
| dataRows.splice(0, 0, _react2.default.createElement(_dataRow2.default, { key: props.positionedProps[x], name: props.positionedProps[x], value: props.objectToDisplay[props.positionedProps[x]] })); | ||
| } | ||
| } | ||
| return _react2.default.createElement( | ||
| 'div', | ||
| null, | ||
| dataRows | ||
| ); | ||
| }; | ||
|
|
||
| DataDiv.propTypes = { | ||
| objectToDisplay: _react2.default.PropTypes.object.isRequired, | ||
| positionedProps: _react2.default.PropTypes.array, | ||
| hiddenProps: _react2.default.PropTypes.array | ||
| }; | ||
|
|
||
| exports.default = DataDiv; |
| @@ -0,0 +1,38 @@ | ||
| 'use strict'; | ||
|
|
||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
|
|
||
| var _react = require('react'); | ||
|
|
||
| var _react2 = _interopRequireDefault(_react); | ||
|
|
||
| var _reactRedux = require('react-redux'); | ||
|
|
||
| var _reactBootstrap = require('react-bootstrap'); | ||
|
|
||
| var _monsterSearchContainer = require('../container/monsterSearchContainer'); | ||
|
|
||
| var _monsterSearchContainer2 = _interopRequireDefault(_monsterSearchContainer); | ||
|
|
||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
|
||
| var MonsterPage = function MonsterPage(props) { | ||
| return _react2.default.createElement( | ||
| 'div', | ||
| null, | ||
| _react2.default.createElement( | ||
| _reactBootstrap.Row, | ||
| { id: 'spell-page-div', className: 'boostrap-row-margin-override' }, | ||
| _react2.default.createElement( | ||
| _reactBootstrap.Col, | ||
| { id: 'search-container', xs: 12, sm: 3 }, | ||
| _react2.default.createElement(_monsterSearchContainer2.default, null) | ||
| ) | ||
| ), | ||
| _react2.default.createElement('script', { src: 'bundle.js' }) | ||
| ); | ||
| }; | ||
|
|
||
| exports.default = MonsterPage; |
| @@ -0,0 +1,43 @@ | ||
| "use strict"; | ||
|
|
||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
|
|
||
| var _monsterSearcher = require("../searchers/monsterSearcher"); | ||
|
|
||
| var _monsterSearcher2 = _interopRequireDefault(_monsterSearcher); | ||
|
|
||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
|
||
| function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
|
|
||
| function monsters() { | ||
| var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { monsterList: [] }; | ||
| var action = arguments[1]; | ||
|
|
||
| switch (action.type) { | ||
| case "SEARCH_MONSTER": | ||
| var newMonster = _monsterSearcher2.default.search(action.monsterName); | ||
| if (newMonster) { | ||
| console.log(JSON.stringify(state)); | ||
| return Object.assign({}, state, { currentMonster: newMonster }); | ||
| } else { | ||
| return state; | ||
| } | ||
| break; | ||
| case "ADD_MONSTER": | ||
| var addedMonsterList = [].concat(_toConsumableArray(state.monsterList), [action.newMonster]); | ||
| return Object.assign({}, state, { monsterList: addedMonsterList }); | ||
| console.log(JSON.stringify(state)); | ||
| break; | ||
| case "REMOVE_MONSTER": | ||
| var removedMonsterList = [].concat(_toConsumableArray(state.monsterList.slice(0, action.monsterIndex)), _toConsumableArray(state.monsterList.slice(action.monsterIndex + 1))); | ||
| return Object.assign({}, state, { monsterList: removedMonsterList }); | ||
| break; | ||
| default: | ||
| return state; | ||
| } | ||
| } | ||
|
|
||
| exports.default = monsters; |
| @@ -0,0 +1,78 @@ | ||
| //import {storeMonsterList, retrieveMonsterList} from '../databaseConvenienceFunctions'; | ||
|
|
||
| function searchMonster(monsterName){ | ||
| return {type: "SEARCH_MONSTER", monsterName: monsterName}; | ||
| } | ||
|
|
||
| function addMonster(newMonster){ | ||
| return {type: "ADD_MONSTER", newMonster: newMonster}; | ||
| } | ||
|
|
||
| function removeMonster(monsterIndex){ | ||
| return {type: "REMOVE_MONSTER", monsterIndex: monsterIndex}; | ||
| } | ||
|
|
||
| export {searchMonster, addMonster, removeMonster}; | ||
| // | ||
| // function requestRetrieveMonsterList(user){ | ||
| // return {type: "REQUEST_RETRIEVE_MONSTER_LIST", user: user}; | ||
| // } | ||
| // | ||
| // function recieveRetrieveMonsterList(user, monsterList){ | ||
| // return {type: "RECIEVE_RETRIEVE_MONSTER_LIST", user: user, monsterList: monsterList}; | ||
| // } | ||
| // | ||
| // function errorRetrieveMonsterList(){ | ||
| // return {type: "ERROR_RETRIEVE_MONSTER_LIST"}; | ||
| // } | ||
| // | ||
| // function requestStoreMonsterList(user){ | ||
| // return {type: "REQUEST_STORE_MONSTER_LIST", user: user}; | ||
| // } | ||
| // | ||
| // function recieveStoreMonsterList(user){ | ||
| // return {type: "RECIEVE_STORE_MONSTER_LIST", user: user}; | ||
| // } | ||
| // | ||
| // function attemptStoreMonsterList(monsterList, user) { | ||
| // return ((dispatch, getState) => { | ||
| // dispatch(requestStoreMonsterList(user)); | ||
| // storeMonsterList(monsterList, user) | ||
| // .then((response) => { | ||
| // dispatch(recieveStoreMonsterList(user)); | ||
| // console.log(response); | ||
| // }) | ||
| // .catch((response) => { | ||
| // console.log(response); | ||
| // }); | ||
| // }); | ||
| // } | ||
| // | ||
| // function attemptRetrieveMonsterList(user) { | ||
| // if (user){ | ||
| // return ((dispatch, getState) => { | ||
| // dispatch(requestRetrieveMonsterList(user)); | ||
| // console.log("Sent request"); | ||
| // retrieveMonsterList(user) | ||
| // .then((response) => { | ||
| // let {monsterList} = JSON.parse(response).Item; | ||
| // dispatch(recieveRetrieveMonsterList(user, monsterList)); | ||
| // console.log(response); | ||
| // }, | ||
| // (response) => { | ||
| // console.log("ERROR ACCESSING DB"); | ||
| // dispatch(errorRetrieveMonsterList()); | ||
| // }) | ||
| // .catch((reason) =>{ | ||
| // console.log(`ERROR RESOLVING PROMISE: ${reason}`); | ||
| // dispatch(errorRetrieveMonsterList()); | ||
| // }); | ||
| // }); | ||
| // } | ||
| // else{ | ||
| // console.log("No user"); | ||
| // } | ||
| // } | ||
|
|
||
|
|
||
| //export {searchMonster, attemptAddMonster, removeMonster, attemptStoreMonsterList, attemptRetrieveMonsterList, recieveRetrieveMonsterList, requestRetrieveMonsterList}; |
| @@ -0,0 +1,42 @@ | ||
| import React from "react"; | ||
| import ReactDOM from "react-dom"; | ||
| import {connect} from "react-redux"; | ||
| import {searchMonster, addMonster} from "~/actions/monsterActions" | ||
| import ImageButton from '../presentational/imageButton'; | ||
| import SearchContainer from './searchContainer'; | ||
|
|
||
| //Search container. | ||
| class SpellSearchContainer extends React.Component{ | ||
| constructor(props){ | ||
| super(props); | ||
| this.handleChange = this.handleChange.bind(this); | ||
| this.addMonster = this.addMonster.bind(this); | ||
| this.state = {currentText: ""}; | ||
| } | ||
|
|
||
| handleChange(event){ | ||
| this.setState({currentText: event.target.value}); | ||
| this.props.dispatch(searchMonster(this.state.currentText)); | ||
| } | ||
|
|
||
| addMonster(event){ | ||
| this.props.dispatch(addMonster(this.props.currentMonster)); | ||
| } | ||
|
|
||
| render () { | ||
| return ( | ||
| <SearchContainer positionedProps = {['name']} onFound = {this.addMonster} handleChange = {this.handleChange} currentText = {this.state.currentText} foundItem = {this.props.currentMonster} hiddenProps = {['actions', 'special_abilities', 'legendary_actions']}/> | ||
| ); | ||
| } | ||
| } | ||
| //SearchContainer = Radium(SearchContainer); | ||
|
|
||
|
|
||
|
|
||
| function mapStateToProps(state, ownProps){ | ||
| return { | ||
| currentMonster: state.monsters.currentMonster | ||
| } | ||
| } | ||
|
|
||
| export default connect(mapStateToProps)(SpellSearchContainer); |
| @@ -0,0 +1,35 @@ | ||
| import React from "react"; | ||
| import ReactDOM from "react-dom"; | ||
| import SpellDiv from "../presentational/spellDiv"; | ||
| import ImageButton from '../presentational/imageButton'; | ||
| import DataDiv from '../presentational/dataDiv'; | ||
|
|
||
| //Search container. | ||
| class SearchContainer extends React.Component{ | ||
| constructor(props){ | ||
| super(props); | ||
| this.onKeyUp = this.onKeyUp.bind(this); | ||
| } | ||
|
|
||
| onKeyUp(event){ | ||
| let keycode = (event.keyCode ? event.keyCode : event.which); | ||
| if(keycode === 13){ | ||
| this.props.onFound(); | ||
| } | ||
| } | ||
|
|
||
| render () { | ||
| return ( | ||
| <div> | ||
| <div id = 'search-input'> | ||
| <input className = "styled-input" type = "text" onKeyUp = {this.onKeyUp} value = {this.props.currentText} onChange = {this.props.handleChange} /> | ||
| {this.props.foundItem && <ImageButton imageSrc = {"plus"} handleClick = {this.props.onFound}/>} | ||
| </div> | ||
| {this.props.foundItem && <DataDiv positionedProps = {this.props.positionedProps} hiddenProps = {this.props.hiddenProps} objectToDisplay = {this.props.foundItem}/>} | ||
| {/*{this.props.foundItem && <SpellDiv spell = {this.props.foundItem}/>}*/} | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export default SearchContainer; |
| @@ -0,0 +1,36 @@ | ||
| import React from 'react'; | ||
| import DataRow from './dataRow'; | ||
|
|
||
| let DataDiv = (props) => { | ||
| let mergedArray = Object.keys(props.objectToDisplay).concat(props.hiddenProps); | ||
| mergedArray.sort(); | ||
| let dataRows = []; | ||
| for (let i = 0; i < mergedArray.length; i++){ | ||
| if(mergedArray[i] != mergedArray[i + 1]){ | ||
| if(props.positionedProps.indexOf(mergedArray[i]) < 0){ | ||
| dataRows.push(<DataRow key = {mergedArray[i]} name = {mergedArray[i]} value = {props.objectToDisplay[mergedArray[i]]}/>); | ||
| } | ||
| } | ||
| else{ | ||
| i++; | ||
| } | ||
| } | ||
| for (let x = props.positionedProps.length - 1; x > -1; x--){ | ||
| if(props.hiddenProps.indexOf(props.positionedProps[x]) < 0){ | ||
| dataRows.splice(0, 0, <DataRow key = {props.positionedProps[x]} name = {props.positionedProps[x]} value = {props.objectToDisplay[props.positionedProps[x]]}/>); | ||
| } | ||
| } | ||
| return ( | ||
| <div> | ||
| {dataRows} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| DataDiv.propTypes = { | ||
| objectToDisplay: React.PropTypes.object.isRequired, | ||
| positionedProps: React.PropTypes.array, | ||
| hiddenProps: React.PropTypes.array | ||
| } | ||
|
|
||
| export default DataDiv; |
| @@ -0,0 +1,28 @@ | ||
| import React from 'react'; | ||
| import {connect} from "react-redux"; | ||
| import {Row, Col} from 'react-bootstrap'; | ||
| import MonsterSearchContainer from '../container/monsterSearchContainer'; | ||
|
|
||
| let MonsterPage = (props) => { | ||
| return ( | ||
| <div> | ||
| {/* <Row> | ||
| <Col className = "title-background" xs={12}> | ||
| <SpellPageHeaderContainer/> | ||
| </Col> | ||
| </Row> | ||
| <SettingsModalContainer/>*/} | ||
| <Row id = "spell-page-div" className = "boostrap-row-margin-override"> | ||
| <Col id = 'search-container' xs = {12} sm = {3}> | ||
| <MonsterSearchContainer/> | ||
| </Col> | ||
| {/*<Col id = 'spell-list' xs = {12} sm = {9}> | ||
| <SpellList/> | ||
| </Col> */} | ||
| </Row> | ||
| <script src="bundle.js"></script> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default MonsterPage; |
| @@ -1,41 +1,10 @@ | ||
| import React from "react"; | ||
| import DataDiv from "./dataDiv"; | ||
|
|
||
| function SpellDiv(props){ | ||
| return (<div> | ||
| <DataDiv objectToDisplay = {props.spell} hiddenProps = {props.filters} positionedProps = {['name', 'description']}/> | ||
| </div>) | ||
| } | ||
|
|
||
| export default SpellDiv; |
| @@ -0,0 +1,30 @@ | ||
| import monsterSearcher from "~/searchers/monsterSearcher"; | ||
|
|
||
| function monsters(state = {monsterList: []}, action) | ||
| { | ||
| switch (action.type){ | ||
| case "SEARCH_MONSTER": | ||
| let newMonster = monsterSearcher.search(action.monsterName); | ||
| if(newMonster){ | ||
| console.log(JSON.stringify(state)); | ||
| return Object.assign({}, state, {currentMonster: newMonster}); | ||
| } | ||
| else{ | ||
| return state; | ||
| } | ||
| break; | ||
| case "ADD_MONSTER": | ||
| let addedMonsterList = [...state.monsterList, action.newMonster]; | ||
| return Object.assign({}, state, {monsterList: addedMonsterList}); | ||
| console.log(JSON.stringify(state)); | ||
| break; | ||
| case "REMOVE_MONSTER": | ||
| let removedMonsterList = [...state.monsterList.slice(0, action.monsterIndex), ...state.monsterList.slice(action.monsterIndex + 1)]; | ||
| return Object.assign({}, state, {monsterList: removedMonsterList}); | ||
| break; | ||
| default: | ||
| return state; | ||
| } | ||
| } | ||
|
|
||
| export default monsters; |