Commit 4b8c3bbe by chenway

add loading

parent e39747be
Pipeline #159012 passed with stages
in 1 minute 37 seconds
import { useState } from "react"; import React, { useEffect, useState } from "react";
import { import {
Button,
Col, Col,
Container, Container,
Form, Form,
FormLabel, FormLabel,
Row,
ListGroup, ListGroup,
Row
} from "react-bootstrap"; } from "react-bootstrap";
import io from "socket.io-client"; import io from "socket.io-client";
import "../App.css"; import "../App.css";
import React, { useEffect } from "react";
const url = 'https://staging.strk-ai-support.ngrok.app/' const url = 'https://staging.strk-ai-support.ngrok.app/'
// const url = "http://localhost:8000"; // const url = "http://localhost:8000";
...@@ -33,6 +31,8 @@ function ChatTrans() { ...@@ -33,6 +31,8 @@ function ChatTrans() {
const [supportMessages, setSupportMessages] = useState([]); const [supportMessages, setSupportMessages] = useState([]);
const [room, setRoom] = useState(""); const [room, setRoom] = useState("");
const [loading, setLoading] = useState(true);
const generateToken = () => { const generateToken = () => {
return Math.random().toString(36).substr(2, 9); return Math.random().toString(36).substr(2, 9);
}; };
...@@ -85,7 +85,9 @@ function ChatTrans() { ...@@ -85,7 +85,9 @@ function ChatTrans() {
setUserMessages(messages); setUserMessages(messages);
} else { } else {
setSupportMessages(messages); setSupportMessages(messages);
setLoading(false);
} }
}); });
const sendMessage = ( const sendMessage = (
...@@ -202,6 +204,7 @@ function ChatTrans() { ...@@ -202,6 +204,7 @@ function ChatTrans() {
<Row> <Row>
<Col> <Col>
{loading ? <FormLabel>Loading...</FormLabel> : null}
<ListGroup variant="flush"> <ListGroup variant="flush">
{userMessages.map((message, index) => ( {userMessages.map((message, index) => (
<ListGroup.Item key={index}>{message}</ListGroup.Item> <ListGroup.Item key={index}>{message}</ListGroup.Item>
...@@ -209,6 +212,7 @@ function ChatTrans() { ...@@ -209,6 +212,7 @@ function ChatTrans() {
</ListGroup> </ListGroup>
</Col> </Col>
<Col> <Col>
{loading ? <FormLabel>Loading...</FormLabel> : null}
<ListGroup variant="flush"> <ListGroup variant="flush">
{supportMessages.map((message, index) => ( {supportMessages.map((message, index) => (
<ListGroup.Item key={index}>{message}</ListGroup.Item> <ListGroup.Item key={index}>{message}</ListGroup.Item>
......
Markdown is supported
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