Skip to content

Commit

Permalink
refactor: useLandingSocket에서 더 이상 사용하지 않는 부분 삭
Browse files Browse the repository at this point in the history
  • Loading branch information
surinkwon committed Jun 18, 2024
1 parent 6a3dad7 commit f9115a4
Showing 1 changed file with 3 additions and 47 deletions.
50 changes: 3 additions & 47 deletions frontend/src/hooks/common/socket/useLandingSocket.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,27 @@
import { Socket } from "socket.io-client";
import { useEffect, useState } from "react";
import {
LandingDTO,
LandingLinkDTO,
LandingMemoDTO,
LandingProjectDTO,
LandingSprintDTO,
} from "../../../types/DTO/landingDTO";
import { LandingDTO, LandingProjectDTO } from "../../../types/DTO/landingDTO";
import { DEFAULT_VALUE } from "../../../constants/landing";
import {
LandingSocketData,
LandingSocketDomain,
LandingSocketMemoAction,
} from "../../../types/common/landing";

const useLandingSocket = (socket: Socket) => {
const [project, setProject] = useState<LandingProjectDTO>(
DEFAULT_VALUE.PROJECT
);
const [sprint, setSprint] = useState<LandingSprintDTO | null>(null);
const [memoList, setMemoList] = useState<LandingMemoDTO[]>([]);
const [link, setLink] = useState<LandingLinkDTO[]>([]);

const handleInitEvent = (content: LandingDTO) => {
const { project, sprint, memoList, link } = content as LandingDTO;
const { project } = content as LandingDTO;
setProject(project);
setSprint(sprint);
setMemoList(memoList);
setLink(link);
};

const handleMemoEvent = (
action: LandingSocketMemoAction,
content: LandingMemoDTO
) => {
switch (action) {
case LandingSocketMemoAction.CREATE:
setMemoList((memoList: LandingMemoDTO[]) => [content, ...memoList]);
break;
case LandingSocketMemoAction.DELETE:
setMemoList((memoList: LandingMemoDTO[]) =>
memoList.filter((memo: LandingMemoDTO) => memo.id !== content.id)
);
break;
case LandingSocketMemoAction.COLOR_UPDATE:
setMemoList((memoList: LandingMemoDTO[]) =>
memoList.map((memo: LandingMemoDTO) => {
if (memo.id !== content.id) {
return memo;
}
return { ...memo, color: content.color };
})
);
}
};

const handleOnLanding = ({ domain, action, content }: LandingSocketData) => {
const handleOnLanding = ({ domain, content }: LandingSocketData) => {
switch (domain) {
case LandingSocketDomain.INIT:
handleInitEvent(content);
break;
case LandingSocketDomain.MEMO:
handleMemoEvent(action, content);
break;
}
};

Expand All @@ -77,9 +36,6 @@ const useLandingSocket = (socket: Socket) => {

return {
project,
sprint,
memoList,
link,
};
};

Expand Down

0 comments on commit f9115a4

Please sign in to comment.