Skip to content

Commit

Permalink
Refactor layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio-e committed Sep 24, 2024
1 parent 257ddb0 commit fa9f84d
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 58 deletions.
54 changes: 11 additions & 43 deletions app/helpers/navigation_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
module NavigationHelper
def nav_icon_class_for(paths)
return "fill-red w-6 h-6" if paths.any? { |p| active_path?(p) }
"fill-grey-400 w-6 h-6"
if paths.any? { |p| active_path?(p) }
"fill-red w-6 h-6"
else
"fill-grey-400 w-6 h-6"
end
end

def nav_text_class_for(paths)
return "text-red" if paths.any? { |p| active_path?(p) }
"text-grey-400"
if paths.any? { |p| active_path?(p) }
"text-red"
else
"text-grey-400"
end
end

def active_path?(path)
Expand All @@ -19,12 +25,6 @@ def title(title)
content_for :title, title
end

def show_back_button?
current_page?(notification_settings_path) ||
resource_show_page?("speakers") ||
resource_show_page?("sessions")
end

def back_title
if controller_name.include?("_")
controller_name.humanize
Expand All @@ -33,39 +33,7 @@ def back_title
end
end

def show_header?
(user_signed_in? || !current_page?(unauthenticated_root_path)) &&
!current_page?(new_user_session_path) &&
!current_page?(about_path) &&
!current_page?(coming_soon_path) &&
!show_back_button?
end

def show_bottom_navbar?
current_page?(sessions_path) ||
(user_signed_in? || !current_page?(unauthenticated_root_path)) &&
!bottom_navbar_excluded_paths.any? { |path| current_page?(path) }
end

def show_bookmark_button?(session)
return true if controller_name == "schedules"

!session.past?
end

private

def bottom_navbar_excluded_paths
[
new_user_session_path,
new_registration_path,
new_password_reset_path,
edit_password_reset_path,
post_submit_password_reset_path
]
end

def resource_show_page?(resource)
controller_name == resource && action_name == "show"
controller_name == "schedules" || !session.past?
end
end
4 changes: 4 additions & 0 deletions app/views/abouts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@
</div>
</div>
</div>

<% content_for :bottom_nav do %>
<%= render partial: "layouts/bottom_navbar", locals: { unread_notifications: current_user&.notifications&.unread } %>
<% end %>
File renamed without changes.
File renamed without changes.
12 changes: 2 additions & 10 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@
data-web-push-notifications-notifications-enabled-value=#{current_profile.web_push_notifications}" : '' %>>

<div class="fixed top-0 z-40 w-full">
<% if show_back_button? %>
<%= render partial: "layouts/back_button" %>
<% end %>
<% if show_header? %>
<%= render partial: "layouts/header" %>
<% end %>
<%= yield :top_nav %>
</div>

<main class="flex flex-col flex-1 w-full mx-auto">
Expand All @@ -56,8 +50,6 @@
<%= yield %>
</main>

<% if show_bottom_navbar? %>
<%= render partial: "layouts/bottom_navbar", locals: { unread_notifications: current_user&.notifications&.unread } %>
<% end %>
<%= yield :bottom_nav %>
</body>
</html>
8 changes: 8 additions & 0 deletions app/views/notification_settings/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<%= title "Notifications settings - Rails World 2024" %>
<% content_for :top_nav do %>
<%= render partial: "layouts/secondary_top_nav" %>
<% end %>
<%= form_with(
model: current_user.profile,
url: notification_settings_path,
Expand Down Expand Up @@ -32,3 +36,7 @@
</p>
</div>
<% end %>
<% content_for :bottom_nav do %>
<%= render partial: "layouts/bottom_navbar", locals: { unread_notifications: current_user&.notifications&.unread } %>
<% end %>
8 changes: 8 additions & 0 deletions app/views/notifications/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<%= title "Notifications - Rails World 2024" %>
<% content_for :top_nav do %>
<%= render partial: "layouts/primary_top_nav" %>
<% end %>

<div class="flex flex-col items-center flex-1 px-5 pt-safe-area-header pb-safe-area-bottom-navbar">
<div class="flex flex-col items-start w-full h-full max-w-screen-sm pt-6">
<h1 class="text-3xl italic font-bold">Notifications</h1>
Expand Down Expand Up @@ -43,3 +47,7 @@
<% end %>
</div>
</div>

<% content_for :bottom_nav do %>
<%= render partial: "layouts/bottom_navbar", locals: { unread_notifications: current_user&.notifications&.unread } %>
<% end %>
4 changes: 4 additions & 0 deletions app/views/password_resets/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<% content_for :top_nav do %>
<%= render partial: "layouts/primary_top_nav" %>
<% end %>

<div class="flex flex-col items-center flex-1 h-screen px-5 pb-10 bg-purple-dark pt-safe-area-header">
<%= form_with model: @user, url: password_reset_path, class: "flex flex-col h-full w-full max-w-screen-sm justify-between pt-10" do |form| %>
<div class="flex flex-col">
Expand Down
4 changes: 4 additions & 0 deletions app/views/passwords/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<% content_for :top_nav do %>
<%= render partial: "layouts/primary_top_nav" %>
<% end %>

<h1>Update Password</h1>

<%= form_with model: Current.user, url: password_path do |form| %>
Expand Down
8 changes: 8 additions & 0 deletions app/views/profiles/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<%= title "Edit profile - Rails World 2024" %>
<% content_for :top_nav do %>
<%= render partial: "layouts/primary_top_nav" %>
<% end %>
<%= content_for(:head) do %>
<%# Disabling morphing so that when an error occurs, the user is "redirected" to the top of the page %>
<meta name="turbo-refresh-method" content="replace">
Expand Down Expand Up @@ -115,3 +119,7 @@
<% end %>
</div>
</div>

<% content_for :bottom_nav do %>
<%= render partial: "layouts/bottom_navbar", locals: { unread_notifications: current_user&.notifications&.unread } %>
<% end %>
9 changes: 8 additions & 1 deletion app/views/profiles/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<% profile_name = @profile.name.presence || "Anonymous" %>
<%= title "#{profile_name}'s Profile - Rails World 2024" %>
<% content_for :top_nav do %>
<%= render partial: "layouts/primary_top_nav" %>
<% end %>

<div class="relative flex flex-col h-full items-center justify-between flex-1 bg-grey-50 pt-safe-area-header pb-safe-area-bottom-navbar">
<div class="flex flex-col items-center bg-cover bg-bottom bg-no-repeat max-h-[430px] w-full" style="background-image: url(<%= asset_path 'background_design.svg' %>)">
<div class="z-10 flex flex-col items-start w-full max-w-screen-sm px-5 pt-6 pb-12">
Expand Down Expand Up @@ -82,3 +85,7 @@
</div>
<% end %>
</div>

<% content_for :bottom_nav do %>
<%= render partial: "layouts/bottom_navbar", locals: { unread_notifications: current_user&.notifications&.unread } %>
<% end %>
18 changes: 16 additions & 2 deletions app/views/registrations/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<% content_for :top_nav do %>
<%= render partial: "layouts/primary_top_nav" %>
<% end %>

<div class="flex flex-col items-center flex-1 px-5 pb-10 bg-purple-dark pt-safe-area-header">
<%= form_with model: @user, url: registration_path, class: "flex flex-col h-full justify-between w-full max-w-screen-sm pt-10" do |form| %>
<div class="flex flex-col">
Expand All @@ -17,13 +21,23 @@

<div class="flex flex-col mb-6">
<%= form.label :password, class: "text-white italic font-bold mb-2" %>
<%= form.password_field :password, required: true, data: { test_id: "password_field" }, placeholder: "You know how a strong password goes, right?" %>
<%= form.password_field(
:password, required: true,
data: { test_id: "password_field" },
pattern: ".{8,}",
placeholder: "Enter your password"
) %>
<p class="pt-1 text-xs text-white">Password should contain at least 8 characters</p>
</div>

<div class="flex flex-col">
<%= form.label :password_confirmation, class: "text-white italic font-bold mb-2" %>
<%= form.password_field :password_confirmation, required: true, data: { test_id: "password_confirmation_field" }, placeholder: "Confirm strong password" %>
<%= form.password_field(
:password_confirmation, required: true,
data: { test_id: "password_confirmation_field" },
pattern: ".{8,}",
placeholder: "Confirm password"
) %>
<%= form.error_message :password_confirmation %>
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions app/views/schedules/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<%= title "My Schedule - Rails World 2024" %>
<% content_for :top_nav do %>
<%= render partial: "layouts/primary_top_nav" %>
<% end %>

<div class="flex flex-col items-center h-full bg-grey-50 pt-safe-area-header">
<div class="flex flex-col items-center w-full h-full max-w-screen-md px-5">
<div class="sticky top-safe-area-header z-30 flex flex-col items-center w-full pt-6 bg-grey-50">
Expand Down Expand Up @@ -63,3 +67,7 @@
</div>
</div>
</div>

<% content_for :bottom_nav do %>
<%= render partial: "layouts/bottom_navbar", locals: { unread_notifications: current_user&.notifications&.unread } %>
<% end %>
8 changes: 8 additions & 0 deletions app/views/sessions/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<%= title "Agenda - Rails World 2024" %>
<% content_for :top_nav do %>
<%= render partial: "layouts/primary_top_nav" %>
<% end %>

<div class="flex flex-col items-center h-full bg-grey-50 pt-safe-area-header">
<div class="flex flex-col items-center w-full h-full max-w-screen-md px-5">
<div class="sticky top-safe-area-header z-30 flex flex-col items-center w-full pt-6 bg-grey-50">
Expand Down Expand Up @@ -62,3 +66,7 @@
</div>
</div>
</div>

<% content_for :bottom_nav do %>
<%= render partial: "layouts/bottom_navbar", locals: { unread_notifications: current_user&.notifications&.unread } %>
<% end %>
8 changes: 8 additions & 0 deletions app/views/sessions/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<%= title "#{@session.title} - Rails World 2024" %>
<% content_for :top_nav do %>
<%= render partial: "layouts/secondary_top_nav" %>
<% end %>

<div class="relative flex flex-col items-center justify-between flex-1 pb-5 bg-grey-50 pt-safe-area-back-button pb-safe-area-bottom-navbar">
<div class="w-full px-5 pt-3 pb-12 bg-bottom bg-no-repeat bg-cover" style="background-image: url(<%= asset_path 'background_design.svg' %>)">
<div class="flex flex-col max-w-screen-sm mx-auto">
Expand Down Expand Up @@ -113,3 +117,7 @@
</div>
<% end %>
</div>

<% content_for :bottom_nav do %>
<%= render partial: "layouts/bottom_navbar", locals: { unread_notifications: current_user&.notifications&.unread } %>
<% end %>
4 changes: 2 additions & 2 deletions app/views/shared/_form_errors.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
</template>
<div id="shared-errors" class="w-full p-3 my-5 text-white rounded-md bg-red">
<h2 class="font-bold">The following errors were found:</h2>
<ol>
<ul>
<% local_assigns[:errors].each do |message| %>
<li><%= message %></li>
<% end %>
</ol>
</ul>
</div>
<% end %>
8 changes: 8 additions & 0 deletions app/views/speakers/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<%= title "#{@profile.name} - Rails World 2024" %>
<% content_for :top_nav do %>
<%= render partial: "layouts/secondary_top_nav" %>
<% end %>

<div class="relative flex flex-col items-center justify-between flex-1 bg-grey-50 pt-safe-area-back-button pb-safe-area-bottom-navbar">
<div class="w-full px-5 pt-6 pb-12 bg-bottom bg-no-repeat bg-cover " style="background-image: url(<%= asset_path 'background_design.svg' %>)">
<div class="z-10 flex flex-col items-start max-w-screen-sm mx-auto">
Expand Down Expand Up @@ -75,3 +79,7 @@
</div>
</div>
</div>

<% content_for :bottom_nav do %>
<%= render partial: "layouts/bottom_navbar", locals: { unread_notifications: current_user&.notifications&.unread } %>
<% end %>
8 changes: 8 additions & 0 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<% content_for :top_nav do %>
<%= render partial: "layouts/primary_top_nav" %>
<% end %>

<div class="flex flex-col items-center flex-1 px-5 pb-10 bg-purple-dark pt-safe-area-header pb-safe-area-bottom-navbar">
<%= form_with model: Current.user, url: user_path, class: "flex flex-col h-full w-full max-w-screen-sm" do |form| %>
<div class="flex flex-col w-full h-full">
Expand Down Expand Up @@ -55,3 +59,7 @@
) %>
<% end %>
</div>

<% content_for :bottom_nav do %>
<%= render partial: "layouts/bottom_navbar", locals: { unread_notifications: current_user&.notifications&.unread } %>
<% end %>

0 comments on commit fa9f84d

Please sign in to comment.