-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathindex.html
149 lines (132 loc) · 4.29 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous"
/>
<title>Livestream Project Ideas</title>
</head>
<body class="bg-dark text-white">
<nav class="navbar navbar-light bg-light">
<div class="container">
<span class="navbar-brand mb-0 h1">Livestream Project Ideas</span>
</div>
</nav>
<div class="container mt-5">
<div class="row">
<div class="col-md-6">
<h1 class="text-center mb-3">
Submit an Idea
</h1>
<form id="form">
<div class="form-group">
<input
type="text"
id="idea-text"
class="form-control bg-dark text-white"
placeholder="Enter idea (30 chars max)"
maxlength="30"
required
/>
</div>
<div class="form-group">
<input
type="text"
id="idea-tech"
class="form-control bg-dark text-white"
placeholder="Language, framework, etc"
maxlength="30"
required
/>
</div>
<div class="form-group">
<input
type="text"
id="idea-viewer"
class="form-control bg-dark text-white"
placeholder="Enter your name"
maxlength="20"
required
/>
</div>
<button type="submit" class="btn btn-primary btn-block">
Suggest Idea
</button>
</form>
</div>
<div class="col-md-6">
<div id="ideas">
<!-- <div class="card bg-secondary my-3">
<div class="card-body">
<p class="lead">
Create a realtime app <strong>(Feathers.js)</strong>
<br />
<em>Submitted by John Doe</em>
<br />
<small>2:05:10</small>
</p>
</div>
</div> -->
</div>
</div>
</div>
</div>
<script src="https://unpkg.com/@feathersjs/client@^4.3.0/dist/feathers.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>
<script>
// Socket.io setup
const socket = io('http://localhost:3030');
// Init feathers app
const app = feathers();
// Register socket.io to talk to server
app.configure(feathers.socketio(socket));
document.getElementById('form').addEventListener('submit', sendIdea);
async function sendIdea(e) {
e.preventDefault();
const text = document.getElementById('idea-text');
const tech = document.getElementById('idea-tech');
const viewer = document.getElementById('idea-viewer');
// Create new idea
app.service('ideas').create({
text: text.value,
tech: tech.value,
viewer: viewer.value
});
// Clear inputs
text.value = '';
tech.value = '';
viewer.value = '';
}
function renderIdea(idea) {
document.getElementById(
'ideas'
).innerHTML += `<div class="card bg-secondary my-3">
<div class="card-body">
<p class="lead">
${idea.text} <strong>(${idea.tech})</strong>
<br />
<em>Submitted by ${idea.viewer}</em>
<br />
<small>${idea.time}</small>
</p>
</div>
</div>`;
}
async function init() {
// Find ideas
const ideas = await app.service('ideas').find();
// Add existing ideas to list
ideas.forEach(renderIdea);
// Add idea in realtime
app.service('ideas').on('created', renderIdea);
}
init();
</script>
</body>
</html>