diff --git a/src/components/SearchModal/SearchModal.tsx b/src/components/SearchModal/SearchModal.tsx index 3e93dc4c..ca0b5abf 100644 --- a/src/components/SearchModal/SearchModal.tsx +++ b/src/components/SearchModal/SearchModal.tsx @@ -1,10 +1,9 @@ import React from 'react' -import { v1 as uuidv1 } from 'uuid' - import Portal from '../../Portal' import Modal from '../Modal/Modal' import Overlay from '../Overlay/Overlay' +import WeaponResult from '../WeaponResult/WeaponResult' import './SearchModal.css' @@ -16,8 +15,9 @@ interface Props { interface State { query: string, results: { [key: string]: any } - isLoaded: boolean + loading: boolean message: string + totalResults: number } class SearchModal extends React.Component { @@ -28,62 +28,78 @@ class SearchModal extends React.Component { this.state = { query: '', results: {}, - isLoaded: false, - message: '' - } + loading: false, + message: '', + totalResults: 0 + } } fetchResults = (query) => { - fetch(`http://127.0.0.1:3000/api/v1/search?query=${query}`) + fetch(`http://grid-api.ngrok.io/api/v1/search?query=${query}`) .then(res => res.json()) .then((result) => { - // console.log("hello world!") - console.log(result) - // this.setState({ - // isLoaded: true, - // results: result - // }) + const totalResults = result.length + this.setState({ + results: result, + totalResults: totalResults, + loading: false + }) }, (error) => { - // this.setState({ - // isLoaded: true, - // message: error - // }) + this.setState({ + loading: false, + message: error + }) }) } inputChanged = (event) => { - const query = this.searchQuery.value - if (query.length > 2) { - console.log(query) - this.fetchResults(query) + const query = event.target.value + if (query.length) { + this.setState({ query, loading: true, message: '' }, () => { + this.fetchResults(query) + }) + } else { + this.setState({ query, results: {}, message: '' }) + } + } + + renderSearchResults = () => { + const { results } = this.state + + if (results.length) { + return ( +
+ { results.map( result => { + return + })} +
+ ) } - - // if (query) { - // this.setState({ query, isLoaded: true, message: '' }, () => { - // // this.fetchResults(query) - // }) - // } else { - // this.setState({ query, results: {}, message: '' }) - // } } render() { - const { query, isLoaded, message } = this.state + const { query, loading } = this.state return ( - this.searchQuery = el} - onChange={this.inputChanged} - placeholder={this.props.placeholderText} - /> +
+ +
+ + { this.renderSearchResults() } +
diff --git a/src/components/WeaponLabelIcon/WeaponLabelIcon.css b/src/components/WeaponLabelIcon/WeaponLabelIcon.css new file mode 100644 index 00000000..d2b661a5 --- /dev/null +++ b/src/components/WeaponLabelIcon/WeaponLabelIcon.css @@ -0,0 +1,79 @@ +.WeaponLabelIcon { + display: inline-block; + background-size: 60px 25px; + height: 25px; + width: 60px; +} + +/* Elements */ + +.fire { + background-image: url('../../images/labels/element/Label_Element_Fire.png') +} + +.water { + background-image: url('../../images/labels/element/Label_Element_Water.png') +} + +.earth { + background-image: url('../../images/labels/element/Label_Element_Earth.png') +} + +.wind { + background-image: url('../../images/labels/element/Label_Element_Wind.png') +} + +.dark { + background-image: url('../../images/labels/element/Label_Element_Dark.png') +} + +.light { + background-image: url('../../images/labels/element/Label_Element_Light.png') +} + +.null { + background-image: url('../../images/labels/element/Label_Element_Any.png') +} + +/* Proficiencies */ + +.sword { + background-image: url('../../images/labels/proficiency/Label_Weapon_Sabre.png') +} + +.dagger { + background-image: url('../../images/labels/proficiency/Label_Weapon_Dagger.png') +} + +.axe { + background-image: url('../../images/labels/proficiency/Label_Weapon_Axe.png') +} + +.spear { + background-image: url('../../images/labels/proficiency/Label_Weapon_Spear.png') +} + +.staff { + background-image: url('../../images/labels/proficiency/Label_Weapon_Staff.png') +} + +.fist { + background-image: url('../../images/labels/proficiency/Label_Weapon_Melee.png') +} + +.harp { + background-image: url('../../images/labels/proficiency/Label_Weapon_Harp.png') +} + +.gun { + background-image: url('../../images/labels/proficiency/Label_Weapon_Gun.png') +} + +.bow { + background-image: url('../../images/labels/proficiency/Label_Weapon_Bow.png') +} + +.katana { + background-image: url('../../images/labels/proficiency/Label_Weapon_Katana.png') +} + diff --git a/src/components/WeaponLabelIcon/WeaponLabelIcon.tsx b/src/components/WeaponLabelIcon/WeaponLabelIcon.tsx new file mode 100644 index 00000000..6df5e4ef --- /dev/null +++ b/src/components/WeaponLabelIcon/WeaponLabelIcon.tsx @@ -0,0 +1,16 @@ +import React from 'react' +import './WeaponLabelIcon.css' + +interface Props { + labelType: string +} + +class WeaponLabelIcon extends React.Component { + render() { + return ( + + ) + } +} + +export default WeaponLabelIcon \ No newline at end of file diff --git a/src/components/WeaponResult/WeaponResult.css b/src/components/WeaponResult/WeaponResult.css new file mode 100644 index 00000000..76f48633 --- /dev/null +++ b/src/components/WeaponResult/WeaponResult.css @@ -0,0 +1,48 @@ +.WeaponResult { + -webkit-font-smoothing: antialiased; + + border-radius: 6px; + display: flex; + font-family: -apple-system, "Helvetica Neue", "Lucida Grande"; + gap: 8px; + padding: 12px; +} + +.WeaponResult img { + background: #e9e9e9; + border-radius: 6px; + display: inline-block; + height: 72px; + width: 120px; +} + +.WeaponResult h5 { + color: #555; + display: inline-block; + font-size: 18px; + font-weight: 500; + margin: 2px 4px 4px 0; +} + +.WeaponResult .WeaponLabelIcon { + margin-right: 4px; +} + +.WeaponResult .stars { + display: inline-block; + color: #FFA15E; + font-size: 21px; +} + +.WeaponResult .stars > span { + color: #65DAFF; +} + +.WeaponResult:hover { + background: #e9e9e9; + cursor: pointer; +} + +.WeaponResult:hover .image_placeholder { + background: #dadada; +} \ No newline at end of file diff --git a/src/components/WeaponResult/WeaponResult.tsx b/src/components/WeaponResult/WeaponResult.tsx new file mode 100644 index 00000000..70b15271 --- /dev/null +++ b/src/components/WeaponResult/WeaponResult.tsx @@ -0,0 +1,65 @@ +import React from 'react' +import './WeaponResult.css' + +import '../WeaponLabelIcon/WeaponLabelIcon' +import WeaponLabelIcon from '../WeaponLabelIcon/WeaponLabelIcon' + +import gridImages from '../../images/grid/*.jpg' + +interface Weapon { + id: string + granblue_id: number + element: number + proficiency: number + max_level: number + max_skill_level: number + name: { + en: string + jp: string + } + hp: { + min_hp: number + max_hp: number + max_hp_flb: number + max_hp_ulb: number + } + atk: { + min_atk: number + max_atk: number + max_atk_flb: number + max_atk_ulb: number + } + uncap: { + flb: boolean + ulb: boolean + } +} + +interface Props { + data: Weapon +} + +const Element = ['null', 'wind', 'fire', 'water', 'earth', 'dark', 'light'] +const Proficiency = ['none', 'sword', 'dagger', 'axe', 'spear', 'bow', 'staff', 'fist', 'harp', 'gun', 'katana'] + + +class WeaponResult extends React.Component { + render() { + const weapon = this.props.data + return ( +
+ {weapon.name.en} +
+
+
{weapon.name.en}
+
⭑⭑⭑{(weapon.uncap.flb) ? : ''}{(weapon.uncap.ulb) ? : ''}
+
+ + +
+
+ ) + } +} + +export default WeaponResult \ No newline at end of file