mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-22 22:30:52 +01:00
Fix number stacktile
This commit is contained in:
parent
2fa3662860
commit
96508ab5f2
@ -7,7 +7,7 @@ import { useFurnitureStackHeightWidget } from '../../../../hooks';
|
||||
|
||||
export const FurnitureStackHeightView: FC<{}> = props =>
|
||||
{
|
||||
const { objectId = -1, height = 0, maxHeight = 40, onClose = null, updateHeight = null } = useFurnitureStackHeightWidget();
|
||||
const { objectId = -1, height = 0, maxHeight = 40, onClose = null, setHeight = null } = useFurnitureStackHeightWidget();
|
||||
|
||||
if(objectId === -1) return null;
|
||||
|
||||
@ -22,10 +22,10 @@ export const FurnitureStackHeightView: FC<{}> = props =>
|
||||
min={ 0 }
|
||||
max={ maxHeight }
|
||||
step={ 0.01 }
|
||||
value={ height }
|
||||
onChange={ event => updateHeight(event) }
|
||||
value={ isNaN(parseFloat(height.toString())) ? 0 : parseFloat(height.toString()) }
|
||||
onChange={ event => setHeight(parseFloat(event.toString())) }
|
||||
renderThumb={ (props, state) => <div { ...props }>{ state.valueNow }</div> } />
|
||||
<input className="show-number-arrows" type="number" min={ 0 } max={ maxHeight } value={ height } onChange={ event => updateHeight(parseFloat(event.target.value)) } />
|
||||
<input className="show-number-arrows" style={ { width: '50px' } } type="number" min={ 0 } max={ maxHeight } value={ isNaN(parseFloat(height.toString())) ? '' : height } onChange={ event => setHeight(parseFloat(event.target.value)) } />
|
||||
</Flex>
|
||||
<Column gap={ 1 }>
|
||||
<Button onClick={ event => SendMessageComposer(new FurnitureStackHeightComposer(objectId, -100)) }>
|
||||
|
@ -10,7 +10,7 @@ const useFurnitureStackHeightWidgetState = () =>
|
||||
{
|
||||
const [ objectId, setObjectId ] = useState(-1);
|
||||
const [ category, setCategory ] = useState(-1);
|
||||
const [ height, setHeight ] = useState(0);
|
||||
const [ height, setHeight ] = useState<number | string>(0);
|
||||
const [ pendingHeight, setPendingHeight ] = useState(-1);
|
||||
|
||||
const onClose = () =>
|
||||
@ -21,17 +21,29 @@ const useFurnitureStackHeightWidgetState = () =>
|
||||
setPendingHeight(-1);
|
||||
}
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
if (isNaN(parseFloat(height.toString()))) return;
|
||||
|
||||
if (Number(height) || height == 0)
|
||||
{
|
||||
setHeight(parseFloat(height.toString()));
|
||||
updateHeight(parseFloat(height.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
const updateHeight = (height: number, server: boolean = false) =>
|
||||
{
|
||||
if(!height) height = 0;
|
||||
|
||||
height = Math.abs(height);
|
||||
if (height || height == 0)
|
||||
{
|
||||
height = Math.abs(parseFloat(height.toString()));
|
||||
|
||||
if(!server) ((height > MAX_HEIGHT) && (height = MAX_HEIGHT));
|
||||
if(!server) ((height > MAX_HEIGHT) && (height = MAX_HEIGHT));
|
||||
|
||||
setHeight(parseFloat(height.toFixed(2)));
|
||||
setHeight(parseFloat(height.toFixed(2)));
|
||||
|
||||
if(!server) setPendingHeight(height * 100);
|
||||
if(!server) setPendingHeight(height * 100);
|
||||
}
|
||||
}
|
||||
|
||||
useMessageEvent<FurnitureStackHeightEvent>(FurnitureStackHeightEvent, event =>
|
||||
@ -73,7 +85,7 @@ const useFurnitureStackHeightWidgetState = () =>
|
||||
return () => clearTimeout(timeout);
|
||||
}, [ objectId, pendingHeight ]);
|
||||
|
||||
return { objectId, height, maxHeight: MAX_HEIGHT, onClose, updateHeight };
|
||||
return { objectId, height, maxHeight: MAX_HEIGHT, onClose, setHeight };
|
||||
}
|
||||
|
||||
export const useFurnitureStackHeightWidget = useFurnitureStackHeightWidgetState;
|
||||
|
Loading…
Reference in New Issue
Block a user