-
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 branch 'feat/chat-socket-file'
- Loading branch information
Showing
12 changed files
with
251 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
export type MessageType = "message" | "file" | "account"; | ||
export interface AppMessage { | ||
roomId: number; | ||
sendUserUid: string; | ||
messageType: MessageType; | ||
message: string; | ||
createdAt: string; | ||
} |
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,78 @@ | ||
import { Button, Modal, Skeleton, css } from "@mui/material"; | ||
import { ReactElement, useState } from "react"; | ||
interface ImageOrVideoProps { | ||
src: string; | ||
className?: string; | ||
} | ||
export const ImageOrVideo = ({ | ||
src, | ||
className, | ||
}: ImageOrVideoProps): ReactElement => { | ||
const getFileType = (filePath: string): string => { | ||
// 확장자를 추출합니다 | ||
const extension = filePath.split(".").pop()?.toLowerCase() ?? ""; | ||
|
||
// 이미지 확장자 목록 | ||
const imageExtensions = ["jpg", "jpeg", "png", "gif", "bmp", "svg", "webp"]; | ||
// 비디오 확장자 목록 | ||
const videoExtensions = ["mp4", "mov", "wmv", "flv", "avi", "mkv", "webm"]; | ||
|
||
// 확장자에 따라 파일 타입을 결정합니다 | ||
if (imageExtensions.includes(extension)) { | ||
return "image"; | ||
} else if (videoExtensions.includes(extension)) { | ||
return "video"; | ||
} else { | ||
return "unknown"; // 알 수 없는 파일 타입 | ||
} | ||
}; | ||
|
||
const [modalOpen, setModalOpen] = useState(false); | ||
const fileType = getFileType(src); | ||
return ( | ||
<> | ||
<Modal | ||
open={modalOpen} | ||
onClose={() => setModalOpen(false)} | ||
css={styles.modal} | ||
> | ||
<> | ||
{fileType == "image" && <img src={src} css={styles.modalImage} />} | ||
{fileType == "video" && ( | ||
<video src={src} css={styles.modalImage} controls /> | ||
)} | ||
{fileType == "unknown" && ( | ||
<Skeleton variant="rectangular" css={styles.modalImage} /> | ||
)} | ||
</> | ||
</Modal> | ||
<Button onClick={() => setModalOpen(true)}> | ||
{fileType == "image" && <img src={src} className={className} />} | ||
{fileType == "video" && ( | ||
<video | ||
src={src} | ||
className={className} | ||
controls | ||
controlsList="nofullscreen" | ||
/> | ||
)} | ||
{fileType == "unknown" && ( | ||
<Skeleton variant="rectangular" className={className} /> | ||
)} | ||
</Button> | ||
</> | ||
); | ||
}; | ||
|
||
const styles = { | ||
modal: css` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding: 64px; | ||
`, | ||
modalImage: css` | ||
width: 100%; | ||
object-fit: contain; | ||
`, | ||
}; |
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
Oops, something went wrong.