21
lib/anonbb_web/templates/layout/app.html.eex
Normal file
21
lib/anonbb_web/templates/layout/app.html.eex
Normal file
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>Anonbb · Phoenix Framework</title>
|
||||
<link rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/>
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript" src="<%= Routes.static_path(@conn, "/js/jquery-3.3.1.slim.min.js") %>" ></script>
|
||||
<script type="text/javascript" src="<%= Routes.static_path(@conn, "/js/popper.min.js") %>" ></script>
|
||||
<script type="text/javascript" src="<%= Routes.static_path(@conn, "/js/bootstrap.min.js") %>" ></script>
|
||||
<script type="text/javascript" src="<%= Routes.static_path(@conn, "/js/app.js") %>"></script>
|
||||
<main role="main" class="container">
|
||||
<!--<p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>-->
|
||||
<!--<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>-->
|
||||
<%= render @view_module, @view_template, assigns %>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
26
lib/anonbb_web/templates/page/index.html.eex
Normal file
26
lib/anonbb_web/templates/page/index.html.eex
Normal file
@@ -0,0 +1,26 @@
|
||||
<div class="row">
|
||||
<div class="col-md">
|
||||
<h1 class="my-3">Here's-a some rooms</h1>
|
||||
<p>No rooms!</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md">
|
||||
<h1 class="mb-3">Join-a a room</h1>
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="joinRoomName" placeholder="Room name" />
|
||||
<div class="input-group-append">
|
||||
<button type="button" class="btn btn-primary" id="joinRoomButton" disabled>Join</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
TODO input validation
|
||||
<script type="text/javascript">
|
||||
$(document).ready(() => {
|
||||
});
|
||||
</script>
|
||||
-->
|
||||
81
lib/anonbb_web/templates/room/show.html.eex
Normal file
81
lib/anonbb_web/templates/room/show.html.eex
Normal file
@@ -0,0 +1,81 @@
|
||||
<div class="row justify-content-md-center my-3">
|
||||
<div class="col-8">
|
||||
<textarea rows="5" class="form-control" id="messageInput" placeholder="Message..."></textarea>
|
||||
<button type="button" class="btn btn-primary my-2" id="sendButton" disabled>Send</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row justify-content-md-center">
|
||||
<div class="col-8">
|
||||
<ul id="messageOutput">
|
||||
<%= for m <- @messages do %>
|
||||
<li id="<%= m.id %>">
|
||||
<p><a href="#<% m.id%>">>><%= m.id %></a> <%= m.inserted_at %></p>
|
||||
<p><%= m.text %></p>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
let input;
|
||||
$(document).ready(() => {
|
||||
const NEW_MSG = "new_msg";
|
||||
let room = window.room;
|
||||
let socket = window.socket;
|
||||
let channel = socket.channel("room:" + room, {});
|
||||
channel.join()
|
||||
.receive("ok", resp => console.log("Joined successfully", resp))
|
||||
.receive("error", resp => console.log("Could not join", resp));
|
||||
input = $("#messageInput")[0];
|
||||
let output = $("#messageOutput");
|
||||
let sendbutton = $("#sendButton")[0];
|
||||
|
||||
function sendMessage() {
|
||||
try {
|
||||
let message_text = input.value;
|
||||
// empty and space-only messages not allowed
|
||||
if (message_text.match(/^[\s]*$/m)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
input.disabled = true;
|
||||
channel.push(NEW_MSG, {body: message_text});
|
||||
} finally {
|
||||
input.value = "";
|
||||
}
|
||||
} finally {
|
||||
input.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
channel.on(NEW_MSG, payload => {
|
||||
console.log(payload);
|
||||
let body = payload.body;
|
||||
let now = new Date();
|
||||
let messageItem = $("<li>").html(
|
||||
`<p>${now.toISOString()}</p><p>${body}</p>`
|
||||
);
|
||||
output.prepend(messageItem);
|
||||
});
|
||||
|
||||
input.onkeydown = (e => {
|
||||
if (e.keyCode == 13 && e.shiftKey) {
|
||||
sendMessage();
|
||||
}
|
||||
|
||||
sendButton.disabled = input.value === "";
|
||||
});
|
||||
|
||||
input.onkeyup = (e => {
|
||||
if (e.keyCode == 13 && e.shiftKey) {
|
||||
input.value = "";
|
||||
input.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
$("#messageInput").attr("placeholder", "Message to :" + room);
|
||||
});
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user