Make some props optional for read-only

This commit is contained in:
Justin Edmund 2022-02-28 18:17:04 -08:00
parent f16c53ed16
commit 67bd3e8c73

View file

@ -6,11 +6,11 @@ import './index.scss'
interface Props { interface Props {
type: 'character' | 'weapon' | 'summon' type: 'character' | 'weapon' | 'summon'
rarity?: number rarity?: number
uncapLevel: number uncapLevel?: number
flb: boolean flb: boolean
ulb: boolean ulb: boolean
special: boolean special: boolean
updateUncap: (uncap: number) => void updateUncap?: (uncap: number) => void
} }
const UncapIndicator = (props: Props) => { const UncapIndicator = (props: Props) => {
@ -52,25 +52,27 @@ const UncapIndicator = (props: Props) => {
} }
function toggleStar(index: number, empty: boolean) { function toggleStar(index: number, empty: boolean) {
if (empty) props.updateUncap(index + 1) if (props.updateUncap) {
else props.updateUncap(index) if (empty) props.updateUncap(index + 1)
else props.updateUncap(index)
}
} }
const transcendence = (i: number) => { const transcendence = (i: number) => {
return <UncapStar ulb={true} empty={i >= props.uncapLevel} key={`star_${i}`} index={i} onClick={toggleStar} /> return <UncapStar ulb={true} empty={ (props.uncapLevel) ? i >= props.uncapLevel : false } key={`star_${i}`} index={i} onClick={toggleStar} />
} }
const ulb = (i: number) => { const ulb = (i: number) => {
return <UncapStar ulb={true} empty={i >= props.uncapLevel} key={`star_${i}`} index={i} onClick={toggleStar} /> return <UncapStar ulb={true} empty={ (props.uncapLevel) ? i >= props.uncapLevel : false } key={`star_${i}`} index={i} onClick={toggleStar} />
} }
const flb = (i: number) => { const flb = (i: number) => {
return <UncapStar flb={true} empty={i >= props.uncapLevel} key={`star_${i}`} index={i} onClick={toggleStar} /> return <UncapStar flb={true} empty={ (props.uncapLevel) ? i >= props.uncapLevel : false } key={`star_${i}`} index={i} onClick={toggleStar} />
} }
const mlb = (i: number) => { const mlb = (i: number) => {
// console.log("MLB; Number of stars:", props.uncapLevel) // console.log("MLB; Number of stars:", props.uncapLevel)
return <UncapStar empty={i >= props.uncapLevel} key={`star_${i}`} index={i} onClick={toggleStar} /> return <UncapStar empty={ (props.uncapLevel) ? i >= props.uncapLevel : false } key={`star_${i}`} index={i} onClick={toggleStar} />
} }
return ( return (