Skip to content

Commit

Permalink
beautified chatroom and added different avtars for user
Browse files Browse the repository at this point in the history
  • Loading branch information
Tejas Zambre committed Jun 1, 2020
1 parent e6cce5c commit 8dc63be
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 127 deletions.
Binary file added app/assets/images/avtar-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added app/assets/images/avtar-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/avtar-anonymous.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/avtar-beard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
182 changes: 155 additions & 27 deletions app/assets/stylesheets/custom.css.scss
Original file line number Diff line number Diff line change
@@ -1,62 +1,190 @@
@import "semantic-ui";

.chatbox{
height: 1305px;
#h1-tag-index{
font-size: 50px;
margin: 2% 0 0 5% !important;
padding-top: 10px;
}

#profile-pic-online{
margin-left: 20px;
}

#flash-messages{
font-size: 40px;
background-color: rgba(240, 240, 240, 1) !important;
border-radius: 65px;
margin-left: 10%;
position: absolute;
top: 10px;
width: 80%;
display: flex;
align-items: center;
justify-content: center;
}

#search-icon{
border-radius: 50;
background-color: rgba(240, 240, 240, 0.3);
display: flex;
align-items: flex-end;
padding-bottom: 5px;
justify-content: center;
color: white;
}

.rounded-text-field{
display: flex;
flex-direction: column;
}

#message_body{
border-radius: 80px !important;
background-color: rgba(240, 240, 240, 1);
height: 125px;
position: absolute;
border: white 5px solid;
margin: 0 3% 0 3%;
width: 94%;
font-size: 4rem;
bottom: 30px;
padding-left: 50px;
}

.cover{
background-color: black;
width: 100%;
}

.rounded-top{
border-top-right-radius: 65px;
border-top-left-radius: 65px;
border-top: rgba(255, 255, 255, 1) 30px solid;
height: 83vh !important;
display: flex;
flex-direction: column;
padding-bottom: 175px;
}

.user-name-online-list{
font-size: 30px;
text-align: center;
color: white;
}

#online-users-container{
display: flex;
flex: row wrap;
position: absolute;
width: 92%;
margin-left: 7%;
bottom: 84vh;
font-size: 60px;
overflow-x: auto;
}

#online-users-container::-webkit-scrollbar {
width: 0px;
background: transparent; /* make scrollbar transparent */
}

body{
background-image: linear-gradient(to right, rgb(35, 7, 77), rgb(204, 83, 51));
background-image: linear-gradient(to bottom, rgba(90, 80, 230, 1), rgba(255, 0, 0, 0.5));
// background-color: rgba(90, 80, 230, 1);
height: 100vh;
overflow: visible;
}

.half-chatbox{
height: 200px;
height: 15vh;
overflow: auto;
}

.chatbox{
position: absolute;
width: 100%;
bottom: 1px;
}

.custom-container{
margin: 0% 5%;
#navbar{
background-color: rgba(90, 80, 230, 1);
color: white;
}

#messages{
height: 15em;
overflow: auto;
background-image: linear-gradient(to right, rgba(35, 7, 77, 1), rgba(204, 83, 51, 1));
overflow: scroll;
background-color: white;
// background-image: linear-gradient(to right, rgba(35, 7, 77, 1), rgba(204, 83, 51, 1));
}

#time-on-message{
float: right;
margin-top: 5px;
margin-right: 0px;
#messages::-webkit-scrollbar {
width: 0px;
background: transparent; /* make scrollbar transparent */
}

#username-on-message{
float: left;
margin-left: 0px;
color: smokewhite;
font-size: 15px;
font-size: 25px;
}

#navbar{
font-size: 30px;
}

#users{
height: 15em;
overflow: auto;
}

// #h1-tag-index{
// color: white;
// }

#my-message-body{
margin: 2%;
font-size: 25px;
background-image: linear-gradient(to right, rgba(35, 7, 77, 1), rgba(204, 83, 51, 1));
color: white;
border-bottom-left-radius: 50px;
border-top-left-radius: 50px;
font-size: 35px;
padding-right: 40px;
max-width: 70%;
overflow-wrap: break-word;
word-wrap: break-word;
hyphens: auto;
margin: 2% 0;
// background-image: linear-gradient(to right, rgba(35, 7, 77, 1), rgba(204, 83, 51, 1));
background-color: rgba(229, 223, 237, 1);
border-bottom-left-radius: 60px;
border-top-left-radius: 60px;
border-top-right-radius: 60px;
}

#message-box{
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin: 0 3% 0 3%;
}

#frnd-message-body{
margin: 2%;
border-bottom-right-radius: 50px;
border-top-right-radius: 50px;
font-size: 25px;
background-image: linear-gradient(to right, rgba(35, 7, 77, 1), rgba(204, 83, 51, 1));
color: white;
margin: 2% 0;
padding-left: 40px;
border-bottom-right-radius: 60px;
max-width: 70%;
border-top-right-radius: 60px;
border-top-left-radius: 60px;
overflow-wrap: break-word;
word-wrap: break-word;
hyphens: auto;
font-size: 35px;
background-color: rgba(240, 240, 240, 1);
// background-image: linear-gradient(to right, rgba(35, 7, 77, 1), rgba(204, 83, 51, 1));
}

#time-on-message{
font-size: 30px !important;
}

#message-submit{
display: none;
#message-button {
display:none;
}
13 changes: 12 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ApplicationController < ActionController::Base

helper_method :current_user, :logged_in?
helper_method :current_user, :logged_in?, :avtar_selector

private
def current_user
Expand All @@ -25,4 +25,15 @@ def require_user
end
end

def avtar_selector(user)
if current_user
if user.id == 1
"avtar-beard.png"
elsif user.username == "anonymous"
"avtar-anonymous.png"
else
"avtar-#{user.id.modulo(3)}.png"
end
end
end
end
4 changes: 2 additions & 2 deletions app/javascript/channels/chatroom_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ consumer.subscriptions.create("ChatroomChannel", {

received(data) {
if ($('#h1-tag-index').data('current') == data.user) {
$('#message-container').append("<p class= 'ui right teal aligned header'><span class='ui label' id='my-message-body'><span id='username-on-message'><em>" + data.username + " :</em></span><br>" + data.mod_message + "<br><span class= 'ui grey circular mini label' id='time-on-message'>" + data.create_at + "</span></span></p>")
$('#message-container').append("<p class= 'ui right grey aligned header' id= 'message-box'><span class= '' id='time-on-message'>" + data.create_at + "</span><span class='ui label' id='my-message-body'>" + data.mod_message + "<br></span></p>")
} else {
$('#message-container').append("<p class= 'ui left teal aligned header'><span class='ui label' id='frnd-message-body'><span id='username-on-message'><em>" + data.username + " :</em></span><br>" + data.mod_message + "<br><span class= 'ui grey circular mini label' id='time-on-message'>" + data.create_at + "</span></span></p>")
$('#message-container').append("<p class= 'ui left grey aligned header' id= 'message-box'><span class='ui label' id='frnd-message-body'><span id='username-on-message'><em>" + data.username + " :</em></span><br>" + data.mod_message + "<br></span><span class= '' id='time-on-message'>" + data.create_at + "</span></p>")
}
scroll_bottom()
}
Expand Down
9 changes: 8 additions & 1 deletion app/javascript/channels/online_users_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ consumer.subscriptions.create("OnlineUsersChannel", {

received(data) {
// Called when there's incoming data on the websocket for this channel
$('#online-users-container').append("<div class='item' id='"+ data.id +"'><img class= 'ui avatar image' src= '/assets/avtar-for-message-me.png' id= 'profile-pic-online'><div class='content'><div class='header'>" + data.username + "</div></div></div>")
if (data.id == 1)
$('#online-users-container').append("<div class='item' id='"+ data.id +"'><img class= 'ui avatar image' src= '/assets/avtar-beard.png' id= 'profile-pic-online'></div>")
else if (data.username == "anonymous") {
$('#online-users-container').append("<div class='item' id='"+ data.id +"'><img class= 'ui avatar image' src= '/assets/avtar-anonymous.png' id= 'profile-pic-online'></div>")
}
else {
$('#online-users-container').append("<div class='item' id='"+ data.id +"'><img class= 'ui avatar image' src= '/assets/avtar-" + data.id % 3 + ".png' id= 'profile-pic-online'></div>")
}
}
});
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class User < ApplicationRecord
has_many :messages
has_secure_password
validates :username, length: { minimum: 5, maximum: 20 }, presence: true
validates :username, length: { minimum: 2, maximum: 20 }, presence: true
validates :password_digest, presence: true
end
48 changes: 17 additions & 31 deletions app/views/chatroom/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
<%= content_tag "h1", class: "ui center aligned inverted icon header", id: "h1-tag-index", data: {current: current_user.id} do%>
<i class="users icon"></i>
Welcome to Chatroom
<%= content_tag "h1", class: "ui inverted icon header", id: "h1-tag-index", data: {current: current_user.id} do%>
Message Me
<% end %>
<div class="ui stackable two column grid">
<div class="sixteen wide column">
<div class="ui fluid raised card half-chatbox">
<div class="content" id="users">
<div class="ui celled list" id= "online-users-container">
<h3>Online Friends:</h3>
<%= render partial: 'users/user', locals: { user: @user } %>
</div>
</div>
</div>
<div class="content" id="users">
<div class="" id= "online-users-container">
<div class= "ui avatar image" id= "search-icon"><i class="search icon"></i></div>
<%= render partial: 'users/user', locals: { user: @user } %>
</div>
<div class="sixteen wide column">
<div class="ui fluid raised green card chatbox">
<div class="content" id="messages">
<div class="ui feed" id="message-container">
<%= render @messages %>
</div>
</div>
<div class="extra content">
<%= form_for(@message, html: {class: "ui reply form", role: "form"}, url: message_path, remote: true) do |f| %>
<div class="field">
<div class="ui right massive icon input">
<%= f.text_field :body, id: "message_body", placeholder: "Enter your message"%>
<i class="rocket icon"></i>
<%= f.button '<i class="rocket icon"></i>'.html_safe, id: "message-submit" %>
</div>
</div>
<% end %>
</div>
</div>
<div class="chatbox">
<div class="rounded-top" id="messages">
<div class="ui feed" id="message-container">
<%= render @messages %>
</div>
</div>
<div class= "cover">
<%= form_for(@message, html: {class: "rounded-text-field", role: "form"}, url: message_path, remote: true) do |f| %>
<%= f.text_field :body, id: "message_body", placeholder: "Enter your message" %>
<%= f.button '<i class="rocket icon"></i>'.html_safe, id: "message-button"%>
<% end %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/layouts/_messages.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% flash.each do |type, content|%>
<div class="ui <%= type %> message transition">
<div class="ui <%= type %> message transition" id= "flash-messages">
<i class="close icon"></i>
<div class="header">
<%= content %>
Expand Down
26 changes: 9 additions & 17 deletions app/views/layouts/_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
<div class="ui massive inverted menu">
<div class="ui container">
<%= link_to "Chatroom", chatroom_path, class: "item"%>
<a class="item">
Friends
</a>
<div class="right menu">
<div class="ui dropdown item">
Account <i class="dropdown icon"></i>
<div class="menu">
<% if !logged_in? %>
<%= link_to "login", login_path, class: "item"%>
<% else %>
<%= link_to "logout", logout_path, method: :delete, class: "item"%>
<% end %>
</div>
</div>
<div class="ui massive top right attached label" id= "navbar">
<div class="ui dropdown item">
<i class="ellipsis vertical icon"></i>
<div class="menu">
<% if !logged_in? %>
<%= link_to "login", login_path, class: "item"%>
<% else %>
<%= link_to "logout", logout_path, method: :delete, class: "item"%>
<% end %>
</div>
</div>
</div>
5 changes: 1 addition & 4 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

<body>
<%= render 'layouts/navigation' %>
<div class="ui custom-container">
<%= render 'layouts/messages' %>
<%= yield %>
</div>
<%= yield %>
</body>
</html>
Loading

0 comments on commit 8dc63be

Please sign in to comment.