From 862cb4e3f9b9864bc1b5a20cd7ebd7c4d6cccb77 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 29 Oct 2023 14:46:27 -0400 Subject: added timer --- app/assets/stylesheets/wittle/general.css.scss | 33 ++++++++++++++++++++++-- app/controllers/wittle/puzzles_controller.rb | 4 ++- app/helpers/wittle/puzzles_helper.rb | 5 ++++ app/views/wittle/puzzles/_handle_puzzle.html.erb | 32 ++++++++++++++++++++--- app/views/wittle/puzzles/_submission.html.haml | 2 ++ app/views/wittle/puzzles/show.html.haml | 14 +++++++--- 6 files changed, 79 insertions(+), 11 deletions(-) diff --git a/app/assets/stylesheets/wittle/general.css.scss b/app/assets/stylesheets/wittle/general.css.scss index b2b432d..9d893b6 100644 --- a/app/assets/stylesheets/wittle/general.css.scss +++ b/app/assets/stylesheets/wittle/general.css.scss @@ -75,17 +75,46 @@ input[type="range"]::-ms-thumb { #scores { display: flex; - + div { flex: 0 0 48%; h2 { text-align: center; } - + table { width: max-content; margin: 0 auto; } } } + +#activation-button { + button { + display: block; + margin: 0 auto; + width: 25%; + background-color: #04AA6D; + padding: 14px 28px; + font-size: 16px; + cursor: pointer; + text-align: center; + color: white; + } +} + +#timer { + width: max-content; + margin: 0.5em auto 0; + font-size: 3em; + + %label { + padding: 0; + } +} + +.score-field { + padding-left: 1em; + text-align: right; +} diff --git a/app/controllers/wittle/puzzles_controller.rb b/app/controllers/wittle/puzzles_controller.rb index 9599307..ed7087a 100644 --- a/app/controllers/wittle/puzzles_controller.rb +++ b/app/controllers/wittle/puzzles_controller.rb @@ -24,6 +24,8 @@ module Wittle @puzzle.save! end + @time = (params.include? :time) ? params[:time] : nil + session[:played_puzzles] ||= [] session[:played_puzzles] << @puzzle.id end @@ -33,7 +35,7 @@ module Wittle raise ActiveRecord::RecordNotFound unless @puzzle.latest? - @puzzle.scores.create!(name: params[:name], ip: request.ip) + @puzzle.scores.create!(name: params[:name], ip: request.ip, seconds_taken: (params.include? :time) ? params[:time] : nil) redirect_to @puzzle end diff --git a/app/helpers/wittle/puzzles_helper.rb b/app/helpers/wittle/puzzles_helper.rb index 6230940..64364c6 100644 --- a/app/helpers/wittle/puzzles_helper.rb +++ b/app/helpers/wittle/puzzles_helper.rb @@ -1,4 +1,9 @@ module Wittle module PuzzlesHelper + + def humanize_interval(seconds) + "#{(seconds / 60).to_s.rjust(2, '0')}:#{(seconds % 60).to_s.rjust(2, '0')}" + end + end end diff --git a/app/views/wittle/puzzles/_handle_puzzle.html.erb b/app/views/wittle/puzzles/_handle_puzzle.html.erb index 3ac868e..3d593a4 100644 --- a/app/views/wittle/puzzles/_handle_puzzle.html.erb +++ b/app/views/wittle/puzzles/_handle_puzzle.html.erb @@ -1,6 +1,23 @@