diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 94e7183..4b26cd2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,16 @@ class ApplicationController < ActionController::Base include Authentication # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. allow_browser versions: :modern + before_action :set_title, :set_current_user + layout "authenticated" + + private + + def set_title + @title = "Public scoreboard" + end + + def set_current_user + @current_user = current_user + end end diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index 8ff3af8..f9f1c14 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -3,14 +3,16 @@ class ContestsController < ApplicationController def index @contests = current_user.contests - @user = current_user + @title = "Welcome #{current_user.username}!" end def show + @title = "Contest: #{@contest.name}" end def new @contest = Contest.new + @title = "Create a new jigsaw puzzle competition" end def create diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index bcfe9e4..df35597 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2,9 +2,11 @@ class UsersController < ApplicationController before_action :set_user, only: %i[ destroy edit update show ] def index + @title = "All users" end def edit + @title = "My settings" end def update @@ -16,6 +18,7 @@ class UsersController < ApplicationController end def show + redirect_to edit_user_path(@user) end def new diff --git a/app/views/contests/_form.html.slim b/app/views/contests/_form.html.slim new file mode 100644 index 0000000..4e6cc02 --- /dev/null +++ b/app/views/contests/_form.html.slim @@ -0,0 +1,8 @@ += form_with model: contest do |form| + .row + .col.g-3 + .form-floating.mt-5 + = form.text_field :name, autocomplete: "off", class: "form-control" + = form.label :name, class: "required" + div.mt-3 + = form.submit \ No newline at end of file diff --git a/app/views/contests/index.html.slim b/app/views/contests/index.html.slim index 862f2ee..ce95c01 100644 --- a/app/views/contests/index.html.slim +++ b/app/views/contests/index.html.slim @@ -1,14 +1,3 @@ -- if authenticated? - .float-end.ms-3 - = button_to "Log out", session_path, method: :delete - .float-end.mt-1 - = link_to "Settings", user_path(@user) - -h1 Welcome! - -.alert.alert-primary role="alert" - | This is a brand new website! - h4.mt-4 Manage your contests - @contests.each do |contest| diff --git a/app/views/contests/new.html.slim b/app/views/contests/new.html.slim index 61e912d..ba7dd39 100644 --- a/app/views/contests/new.html.slim +++ b/app/views/contests/new.html.slim @@ -1,8 +1 @@ -h1 Create a new contest - -= form_with model: @contest do |form| - div - = form.label :name - = form.text_field :name - div - = form.submit \ No newline at end of file += render "form", contest: @contest \ No newline at end of file diff --git a/app/views/contests/show.html.slim b/app/views/contests/show.html.slim index d9343b3..e69de29 100644 --- a/app/views/contests/show.html.slim +++ b/app/views/contests/show.html.slim @@ -1,4 +0,0 @@ -h1 Contest: "#{@contest.name}" - -a.btn.btn-primary href=root_path - | Back to all contests \ No newline at end of file diff --git a/app/views/layouts/_header.html.slim b/app/views/layouts/_header.html.slim new file mode 100644 index 0000000..292144e --- /dev/null +++ b/app/views/layouts/_header.html.slim @@ -0,0 +1,16 @@ +head + title Puzzle Scoreboard + meta name="viewport" content="width=device-width,initial-scale=1" + meta name="apple-mobile-web-app-capable" content="yes" + meta name="mobile-web-app-capable" content="yes" + = csrf_meta_tags + = csp_meta_tag + + = yield :head + + link rel="icon" href="/icon.png" type="image/png" + link rel="icon" href="/icon.svg" type="image/svg+xml" + link rel="apple-touch-icon" href="/icon.png" + + = stylesheet_link_tag :app, "data-turbo-track": "reload" + = javascript_importmap_tags \ No newline at end of file diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim index a259889..fa8505f 100644 --- a/app/views/layouts/application.html.slim +++ b/app/views/layouts/application.html.slim @@ -1,22 +1,7 @@ doctype html html - head - title Puzzle Scoreboard - meta name="viewport" content="width=device-width,initial-scale=1" - meta name="apple-mobile-web-app-capable" content="yes" - meta name="mobile-web-app-capable" content="yes" - = csrf_meta_tags - = csp_meta_tag - - = yield :head - - link rel="icon" href="/icon.png" type="image/png" - link rel="icon" href="/icon.svg" type="image/svg+xml" - link rel="apple-touch-icon" href="/icon.png" - - = stylesheet_link_tag :app, "data-turbo-track": "reload" - = javascript_importmap_tags + = render "layouts/header" body .container.mt-5 - = yield + = yield \ No newline at end of file diff --git a/app/views/layouts/authenticated.html.slim b/app/views/layouts/authenticated.html.slim new file mode 100644 index 0000000..cb47eff --- /dev/null +++ b/app/views/layouts/authenticated.html.slim @@ -0,0 +1,16 @@ +doctype html +html + = render "layouts/header" + + body + .container.mt-5 + .float-end.ms-3 + = button_to "Log out", session_path, method: :delete + .float-end.mt-1.ms-3 + = link_to "Settings", user_path(@current_user) + .float-end.mt-1 + = link_to "Home", contests_path + + h1 = @title + + = yield \ No newline at end of file diff --git a/app/views/users/edit.html.slim b/app/views/users/edit.html.slim index aa549a3..4562a6b 100644 --- a/app/views/users/edit.html.slim +++ b/app/views/users/edit.html.slim @@ -1,3 +1 @@ -h1 Edit settings - = render "form", user: @user \ No newline at end of file diff --git a/app/views/users/new.html.slim b/app/views/users/new.html.slim index a1173f0..4562a6b 100644 --- a/app/views/users/new.html.slim +++ b/app/views/users/new.html.slim @@ -1,3 +1 @@ -h1 Create a new user - = render "form", user: @user \ No newline at end of file diff --git a/app/views/users/show.html.slim b/app/views/users/show.html.slim index 8822529..bf2e030 100644 --- a/app/views/users/show.html.slim +++ b/app/views/users/show.html.slim @@ -1,5 +1,3 @@ -h1 = @user.username - p |> Email: = @user.email_address