Skip to content

Commit

Permalink
✨ feat: 거래채결 현황 API 연결 #61
Browse files Browse the repository at this point in the history
  • Loading branch information
dannysir committed Nov 13, 2024
1 parent 0323d6b commit 2996bc3
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 23 deletions.
4 changes: 2 additions & 2 deletions FE/src/components/Search/SearchCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export default function SearchCard({ data }: SearchCardProps) {
>
<div className={'my-2 flex w-full items-center justify-between px-4'}>
<div className={'flex-1 flex-col'}>
<p className='text-left font-medium text-gray-900'>
<div className='text-left font-medium text-gray-900'>
<SearchCardHighLight text={name} highlight={searchInput} />
</p>
</div>
<div className={'text-left text-xs font-normal text-gray-500'}>
{code}
</div>
Expand Down
7 changes: 7 additions & 0 deletions FE/src/components/StocksDetail/PriceDataType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type PriceDataType = {
stck_cntg_hour: string;
stck_prpr: 'string';
prdy_vrss_sign: 'string';
cntg_vol: 'string';
prdy_ctrt: 'string';
};
40 changes: 29 additions & 11 deletions FE/src/components/StocksDetail/PriceSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,31 @@ import { useEffect, useRef, useState } from 'react';
import PriceTableColumn from './PriceTableColumn.tsx';
import PriceTableLiveCard from './PriceTableLiveCard.tsx';
import PriceTableDayCard from './PriceTableDayCard.tsx';
import { useParams } from 'react-router-dom';
import { useQuery } from '@tanstack/react-query';
import { PriceDataType } from './PriceDataType.ts';

export const tradeHistoryApi = async (id: string) => {

Check warning on line 9 in FE/src/components/StocksDetail/PriceSection.tsx

View workflow job for this annotation

GitHub Actions / FE-test-and-build

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components
const response = await fetch(
`http://223.130.151.42:3000/api/stocks/${id}/trade-history`,
);
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
};

export default function PriceSection() {
const [buttonFlag, setButtonFlag] = useState(true);
const indicatorRef = useRef<HTMLDivElement>(null);
const buttonRefs = useRef<(HTMLButtonElement | null)[]>([]);
const { id } = useParams();

const { data } = useQuery({
queryKey: ['detail', id],
queryFn: () => tradeHistoryApi(id as string),
enabled: !!id,
});

useEffect(() => {
const tmpIndex = buttonFlag ? 0 : 1;
Expand Down Expand Up @@ -44,11 +64,11 @@ export default function PriceSection() {
style={{ height: '28px' }}
/>
<button
className={`${
className={`z-7 relative w-full rounded-lg px-4 py-1 ${
buttonFlag
? 'text-juga-grayscale-black'
: 'text-juga-grayscale-400'
} z-7 relative w-full rounded-lg px-4 py-1`}
}`}
onClick={() => setButtonFlag(true)}
ref={(el) => (buttonRefs.current[0] = el)}
>
Expand All @@ -71,15 +91,13 @@ export default function PriceSection() {
<table className={'w-full table-fixed text-xs font-normal'}>
<PriceTableColumn viewMode={buttonFlag} />
<tbody>
{Array(30)
.fill(null)
.map((_, index) =>
buttonFlag ? (
<PriceTableLiveCard key={index} />
) : (
<PriceTableDayCard key={index} />
),
)}
{data?.map((eachData: PriceDataType, index: number) =>
buttonFlag ? (
<PriceTableLiveCard key={index} data={eachData} />
) : (
<PriceTableDayCard key={index} />
),
)}
</tbody>
</table>
</div>
Expand Down
2 changes: 1 addition & 1 deletion FE/src/components/StocksDetail/PriceTableColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function PriceTableColumn({ viewMode }: Props) {
<th className={'px-4 py-1 text-left font-medium'}>채결가</th>
<th className={'px-4 py-1 text-right font-medium'}>채결량(주)</th>
<th className={'px-4 py-1 text-right font-medium'}>등락률</th>
<th className={'px-4 py-1 text-right font-medium'}>거래량(주)</th>
{/*<th className={'px-4 py-1 text-right font-medium'}>거래량(주)</th>*/}
<th className={'px-4 py-1 text-right font-medium'}>시간</th>
</tr>
</thead>
Expand Down
31 changes: 22 additions & 9 deletions FE/src/components/StocksDetail/PriceTableLiveCard.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
export default function PriceTableLiveCard() {
import { PriceDataType } from './PriceDataType.ts';

type PriceTableLiveCardProps = {
data: PriceDataType;
};
export default function PriceTableLiveCard({ data }: PriceTableLiveCardProps) {
const percent = Number(data.prdy_ctrt);
const color = percent > 0 ? 'text-juga-red-60' : 'text-juga-blue-50';
function formatTime(time: string) {
const hour = time.slice(0, 2);
const min = time.slice(2, 4);
const sec = time.slice(4, 6);
return `${hour}.${min}.${sec}`;
}
return (
<tr className={'h-[30px] hover:bg-juga-grayscale-50'}>
<td className={'px-4 py-1 text-start'}>채결가</td>
<td className={'px-4 py-1 text-right'}>채결량 갯수</td>
<td
className={`px-4 py-1 text-right ${Math.round(Math.random() * 10) % 2 ? 'text-juga-blue-50' : 'text-juga-red-60'}`}
>
등략률 퍼센트
<td className={'px-4 py-1 text-start'}>{data.stck_prpr}</td>
<td className={'px-4 py-1 text-right'}>{data.cntg_vol}</td>
<td className={`px-4 py-1 text-right ${color}`}>
{percent > 0 ? `+${percent}` : `${percent}`}
</td>
{/*<td className={'px-4 py-1 text-right'}>거래량 갯수</td>*/}
<td className={'px-4 py-1 text-right'}>
{formatTime(data.stck_cntg_hour)}
</td>
<td className={'px-4 py-1 text-right'}>거래량 갯수</td>
<td className={'px-4 py-1 text-right'}>시간</td>
</tr>
);
}

0 comments on commit 2996bc3

Please sign in to comment.