Skip to content

Commit 172f76b

Browse files
update code review feedback
1 parent 898444b commit 172f76b

5 files changed

Lines changed: 70 additions & 58 deletions

File tree

README.md

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,3 @@
11
# Coursework
22

33
Exercises to practice and solidify your understanding of the Decomposition module of the Software Development Course.
4-
5-
---
6-
7-
# Beeko Chat App
8-
9-
A real-time chat application where users can send and receive messages instantly without refreshing the page.
10-
11-
## Project Structure
12-
13-
```
14-
chat-app/
15-
client/ - Vite + React + TypeScript frontend
16-
server/ - Node.js + Express backend
17-
```
18-
19-
## Features
20-
21-
- Send a message to the chat
22-
- See all messages when opening the chat
23-
- New messages appear instantly for all connected users
24-
- Message count display
25-
- Username persisted across sessions
26-
27-
## How It Works
28-
29-
The frontend loads existing messages from the server on page load via a REST API. When a user sends a message, it is posted to the server which saves it and broadcasts it to all connected clients over a WebSocket channel. Every connected user receives the new message instantly without needing to refresh.
30-
31-
## Getting Started
32-
33-
**Backend**
34-
```bash
35-
cd server
36-
npm install
37-
node index.js
38-
```
39-
40-
**Frontend**
41-
```bash
42-
cd client
43-
npm install
44-
npm run dev
45-
```
46-
47-
## Deployment
48-
49-
- Backend is deployed as a Docker container
50-
- Frontend is deployed as a static site via Nixpacks

chat-app/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,53 @@ Exploring and understanding different ways of sending information between a clie
3232
* Create a pull request back into the original Module-Decomposition repo, including:
3333
* A link to the deployed frontend on the CYF hosting environment
3434
* A link to the deployed backend on the CYF hosting environment
35+
36+
37+
---
38+
## Implementation
39+
40+
41+
# Beeko Chat App
42+
43+
A real-time chat application where users can send and receive messages instantly without refreshing the page.
44+
45+
## Project Structure
46+
47+
```
48+
chat-app/
49+
client/ - Vite + React + TypeScript frontend
50+
server/ - Node.js + Express backend
51+
```
52+
53+
## Features
54+
55+
- Send a message to the chat
56+
- See all messages when opening the chat
57+
- New messages appear instantly for all connected users
58+
- Message count display
59+
- Username persisted across sessions
60+
61+
## How It Works
62+
63+
The frontend loads existing messages from the server on page load via a REST API. When a user sends a message, it is posted to the server which saves it and broadcasts it to all connected clients over a WebSocket channel. Every connected user receives the new message instantly without needing to refresh.
64+
65+
## Getting Started
66+
67+
**Backend**
68+
```bash
69+
cd server
70+
npm install
71+
node index.js
72+
```
73+
74+
**Frontend**
75+
```bash
76+
cd client
77+
npm install
78+
npm run dev
79+
```
80+
81+
## Deployment
82+
83+
- Backend is deployed as a Docker container
84+
- Frontend is deployed as a static site via Nixpacks

chat-app/client/src/App.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,10 @@ body {
4040
border-radius: 12px;
4141
padding: 1rem;
4242
background-color: #16213e;
43+
}
44+
45+
.error {
46+
color: #f87171;
47+
text-align: center;
48+
font-size: 0.9rem;
4349
}

chat-app/client/src/App.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import { useState, useEffect } from "react";
2-
import MessageList from "./components/MessageList";
3-
import MessageForm from "./components/MessageForm";
4-
import type { Message } from "./types";
1+
import { useState, useEffect } from "react";
2+
import MessageList from "./components/MessageList";
3+
import MessageForm from "./components/MessageForm";
4+
import type { Message } from "./types";
55
import "./App.css";
66

7-
const SERVER_URL = "https://ggjpdb4d0e0lrtcdbxpdpsrk.hosting.codeyourfuture.io";
8-
const WS_URL = "wss://ggjpdb4d0e0lrtcdbxpdpsrk.hosting.codeyourfuture.io";
7+
const SERVER_URL = "https://ggjpdb4d0e0lrtcdbxpdpsrk.hosting.codeyourfuture.io";
8+
const WS_URL = "wss://ggjpdb4d0e0lrtcdbxpdpsrk.hosting.codeyourfuture.io";
99

1010
function App() {
1111
const [messages, setMessages] = useState<Message[]>([]);
12+
const [error, setError] = useState<string | null>(null);
13+
1214
const [name, setName] = useState<string>(() => {
1315
return localStorage.getItem("chatNameKey") ?? "";
1416
});
@@ -38,13 +40,16 @@ function App() {
3840
}, [name]);
3941

4042
const handleSend = async (text: string) => {
43+
4144
try {
4245
await fetch(`${SERVER_URL}/messages`, {
4346
method: "POST",
4447
headers: { "Content-Type": "application/json" },
4548
body: JSON.stringify({ name, text }),
4649
});
50+
4751
} catch (err) {
52+
setError("Failed to send message. Please try again.");
4853
console.error("failed to send message", err);
4954
}
5055
};
@@ -54,6 +59,7 @@ function App() {
5459
<h1 className="app_title">Beeko Chat App</h1>
5560
<div className="app_container">
5661
<MessageList messages={messages} />
62+
{error && <p className="error">{error}</p>}
5763
<MessageForm name={name} onNameChange={setName} onSend={handleSend} messageCount={messages.length} />
5864
</div>
5965
</div>

chat-app/server/endPoints/postMessage.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ const postMessage = (req, res, wss) => {
1212
id: uuidv4(),
1313
name,
1414
text,
15-
timestamp: new Date().toLocaleTimeString([], {
16-
hour: "2-digit",
17-
minute: "2-digit",
18-
}),
15+
timestamp: new Date().toISOString(),
1916
};
2017

2118
messages.push(newMessage);
@@ -26,7 +23,7 @@ const postMessage = (req, res, wss) => {
2623
}
2724
});
2825

29-
res.status(201).json(newMessage);
26+
res.status(201).end();
3027
};
3128

3229
module.exports = postMessage;

0 commit comments

Comments
 (0)