Skip to content

Commit 58c10a0

Browse files
committed
Merge branch 'fix/devise-authentication' of github.com:emmvs/five_things into fix/devise-authentication
2 parents 6488554 + 8ac27c2 commit 58c10a0

37 files changed

+244
-303
lines changed

Gemfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ gem 'sassc-rails' # Use SCSS for stylesheets
3333
# Devise for authentication
3434
gem 'devise', '~> 4.8'
3535

36-
#OAauth Providers
36+
# OAauth Providers
3737
gem 'omniauth-google-oauth2'
3838
gem 'omniauth-rails_csrf_protection'
3939

@@ -71,16 +71,15 @@ group :development, :test do
7171
end
7272

7373
group :development do
74-
gem 'web-console' # Rails console for the browser
7574
gem 'annotate' # Annotate models with schema
75+
gem 'web-console' # Rails console for the browser
7676
# gem 'spring' # Speeds up development by keeping app running in the background
7777
# gem 'rack-mini-profiler' # Displays speed badge for performance profiling
7878
end
7979

8080
group :test do
8181
gem 'capybara' # Capybara for integration testing
8282
gem 'selenium-webdriver' # WebDriver for browsers
83-
gem 'webdrivers' # Auto-updates webdrivers
8483
end
8584

8685
# Optional gems for specific features

Gemfile.lock

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ GEM
332332
http-cookie (>= 1.0.2, < 2.0)
333333
mime-types (>= 1.16, < 4.0)
334334
netrc (~> 0.8)
335-
rexml (3.2.6)
335+
rexml (3.4.1)
336336
rspec-core (3.12.2)
337337
rspec-support (~> 3.12.0)
338338
rspec-expectations (3.12.3)
@@ -369,7 +369,7 @@ GEM
369369
faraday-multipart (>= 1)
370370
ruby-progressbar (1.13.0)
371371
ruby2_keywords (0.0.5)
372-
rubyzip (2.3.2)
372+
rubyzip (2.4.1)
373373
sassc (2.4.0)
374374
ffi (~> 1.9)
375375
sassc-rails (2.1.2)
@@ -378,7 +378,9 @@ GEM
378378
sprockets (> 3.0)
379379
sprockets-rails
380380
tilt
381-
selenium-webdriver (4.16.0)
381+
selenium-webdriver (4.32.0)
382+
base64 (~> 0.2)
383+
logger (~> 1.4)
382384
rexml (~> 3.2, >= 3.2.5)
383385
rubyzip (>= 1.2.2, < 3.0)
384386
websocket (~> 1.0)
@@ -420,11 +422,7 @@ GEM
420422
activemodel (>= 6.0.0)
421423
bindex (>= 0.4.0)
422424
railties (>= 6.0.0)
423-
webdrivers (5.2.0)
424-
nokogiri (~> 1.6)
425-
rubyzip (>= 1.3.0)
426-
selenium-webdriver (~> 4.0)
427-
websocket (1.2.10)
425+
websocket (1.2.11)
428426
websocket-driver (0.7.6)
429427
websocket-extensions (>= 0.1.0)
430428
websocket-extensions (0.1.5)
@@ -479,7 +477,6 @@ DEPENDENCIES
479477
stimulus-rails
480478
turbo-rails
481479
web-console
482-
webdrivers
483480

484481
RUBY VERSION
485482
ruby 3.1.2p20

app/assets/stylesheets/components/_calendar.scss

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
padding: 1px;
3131
position: relative;
3232
height: 40px !important;
33-
width: 40px !important;
3433
border-radius: $border-radius !important;
3534
}
3635

@@ -40,6 +39,11 @@
4039
color: darken($soft-purple, 50%);
4140
}
4241

42+
.day.has-many-emojis .calendar-day-link {
43+
z-index: 1;
44+
font-weight: calc(var(--bs-body-font-weight) * 1.1);
45+
}
46+
4347
.calendar-day-link:hover {
4448
background-color: #f0f0f0;
4549
border-radius: 50%;
@@ -65,11 +69,15 @@
6569
--bs-table-bg-type: none;
6670
}
6771

68-
.event-indicator {
72+
.emoji-grid {
73+
display: grid;
74+
aspect-ratio: 1 / 1;
6975
position: absolute;
70-
z-index: 1;
71-
right: -5px;
72-
top: -4px;
73-
font-size: 1.1em;
76+
pointer-events: none;
77+
}
78+
79+
.emoji {
80+
position: relative;
81+
line-height: 1;
7482
}
7583
}

app/assets/stylesheets/components/_navbar.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@
7070
border-bottom-right-radius: 50px;
7171
}
7272

73-
/* Mobile */
73+
/* Desktop */
7474
@media screen and (min-width: 768px) {
7575
.bottom-navbar {
7676
display: none !important;
7777
}
7878
}
7979

80-
/* Desktop */
80+
/* Mobile */
8181
@media screen and (max-width: 767px) {
8282
.bottom-navbar {
8383
display: flex;

app/controllers/dashboards_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def daily_quote_cache_key
4242

4343
def set_happy_things
4444
friend_ids = current_user.friends_and_friends_who_added_me_ids
45-
user_ids = friend_ids + [current_user.id]
45+
@user_ids = [current_user.id] + friend_ids
4646

47-
@happy_things_of_you_and_friends = HappyThing.where(user_id: user_ids).order(created_at: :desc)
47+
@happy_things_of_you_and_friends = HappyThing.where(user_id: @user_ids).order(created_at: :desc)
4848
fetch_happy_things_by_time(friend_ids)
4949
end
5050

app/helpers/dashboard_helper.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,35 @@ def moon_phase_emojis
6767
full_moon: '🌕'
6868
}
6969
end
70+
71+
# Calender
72+
def calculate_grid_size(number_of_emojis)
73+
return 2 if number_of_emojis == 1
74+
75+
Math.sqrt(number_of_emojis).ceil
76+
end
77+
78+
def calculate_emoji_size(number_of_emojis)
79+
grid_size = calculate_grid_size(number_of_emojis)
80+
case grid_size
81+
when 2 then 1.1
82+
when 3 then 0.8
83+
when 4 then 0.5
84+
else
85+
raise "Failure in calculate_emoji_size: number_of_emojis = #{number_of_emojis}, grid_size = #{grid_size}"
86+
end
87+
end
88+
89+
def calculate_emoji_position(tile_number, number_of_emojis)
90+
return '0px, 0px' if number_of_emojis > 4
91+
92+
case tile_number
93+
when 1 then '-4px, -5px'
94+
when 2 then '4px, -5px'
95+
when 3 then '-4px, 5px'
96+
when 4 then '4px, 5px'
97+
else
98+
raise "Failure in calculate_emoji_position: number_of_emojis = #{number_of_emojis}, tile_number = #{tile_number}"
99+
end
100+
end
70101
end

app/models/happy_thing.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ class HappyThing < ApplicationRecord
2323

2424
belongs_to :user
2525
belongs_to :category
26-
has_many :likes
27-
has_many :comments
26+
has_many :comments, dependent: :destroy
2827
has_many :happy_thing_user_shares, dependent: :destroy
2928
has_many :shared_users, through: :happy_thing_user_shares, source: :friend
3029
has_many :happy_thing_group_shares, dependent: :destroy

app/models/like.rb

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/models/user.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,17 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength
6161

6262
before_validation :normalize_email
6363

64-
has_many :happy_things
65-
has_many :comments
66-
has_many :likes
64+
has_many :happy_things, dependent: :destroy
65+
has_many :comments, dependent: :destroy
6766
has_many :groups, dependent: :destroy
6867
has_many :happy_thing_user_shares, foreign_key: :friend_id, dependent: :destroy
6968
has_many :received_happy_things, through: :happy_thing_user_shares, source: :happy_thing
70-
has_many :group_memberships, foreign_key: :friend_id
69+
has_many :group_memberships, foreign_key: :friend_id, dependent: :destroy
7170
has_many :groups_as_member, through: :group_memberships, source: :group
7271

7372
# Friendships
74-
has_many :friendships
75-
has_many :received_friend_requests, class_name: 'Friendship', foreign_key: 'friend_id'
73+
has_many :friendships, dependent: :destroy
74+
has_many :received_friend_requests, class_name: 'Friendship', foreign_key: 'friend_id', dependent: :destroy
7675
has_many :friends, -> { where(friendships: { accepted: true }) }, through: :friendships, source: :friend
7776
has_many :friends_who_added_me, lambda {
7877
where(friendships: { accepted: true })
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<div class="d-flex justify-content-center align-items-center">
2+
<div id="calendar" class="mb-2 my-3">
3+
<%= month_calendar(events: @happy_things_of_you_and_friends, param_name: :date) do |date, happy_things_bubbles| %>
4+
<% unique_users = happy_things_bubbles.map(&:user).uniq %>
5+
<% unique_users_sorted = unique_users.sort_by { |user| @user_ids.index(user.id) } %>
6+
<% number_of_emojis = unique_users.length %>
7+
<div class="day d-flex justify-content-center align-items-center <%= 'has-many-emojis' if number_of_emojis > 4 %>">
8+
<% if happy_things_bubbles.any? %>
9+
<div
10+
class="emoji-grid"
11+
style="
12+
grid-template-columns: repeat(<%= calculate_grid_size(number_of_emojis) %>, 1fr);
13+
grid-template-rows: repeat(<%= calculate_grid_size(number_of_emojis) %>, 1fr);
14+
">
15+
<% unique_users_sorted.each_with_index do |user, index| %>
16+
<div
17+
class="emoji"
18+
style="
19+
font-size: <%= calculate_emoji_size(number_of_emojis) %>em;
20+
transform: translate(<%= calculate_emoji_position(index + 1, number_of_emojis) %>);
21+
">
22+
<%= user.emoji %>
23+
</div>
24+
<% end %>
25+
</div>
26+
<% end %>
27+
<%= link_to happy_things_by_date_path(date: date.strftime('%Y-%m-%d')), class: 'calendar-day-link' do %>
28+
<%= date.day %>
29+
<% end %>
30+
</div>
31+
<% end %>
32+
</div>
33+
</div>

0 commit comments

Comments
 (0)