remove bugs

This commit is contained in:
ilia 2022-10-23 09:02:36 +03:00
parent 06f2502a20
commit 8009f1128e
2 changed files with 67 additions and 9 deletions

View File

@ -56,6 +56,32 @@ const nodesInputSlice = createSlice({
},
setLoading(state, action: PayloadAction<boolean>){
state.loading = action.payload
},
updateNumberNode(state, action: PayloadAction<{value: string, number: number}>) {
state.nodes = state.nodes.map((e) => {
var operation = '=';
if (e.value[0] == '>' && e.value[1] == '=') operation = '>='
if (e.value[0] == '<' && e.value[1] == '=') operation = '<='
return e.value == e.value ? {
type: e.type,
value: operation + action.payload.number.toString()
} : e
})
},
updateOperationNode(state, action: PayloadAction<{value: string, operation: string}>) {
state.nodes = state.nodes.map((e) => {
var value = 0
if (action.payload.operation.length == 2) {
value = Number.parseInt(e.value.slice(2, e.value.length))
}
else {
value = Number.parseInt(e.value.slice(1, e.value.length))
}
return e.value == e.value ? {
type: e.type,
value: action.payload.operation + value
} : e
})
}
},
@ -70,7 +96,14 @@ const nodesInputSlice = createSlice({
}
})
export const {setCurrentWord, createNode, deleteNode, setLoading} = nodesInputSlice.actions;
export const {
setCurrentWord,
createNode,
deleteNode,
setLoading,
updateNumberNode,
updateOperationNode
} = nodesInputSlice.actions;
export const hints = createSelector((state: INodesInput) => state.hints, hints => hints)

View File

@ -2,7 +2,7 @@ import React, { useState } from "react";
import { AutoComplete, Input, Tag, Tooltip } from 'antd';
import { InputNumber, Popover, Radio } from 'antd';
import { useAppDispatch, useAppSelector } from "../../hooks";
import { createNode, deleteNode, hints, INode, loading, nodes, products, setLoading } from "../../store/reducers/nodesInputReducer";
import { createNode, deleteNode, hints, INode, loading, nodes, products, setLoading, updateNumberNode, updateOperationNode } from "../../store/reducers/nodesInputReducer";
import { createHints, search } from "../../store/reducers/asyncActions";
import styles from "./search.module.css"
@ -65,16 +65,34 @@ export const Search: React.FC<{onData:(data:any)=>void}> = (props) =>{
if (value.type.split("_")[1] == "numeric"){
let popver = <div className={styles.popover}>
<div>{value.type.split("_")[0]}</div>
<Radio.Group defaultValue="=" size="small">
<Radio.Group defaultValue="=" size="small" onChange={(e) => {
console.log(e.target.value)
dispatch(
updateOperationNode({value: value.value, operation: e.target.value})
)
}}>
<Radio.Button value=">="></Radio.Button>
<Radio.Button value="=">=</Radio.Button>
<Radio.Button value="<="></Radio.Button>
</Radio.Group>
<InputNumber autoFocus onClick={()=>setDisableInput(true)} size="small" min={1} max={100000} defaultValue={100}/>
<InputNumber
autoFocus
onClick={()=>setDisableInput(true)}
size="small"
min={1}
max={100000}
defaultValue={100}
onChange={(ee) => {
console.log(ee)
dispatch(
updateNumberNode({value: value.value, number: ee!})
)
}}
/>
</div>
tag = <Popover onOpenChange={(e)=> e?null:setDisableInput(false)} content={popver} title="Задать значение">
tag = <Popover onOpenChange={(e)=> e?null:setDisableInput(false)} content={popver} title="Задать значение">
<Tag
color={"cyan"}
closable
@ -85,7 +103,11 @@ export const Search: React.FC<{onData:(data:any)=>void}> = (props) =>{
)
}}
>
<CalculatorOutlined></CalculatorOutlined>
<CalculatorOutlined
onChange={(e) => {
console.log(e)
}}
></CalculatorOutlined>
{value.value.length < 13? value.value:value.value.slice(0,10)+"..."}
</Tag>
</Popover>
@ -95,12 +117,15 @@ export const Search: React.FC<{onData:(data:any)=>void}> = (props) =>{
}
const onSelect = (value:string, type:any) =>{
const vts = value.split('--');
var vts = value.split('--');
addTag({
'type': vts[1],
'value': vts[0]
})
if (vts[1].endsWith('_numeric')){
vts[1] = '*'+vts[1].split('_')[0]
vts[0] = '=0'
}
dispatch(createNode({
'type': vts[1],
'value': vts[0]
@ -158,7 +183,7 @@ export const Search: React.FC<{onData:(data:any)=>void}> = (props) =>{
<span>{after_str}</span>
</div>
</Tooltip>,
value: e.value.value + '--' + e.value.type
value: e.value.value + '--' + e.value.type + '--' + Date.now().toString()
}
})}
onSelect={onSelect as any}