Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the issue #136 #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/App.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { Button } from "@material-ui/core";
import Brightness4Icon from "@material-ui/icons/Brightness4";
import logo from "./logo.png";

import CircularProgress from '@material-ui/core/CircularProgress';
import CircularProgress from "@material-ui/core/CircularProgress";
import Messages from "./components/messages/Messages.js";
import WelcomeDialogBox from "./WelcomeDialogBox";
import db from "./firebase.js";
import firebase from "firebase";

function App() {
const [loading,setLoading]=useState(false)
const [loading, setLoading] = useState(false);
const [input, setInput] = useState("");
const [messages, setMessages] = useState([]);
const [username, setUsername] = useState("");
Expand All @@ -24,13 +24,13 @@ function App() {
}, []);

useEffect(() => {
setLoading(true)
console.log("setting true",loading)
setLoading(true);
console.log("setting true", loading);
db.collection("messages")
.orderBy("timestamp", "asc")
.onSnapshot((snapshot) =>{
.onSnapshot((snapshot) => {
setMessages(snapshot.docs.map((doc) => doc.data()));
setLoading(false)
setLoading(false);
});
}, []);

Expand All @@ -39,7 +39,8 @@ function App() {
}, [messages]);

const scrollToBottom = () => {
messagesEndRef.current?.scrollIntoView({ behavior: "auto" });
if (messagesEndRef.current)
messagesEndRef.current.scrollIntoView({ behavior: "smooth" });
};

const newMessage = (event) => {
Expand All @@ -57,7 +58,7 @@ function App() {

const handleKeyPress = (event) => {
//it triggers by pressing the enter key
if (event.key === 'Enter') {
if (event.key === "Enter") {
newMessage(event);
}
};
Expand Down Expand Up @@ -97,9 +98,10 @@ function App() {
</Button>
</div>
</nav>
{
loading?<CircularProgress className="loading"/>:
<>
{loading ? (
<CircularProgress className="loading" />
) : (
<>
<div className="scroll">
<br />
<br />
Expand Down Expand Up @@ -156,7 +158,7 @@ function App() {
/>
</div>
</>
}
)}
</div>
);
}
Expand Down