Skip to content

Commit

Permalink
[Add] 가격설정 관련 input 이벤트 구현 중
Browse files Browse the repository at this point in the history
 - 가격설정 관련하여 현재 클릭 이벤트만 구현되어 있는 상황 (주가 리스트에서 직접 선택하거나, 상/하 버튼을 클릭하여 설정)
- input 엘리먼트에서 키보드로 직접 입력하는 기능이 필요하다고 생각되어 구현 중에 있음
- 로직 미완성된 상태이므로 브랜치 새로 따로 작업내용 저장함

Issues #17
  • Loading branch information
novice1993 committed Sep 10, 2023
1 parent 76e7535 commit b13dfd6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
48 changes: 42 additions & 6 deletions client/src/components/StockOrderSection/PriceSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { styled } from "styled-components";
import { setStockOrderPrice, plusStockOrderPrice, minusStockOrderPrice } from "../../reducer/StockOrderPrice-Reducer";
import { StateProps } from "../../models/stateProps";
import { StockInfoprops } from "../../models/stockInfoProps";
import { number } from "echarts";

const priceSettingTitle: string = "가격";
const unitText: string = "원";
Expand All @@ -21,11 +22,6 @@ const PriceSetting = (props: OwnProps) => {
const defaultPrice = existSellingPrice[0];
const priceInterval = existSellingPrice[1] - existSellingPrice[0];

// 초기 설정값 세팅
useEffect(() => {
dispatch(setStockOrderPrice(defaultPrice));
}, [companyId]);

// 거래가 증가/감소
const handlePlusOrderPrice = () => {
dispatch(plusStockOrderPrice(priceInterval));
Expand All @@ -35,13 +31,53 @@ const PriceSetting = (props: OwnProps) => {
dispatch(minusStockOrderPrice(priceInterval));
};

// 거래가 직접 기입 시 1) 음수 => 0으로 재설정 2) priceInteval로 나누어 떨어지지 않으면 => 나누어 떨어지는 수로 변경
const handleWriteOrderPrice = (event: React.ChangeEvent<HTMLInputElement>) => {

const inputValue = event.target.value;
const numberInputValue = parseInt(inputValue, 10);

if(inputValue === ''){
dispatch(setStockOrderPrice(0));
}



if(event.target.value !== ''){
const inputValue = parseInt(event.target.value, 10);
dispatch(setStockOrderPrice(inputValue));
}

// if(inputValue < 0) {
// dispatch(setStockOrderPrice(0));
// }

// if(inputValue % priceInterval !== 0){
// const remainder = inputValue % priceInterval;
// const modifiedInputValue = inputValue - remainder;
// dispatch(setStockOrderPrice(modifiedInputValue));
// }
}

// 종목이 달리지면 -> 가격도 변경
useEffect(() => {
dispatch(setStockOrderPrice(defaultPrice));
}, [companyId]);

// 입력 값 -> event 속성에 담겨 있음
// onChange 이벤트 발생할 때 -> 해당 입력값을 Price 관련 전역 상태로 (전역 상태 관리함수 활용)
// set => 으로 actionPayload를 설정해야하는데,,,
// payload에 넘기기 전에 1) 0보다 큰 값인지, 2) PriceInterval로 나누어 떨어지는지 => 안된다면
// 전역 상태관리 함수를 2번 사용? 1) 일단 입력값으로 바꾸고 2) 2차로 필터링 해서 바꾸고?
// 2차 변경 때 -> 음수면 0으로 바꾸고,,, Iterval이랑 안맞으면 -> Interval로 나눈 나머지 값 차감

return (
<Container>
<div className="PriceCategoryBox">
<div className="Title">{priceSettingTitle}</div>
</div>
<div className="PriceSettingBox">
<PriceController defaultValue={orderPrice} value={orderPrice} />
<PriceController defaultValue={orderPrice} value={orderPrice} onChange={handleWriteOrderPrice}/>
<UnitContent>{unitText}</UnitContent>
<div className="DirectionBox">
<button className="PriceUp" onClick={handlePlusOrderPrice}>
Expand Down
6 changes: 5 additions & 1 deletion client/src/components/StockOrderSection/VolumeSetteing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const VolumeSetting = () => {
const orderPrice = useSelector((state: StateProps) => state.stockOrderPrice);
const orderVolume = useSelector((state: StateProps) => state.stockOrderVolume);

const maximumBuyingVolume = Math.trunc(dummyMoney / orderPrice);
// 🎾 임시로직 추가
// const maximumBuyingVolume = Math.trunc(dummyMoney / orderPrice);
const maximumBuyingVolume = orderPrice !==0 ? Math.trunc(dummyMoney / orderPrice) : Math.trunc(dummyMoney/1);

const handlePlusOrderVolume = () => {
// 매수 -> 증가 버튼 클릭 시, 최대 구매수량 보다 낮으면 개수 1증가
Expand Down Expand Up @@ -59,6 +61,8 @@ const VolumeSetting = () => {

// 지정가 증가 -> (현재 주문수량 > 최대 주문가능 수량)일 경우 -> 현재 주문수량을 최대 주문수량으로 변경
useEffect(() => {


if (maximumBuyingVolume < orderVolume) {
dispatch(setStockOrderVolume(maximumBuyingVolume));
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/reducer/CompanyId-Reducer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSlice } from "@reduxjs/toolkit";

const initialState: number = 0;
const initialState: number = 1;

const companyIdSlice = createSlice({
name: "companyId",
Expand Down

0 comments on commit b13dfd6

Please sign in to comment.