Skip to content

Commit

Permalink
chatResponsive
Browse files Browse the repository at this point in the history
  • Loading branch information
Kojimena committed Nov 5, 2023
1 parent 4298a7f commit 771af04
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 13 deletions.
15 changes: 11 additions & 4 deletions uniEmpleos/src/components/Chat/Chat.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
width: auto;
border-radius: 10px;
/* Sombras más pronunciadas */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
box-shadow: 0 4px 8px #94bd0f;
animation: chatAnimation 0.5s ease-in-out;
}

Expand All @@ -24,7 +24,7 @@
}

.button {
background-color: #e1dede;
background-color: #fff;
border: none;
border-radius: 5px;
padding: 5px;
Expand All @@ -39,11 +39,11 @@

.button:focus {
outline: none;
background-color: #d1cece;
background-color: #94bd0f75;
}

.button:hover {
background-color: #d1cece;
background-color: #94bd0f75;
}

.pfp {
Expand Down Expand Up @@ -83,4 +83,11 @@
color: #252525;
font-weight: normal;
text-align: start;
}


@media (max-width: 768px) {
.lastChat {
display: none;
}
}
36 changes: 29 additions & 7 deletions uniEmpleos/src/pages/ChatPage/ChatPage.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable camelcase */
/* eslint-disable react/prop-types */
import React, { useEffect, useState, useRef } from "react"
import { FaUserFriends } from "react-icons/fa"
import { useStoreon } from "storeon/react"
import style from "./ChatPage.module.css"
import { Header } from "../../components/Header/Header"
Expand Down Expand Up @@ -79,11 +80,6 @@ const ChatPage = () => {
scrollDown()
obtainMessages()
}

const handleChat = (receptor, id) => {
setCurrentChat(receptor)
setIdCurrentChat(id)
}

const handleInputChange = (e) => {
setTextMessage(e.target.value)
Expand All @@ -105,6 +101,20 @@ const ChatPage = () => {
return () => clearInterval(intervalListadeChats)
}, [])

// Estado para controlar la visibilidad del contenedor de chats
const [showChats, setShowChats] = useState(false)

// Función para alternar la visibilidad del contenedor de chats
const toggleChats = () => {
setShowChats(!showChats)
}

const handleChat = (receptor, id) => {
setCurrentChat(receptor)
setIdCurrentChat(id)
setShowChats(false)
}

return (
<div className={style.container}>
<Header userperson="student" />
Expand All @@ -114,8 +124,15 @@ const ChatPage = () => {
style={typePopUp}
close={() => setWarning(false)}
/>
<button type="button" className={style.menuButton} onClick={toggleChats}>
<FaUserFriends size={30} color="#000" />
</button>
<div className={style.generalChatContainer}>
<div className={style.chatsContainer}>
<div
className={`${style.chatsContainer} ${
showChats ? style.showChat : style.hideChat
}`}
>
{apiLastChats.data && apiLastChats.data.messages.length > 0 ? (
apiLastChats.data.messages.map((chat) =>
chat.last_message.length === 0 ? null : (
Expand All @@ -139,7 +156,12 @@ const ChatPage = () => {
<div className={style.noUsersMessage}>No hay chats recientes.</div>
)}
</div>
<div className={style.currentChatContainer} ref={chatContainerRef}>
<div
className={`${style.currentChatContainer} ${
showChats ? style.hide : style.show
}`}
ref={chatContainerRef}
>
{apiMessages.data && apiMessages.data.messages.length > 0 ? (
apiMessages.data.messages.map((message, number) => {
const side = message.id_emisor === user.id_user ? "right" : "left"
Expand Down
55 changes: 53 additions & 2 deletions uniEmpleos/src/pages/ChatPage/ChatPage.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
.chatsContainer {
display: flex;
flex-direction: column;
background-color: #f5f5f5;
background-color: #fff;
color: #fff;
width: 30%;
padding: 10px;
overflow: hidden;
overflow-y: auto;
scrollbar-width: none;
Expand Down Expand Up @@ -140,4 +141,54 @@
color: #000;
width: 100%;
height: 100%;
}
}

.show {
display: block;
}

.hide {
display: none;
}

/* Estilos para el botón de menú, solo visible en móviles */
.menuButton {
display: none;
}

/* Usa media queries para hacer que el botón de menú solo se muestre en dispositivos móviles */
@media (max-width: 768px) {
.menuButton {
display: flex;
background-color: transparent;
border: none;
cursor: pointer;
}

.currentChatContainer {
width: calc(100% - 20px);
overflow: hidden;
padding: 10px;
box-shadow: none;
background-color: #fff;
}

.showChat {
display: flex;
gap: 20px;
}

.hideChat {
display: none;
}

.chatsContainer {
width: 100%;
padding: 10px;
}

.inputContainer {
width: 90%;
padding: 10px;
}
}

0 comments on commit 771af04

Please sign in to comment.