Skip to content

Commit 8d34b41

Browse files
committed
Styling and server restructuring
1 parent e51433d commit 8d34b41

File tree

6 files changed

+69
-39
lines changed

6 files changed

+69
-39
lines changed

app/src/App.css

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
height: 75%;
44
width: 75%;
55
flex-direction: column;
6-
border-radius: 10px;
7-
background-color: #FFF;
6+
background-color: #F5F7F9;
7+
border-left: 3px solid #69c;
8+
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
89
}
910

1011
#init {
@@ -26,14 +27,25 @@
2627
height: calc(100% - 20px);
2728
overflow: auto;
2829
padding: 10px;
29-
background-color: #DDD;
30+
background-color: #EEE;
31+
border-right: 1px solid #DDD;
32+
border-top: 1px solid #DDD;
3033
}
3134
#conversation-main {
3235
width: 80%;
3336
height: calc(100% - 20px);
3437
overflow: auto;
3538
padding: 10px;
36-
background-color: #FFF;
39+
border-right: 1px solid #DDD;
40+
border-top: 1px solid #DDD;
41+
position: relative;
42+
}
43+
44+
#source {
45+
position: absolute;
46+
top: 10px;
47+
right: 10px;
48+
opacity: 0.7;
3749
}
3850

3951
#bottom {
@@ -48,27 +60,17 @@
4860
flex-direction: row;
4961
height: 100%;
5062
width: 100%;
51-
background-color: #CCC;
52-
}
53-
#text-entry {
54-
width: 80%;
55-
height: 100%;
56-
padding: 10px;
63+
border-top: 1px solid #DDD;
64+
border-bottom: 1px solid #DDD;
65+
border-right: 1px solid #DDD;
66+
background-color: #EEE;
5767
}
5868
#text-entry-form {
59-
width: calc(100% - 7px);
60-
height: calc(100% - 28px);
61-
}
62-
#text-entry-input {
6369
width: 100%;
6470
height: 100%;
6571
}
66-
#text-entry-submit {
67-
display: flex;
68-
align-items: center;
69-
justify-content: center;
70-
width: 20%;
71-
height: 100%;
72-
background-color: #FB4F4F;
73-
cursor: pointer;
72+
#text-entry-input {
73+
margin: 10px;
74+
width: calc(100% - 25px);
75+
height: calc(100% - 28px);
7476
}

app/src/App.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ socket.onerror = (event) => {
1212
console.log(event);
1313
}
1414

15-
1615
class App extends Component {
1716
constructor(props) {
1817
super(props);
@@ -60,6 +59,13 @@ class App extends Component {
6059
document.getElementById("text-entry-input").value = "";
6160
}
6261

62+
componentDidUpdate() {
63+
// keep message box scrolled appropriately with new messages
64+
if (!this.state.init) {
65+
document.getElementById("conversation-main").scrollTop = document.getElementById("conversation-main").scrollHeight;
66+
}
67+
}
68+
6369
componentDidMount() {
6470
socket.onmessage = (event) => {
6571
const { text, client, timestamp } = JSON.parse(event.data);
@@ -100,21 +106,20 @@ class App extends Component {
100106
)}
101107
</div>
102108
<div id="conversation-main">
109+
<a href="https://github.com/stefaluc/go-react-chat"
110+
id="source"
111+
target="_blank"
112+
rel="noopener noreferrer">View source code</a>
103113
{this.state.messages.map(message =>
104114
<Message message={message} />
105115
)}
106116
</div>
107117
</div>
108118
<div id="bottom">
109119
<div id="text-entry-main">
110-
<div id="text-entry">
111-
<form onSubmit={this.textSubmit} id="text-entry-form">
112-
<input type="text" id="text-entry-input" />
113-
</form>
114-
</div>
115-
<div onClick={this.textSubmit} id="text-entry-submit">
116-
Send Message
117-
</div>
120+
<form onSubmit={this.textSubmit} id="text-entry-form">
121+
<input type="text" id="text-entry-input" />
122+
</form>
118123
</div>
119124
</div>
120125
</div>

app/src/index.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ body {
55
height: 100vh;
66
width: 100vw;
77
background-color: #6CC0E5;
8+
color: #555;
9+
}
10+
11+
a {
12+
color: #E81C4F;
13+
cursor: pointer;
14+
text-decoration: underline;
815
}
916

1017
#root {

server/conn_hub.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package main

server/main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"net/http"
5+
"fmt"
6+
)
7+
8+
func main() {
9+
fmt.Println("Launching server...")
10+
11+
// start conn_hub
12+
// connHub := newConnHub
13+
// go connHub.run()
14+
15+
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
16+
wsHandler(/* hub ,*/ w, r)
17+
})
18+
err := http.ListenAndServe(":8081", nil)
19+
if err != nil {
20+
fmt.Println("ListenAndServeError:", err)
21+
}
22+
}

server/websocket.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var upgrader = websocket.Upgrader{
2020
}
2121

2222
// handle /ws route, upgrade HTTP request and forward ws conn to worker
23-
func websocketHandler(w http.ResponseWriter, r *http.Request) {
23+
func wsHandler(w http.ResponseWriter, r *http.Request) {
2424
conn, err := upgrader.Upgrade(w, r, nil)
2525
if err != nil {
2626
http.Error(w, "Could not open websocket connection", http.StatusBadRequest)
@@ -48,10 +48,3 @@ func handleConnection(conn *websocket.Conn) {
4848
}
4949
}
5050
}
51-
52-
func main() {
53-
fmt.Println("Launching server...")
54-
55-
http.HandleFunc("/ws", websocketHandler)
56-
http.ListenAndServe(":8081", nil)
57-
}

0 commit comments

Comments
 (0)