Receive and send ring values (WIP)
This commit is contained in:
parent
a428a69ec7
commit
ad07e9b727
1 changed files with 16 additions and 9 deletions
|
|
@ -1,8 +1,5 @@
|
||||||
// Core dependencies
|
// Core dependencies
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useEffect, useState } from 'react'
|
||||||
import { useRouter } from 'next/router'
|
|
||||||
import { useTranslation } from 'next-i18next'
|
|
||||||
import classNames from 'classnames'
|
|
||||||
|
|
||||||
// UI dependencies
|
// UI dependencies
|
||||||
import SelectWithSelect from '~components/SelectWithSelect'
|
import SelectWithSelect from '~components/SelectWithSelect'
|
||||||
|
|
@ -14,7 +11,7 @@ import { overMastery } from '~data/overMastery'
|
||||||
import './index.scss'
|
import './index.scss'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import { CharacterOverMastery } from '~types'
|
import { CharacterOverMastery, ExtendedMastery } from '~types'
|
||||||
|
|
||||||
const emptyRing: ExtendedMastery = {
|
const emptyRing: ExtendedMastery = {
|
||||||
modifier: 0,
|
modifier: 0,
|
||||||
|
|
@ -35,6 +32,9 @@ const RingSelect = (props: Props) => {
|
||||||
4: emptyRing,
|
4: emptyRing,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
props.sendValues(rings)
|
||||||
|
}, [rings])
|
||||||
|
|
||||||
function dataSet(index: number) {
|
function dataSet(index: number) {
|
||||||
const noValue = {
|
const noValue = {
|
||||||
|
|
@ -65,25 +65,32 @@ const RingSelect = (props: Props) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function receiveRingValues(index: number, left: number, right: number) {
|
||||||
|
setRings({
|
||||||
|
...rings,
|
||||||
|
[index]: {
|
||||||
|
modifier: left,
|
||||||
|
strength: right,
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="Rings">
|
<div className="Rings">
|
||||||
{[...Array(4)].map((element, i) => {
|
{[...Array(4)].map((e, i) => {
|
||||||
const ringIndex = i + 1
|
const ringIndex = i + 1
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SelectWithSelect
|
<SelectWithSelect
|
||||||
name={`ring${ringIndex}`}
|
name={`ring-${ringIndex}`}
|
||||||
object="ring"
|
object="ring"
|
||||||
key={`ring-${ringIndex}`}
|
key={`ring-${ringIndex}`}
|
||||||
dataSet={dataSet(ringIndex)}
|
dataSet={dataSet(ringIndex)}
|
||||||
leftSelectDisabled={i === 0 || i === 1}
|
leftSelectDisabled={i === 0 || i === 1}
|
||||||
leftSelectValue={rings[ringIndex].modifier}
|
leftSelectValue={rings[ringIndex].modifier}
|
||||||
rightSelectValue={rings[ringIndex].strength}
|
rightSelectValue={rings[ringIndex].strength}
|
||||||
onOpenChange={(index: 'left' | 'right', open: boolean) => {}}
|
sendValues={(left: number, right: number) => {
|
||||||
sendValues={(value: number) => {
|
receiveRingValues(ringIndex, left, right)
|
||||||
console.log(`VALUE ${value} RECEIVED`)
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue