Skip to content

Commit

Permalink
Merge pull request #12 from jahseng-lee/feature/cleanup-mobile-views
Browse files Browse the repository at this point in the history
Feature/cleanup mobile views
  • Loading branch information
jahseng-lee authored Dec 12, 2023
2 parents 7216439 + 750fedc commit 25bd3f4
Show file tree
Hide file tree
Showing 39 changed files with 695 additions and 239 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ GEM
racc (~> 1.4)
orm_adapter (0.5.0)
os (1.1.4)
pagy (6.0.4)
pagy (6.2.0)
pg (1.5.4)
pg_search (2.3.6)
activerecord (>= 5.2)
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $primary: #262626;
@import 'home';
@import 'location';
@import 'profiles';
@import 'reviews';
@import 'search_location';
@import 'visas';

Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/channels.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

border-bottom: 1px solid $primary;

.dropdown {
flex: 1;
}

.leave-channel-button {
color: $danger;
}
Expand Down
11 changes: 11 additions & 0 deletions app/assets/stylesheets/chats.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ body {
display: flex;
flex-direction: column;

&.offcanvas-body {
padding: 0;
}

.channel-list-frame {
flex: 1;

display: flex;
flex-direction: column;
}

.channel-list {
flex: 1;

Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

.pagination-nav-container {
width: 100%;
max-width: 100vw;
display: flex;
justify-content: center;
}
Expand Down
6 changes: 6 additions & 0 deletions app/assets/stylesheets/reviews.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.review-form {
.form-select {
width: 4rem;
min-width: 4rem;
}
}
18 changes: 2 additions & 16 deletions app/controllers/channels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,13 @@ def joinable
.order(:last_action_at)

respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.replace(
"channel-list",
partial: "chats/joinable_channel_list",
locals: { channels: @channels }
)
end
format.turbo_stream
end
end

def current_user_list
respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.replace(
"joinable-channel-list",
partial: "chats/current_user_channel_list",
locals: {
user: current_user
}
)
end
format.turbo_stream
end
end

Expand Down
30 changes: 30 additions & 0 deletions app/controllers/countries_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class CountriesController < ApplicationController
def edit
@country = Country.find(params[:id])
@location = @country.locations.find(params[:location_id])

authorize(@country)
end

def update
@country = Country.find(params[:id])
@location = @country.locations.find(params[:location_id])

authorize(@country)

# NOTE this is supremely lazy
# however, admin only. Fine for now
@country.update!(country_params)
redirect_to @location
end

private

def country_params
params.require(:country).permit(
:ambulance_number,
:police_number,
:fire_number
)
end
end
13 changes: 7 additions & 6 deletions app/controllers/locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ def upload_banner_image_modal
end
end

def emergency_info
# Intended to be a mobile/small screen only link as normally the
# emergency info is hidden on mobile
@location = Location.find(params[:id])
end

private

def location_params
params.require(:location).permit(
:description,
:ambulance_number,
:police_number,
:fire_number,
)
params.require(:location).permit(:description)
end
end
3 changes: 3 additions & 0 deletions app/javascript/controllers/location_tabs_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default class extends Controller {
"overviewLink",
"reviewsLink",
"visaLink",
"emergencyInfoLink"
];

connect() {
Expand All @@ -15,6 +16,8 @@ export default class extends Controller {
this.visaLinkTarget.classList.add("active");
} else if (pathElements.includes("reviews")) {
this.reviewsLinkTarget.classList.add("active");
} else if (pathElements.includes("emergency_info")) {
this.emergencyInfoLinkTarget.classList.add("active");
} else {
this.overviewLinkTarget.classList.add("active");
}
Expand Down
6 changes: 3 additions & 3 deletions app/models/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def review_summary

def emergency_numbers
[
{ name: "ambulance", number: ambulance_number },
{ name: "police", number: police_number },
{ name: "fire", number: fire_number },
{ name: "ambulance", number: country.ambulance_number },
{ name: "police", number: country.police_number },
{ name: "fire", number: country.fire_number },
]
end

Expand Down
6 changes: 5 additions & 1 deletion app/policies/country_policy.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class CountryPolicy < ApplicationPolicy
def update?
def edit?
user.admin?
end

def update?
edit?
end
end
8 changes: 8 additions & 0 deletions app/views/channels/_chat_message_section.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@
</ul>
</div>
<% end %>

<div class="d-md-none">
<%= render partial: "chats/shared/mobile_user_channel_list",
locals: {
user: current_user
}
%>
</div>
</div>

<div class="channel-message-section">
Expand Down
17 changes: 17 additions & 0 deletions app/views/channels/current_user_list.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= turbo_stream.replace(
"joinable-channel-list",
partial: "chats/current_user_channel_list",
locals: {
user: current_user
}
) %>

<%= turbo_stream.replace(
"mobile-joinable-channel-list",
partial: "chats/current_user_channel_list",
locals: {
user: current_user,
turbo_id: "mobile-channel-list"
}
) %>

14 changes: 14 additions & 0 deletions app/views/channels/joinable.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%= turbo_stream.replace(
"channel-list",
partial: "chats/joinable_channel_list",
locals: { channels: @channels }
) %>

<%= turbo_stream.replace(
"mobile-channel-list",
partial: "chats/joinable_channel_list",
locals: {
channels: @channels,
turbo_id: "mobile-joinable-channel-list"
}
) %>
5 changes: 4 additions & 1 deletion app/views/chats/_current_user_channel_list.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<%= turbo_frame_tag "channel-list", class: "channel-list-container col pe-0" do %>
<%= turbo_frame_tag(
local_assigns[:turbo_id] ? turbo_id : "channel-list",
class: "channel-list-frame"
) do %>
<div class="channel-list">
<%= render partial: "chats/shared/channel_list",
locals: {
Expand Down
2 changes: 1 addition & 1 deletion app/views/chats/_joinable_channel_list.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= turbo_frame_tag(
"joinable-channel-list",
local_assigns[:turbo_id] ? turbo_id : "joinable-channel-list",
class: "channel-list-container col pe-0",
data: {
controller: "joinable-channel-list"
Expand Down
18 changes: 18 additions & 0 deletions app/views/chats/shared/_mobile_user_channel_list.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#channelList" aria-controls="channelList">
<i class="bi bi-chevron-left"></i>
<%= local_assigns[:button_label] ? button_label : "Browse" %>
</button>

<div class="offcanvas offcanvas-end" tabindex="-1" id="channelList" aria-labelledby="Channel list">
<div class="offcanvas-header">
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="channel-list-container offcanvas-body">
<%= render partial: "chats/current_user_channel_list",
locals: {
user: user,
turbo_id: "mobile-channel-list"
}
%>
</div>
</div>
29 changes: 20 additions & 9 deletions app/views/chats/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,33 @@
<%= turbo_stream_from "user-#{current_user.id}-chat" %>

<div class="chat-screen-container row">
<%= render partial: "chats/current_user_channel_list",
locals: {
user: current_user
}
%>
<div class="channel-list-container col pe-0 d-none d-md-flex">
<%= render partial: "chats/current_user_channel_list",
locals: {
user: current_user
}
%>
</div>

<% if @channel.present? %>
<div class="chat-message-section col-9 ps-0">
<div class="chat-message-section col col-md-9 ps-md-0">
<%= render partial: "channels/chat_message_section",
locals: { channel: @channel, message: @message }
%>
</div>
<% else %>
<div class="chat-message-section no-chat col-9 ps-0">
<p class="h2">
Click on one of channels on the left to start chatting
<div class="chat-message-section no-chat col col-md-9 ps-md-0">
<p class="h2 d-none d-md-block">
Click on one of the channels to start chatting
</p>

<div class="d-md-none">
<%= render partial: "chats/shared/mobile_user_channel_list",
locals: {
user: current_user,
button_label: "Browse channels"
}
%>
</p>
</div>
<% end %>
Expand Down
39 changes: 39 additions & 0 deletions app/views/countries/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<div class="container mt-5">
<%= render partial: "locations/shared/back_link",
locals: {
location: @location,
}
%>

<h1>Emergency info. for <%= @country.name %></h1>

<%= form_for [@location, @country] do |f| %>
<div class="mb-3">
<%= f.label(
:ambulance_number,
"Ambulance",
class: "form-label fw-bold"
) %>
<%= f.text_field :ambulance_number, class: "form-control" %>
</div>

<div class="mb-3">
<%= f.label(
:police_number,
"Police",
class: "form-label fw-bold"
) %>
<%= f.text_field :police_number, class: "form-control" %>
</div>

<div class="mb-3">
<%= f.label :fire_number, "Fire", class: "form-label fw-bold" %>
<%= f.text_field :fire_number, class: "form-control" %>
</div>

<%= f.button "Save",
type: :submit,
class: "btn btn-primary"
%>
<% end %>
</div>
10 changes: 10 additions & 0 deletions app/views/locations/_tabs.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,15 @@
}
) %>
</li>
<li class="nav-item">
<%= link_to(
"Emergency info.",
emergency_info_location_path(location.id),
class: "nav-link d-lg-none d-xl-none d-xxl-none",
data: {
"location-tabs-target": "emergencyInfoLink"
}
) %>
</li>
</ul>
</div>
Loading

0 comments on commit 25bd3f4

Please sign in to comment.