Skip to content

Commit

Permalink
๐Ÿ”ง fix: ์†Œ์ผ“ ์ด๋ฒคํŠธ off ๋กœ์ง ์ถ”๊ฐ€ & ์ž์ž˜ํ•œ ๋ฒ„๊ทธ ์ˆ˜์ •
Browse files Browse the repository at this point in the history
์†Œ์ผ“ off๋กœ ์ด๋ฒคํŠธ ๊ตฌ๋… ํ•ด์ง€ ๋กœ์ง ์ถ”๊ฐ€.
์˜คํƒ€ ์ˆ˜์ •.
formatTime ๊ด€๋ จ ๋ฒ„๊ทธ ์ˆ˜์ •.
  • Loading branch information
dannysir committed Nov 27, 2024
1 parent ebbbdd5 commit d018fce
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 42 deletions.
11 changes: 6 additions & 5 deletions FE/src/components/StocksDetail/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { useEffect, useState } from 'react';
import { unsbscribe } from 'service/stocks';
import { unsubscribe } from 'service/stocks';
import { StockDetailType } from 'types';
import { stringToLocaleString } from 'utils/common';
import { socket } from 'utils/socket';

type StocksDeatailHeaderProps = {
type StocksDetailHeaderProps = {
code: string;
data: StockDetailType;
};

export default function Header({ code, data }: StocksDeatailHeaderProps) {
export default function Header({ code, data }: StocksDetailHeaderProps) {
const {
hts_kor_isnm,
stck_prpr,
Expand Down Expand Up @@ -42,7 +42,8 @@ export default function Header({ code, data }: StocksDeatailHeaderProps) {
socket.on(`detail/${code}`, handleSocketData);

return () => {
unsbscribe(code);
socket.off(`detail/${code}`, handleSocketData);
unsubscribe(code);
};
}, [code]);

Expand All @@ -64,7 +65,7 @@ export default function Header({ code, data }: StocksDeatailHeaderProps) {
currPrdyVrssSign === '3' ? '' : currPrdyVrssSign < '3' ? '+' : '-';

return (
<div className='flex items-center justify-between w-full h-16 px-2'>
<div className='flex h-16 w-full items-center justify-between px-2'>
<div className='flex flex-col font-semibold'>
<div className='flex gap-2 text-sm'>
<h2>{hts_kor_isnm}</h2>
Expand Down
44 changes: 9 additions & 35 deletions FE/src/components/StocksDetail/PriceSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useParams } from 'react-router-dom';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { DailyPriceDataType, PriceDataType } from './PriceDataType.ts';
import { getTradeHistory } from 'service/getTradeHistory.ts';
import { createSSEConnection } from './PriceSectionSseHook.ts';
import { socket } from 'utils/socket.ts';

export default function PriceSection() {
const { id } = useParams();
Expand Down Expand Up @@ -34,44 +34,18 @@ export default function PriceSection() {
[id, buttonFlag],

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

View workflow job for this annotation

GitHub Actions / FE-test-and-build

React Hook useCallback has a missing dependency: 'queryClient'. Either include it or remove the dependency array

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

View workflow job for this annotation

GitHub Actions / FE-test-and-build

React Hook useCallback has a missing dependency: 'queryClient'. Either include it or remove the dependency array

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

View workflow job for this annotation

GitHub Actions / build-and-deploy (fe, FE, 5173, juga-docker-fe, ENV_FE)

React Hook useCallback has a missing dependency: 'queryClient'. Either include it or remove the dependency array
);

// useEffect(() => {
// // ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ ๋“ฑ๋ก
// const handleTradeHistory = (chartData: PriceDataType) => {
// addData(chartData);
// };
//
// // ์†Œ์ผ“ ์ด๋ฒคํŠธ ๊ตฌ๋…
// socket.on(`trade-history/${id}`, handleTradeHistory);
//
// return () => {
// console.log('socket unSub!');
// socket.off(`trade-history/${id}`, handleTradeHistory);
//
// fetch(`/api/stocks/trade-history/${id}/unsubscribe`, {
// method: 'GET',
// headers: {
// 'Content-Type': 'application/json',
// },
// }).catch((error) => {
// console.error('Failed to unsubscribe:', error);
// });
// };
// }, [id, addData]);

useEffect(() => {
if (!buttonFlag) return;
const eventSource = createSSEConnection(
`${import.meta.env.VITE_API_URL}/stocks/trade-history/${id}/today-sse`,
addData,
);
// ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ ๋“ฑ๋ก
const handleTradeHistory = (chartData: PriceDataType) => {
addData(chartData);
};

socket.on(`trade-history/${id}`, handleTradeHistory);

return () => {
if (eventSource) {
console.log('SSE connection close');
eventSource.close();
}
socket.off(`trade-history/${id}`, handleTradeHistory);
};
}, [buttonFlag, id, addData]);
}, [id, addData]);

useEffect(() => {
const tmpIndex = buttonFlag ? 0 : 1;
Expand Down
2 changes: 1 addition & 1 deletion FE/src/service/stocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function getStocksChartDataByCode(
}).then((res) => res.json());
}

export async function unsbscribe(code: string) {
export async function unsubscribe(code: string) {
return fetch(
`${import.meta.env.VITE_API_URL}/stocks/trade-history/${code}/unsubscribe`,
{
Expand Down
2 changes: 1 addition & 1 deletion FE/src/utils/formatTime.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function formatTime(time: string) {
if (!time.length) return '----.--.--';
if (!time || !time.length) return '----.--.--';
const year = time.slice(0, 4);
const mon = time.slice(4, 6);
const day = time.slice(6, 8);
Expand Down

0 comments on commit d018fce

Please sign in to comment.