Skip to content
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
8bac5b0
minor fixes
techiealiraza Jun 2, 2023
9685bc3
Merge branch 'develop' of https://github.com/techiealiraza/rock-pappe…
techiealiraza Jun 2, 2023
c63eb8b
refactored
progammer743 Jun 4, 2023
eab445d
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 4, 2023
f4578e3
leaderBoard query optimized
progammer743 Jun 5, 2023
b8703d4
session find_by_email
techiealiraza Jun 5, 2023
f443726
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 5, 2023
30a66ca
enum roles defined
progammer743 Jun 5, 2023
0a4d12c
find removed from tournament_index_view
progammer743 Jun 5, 2023
c1be315
session controller fixed
techiealiraza Jun 5, 2023
a906740
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 5, 2023
503a783
session controller
techiealiraza Jun 5, 2023
b15f867
matches index
techiealiraza Jun 5, 2023
ce66ae2
offset issue resolved
progammer743 Jun 5, 2023
17b17d3
Merge remote-tracking branch 'refs/remotes/origin/develop_new' into d…
progammer743 Jun 5, 2023
1e770b0
undefined winner name fixed
progammer743 Jun 5, 2023
d419bcb
brackets and spacings
techiealiraza Jun 5, 2023
0f93138
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 5, 2023
ee7e900
rename column name match_time to time & message to content
progammer743 Jun 5, 2023
0bb6c22
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 5, 2023
03e7102
selection name in selections to choice
progammer743 Jun 5, 2023
34544af
renamed column from match_winner_id to winner_id
progammer743 Jun 5, 2023
26f80da
rename column tournament_winner_id to winner_id
progammer743 Jun 5, 2023
6e93ee0
session fixes
techiealiraza Jun 5, 2023
fb05e39
Session Fixes
techiealiraza Jun 5, 2023
6f011a7
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 5, 2023
0c55f34
session fixed
techiealiraza Jun 5, 2023
5f7824b
removed unused params method from matches_controller
progammer743 Jun 5, 2023
ae05494
removed winner
progammer743 Jun 5, 2023
6bf4edf
added params to matcehs
progammer743 Jun 5, 2023
2c5342f
Merge remote-tracking branch 'refs/remotes/origin/develop_new' into d…
progammer743 Jun 5, 2023
058b238
removed params & aincludes winner
progammer743 Jun 5, 2023
37efbda
includes user in selections
progammer743 Jun 5, 2023
9f9d99c
choices updated in match model
progammer743 Jun 5, 2023
a8106b7
validation
techiealiraza Jun 5, 2023
3b8b882
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 5, 2023
b7c4da4
controller load_and_authorize fixed
techiealiraza Jun 6, 2023
432274d
comments resolved
progammer743 Jun 6, 2023
6eed13c
Merge remote-tracking branch 'refs/remotes/origin/develop_new' into d…
progammer743 Jun 6, 2023
ff31f54
removed un-used code & refactored
progammer743 Jun 6, 2023
83f6818
removed unused scopes
progammer743 Jun 7, 2023
6206f9a
space removed
techiealiraza Jun 7, 2023
dd56a25
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 7, 2023
0293f8a
replaced ' with " for consistency
techiealiraza Jun 7, 2023
483fc73
' ' to "" changed
techiealiraza Jun 7, 2023
0c33b29
renamed partial of choice_image
progammer743 Jun 7, 2023
01f5de8
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 7, 2023
014230d
selection ability updated
progammer743 Jun 7, 2023
6c6f70e
deleted unnecessary files
techiealiraza Jun 7, 2023
dc3db55
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 7, 2023
8984936
removed comment from load_controller.js
progammer743 Jun 7, 2023
2496747
text size responsiveness in choice_timer
progammer743 Jun 7, 2023
d174db3
added scopes in tournament model
progammer743 Jun 7, 2023
f241a91
resolved commits
progammer743 Jun 7, 2023
ba5eec0
match controller + views updated
progammer743 Jun 7, 2023
b719e16
message controller
techiealiraza Jun 8, 2023
0371c6b
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 8, 2023
1290b14
added match done/un_done scopes in match model
progammer743 Jun 8, 2023
e2d3948
Merge remote-tracking branch 'refs/remotes/origin/develop_new' into d…
progammer743 Jun 8, 2023
585f57c
respond_to fixed
techiealiraza Jun 8, 2023
15612e2
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 8, 2023
4f3dfe8
comments resolved
progammer743 Jun 8, 2023
91d0fd9
renamed tournamentMatchCreator & removed un-used methods from tournam…
progammer743 Jun 8, 2023
c6a32e8
refactored and added js views for create action of msg and selection
progammer743 Jun 9, 2023
88f3d63
image validation added
techiealiraza Jun 9, 2023
ecf5719
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 9, 2023
08bc5e4
Image Validations
techiealiraza Jun 9, 2023
3e8540e
refactored code
progammer743 Jun 9, 2023
52f176e
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 9, 2023
a6a1c91
updated variables_names & refactored
progammer743 Jun 9, 2023
78a4d85
removed un-used includes
progammer743 Jun 9, 2023
b67c214
gem file
techiealiraza Jun 11, 2023
1b0599e
followed camelCase in js & moved model code from Delayed Job
progammer743 Jun 11, 2023
4f743c0
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 11, 2023
7e7f7f8
validation
techiealiraza Jun 12, 2023
b429d5a
image validation
techiealiraza Jun 12, 2023
d4b5ea9
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 12, 2023
ad41d0e
after perform of MAtch Play job is moved to Service
progammer743 Jun 12, 2023
9b2f84c
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 12, 2023
a670aa2
added callback to selection create & removed user_id hidden field mes…
progammer743 Jun 12, 2023
9db7725
rename un_done to undone
progammer743 Jun 12, 2023
f1deb15
DRY
techiealiraza Jun 12, 2023
8485ce0
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 12, 2023
372a718
removed unused method from the match model
progammer743 Jun 12, 2023
98d4da9
wrong route error handled
techiealiraza Jun 12, 2023
be4de17
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 12, 2023
994534e
rename play_match_channel to match_channel
progammer743 Jun 12, 2023
b920d12
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 12, 2023
68bd19a
gem file
techiealiraza Jun 12, 2023
310e49b
removed unused gems
progammer743 Jun 12, 2023
f2bfc57
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 12, 2023
ab8dc1e
gem
techiealiraza Jun 12, 2023
6a66a0c
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 12, 2023
4d1895a
session alert problem fixed
techiealiraza Jun 12, 2023
bdd4890
refactored and removed unused code
progammer743 Jun 12, 2023
ea00633
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 12, 2023
bef894f
refactored code
progammer743 Jun 13, 2023
2b94b97
removed unused code from match.rb
progammer743 Jun 13, 2023
6e79e22
routes fixed
techiealiraza Jun 13, 2023
c3a9139
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 13, 2023
2b1225a
updated routes
progammer743 Jun 13, 2023
7565948
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 13, 2023
0f8f132
un comment routing error
techiealiraza Jun 13, 2023
62f5f9e
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 13, 2023
45b855e
remove unused code
techiealiraza Jun 13, 2023
30e9daa
Session controller fixed
techiealiraza Jun 13, 2023
23a5259
nested selection under the matches
progammer743 Jun 13, 2023
13c8925
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 13, 2023
e6a7369
js files refactoring
techiealiraza Jun 13, 2023
f9f9869
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 13, 2023
1fee544
fixed typo in touranment's form
progammer743 Jun 13, 2023
ab8f4c7
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 13, 2023
9a0677d
removed unused code from tailwind.config.js
progammer743 Jun 13, 2023
ac69b3f
use assets instead of online images in edit file of registration
progammer743 Jun 13, 2023
d0fe754
added routes paths in new of registration and session files
progammer743 Jun 13, 2023
405a2f6
replace all Sign in to Log in
progammer743 Jun 13, 2023
fe6bb12
fixed typo
progammer743 Jun 13, 2023
23102af
added validation in selection
progammer743 Jun 13, 2023
0baa2e3
fixes view issues show matches/tournaments
progammer743 Jun 13, 2023
e74bf13
views fixed
techiealiraza Jun 13, 2023
f4b6b42
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 13, 2023
d369859
session controller invalid password msg updated
progammer743 Jun 13, 2023
6e124f0
tournaments path and render fixed
techiealiraza Jun 13, 2023
74551ce
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 13, 2023
6db77ce
gwm file lock fixed
techiealiraza Jun 13, 2023
f19dcd3
updated Gemfile.lock and renamed broadcaster to action_cable_broadcaster
progammer743 Jun 13, 2023
a4fffae
Merge remote-tracking branch 'origin/develop_new' into develop_new
progammer743 Jun 13, 2023
58d64af
match scores fix
techiealiraza Jun 14, 2023
db3f218
Merge branch 'develop_new' of https://github.com/techiealiraza/rock-p…
techiealiraza Jun 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions app/controllers/matches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class MatchesController < ApplicationController
load_and_authorize_resource :tournament
load_and_authorize_resource through: :tournament
skip_load_and_authorize_resource only: :all
skip_load_and_authorize_resource only: %i[all playmatch]

def index
@matches = @matches.includes([:winner]).desc.page(params[:page])
Expand All @@ -21,8 +21,8 @@ def new
end

def playmatch
@match = Match.includes([:users]).find(params[:match_id])
redirect_to result_tournament_match_path(match_id: @match) unless @match.match_winner_id.nil?
@match = @tournament.matches.includes([:users]).find(params[:match_id])
redirect_to result_tournament_match_path(match_id: @match) unless @match.winner_id.nil?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@players = @match.users
@remaining_tries = @match.remaining_tries(@players.first.id)
@done_tries = @match.selections.by_user(@players.first.id).size
Expand All @@ -33,14 +33,8 @@ def playmatch
def result
@is_player = @match.users.include?(current_user)
@players = @match.users
@players_selections = @match.selections.order(:try_num).group_by(&:user_id)
@players_selections = @match.selections.includes(:user).order(:try_num).group_by(&:user_id)
@players_scores = @match.selections.group(:user_id).winner.count
@result_message = @match.result_message(current_user.id)
end

private

def match_params
params.require(:match).permit(:match_winner_id, :winner_score, :match_time, :tournament_id)
end
end
2 changes: 1 addition & 1 deletion app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ def create
private

def message_params
params.permit(:user_id, :match_id, :message)
params.permit(:user_id, :match_id, :content)
end
end
2 changes: 1 addition & 1 deletion app/controllers/selection_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def new
private

def selection_params
params.require(:selection).permit(:match_id, :user_id, :selection)
params.require(:selection).permit(:match_id, :user_id, :choice)
end
end
9 changes: 4 additions & 5 deletions app/controllers/tournaments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class TournamentsController < ApplicationController
before_action :authenticate_user!, except: [:index]

def index
@tournaments = Tournament.includes(:users).all
@tournaments = Tournament.includes(%i[users winner]).all
@tournaments = @tournaments.order(:registration_deadline).page(params[:page])
end

Expand All @@ -28,10 +28,10 @@ def register
def create_matches
registered_users = @tournament.users
length = registered_users.length
return unless (length - 8) != 0
return if (length - 8) != 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return if (length - 8) != 0
return if length != 8

Check if length is power of 2 or not.


begin

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MatchCreator.new(@tournament, registered_users).create_match
MatchCreator.new(@tournament, registered_users).call
redirect_to tournament_path(@tournament), notice: 'Matches Generated'
rescue StandardError => e
redirect_to tournament_path(@tournament), alert: "Error generating matches: #{e.message}"
Expand All @@ -40,7 +40,6 @@ def create_matches

def create
@tournament = Tournament.new(tournament_params)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Load everything using cancancan, This is missing in some other places as well

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

respond_to do |format|
if @tournament.save
format.html { redirect_to tournament_url(@tournament), notice: 'Tournament was successfully created.' }
Expand Down Expand Up @@ -77,7 +76,7 @@ def tournament_params
:description,
:start_date,
:end_date,
:tournament_winner_id,
:winner_id,
:image,
:registration_deadline)
end
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/users/confirmations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def show
end
end

# protected
protected

def after_confirmation_path_for(_resource_name, resource)
sign_in(resource)
root_path
Expand Down
52 changes: 15 additions & 37 deletions app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,29 @@
# frozen_string_literal: true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed ?


module Users
class SessionsController < Devise::SessionsController
before_action :authenticate_2fa!, only: [:create]
before_action :otp_generate_and_send, only: [:create]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
before_action :otp_generate_and_send, only: [:create]
before_action :generate_and_send_otp, only: [:create]

before_action :authenticate_user!, except: %i[new create destroy]
before_action :load_and_authorize_resource, except: %i[new create destroy]

def create
super do |resource|
if resource.valid? && resource.persisted?
resource.update(
otp_required_for_login: true
)
end
end
def verify_otp
authenticate_2fa!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are calling just another method from the main method ? Never do it.

Always try to break the function and call multiple functions from there ?
Either you can paste all the code of authenticate_2fa! here or break it into functions of its doing multiple things and call those functions ?

end

private

def authenticate_2fa!
user = self.resource = find_user
return unless user

if otp_attempt_present?
authenticate_with_2fa(user)
sign_in(:user, user)
elsif valid_password_and_otp_required?(user)
session[:user_id] = user.id
send_otp_code(user)
render 'user_otp/two_fa'
end
user = User.find_by(id: session[:user_id])
User.auth_with_2fa(user_params[:otp_attempt], user)
sign_in(:user, user)
redirect_to root_path, notice: 'OTP consumed Successfully.'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User can login without entering password and OTP,

end

def otp_attempt_present?
user_params[:otp_attempt].present?
end
def otp_generate_and_send
user = self.resource = User.find_by(email: user_params[:email])

def authenticate_with_2fa(user)
User.auth_with_2fa(user_params[:otp_attempt], user)
return unless user

valid_password_and_otp_required?(user)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will be sending OTP even if the password is wrong. This is a security risk.

session[:user_id] = user.id
send_otp_code(user)
render 'user_otp/two_fa'
end

def valid_password_and_otp_required?(user)
Expand All @@ -48,14 +34,6 @@ def send_otp_code(user)
TwoFactorAuth.new(user).send_otp_code

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed about convention of using .call when using services ?

end

def find_user
if session[:user_id]
User.find_by(id: session[:user_id])
elsif user_params[:email]
User.find_by(email: user_params[:email])
end
end

def user_params
params.require(:user).permit(:authenticity_token, :email, :password, :otp_attempt, :remember_me)
end
Expand Down
7 changes: 7 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module ApplicationHelper
def custom_index(collection, index)
per_page = collection.limit_value
starting_index = (collection.current_page - 1) * per_page + 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collection.offset_value can be used here

starting_index + index
end
end
63 changes: 30 additions & 33 deletions app/javascript/channels/room_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,38 @@ document.addEventListener("turbolinks:load", () => {
received(data) {
const msgs = document.getElementById("message-list");
const current_user = document.getElementById("current_user");
const current_user_name = current_user.getAttribute(
"data-current-user-name"
);
const msg_element = document.getElementById(
`msg_field_${data.user_name}`
);
const current_user_name = current_user.getAttribute("data-current-user-name");
const msg_element = document.getElementById(`msg_field_${data.user_name}`);
let messageHTML;
if (data.user_name === current_user_name) {
messageHTML = `<div class="my-1 flex flex-row">
<div class="rounded-full bg-white w-7 text-black text-center h-7">
${data.user_name.substring(0, 3)}
</div>
<div class ="flex flex-col space-y-2 text-xs ml-2 items-start">
<div class="line-clamp-10 max-w-sm text-lg px-3 py-2 my-1 rounded-lg rounded-br-none rounded-tl-none bg-white text-black">
${data.message}
</div>
<div class="flex flex-row items-end">
<div class="text-white">${data.created_at}</div>
</div>
</div>
</div>`;
} else {
messageHTML = `<div class="my-1 flex flex-row">
<div class="rounded-full bg-gold_shade2 w-7 text-white text-center h-7">
${data.user_name.substring(0, 3)}
</div>
<div class="flex flex-col space-y-2 text-xs ml-2 items-start">
<div class="line-clamp-10 max-w-sm text-lg px-3 py-2 my-1 rounded-lg rounded-br-none rounded-tl-none bg-gold text-black">
${data.message}
</div>
<div class="flex flex-row items-end">
<div class="text-white">${data.created_at}</div>
</div>
</div>
</div>`;
messageHTML = `<div class = "my-1 flex flex-row">

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
messageHTML = `<div class = "my-1 flex flex-row">
messageHTML = `<div class="my-1 flex flex-row">

<div class = "rounded-full bg-white w-7 text-black text-center h-7">
${data.user_name.substring(0, 3)}
</div>
<div class ="flex flex-col space-y-2 text-xs ml-2 items-start">
<div class="line-clamp-10 max-w-sm text-lg px-3 py-2 my-1 rounded-lg rounded-br-none rounded-tl-none bg-white text-black">

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing issue

${data.message}
</div>
<div class = "flex flex-row items-end">
<div class = "text-white">${data.created_at}</div>
</div>
</div>
</div>`;
}
else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for if else, DRY this code.

messageHTML = `<div class = "my-1 flex flex-row">
<div class = "rounded-full bg-gold_shade2 w-7 text-white text-center h-7">
${data.user_name.substring(0, 3)}
</div>
<div class ="flex flex-col space-y-2 text-xs ml-2 items-start">
<div class="line-clamp-10 max-w-sm text-lg px-3 py-2 my-1 rounded-lg rounded-br-none rounded-tl-none bg-gold text-black">
${data.message}
</div>
<div class = "flex flex-row items-end">
<div class = "text-white">${data.created_at}</div>
</div>
</div>
</div>`;
}

msgs.insertAdjacentHTML("afterbegin", messageHTML);
Expand Down
29 changes: 18 additions & 11 deletions app/javascript/controllers/countdown_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,28 @@ import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
connect = (format = "seconds") => {
const reg_date = this.data.get("time");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this variable

const tournament_id = this.data.get("id");
const number = reg_date;
const time_in_seconds = reg_date;
const daysElement = document.getElementById("days");
const hoursElement = document.getElementById("hours");
const minutesElement = document.getElementById("minutes");
const secondsElement = document.getElementById("seconds");
let countdown;
console.log(time_in_seconds);
if (time_in_seconds < 0) {
clearDivs();
return;
}
convertFormat(format);
function convertFormat(format) {
switch (format) {
case "seconds":
return timer(number);
return timer(time_in_seconds);
case "minutes":
return timer(number * 60);
return timer(time_in_seconds * 60);
case "hours":
return timer(number * 60 * 60);
return timer(time_in_seconds * 60 * 60);
case "days":
return timer(number * 60 * 60 * 24);
return timer(time_in_seconds * 60 * 60 * 24);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for this function.

}
}

Expand All @@ -32,18 +36,21 @@ export default class extends Controller {
const secondsLeft = Math.round((then - Date.now()) / 1000);

if (secondsLeft <= 0) {
document.getElementById("days").style.display = "none";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document.getElementById("hours").style.display = "none";
document.getElementById("minutes").style.display = "none";
document.getElementById("seconds").style.display = "none";
clearDivs();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed

clearInterval(countdown);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe its not needed.

location.reload;
return;
}

displayTimeLeft(secondsLeft);
}, 1000);
}

function clearDivs() {
daysElement.style.display = "none";
hoursElement.style.display = "none";
minutesElement.style.display = "none";
secondsElement.style.display = "none";
}
function displayTimeLeft(seconds) {
daysElement.textContent = Math.floor(seconds / 86400);
hoursElement.textContent = Math.floor((seconds % 86400) / 3600);
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ application.load(definitionsFromContext(context));
import CountdownController from "./countdown_controller";
application.register("countdown", CountdownController);

import LoadController from "./load_controller"
application.register("load", LoadController)
import LoadController from "./load_controller";
application.register("load", LoadController);
2 changes: 1 addition & 1 deletion app/javascript/controllers/load_controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller } from "@hotwired/stimulus"
import { Controller } from "@hotwired/stimulus";

// Connects to data-controller="laod-file"
export default class extends Controller {
Expand Down
10 changes: 2 additions & 8 deletions app/javascript/packs/buttons_activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ function event_listener_to_buttons() {
var user_image;
var flag = false;

if (player1_id === user_id) {
user_image = document.getElementById(player1_id);
flag = true;
} else if (player2_id === user_id) {
user_image = document.getElementById(player2_id);
flag = true;
}
if (flag) {
if(player1_id === user_id || player2_id === user_id){

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[player1_id, player2_id].include(user_id)

No samosa point

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user_image = document.getElementById(user_id);
document
.getElementById("rock_button")
.addEventListener("click", function () {
Expand Down
Loading