2022-04-20 18:03:17 -04:00
|
|
|
|
|
|
|
<div class="d-flex justify-content-center">
|
|
|
|
<div class="container">
|
|
|
|
<div>
|
|
|
|
<h1><%= @post.title %></h1>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<%= if Ecto.assoc_loaded?(@post.upload) && !is_nil(@post.upload) do %>
|
|
|
|
<img src={Routes.static_path(@socket, "/uploads/#{@post.upload.file}")} class="img-fluid"/>
|
|
|
|
<% end %>
|
|
|
|
</div>
|
|
|
|
<div class="post-body">
|
|
|
|
<%= @post.body %>
|
|
|
|
</div>
|
|
|
|
<%= if Aggiedit.Roles.guard?(@current_user, :edit, @post) do %>
|
|
|
|
<span><%= live_patch "Edit", to: Routes.post_show_path(@socket, :edit, @room, @post), class: "button" %></span> |
|
|
|
|
<% end %>
|
|
|
|
<span><%= live_redirect "Back", to: Routes.post_index_path(@socket, :index, @room) %></span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- chat container from https://www.bootdey.com/snippets/view/card-chat-list#html -->
|
|
|
|
<div class="container content mt-2">
|
|
|
|
<div class="row">
|
2022-04-20 19:23:27 -04:00
|
|
|
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
|
|
|
|
<div class="card">
|
|
|
|
<div class="card-header">Chat</div>
|
|
|
|
<div class="card-body chat-container">
|
|
|
|
<ul class="chat-list" id="chat">
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-20 18:03:17 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-06 14:55:12 -04:00
|
|
|
|
|
|
|
<%= if @live_action in [:edit] do %>
|
2022-04-13 16:17:28 -04:00
|
|
|
<.modal return_to={Routes.post_show_path(@socket, :show, @room, @post)}>
|
2022-04-06 14:55:12 -04:00
|
|
|
<.live_component
|
|
|
|
module={AggieditWeb.PostLive.FormComponent}
|
|
|
|
id={@post.id}
|
2022-04-13 14:42:01 -04:00
|
|
|
current_user={@current_user}
|
2022-04-06 14:55:12 -04:00
|
|
|
title={@page_title}
|
|
|
|
action={@live_action}
|
|
|
|
post={@post}
|
2022-04-13 16:17:28 -04:00
|
|
|
return_to={Routes.post_show_path(@socket, :show, @room, @post)}
|
2022-04-06 14:55:12 -04:00
|
|
|
/>
|
|
|
|
</.modal>
|
|
|
|
<% end %>
|
|
|
|
|
2022-04-20 18:03:17 -04:00
|
|
|
<script>
|
|
|
|
const scrollToBottom = (element) => {
|
|
|
|
element.scrollIntoView({ behavior: 'smooth', block: 'end' });
|
|
|
|
};
|
2022-04-06 14:55:12 -04:00
|
|
|
|
2022-04-20 19:23:27 -04:00
|
|
|
const appendComment = ({user, body, id, user_id, inserted_at}, element) => {
|
2022-04-20 18:03:17 -04:00
|
|
|
const messageElement = document.createElement("div");
|
|
|
|
messageElement.innerHTML = `
|
2022-04-20 19:23:27 -04:00
|
|
|
<li class="${user_id == <%= @current_user.id %> ? 'out' : 'in'}" id=${id}>
|
|
|
|
<div class="chat-body">
|
2022-04-20 18:03:17 -04:00
|
|
|
<div class="chat-message">
|
|
|
|
<h5>${user}</h5>
|
|
|
|
<p>${body}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
`;
|
|
|
|
element.appendChild(messageElement);
|
|
|
|
scrollToBottom(element);
|
|
|
|
};
|
2022-04-06 14:55:12 -04:00
|
|
|
|
|
|
|
|
2022-04-20 19:23:27 -04:00
|
|
|
let channel;
|
2022-04-20 18:03:17 -04:00
|
|
|
window.addEventListener('phx:initial-post', (e) => {
|
|
|
|
const chatWindow = document.getElementById("chat");
|
|
|
|
window.userSocket.connect();
|
2022-04-20 19:23:27 -04:00
|
|
|
channel = window.RoomChat.connect(window.userSocket, e.detail.id);
|
2022-04-06 14:55:12 -04:00
|
|
|
|
2022-04-20 18:03:17 -04:00
|
|
|
channel.on('shout', (comment) => {
|
|
|
|
appendComment(comment, chatWindow);
|
|
|
|
});
|
2022-04-14 15:56:10 -04:00
|
|
|
|
2022-04-20 18:03:17 -04:00
|
|
|
channel.on('initial-comments', ({comments}) => {
|
|
|
|
comments.forEach((comment) => {
|
|
|
|
appendComment(comment, chatWindow);
|
|
|
|
});
|
|
|
|
scrollToBottom(chatWindow);
|
|
|
|
});
|
|
|
|
channel.push("send", {body: "Hello!"});
|
|
|
|
});
|
2022-04-14 15:56:10 -04:00
|
|
|
</script>
|