Skip to content

Commit

Permalink
Merge pull request #36 from primus-teoSprint/feat/#24
Browse files Browse the repository at this point in the history
[#24] ํˆฌ์ž ์ง€ํ‘œ ์‚ฌ๋žŒ ๋ฐ ๊ฒฐ๊ณผ ๋„์ถœ
  • Loading branch information
hanseulhee authored Apr 7, 2024
2 parents 571c4fe + 9cffe39 commit 44bdf5e
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 30 deletions.
26 changes: 15 additions & 11 deletions app/(route)/indicators/_components/result/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import Nav from '@/app/_common/nav'
import Title from '@/app/_common/text/title'
import { investmentItemAtom, totalinputValueAtom } from '@/app/_store/atom'
import { selectedItemAtom, totalinputValueAtom } from '@/app/_store/atom'
import { useRecoilValue } from 'recoil'
import S from './result.module.css'
import Pyramid from './Pyramid'

//* ๊ฒฐ๊ณผํŽ˜์ด์ง€ ์ž…๋‹ˆ๋‹ค.
//TODO: ์‚ฌ์šฉ์ž๊ฐ€ ํด๋ฆญํ•œ ์•„์ด๋””์–ด ์ด๋ฆ„๊ณผ ํ•ด๋‹น ํˆด์„ ์‚ฌ์šฉํ•œ ์‚ฌ์šฉ์ž ์ˆ˜๊ฐ€ ๋ณด์—ฌ์ง‘๋‹ˆ๋‹ค.
function Result() {
const selectedItem = useRecoilValue(investmentItemAtom)
const selectedItem = useRecoilValue(selectedItemAtom)
const totalinputValue = parseInt(useRecoilValue(totalinputValueAtom))

const result =
selectedItem?.score &&
selectedItem?.people &&
Math.floor(
((selectedItem.people * selectedItem.score) /
(selectedItem.score * totalinputValue)) *
100,
)

return (
<div className={S.wrapper}>
<Nav />
Expand All @@ -32,16 +41,11 @@ function Result() {
<div>
<span className={S.title}>๊ฒ€์ฆ ์ง€ํ‘œ</span>
<p className={S.subTitle}>๊ณ„์‚ฐ ๊ฒฐ๊ณผ์ง€์ž…๋‹ˆ๋‹ค.</p>

<p>์ „์ฒด ์ด์šฉ์ž ์ˆ˜ : {totalinputValue}</p>

{selectedItem.map((item) => (
<span key={item.id}>
<p>์„ ํƒํ•œ ์•„์ดํ…œ ์ด๋ฆ„: {item.name}</p>
<p>์„ ํƒํ•œ ์•„์ดํ…œ ์ ์ˆ˜: {item.score}</p>
<p>์ตœ์ข… ์ ์ˆ˜: {item.score && item.score * totalinputValue}</p>
</span>
))}
<p>์„ ํƒํ•œ ์•„์ดํ…œ ์ด๋ฆ„: {selectedItem?.name}</p>
<p>์„ ํƒํ•œ ์•„์ดํ…œ ์ ์ˆ˜: {selectedItem?.score}</p>
<p>์„ ํƒํ•œ ์•„์ดํ…œ ์‚ฌ๋žŒ ์ˆ˜: {selectedItem?.people}</p>
<p>์ตœ์ข… ์ ์ˆ˜: {result}</p>
</div>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion app/(route)/indicators/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import FormS from './_components/form/form.module.css'
import S from './indicators.module.css'

//* ํˆฌ์ž ์ง€ํ‘œ ์ž…๋ ฅ ํŽ˜์ด์ง€์ž…๋‹ˆ๋‹ค.
//TODO: title์— ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ–ˆ๋˜ ์š”์†Œ๋“ค์ด ๋ณด์—ฌ์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
function Indicators() {
const router = useRouter()
const [inputValue, setInputValue] = useRecoilState(totalinputValueAtom)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@

.item_name_input {
width: 200px;
margin-right: 16px;
margin-right: 12px;
}
.score_container {
margin-right: 16px;
display: flex;
flex-direction: row;
align-items: center;
}
.score_container > span {
font-size: 14px;
font-weight: bold;
font-weight: 700;
margin-right: 4px;
}
.item_score_input {
width: 40px;
width: 35px;
margin-right: 4px;
}
.delete_btn {
Expand All @@ -45,10 +48,18 @@
text-align: center;
}

.columnWrapper {
.btnWrapper {
display: flex;
flex-direction: column;
flex-direction: row;
align-items: center;
margin: 15px 0;
}

.rowWrapper {
display: flex;
flex-direction: row;
align-items: center;
height: auto;
gap: 3px;
}

Expand All @@ -60,5 +71,5 @@

.checkbox {
accent-color: var(--purple-700);
margin-bottom: 20px;
margin-right: 10px;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
'use client'

import { ActiveInvestmentItemType, investmentItemAtom } from '@/app/_store/atom'
import {
ActiveInvestmentItemType,
investmentItemAtom,
selectedItemAtom,
} from '@/app/_store/atom'
import cn from 'classnames'
import { ChangeEvent, useState } from 'react'
import { useRecoilState } from 'recoil'
Expand All @@ -22,10 +26,14 @@ function ActiveInvestmentItem({
onSelect,
}: ActiveInvestmentItemProps) {
const [investmentItem, setInvestmentItem] = useRecoilState(investmentItemAtom)
const [, setSelectedItem] = useRecoilState(selectedItemAtom)
const [itemName, setItemName] = useState(item?.name ?? '')
const [itemScore, setItemScore] = useState<number | undefined>(
item?.score ?? undefined,
)
const [itemPeople, setItemPeople] = useState<number | undefined>(
item?.people ?? undefined,
)

const isChecked = selectedIndex === index

Expand All @@ -34,6 +42,12 @@ function ActiveInvestmentItem({
const selectedInvestmentItem = investmentItem[index]
setItemName(selectedInvestmentItem.name)
setItemScore(selectedInvestmentItem?.score ?? undefined)

setSelectedItem({
name: selectedInvestmentItem.name,
score: selectedInvestmentItem.score,
people: selectedInvestmentItem.people,
})
}

const handleDeleteItem = () => {
Expand Down Expand Up @@ -75,6 +89,18 @@ function ActiveInvestmentItem({
)
}

const handleChangePeopleInput = (e: ChangeEvent<HTMLInputElement>) => {
const value = parseInt(e.target.value)
setItemPeople(isNaN(value) ? undefined : value)
setInvestmentItem((prev) =>
prev.map((investmentItem) =>
investmentItem.id === item.id
? { ...item, people: value }
: investmentItem,
),
)
}

return (
<>
<div className={S.item_container}>
Expand All @@ -93,9 +119,24 @@ function ActiveInvestmentItem({
onChange={(e) => handleChangeScoreInput(e)}
/>
<span>์ </span>
<input
className={cn(S.item_score_input, S.input)}
type="number"
value={itemPeople ?? ''}
onChange={(e) => handleChangePeopleInput(e)}
/>
<span>๋ช…</span>
</div>
</div>
<div className={S.columnWrapper}>
</div>
<div className={S.btnWrapper}>
<input
type="checkbox"
className={S.checkbox}
checked={isChecked}
onChange={handleCheckboxChange}
/>
<div className={S.rowWrapper}>
<button
type="button"
className={S.delete_btn}
Expand All @@ -106,12 +147,6 @@ function ActiveInvestmentItem({
<ItemAddBtn />
</div>
</div>
<input
type="checkbox"
className={S.checkbox}
checked={isChecked}
onChange={handleCheckboxChange}
/>
</>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function ItemAddBtn() {
id: new Date().toISOString(),
name: '',
score: null,
people: null,
}
setInvestmentItem((prev) => [...prev, newItem])
}
Expand Down
11 changes: 8 additions & 3 deletions app/_store/atom.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { atom } from 'recoil'

export interface ActiveInvestmentItemType {
id: string
id?: string
name: string
score: number | null
people: number | null
}

// type ActiveType = Omit<ActiveInvestmentItemType, 'id'>
// ์‹œ์˜จ ๊ทธ๋Š” ์‹ ์ด์•ผ...
// ๊ณ ์˜ค๊ธ‰ ํƒ€์ž… ์Šคํฌ๋ฆฝํŠธ,,,

export const selectedItemAtom = atom<ActiveInvestmentItemType | null>({
key: 'selectedItemAtom',
default: null,
})

export const totalinputValueAtom = atom({
key: 'totalinputValueAtom',
Expand All @@ -22,6 +26,7 @@ export const investmentItemAtom = atom<ActiveInvestmentItemType[]>({
id: new Date().toISOString(),
name: '',
score: null,
people: null,
},
],
})

0 comments on commit 44bdf5e

Please sign in to comment.