Skip to content

Commit

Permalink
Merge pull request #40 from scalableinternetservices/move-chat
Browse files Browse the repository at this point in the history
chat segmentation
  • Loading branch information
justinthecao authored Dec 10, 2024
2 parents 163091b + 2a7fb3e commit 3a10f2c
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 63 deletions.
12 changes: 11 additions & 1 deletion app/controllers/chats_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ChatsController < ApplicationController
before_action :set_chat, only: [:show, :create_message]
before_action :set_chat, except: [:index], only: [:show, :create_message]
before_action :require_login

def show
Expand All @@ -12,6 +12,16 @@ def show
@message = Message.new
end

def index
@current_user = User.find_by(id: session[:user_id])

@chats = Chat.where("user1_id = ? OR user2_id = ?", @current_user.id, @current_user.id)
@unresponded_chats = @chats.where("last_message_user_id != ?", @current_user.id)
@newmessages = @unresponded_chats.map do |chat|
Message.find(chat.last_message_id)
end.flatten
end

def new
@chat = Chat.new
end
Expand Down
9 changes: 9 additions & 0 deletions app/views/chats/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<style>
.spacer {
height: 100px;
width: 100%;
}
</style>

<div class = "spacer"></div>
<%=render 'chats/messagechat'%>
6 changes: 0 additions & 6 deletions app/views/meetings/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
border: none;
font-weight: 500;
text-decoration: none;
margin: 0 4px;
}

.button-blue {
Expand All @@ -112,11 +111,6 @@
background: #fff5f5;
}

.logged-in {
text-align: center;
font-size: 18px;
}

.attendees-section {
margin: 16px 0;
padding-right: 24px;
Expand Down
16 changes: 15 additions & 1 deletion app/views/messages/_newmessages.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<style>
.graybackground {
background-color: #f8f9fa;
border-radius: 6px;
padding: 12px 10px;
z-index: 1000;
}
.card-link {
color: inherit;
text-decoration: none;
}

</style>

<%if @newmessages.count == 0%>
<h3>No new messages</h3>
<h3 class = "graybackground">No new messages</h3>
<%else%>
<% @newmessages.each do |newmessage| %>
<% chat = Chat.find(newmessage.chat_id)%>
Expand Down
103 changes: 48 additions & 55 deletions app/views/posts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -298,63 +298,56 @@
<% end %>
</div>

<div class="sidebyside">
<div class="left">
<% if @posts.count != 0%>
<% @posts.each do |post| %>


<div class="container">

<article class="card">

<%= link_to post_path(post), class: "card-link" do %>
<div class = "card-header-comment">
<header class="header">
<h1 class="post-title">Post <%= post.id %></h1>
<p class="meta-text"> Posted by:
<%= link_to post.username, user_profile_path(post.username), class: "username-link" %>
</p>
<p class="meta-text"> Last updated: <%= post.updated_at.strftime("%B %d, %Y, %I:%M %p") %> </p>
</header>

<div class="post-content">
<h2 class="post-body"> <%= post.body %> </h2>
</div>

<p class="meta-text"> Comments: <%= post.comments.count %> </p>
<br>
<br>
</div>
<%end%>

<% if @current_user.instructor? || @current_user.username == post.username %>
<div class="update-section">
<%= link_to "Update Post", post_path(post), class: "button button-blue" %>
<%= link_to "Delete Post", post_path(post), class: "button button-red",
data: {
turbo_method: :delete,
turbo_confirm: "Are you sure?"
} %>
</div>
<% end %>
</article>

</div>
<%end %>
<div style="font-size: 24px;">
<%= paginate @posts %>
</div>
<% if @posts.count != 0%>
<% @posts.each do |post| %>


<div class="container">

<article class="card">

<%= link_to post_path(post), class: "card-link" do %>
<div class = "card-header-comment">
<header class="header">
<h1 class="post-title">Post <%= post.id %></h1>
<p class="meta-text"> Posted by:
<%= link_to post.username, user_profile_path(post.username), class: "username-link" %>
</p>
<p class="meta-text"> Last updated: <%= post.updated_at.strftime("%B %d, %Y, %I:%M %p") %> </p>
</header>

<div class="post-content">
<h2 class="post-body"> <%= post.body %> </h2>
</div>

<p class="meta-text"> Comments: <%= post.comments.count %> </p>
<br>
<br>
</div>
<%end%>

<% if @current_user.instructor? || @current_user.username == post.username %>
<div class="update-section">
<%= link_to "Update Post", post_path(post), class: "button button-blue" %>
<%= link_to "Delete Post", post_path(post), class: "button button-red",
data: {
turbo_method: :delete,
turbo_confirm: "Are you sure?"
} %>
</div>
<% end %>
</article>

</div>
<%else%>
<div class="left">
<h2>"No posts yet"</h2>
</div>
<%end%>
<div class="right">
<%=render 'chats/messagechat'%>
<%end %>
<div style="font-size: 24px;">
<%= paginate @posts %>
</div>
</div>
<%else%>
<div class="left">
<h2>"No posts yet"</h2>
</div>
<%end%>


<%end%>
10 changes: 10 additions & 0 deletions app/views/shared/_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<style>
.logged-in {
font-size: 18px;
}
</style>
<div class="nav-bar">

<p class="logged-in">Currently logged in as: <%= @current_user.username %></p>
Expand All @@ -7,6 +12,11 @@
<span>Posts</span>
<% end %>

<%= link_to chats_path, class: "nav-item #{current_page?(chats_path) ? 'active' : ''}" do %>
<i class="fas fa-users"></i>
<span>Chats</span>
<% end %>

<%= link_to meetings_path, class: "nav-item #{current_page?(meetings_path) ? 'active' : ''}" do %>
<i class="fas fa-users"></i>
<span>Meetings</span>
Expand Down

0 comments on commit 3a10f2c

Please sign in to comment.