REFACTOR: VideoPage Adjustments

This commit is contained in:
Chris-1010
2025-02-16 22:51:52 +00:00
parent b3de7ba238
commit 9f59810833
2 changed files with 120 additions and 112 deletions

View File

@@ -15,11 +15,13 @@ interface ChatMessage {
interface ChatPanelProps { interface ChatPanelProps {
streamId: number; streamId: number;
onViewerCountChange?: (count: number) => void; onViewerCountChange?: (count: number) => void;
onInputFocus: (focused: boolean) => void;
} }
const ChatPanel: React.FC<ChatPanelProps> = ({ const ChatPanel: React.FC<ChatPanelProps> = ({
streamId, streamId,
onViewerCountChange, onViewerCountChange,
onInputFocus,
}) => { }) => {
const { isLoggedIn, username } = useAuth(); const { isLoggedIn, username } = useAuth();
const { showAuthModal, setShowAuthModal } = useAuthModal(); const { showAuthModal, setShowAuthModal } = useAuthModal();
@@ -114,17 +116,19 @@ const ChatPanel: React.FC<ChatPanelProps> = ({
return ( return (
<div <div
id="chat-panel" id="chat-panel"
className="max-w-[30vw] h-full flex flex-col rounded-lg p-4" className="max-w-[30vw] h-[83vh] flex flex-col rounded-lg p-[2vh] justify-between"
style={{ gridArea: "1 / 2 / 3 / 3" }} style={{ gridArea: "1 / 2 / 3 / 3" }}
> >
<h2 className="text-xl font-bold mb-4 text-white text-center"> {/* Chat Header */}
<h2 className="text-xl font-bold mb-4 text-white text-center flex-none">
Stream Chat Stream Chat
</h2> </h2>
{/* Message List */}
<div <div
ref={chatContainerRef} ref={chatContainerRef}
id="chat-message-list" id="chat-message-list"
className="flex-grow w-full max-h-[30em] overflow-y-auto mb-4 space-y-2 rounded-md" className="w-full h-full overflow-y-auto mb-4 space-y-2 rounded-md"
> >
{messages.map((msg, index) => ( {messages.map((msg, index) => (
<div <div
@@ -141,7 +145,7 @@ const ChatPanel: React.FC<ChatPanelProps> = ({
/> />
</div> </div>
<div className="flex-grow"> <div className="flex-grow overflow-hidden">
<div className="flex items-center space-x-0.5em"> <div className="flex items-center space-x-0.5em">
{/* Username */} {/* Username */}
<span <span
@@ -155,7 +159,9 @@ const ChatPanel: React.FC<ChatPanelProps> = ({
</span> </span>
</div> </div>
{/* Message content */} {/* Message content */}
<div className="text-[0.9em] mt-0.5em">{msg.message}</div> <div className="w-full text-[0.9em] mt-0.5em flex flex-col overflow-hidden">
{msg.message}
</div>
</div> </div>
{/* Time sent */} {/* Time sent */}
@@ -166,7 +172,8 @@ const ChatPanel: React.FC<ChatPanelProps> = ({
))} ))}
</div> </div>
<div className="flex justify-center gap-2"> {/* Input area */}
<div className="flex-none flex justify-center gap-2">
{isLoggedIn ? ( {isLoggedIn ? (
<> <>
<Input <Input
@@ -176,7 +183,10 @@ const ChatPanel: React.FC<ChatPanelProps> = ({
onKeyDown={handleKeyPress} onKeyDown={handleKeyPress}
placeholder="Type a message..." placeholder="Type a message..."
extraClasses="flex-grow w-full focus:w-full" extraClasses="flex-grow w-full focus:w-full"
maxLength={200}
onClick={() => !isLoggedIn && setShowAuthModal(true)} onClick={() => !isLoggedIn && setShowAuthModal(true)}
onFocus={() => onInputFocus(true)}
onBlur={() => onInputFocus(false)}
/> />
<button <button

View File

@@ -28,6 +28,7 @@ const VideoPage: React.FC<VideoPageProps> = ({ streamerId }) => {
const [streamData, setStreamData] = useState<StreamDataProps>(); const [streamData, setStreamData] = useState<StreamDataProps>();
const [viewerCount, setViewerCount] = useState(0); const [viewerCount, setViewerCount] = useState(0);
const [isChatOpen, setIsChatOpen] = useState(true); const [isChatOpen, setIsChatOpen] = useState(true);
const [isInputFocused, setIsInputFocused] = useState(false);
const { isFollowing, checkFollowStatus, followUser, unfollowUser } = const { isFollowing, checkFollowStatus, followUser, unfollowUser } =
useFollow(); useFollow();
const { showAuthModal, setShowAuthModal } = useAuthModal(); const { showAuthModal, setShowAuthModal } = useAuthModal();
@@ -78,7 +79,7 @@ const VideoPage: React.FC<VideoPageProps> = ({ streamerId }) => {
// Keyboard shortcut to toggle chat // Keyboard shortcut to toggle chat
useEffect(() => { useEffect(() => {
const handleKeyPress = (e: KeyboardEvent) => { const handleKeyPress = (e: KeyboardEvent) => {
if (e.key === "c") { if (e.key === "c" && !isInputFocused) {
setIsChatOpen((prev) => !prev); setIsChatOpen((prev) => !prev);
} }
}; };
@@ -88,7 +89,7 @@ const VideoPage: React.FC<VideoPageProps> = ({ streamerId }) => {
return () => { return () => {
document.removeEventListener("keydown", handleKeyPress); document.removeEventListener("keydown", handleKeyPress);
}; };
}, []); }, [isInputFocused]);
const toggleChat = () => { const toggleChat = () => {
setIsChatOpen((prev) => !prev); setIsChatOpen((prev) => !prev);
@@ -96,18 +97,16 @@ const VideoPage: React.FC<VideoPageProps> = ({ streamerId }) => {
return ( return (
<SocketProvider> <SocketProvider>
<div id="videoPage" className="w-full"> <div id="videoPage" className="w-full h-full bg-gray-900 flex flex-col">
<Navbar /> <Navbar />
<div <div
id="container" id="container"
className={`grid ${ className={`grid ${
isChatOpen ? "w-[100vw]" : "w-[125vw]" isChatOpen ? "w-[100vw]" : "w-[125vw]"
} grid-rows-[auto_1fr] bg-gray-900 h-full grid-cols-[auto_25vw] transition-all`} } flex-grow bg-gray-900 h-full grid-cols-[auto_25vw] transition-all`}
> >
<div className="relative"> <VideoPlayer />
<VideoPlayer streamId={streamerId} />
</div>
<ToggleButton <ToggleButton
onClick={toggleChat} onClick={toggleChat}
@@ -124,19 +123,21 @@ const VideoPage: React.FC<VideoPageProps> = ({ streamerId }) => {
<ChatPanel <ChatPanel
streamId={streamerId} streamId={streamerId}
onViewerCountChange={(count: number) => setViewerCount(count)} onViewerCountChange={(count: number) => setViewerCount(count)}
onInputFocus={setIsInputFocused}
/> />
</div>
{/* Stream Data */} {/* Stream Data */}
<div <div
id="stream-info" id="stream-info"
className="flex flex-row items-center justify-between gap-4 p-4 bg-[#18181b] text-white text-lg rounded-md shadow-lg" className="flex flex-row items-center justify-evenly gap-4 p-4 bg-[#18181b] text-white text-lg rounded-md shadow-lg"
style={{ gridArea: "2 / 1 / 3 / 3" }}
> >
{/* Streamer Icon */} {/* Streamer Icon */}
<div className="flex flex-col items-center mb-[1em]"> <div className="flex flex-col items-center mb-[1em]">
<img <img
src="/images/monkey.png" src="/images/monkey.png"
alt="streamer" alt="streamer profile picture"
className="w-[3em] h-[3em] rounded-full border-[0.15em] border-purple-500" className="w-[3em] h-[3em] rounded-full border-[0.15em] border-purple-500 cursor-pointer"
onClick={() => navigate(`/user/${streamerName}`)} onClick={() => navigate(`/user/${streamerName}`)}
/> />
<button <button
@@ -148,8 +149,8 @@ const VideoPage: React.FC<VideoPageProps> = ({ streamerId }) => {
</div> </div>
{/* Stream Title */} {/* Stream Title */}
<div className="flex flex-col items-start flex-grow"> <div className="flex flex-col items-start min-w-[45%] max-w-[60%] mx-12 text-pretty">
<h1 className="text-[0.75em] lg:text-[0.85em] xl:text-[1em] font-bold"> <h1 className="text-[1rem] lg:text-[1.25em] xl:text-[1.5em] font-bold">
{streamData ? streamData.streamTitle : "Loading..."} {streamData ? streamData.streamTitle : "Loading..."}
</h1> </h1>
<span className="text-[0.75em] lg:text-[0.85em] xl:text-[1em] text-gray-400"> <span className="text-[0.75em] lg:text-[0.85em] xl:text-[1em] text-gray-400">
@@ -225,10 +226,7 @@ const VideoPage: React.FC<VideoPageProps> = ({ streamerId }) => {
/> />
)} )}
{showReturn && <Return />} {showReturn && <Return />}
{showAuthModal && ( {showAuthModal && <AuthModal onClose={() => setShowAuthModal(false)} />}
<AuthModal onClose={() => setShowAuthModal(false)} />
)}
</div>
</div> </div>
</SocketProvider> </SocketProvider>
); );