Skip to content

Commit

Permalink
refactor: type 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
nim-od committed Aug 15, 2024
1 parent 443aa9a commit f59ef9b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/user/src/hooks/socket/useRacingSocket.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RACING_SOCKET_ENDPOINTS } from '@softeer/common/constants';
import { Category } from '@softeer/common/types';
import type { SocketSubscribeCallbackType } from '@softeer/common/utils';
import { useCallback, useEffect, useMemo, useState } from 'react';
import useRacingRankStorage from 'src/hooks/storage/useRacingRankStorage.ts';
import socketClient from 'src/services/socket.ts';
Expand Down Expand Up @@ -49,17 +50,23 @@ export default function useRacingSocket() {
}
}, [newRankStatus, ranks, storeRank]);

const handleStatusChange = useCallback((data: unknown) => {
const handleStatusChange: SocketSubscribeCallbackType = useCallback((data: unknown) => {
const newVoteStatus = parseSocketVoteData(data as SocketData);
setVotes(newVoteStatus);
}, []);

const handleCarFullyCharged = (category: Category) => {
const chargeData = { [categoryToSocketCategory[category]]: 1 };

const completeChargeData = Object.keys(categoryToSocketCategory).reduce((acc, key) => {
const socketCategory = categoryToSocketCategory[key as Category];
acc[socketCategory] = chargeData[socketCategory] ?? 0;
return acc;
}, {} as Record<SocketCategory, number>);

socketClient.sendMessages({
destination: RACING_SOCKET_ENDPOINTS.PUBLISH,
body: chargeData,
body: completeChargeData,
});
};

Expand Down

0 comments on commit f59ef9b

Please sign in to comment.