소스 검색

Merge branch 'feature/showing_date_and_time_of_sending_message' of stefan.stamenovic/WebAPISignalRChat into development

development
Dzenis 3 년 전
부모
커밋
e0c7cc1604
5개의 변경된 파일105개의 추가작업 그리고 16개의 파일을 삭제
  1. 1
    3
      Frontend/src/components/ChatList.js
  2. 66
    8
      Frontend/src/components/ChatWindow.js
  3. 34
    0
      Frontend/src/helpers.js
  4. 4
    1
      Frontend/src/index.css
  5. 0
    4
      Frontend/src/store/chat-slice.js

+ 1
- 3
Frontend/src/components/ChatList.js 파일 보기

dispatch( dispatch(
chatActions.saveContextId({ connId: data.connId, userId: user.id }) chatActions.saveContextId({ connId: data.connId, userId: user.id })
); );
console.log("Join room", data);
setChatMessage(data); setChatMessage(data);
} }
}); });
chatActions.saveContextId({ connId: data.connId, userId: user.id }) chatActions.saveContextId({ connId: data.connId, userId: user.id })
); );
} }
console.log("Send group message", data);
setChatMessage(data); setChatMessage(data);
}); });
} }
open={showModal} open={showModal}
acceptHandler={dialogHandler} acceptHandler={dialogHandler}
/> />
<div className="p-0 h-100-auto-overflow">
<div className="p-0 h-100-auto-overflow overflow-x">
<div className="pe-4 bg-transparent w-100 mb-3 p-0 border-bottom border-light d-flex justify-content-between align-items-center"> <div className="pe-4 bg-transparent w-100 mb-3 p-0 border-bottom border-light d-flex justify-content-between align-items-center">
<h4 className="p-0 m-0 py-3 w-100 text-start ps-3 text-light bg-transparent"> <h4 className="p-0 m-0 py-3 w-100 text-start ps-3 text-light bg-transparent">
Chat Rooms Chat Rooms

+ 66
- 8
Frontend/src/components/ChatWindow.js 파일 보기

import { chatActions } from "../store/chat-slice"; import { chatActions } from "../store/chat-slice";
import { BsCircleFill } from "react-icons/bs"; import { BsCircleFill } from "react-icons/bs";
import TypingBar from "./TypingBar"; import TypingBar from "./TypingBar";
import {getDate,getMonth} from '../helpers'


const ChatWindow = ({ room }) => { const ChatWindow = ({ room }) => {
const messagesEndRef = useRef(null); const messagesEndRef = useRef(null);
const activeRoom = useSelector((state) => state.chat.activeRoom); const activeRoom = useSelector((state) => state.chat.activeRoom);
const messages = useSelector((state) => state.chat.messages); const messages = useSelector((state) => state.chat.messages);
const dispatch = useDispatch(); const dispatch = useDispatch();
const [proba,setProba] = useState([])

useEffect(() => {
showDate()
},[messages])

const showDate = () => {
let temp = [...messages];
if(temp[0] !== undefined){
let date = getDate(temp[0].createdAtUtc)
let d = date.getDate();
let m = date.getMonth();
let y = date.getFullYear();
temp.splice(0,0,{
content:getMonth(m) + " " + d.toString() + ", " + y.toString(),
senderId:undefined, //is information about date not message
username:undefined,
id:null,
createdAtUtc: undefined,
})
for (let index = 0; index < temp.length; index++) {
const element = temp[index];
let day = getDate(element.createdAtUtc).getDate();
if(temp[index + 1] !== undefined){
if(temp[index + 1].createdAtUtc !== undefined)
{
if(temp[index].isAccessMessage === undefined){
if(getDate(temp[index + 1].createdAtUtc).getDate() > day ){
let elem = temp[index + 1].createdAtUtc;
let d = getDate(elem).getDate()
let m = getDate(elem).getMonth()
let y = getDate(elem).getFullYear()
temp.splice(index+1,0,{
content:getMonth(m) + " " + d.toString() + ", " + y.toString(),
senderId:undefined, //is information about date not message
username:undefined,
id:null,
createdAtUtc: undefined,
})
}
}
}
}
}
}
setProba(temp)
}


useEffect(() => { useEffect(() => {
dispatch(chatActions.setMessages(room.messages)); dispatch(chatActions.setMessages(room.messages));
<div className="overlay p-3 px-4 d-flex flex-column-reverse"> <div className="overlay p-3 px-4 d-flex flex-column-reverse">
{/* mapirane poruke */} {/* mapirane poruke */}
{user && {user &&
messages
proba
.map((n, index) => ( .map((n, index) => (
<div <div
key={index} key={index}
className={ className={
n.isAccessMessage === true
n.isAccessMessage === true || n.senderId === undefined
? "d-flex flex-column align-items-center" ? "d-flex flex-column align-items-center"
: n.senderId === user.id : n.senderId === user.id
? "d-flex flex-column align-items-end" ? "d-flex flex-column align-items-end"
: "d-flex flex-column align-items-start" : "d-flex flex-column align-items-start"
} }
> >
{console.log("Message", n, "User id", user.id)}
<p
className={`p-2 px-4 mb-0 rounded message ${
n.isAccessMessage === true
<div
className={`p-2 px-3 mb-0 rounded message ${
n.isAccessMessage === true || n.senderId === undefined
? "text-muted small" ? "text-muted small"
: n.senderId !== user.id : n.senderId !== user.id
? "bg-main-primary text-light chatMsg" ? "bg-main-primary text-light chatMsg"
: "bg-light text-dark chatMsg" : "bg-light text-dark chatMsg"
}`} }`}
> >
<div style={{display:'flex',flexDirection:'column'}}>
{n.content} {n.content}
</p>
{
n.senderId !== undefined ?
<div style={{fontSize:12,alignSelf:'flex-end'}}>
{(new Date(Date.parse(n.createdAtUtc))).getHours().toString()}
:
{(new Date(Date.parse(n.createdAtUtc))).getMinutes().toString()}
</div> : ''
}
</div>
</div>
<p className="text-muted small m-0 p-0 mb-4"> <p className="text-muted small m-0 p-0 mb-4">
{n.senderId !== user?.id && !n.isAccessMessage ? (
{n.senderId !== user?.id && !n.isAccessMessage && n.senderId !== undefined ? (
activeUsers.some((m) => m === n.senderId) ? ( activeUsers.some((m) => m === n.senderId) ? (
<BsCircleFill className="me-2 text-success" /> <BsCircleFill className="me-2 text-success" />
) : ( ) : (

+ 34
- 0
Frontend/src/helpers.js 파일 보기

export const getMonth = (monthNumber) => {
switch(monthNumber){
case 0:
return "January";
case 1:
return "February";
case 2:
return "March"
case 3:
return "April"
case 4:
return "May"
case 5:
return "June"
case 6:
return "July"
case 7:
return "August"
case 8:
return "September"
case 9:
return "October"
case 10:
return "November"
case 11:
return "December"
default:
return "January"
}
}

export const getDate = (date) => {
return new Date(Date.parse(date))
}

+ 4
- 1
Frontend/src/index.css 파일 보기

} }
.roomsBtn:hover{ .roomsBtn:hover{
transition: 0.35s; transition: 0.35s;
padding: 0 20px;
padding: 0 10px;
transform: scale(1.1); transform: scale(1.1);
} }
/* ======================================= flex */ /* ======================================= flex */
.chatMsg{ .chatMsg{
font-size: 1.25rem; font-size: 1.25rem;
} }
.overflow-x{
overflow-x: hidden;
}

+ 0
- 4
Frontend/src/store/chat-slice.js 파일 보기

state.messages = action.payload; state.messages = action.payload;
}, },
addNotification: (state, action) => { addNotification: (state, action) => {
console.log(1, action.payload);
if (state.notifications.length !== 0) { if (state.notifications.length !== 0) {
console.log(2);
const room = state.notifications.find( const room = state.notifications.find(
(notification) => notification.roomId === action.payload (notification) => notification.roomId === action.payload
); );


if (room) { if (room) {
console.log(3);
room.notificationCount++; room.notificationCount++;
} else { } else {
state.notifications.push({ state.notifications.push({
}); });
} }
} else { } else {
console.log(4);
state.notifications.push({ state.notifications.push({
roomId: action.payload, roomId: action.payload,
notificationCount: 1, notificationCount: 1,

Loading…
취소
저장