Commit 06f8c355 authored by 健杭 徐's avatar 健杭 徐
Browse files

update rooms lastsender and lastcomment

parent cf2d57c6
# README
### 1.go返回数组时格式问题
### 2.添加了头像
### 3.使用了`react-icons/md`
## unfinished
### 1.deleted function
...@@ -224,6 +224,7 @@ func AddMessage(c *gin.Context) { ...@@ -224,6 +224,7 @@ func AddMessage(c *gin.Context) {
return return
} }
// 写入评论
query := ` query := `
INSERT INTO messages (room_id, profile, sender, content, "time") INSERT INTO messages (room_id, profile, sender, content, "time")
VALUES ($1, $2, $3, $4, NOW()) VALUES ($1, $2, $3, $4, NOW())
...@@ -236,8 +237,9 @@ func AddMessage(c *gin.Context) { ...@@ -236,8 +237,9 @@ func AddMessage(c *gin.Context) {
return return
} }
// 更新room
_, err = db.Exec( _, err = db.Exec(
"UPDATE rooms SET lastSender = $1, lastContent = $2, lastTime = NOW() WHERE room_id = $3", "UPDATE rooms SET last_sender = $1, last_content = $2, last_time = NOW() WHERE room_id = $3",
message.Sender, message.Content, message.RoomId, message.Sender, message.Content, message.RoomId,
) )
if err != nil { if err != nil {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import "./ChatRoom.css"; import "./ChatRoom.css";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
const backEnd:string = "http://10.171.208.94:8080"; const backEnd:string = "http://localhost:8080";
const Profile = [ 'https://pic4.zhimg.com/v2-c5a0d0d57c1a85c6db56e918707f54a3_r.jpg', const Profile = [ 'https://pic4.zhimg.com/v2-c5a0d0d57c1a85c6db56e918707f54a3_r.jpg',
'https://pic2.zhimg.com/v2-c2e79191533fdc7fced2f658eef987c9_r.jpg', 'https://pic2.zhimg.com/v2-c2e79191533fdc7fced2f658eef987c9_r.jpg',
...@@ -33,8 +33,6 @@ interface MessageProps { ...@@ -33,8 +33,6 @@ interface MessageProps {
}>; }>;
} }
let RoomName: RoomEntryProps[] = []
function RoomEntry ({rooms, onRoomClick} : {rooms: RoomEntryProps[], onRoomClick: (roomId: number, roomName: string) => void}) { function RoomEntry ({rooms, onRoomClick} : {rooms: RoomEntryProps[], onRoomClick: (roomId: number, roomName: string) => void}) {
return ( return (
<div className="chat-room-nav"> <div className="chat-room-nav">
...@@ -52,8 +50,10 @@ function RoomEntry ({rooms, onRoomClick} : {rooms: RoomEntryProps[], onRoomClick ...@@ -52,8 +50,10 @@ function RoomEntry ({rooms, onRoomClick} : {rooms: RoomEntryProps[], onRoomClick
<img src={RoomProfile} alt="Avatar" className="avatar" /> <img src={RoomProfile} alt="Avatar" className="avatar" />
<div className="chat-info"> <div className="chat-info">
<h3>{room.roomName}</h3> <h3>{room.roomName}</h3>
<span className="chat-message">{room.lastContent && room.lastContent.Valid ? room.lastContent.String : ''}</span> <span className="chat-message">
<span className="chat-time">{room.lastTime && room.lastTime.Valid ? formatTimeToHoursMinutes(room.lastTime.Time) : ''}</span> {room.lastSender.Valid ? room.lastSender.String : ''}:
{room.lastContent.Valid ? room.lastContent.String : ''}</span>
<span className="chat-time">{room.lastTime.Valid ? formatTimeToHoursMinutes(room.lastTime.Time) : ''}</span>
</div> </div>
</div> </div>
))} ))}
...@@ -307,6 +307,7 @@ export function ChatRoom({ userName }: { userName: string }) { ...@@ -307,6 +307,7 @@ export function ChatRoom({ userName }: { userName: string }) {
}) })
const result = await response.json(); const result = await response.json();
debugger;
if (result.code != 0) { if (result.code != 0) {
alert(`Error: ${result.Msg}`); alert(`Error: ${result.Msg}`);
return; return;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment