Merge pull request #1 from Jessidhia/patch-1

Refactor Action.js
dependabot/npm_and_yarn/react-scripts-4.0.3
Rawrington 6 years ago committed by GitHub
commit 7895003b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 67
      src/Action.js

@ -1,7 +1,7 @@
import React from 'react' import React from 'react'
import './css/Action.css' import './css/Action.css'
const gcdExceptions = [ const gcdOverrides = new Set([
15997, //standard step 15997, //standard step
15998, //technical step 15998, //technical step
15999, 15999,
@ -18,47 +18,50 @@ const gcdExceptions = [
16196, //quadruple technical finish 16196, //quadruple technical finish
7418, //flamethrower 7418, //flamethrower
16483 //tsubame-gaeshi 16483 //tsubame-gaeshi
] ])
const ogcdExceptions = [ const ogcdOverrides = new Set([
3559, //bard WM 3559, //bard WM
116, //bard AP 116, //bard AP
114 //bard MB 114 //bard MB
] ])
class Action extends React.Component { export default function Action({ action_id }) {
state = { const [apiData, setApiData] = React.useState()
xivapi_data: []
}
constructor(props) {
super(props);
const actionUrl = "https://xivapi.com/Action/"+props.action_id;
fetch(actionUrl, { mode: 'cors' }) React.useEffect(() => {
.then(response => response.json()) let current = true
.then(data => {this.setState({xivapi_data: data})}) void (async () => {
const data = await (
await fetch(`https://xivapi.com/Action/${action_id}`, { mode: 'cors' })
).json()
if (current) {
setApiData(data)
} }
})()
isGCD() { return () => {
if(ogcdExceptions.indexOf(this.props.action_id) !== -1) return false current = false
if(gcdExceptions.indexOf(this.props.action_id) !== -1) return true
return (this.state.xivapi_data.ActionCategory.ID !== 4)
} }
}, [action_id])
render() { const isGCD = React.useMemo(
if(this.state.xivapi_data.Icon) { () =>
const classes = this.isGCD()?'action-icon gcd':'action-icon ogcd' gcdOverrides.has(action_id) ||
const img = "https://xivapi.com"+this.state.xivapi_data.Icon !ogcdOverrides.has(action_id) ||
return <img className={classes} src={img} alt='' /> apiData !== undefined && apiData.ActionCategory.ID !== 4,
} [action_id]
else )
{
if (apiData === undefined || !apiData.Icon) {
return null return null
} }
}
}
export default Action return (
<img
className={isGCD ? 'action-icon gcd' : 'action-icon ogcd'}
src={`https://xivapi.com/${apiData.Icon}`}
alt={apiData.Name || ''}
/>
)
}

Loading…
Cancel
Save