Refactor Action.js

dependabot/npm_and_yarn/react-scripts-4.0.3
Jessica Franco 5 years ago committed by GitHub
parent 2ceadb90f5
commit 8a8591cb93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 73
      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) { React.useEffect(() => {
super(props); let current = true
void (async () => {
const actionUrl = "https://xivapi.com/Action/"+props.action_id; const data = await (
await fetch(`https://xivapi.com/Action/${action_id}`, { mode: 'cors' })
fetch(actionUrl, { mode: 'cors' }) ).json()
.then(response => response.json()) if (current) {
.then(data => {this.setState({xivapi_data: data})}) setApiData(data)
} }
})()
return () => {
current = false
}
}, [action_id])
isGCD() { const isGCD = React.useMemo(
if(ogcdExceptions.indexOf(this.props.action_id) !== -1) return false () =>
if(gcdExceptions.indexOf(this.props.action_id) !== -1) return true gcdOverrides.has(action_id) ||
!ogcdOverrides.has(action_id) ||
return (this.state.xivapi_data.ActionCategory.ID !== 4) apiData !== undefined && apiData.ActionCategory.ID !== 4,
[action_id]
)
if (apiData === undefined || !apiData.Icon) {
return null
} }
render() { return (
if(this.state.xivapi_data.Icon) { <img
const classes = this.isGCD()?'action-icon gcd':'action-icon ogcd' className={isGCD ? 'action-icon gcd' : 'action-icon ogcd'}
const img = "https://xivapi.com"+this.state.xivapi_data.Icon src={`https://xivapi.com/${apiData.Icon}`}
return <img className={classes} src={img} alt='' /> alt={apiData.Name || ''}
} />
else )
{
return null
}
}
} }
export default Action
Loading…
Cancel
Save