-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from boostcampwm2023/refactor/socket_context
refactor : Landing 페이지 데이터 구조 및 렌더링 최적화 리펙토링
- Loading branch information
Showing
17 changed files
with
308 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 24 additions & 17 deletions
41
frontend/src/components/landing/project/LandingProject.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
import { LandingProjectDTO } from "../../../types/DTO/landingDTO"; | ||
import { Socket } from "socket.io-client"; | ||
import formatDate from "../../../utils/formatDate"; | ||
import LandingProjectLink from "./LandingProjectLink"; | ||
import { useOutletContext } from "react-router-dom"; | ||
|
||
import useLandingProjectSocket from "../../../hooks/common/landing/useLandingProjectSocket"; | ||
|
||
interface LandingProjectProps { | ||
project: LandingProjectDTO; | ||
projectId: string; | ||
} | ||
|
||
const LandingProject = ({ project, projectId }: LandingProjectProps) => ( | ||
<div className="flex flex-col justify-between w-full p-6 rounded-lg shadow-box"> | ||
<div className="flex items-baseline justify-between font-bold text-middle-green"> | ||
<p className="text-xl">| {project.title}</p> | ||
<p className="text-xs"> | ||
{project.createdAt && formatDate(project.createdAt)} | ||
</p> | ||
</div> | ||
<div className="text-xs">{project.subject}</div> | ||
<div className="flex justify-between"> | ||
<LandingProjectLink projectId={projectId} type="BACKLOG" /> | ||
<LandingProjectLink projectId={projectId} type="SPRINT" /> | ||
<LandingProjectLink projectId={projectId} type="SETTINGS" /> | ||
const LandingProject = ({ projectId }: LandingProjectProps) => { | ||
const { socket }: { socket: Socket } = useOutletContext(); | ||
const { project } = useLandingProjectSocket(socket); | ||
|
||
return ( | ||
<div className="flex flex-col justify-between w-full p-6 rounded-lg shadow-box"> | ||
<div className="flex items-baseline justify-between font-bold text-middle-green"> | ||
<p className="text-xl">| {project.title}</p> | ||
<p className="text-xs"> | ||
{project.createdAt && formatDate(project.createdAt)} | ||
</p> | ||
</div> | ||
<div className="text-xs">{project.subject}</div> | ||
<div className="flex justify-between"> | ||
<LandingProjectLink projectId={projectId} type="BACKLOG" /> | ||
<LandingProjectLink projectId={projectId} type="SPRINT" /> | ||
<LandingProjectLink projectId={projectId} type="SETTINGS" /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
); | ||
}; | ||
|
||
export default LandingProject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useEffect, useState } from "react"; | ||
import { Socket } from "socket.io-client"; | ||
import { LandingDTO, LandingLinkDTO } from "../../../types/DTO/landingDTO"; | ||
import { | ||
LandingSocketData, | ||
LandingSocketDomain, | ||
} from "../../../types/common/landing"; | ||
|
||
const useLandingLinkSocket = (socket: Socket) => { | ||
const [link, setLink] = useState<LandingLinkDTO[]>([]); | ||
const handleInitEvent = (content: LandingDTO) => { | ||
const { link } = content as LandingDTO; | ||
setLink(link); | ||
}; | ||
|
||
const handleOnLanding = ({ domain, content }: LandingSocketData) => { | ||
if (domain !== LandingSocketDomain.INIT) return; | ||
handleInitEvent(content); | ||
}; | ||
|
||
useEffect(() => { | ||
socket.on("landing", handleOnLanding); | ||
|
||
return () => { | ||
socket.off("landing"); | ||
}; | ||
}); | ||
|
||
return { link }; | ||
}; | ||
|
||
export default useLandingLinkSocket; |
Oops, something went wrong.