Skip to content

Commit e329fa9

Browse files
committed
fixed display overlaping and layout, removed messageString and userString from state, replaced input handler by formSubmithandler, pending to fix deploy version
1 parent 1f6e2a7 commit e329fa9

3 files changed

Lines changed: 70 additions & 43 deletions

File tree

chat-app/backend/app.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import express from "express";
22
import cors from "cors";
33

4-
const app = express();
5-
app.use(
6-
cors({
7-
// origin: "https://tzemingho-chatapp-server-frontend.hosting.codeyourfuture.io"
8-
}),
9-
);
10-
app.use(express.json());
114
const port = 4000;
125

136
const waitingRoom = [];
@@ -20,6 +13,14 @@ const chatHistory = [
2013
},
2114
];
2215

16+
const app = express();
17+
app.use(
18+
cors({
19+
// origin: "https://tzemingho-chatapp-server-frontend.hosting.codeyourfuture.io"
20+
}),
21+
);
22+
app.use(express.json());
23+
2324
app.get("/", (req, res) => {
2425
res.json(chatHistory);
2526
});

chat-app/frontend/scripts.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { scrollToBottom } from "./utilities.js";
22

33
const state = {
4-
messageString: "",
5-
userString: "",
64
// backendURL: "https://tzemingho-chatapp-server-backend.hosting.codeyourfuture.io",
75
backendURL: "http://localhost:4000",
86
messages: [],
@@ -72,8 +70,6 @@ const keepFetchingMessages = async () => {
7270
};
7371

7472
function messageInputReset() {
75-
state.messageString = "";
76-
state.userString = "";
7773
const messageInputElement = document.getElementById("message-input");
7874
const userInputElement = document.getElementById("user-name-input");
7975
messageInputElement.value = "";
@@ -95,7 +91,6 @@ async function postingMessage(messageString, userString) {
9591
if (response.ok) {
9692
const confirmMessage = await response.text();
9793
if (confirmMessage == "sent") {
98-
chatDisplay();
9994
messageInputReset();
10095
}
10196
}
@@ -104,8 +99,12 @@ async function postingMessage(messageString, userString) {
10499
}
105100
}
106101

107-
async function messageSubmitHandler(e, messageString, userString) {
102+
async function messageSubmitHandler(e) {
108103
e.preventDefault();
104+
105+
const messageString = document.getElementById("message-input").value.trim();
106+
const userString = document.getElementById("user-name-input").value.trim();
107+
109108
if (!messageString || !userString) {
110109
console.error(`Message or user cannot be empty.`);
111110
window.alert("Message or user cannot be empty.");
@@ -115,25 +114,12 @@ async function messageSubmitHandler(e, messageString, userString) {
115114
}
116115
}
117116

118-
function messageInputHandler() {
119-
const messageInputElement = document.getElementById("message-input");
120-
messageInputElement.addEventListener("input", (e) => {
121-
state.messageString = e.target.value.trim();
122-
});
123-
124-
const userInputElement = document.getElementById("user-name-input");
125-
userInputElement.addEventListener("input", (e) => {
126-
state.userString = e.target.value.trim();
127-
});
128-
129-
document
130-
.getElementById("message-submit-button")
131-
.addEventListener("click", async (e) => {
132-
await messageSubmitHandler(e, state.messageString, state.userString);
133-
});
117+
function messageFormHandler() {
118+
const formElement = document.getElementById("message-form");
119+
formElement.addEventListener("submit", messageSubmitHandler);
134120
}
135121

136122
window.onload = async () => {
137123
keepFetchingMessages();
138-
messageInputHandler();
124+
messageFormHandler();
139125
};

chat-app/frontend/styles.css

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,73 @@
44
box-sizing: border-box;
55
}
66

7+
html,
8+
body {
9+
height: 100vh;
10+
max-width: 100vw;
11+
overflow: hidden;
12+
}
13+
14+
body {
15+
display: flex;
16+
flex-direction: column;
17+
}
18+
19+
header {
20+
padding: 10px 20px;
21+
background-color: aliceblue;
22+
}
23+
24+
main {
25+
flex: 1;
26+
display: flex;
27+
flex-direction: column;
28+
align-items: center;
29+
gap: 15px;
30+
padding: 15px;
31+
min-height: 0;
32+
overflow: hidden;
33+
}
34+
735
#chat-display-area {
836
background-color: aliceblue;
937
border: 1px solid;
1038
border-radius: 5px;
11-
width: 80%;
12-
height: 68vh;
39+
width: 100%;
40+
max-width: 800px;
41+
flex: 1;
1342
display: flex;
1443
flex-direction: column;
15-
gap: 5px;
16-
overflow-y: hidden;
44+
gap: 10px;
45+
padding: 10px;
46+
overflow-y: auto;
1747
scroll-behavior: smooth;
1848
}
1949

2050
.chat-thread {
2151
background-color: white;
2252
border: navy solid 1.5px;
23-
max-width: 90%;
53+
width: 100%;
54+
max-width: 95%;
2455
border-radius: 5px;
25-
height: 10vh;
56+
flex-shrink: 0;
57+
min-height: 80px;
2658
display: flex;
2759
flex-direction: column;
2860
justify-content: space-between;
2961
}
3062

3163
.message-in-thread {
3264
height: 8vh;
65+
word-break: break-word;
3366
}
3467

3568
.info-in-thread {
3669
background-color: navy;
3770
color: white;
3871
display: flex;
3972
justify-content: space-between;
73+
padding: 4px 8px;
4074
}
4175

4276
.timestamp-in-thread {
@@ -54,15 +88,20 @@
5488

5589
#message-form {
5690
border: 1px solid;
57-
width: 80%;
58-
height: 20vh;
59-
padding: 2px;
91+
border-radius: 5px;
92+
width: 100%;
93+
max-width: 800px;
94+
padding: 10px;
95+
background: white;
96+
flex-shrink: 0;
6097
}
6198

6299
#message-input {
63-
height: 11.5vh;
100+
height: 60px;
64101
width: 100%;
65102
padding: 8px;
103+
resize: none;
104+
margin-bottom: 8px;
66105
}
67106

68107
#signature-and-send-area {
@@ -79,8 +118,9 @@
79118
}
80119

81120
footer {
82-
position: fixed;
83-
bottom: 0;
84-
width: 100%;
121+
text-align: center;
122+
padding: 8px;
85123
background-color: aliceblue;
124+
font-size: 0.9rem;
125+
flex-shrink: 0;
86126
}

0 commit comments

Comments
 (0)