Skip to content

Commit

Permalink
Connected disconnected messages
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaserlang committed Oct 31, 2024
1 parent c7c7c2c commit 2e7e2b3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tbot/web/ui/live_chat/components/chat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ import "./chat.scss";
export function Chat({ channelId }) {
const { lastJsonMessage } = useWebSocket(`/api/live-chat/${channelId}`, {
shouldReconnect: () => true,
onOpen: () => {
setMessageHistory([
...messageHistory,
{
id: Math.random().toString(),
type: "mod_action",
message: "Connected to chat",
created_at: new Date().toISOString(),
},
]);
},
onClose: () => {
setMessageHistory([
...messageHistory,
{
id: Math.random().toString(),
type: "mod_action",
message: "Disconnected from chat",
created_at: new Date().toISOString(),
},
]);
},
});
const [messageHistory, setMessageHistory] = useState([]);
const messagesEndRef = useRef(null);
Expand Down

0 comments on commit 2e7e2b3

Please sign in to comment.