From 0079513b35b210dcd90f8a6f795daccf7c33b282 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 1 Sep 2025 19:51:24 +0930 Subject: [PATCH] Merge pull request #4183 from Growstuff/feature/timeline-likes Feature: Display likes on timeline --- app/helpers/event_helper.rb | 2 ++ app/services/timeline_service.rb | 10 ++++++++++ app/views/likes/_description.html.haml | 1 + app/views/timeline/_like.html.haml | 2 ++ app/views/timeline/index.html.haml | 1 + app/views/timeline/likeables/_photo.html.haml | 1 + app/views/timeline/likeables/_post.html.haml | 6 ++++++ spec/features/timeline/index_spec.rb | 6 ++++++ 8 files changed, 29 insertions(+) create mode 100644 app/views/likes/_description.html.haml create mode 100644 app/views/timeline/_like.html.haml create mode 100644 app/views/timeline/likeables/_photo.html.haml create mode 100644 app/views/timeline/likeables/_post.html.haml diff --git a/app/helpers/event_helper.rb b/app/helpers/event_helper.rb index 4bc8033b5..2e127c319 100644 --- a/app/helpers/event_helper.rb +++ b/app/helpers/event_helper.rb @@ -7,6 +7,8 @@ module EventHelper def event_description(event) render "#{event.event_type.pluralize}/description", event_model: resolve_model(event) +rescue ActionView::MissingTemplate + "#{event.event_type.humanize.downcase}d" end def resolve_model(event) diff --git a/app/services/timeline_service.rb b/app/services/timeline_service.rb index 25c5706df..3b813bc5b 100644 --- a/app/services/timeline_service.rb +++ b/app/services/timeline_service.rb @@ -18,10 +18,20 @@ class TimelineService .union_all(photos_query) .union_all(seeds_query) .union_all(activities_query) + .union_all(likes_query) .where.not(event_at: nil) .order(event_at: :desc) end + def self.likes_query + Like + .select("likes.id", + "'like' as event_type", + "likes.created_at as event_at", + "likes.member_id as owner_id", + "null as crop_id") + end + def self.activities_query Activity.select( :id, diff --git a/app/views/likes/_description.html.haml b/app/views/likes/_description.html.haml new file mode 100644 index 000000000..d8427969d --- /dev/null +++ b/app/views/likes/_description.html.haml @@ -0,0 +1 @@ +#{link_to event_model.member, event_model.member} liked #{link_to event_model.likeable.class.name.downcase, event_model.likeable} diff --git a/app/views/timeline/_like.html.haml b/app/views/timeline/_like.html.haml new file mode 100644 index 000000000..fa1f6bb44 --- /dev/null +++ b/app/views/timeline/_like.html.haml @@ -0,0 +1,2 @@ +- likeable = like.likeable += render "timeline/likeables/#{likeable.class.name.downcase}", likeable: likeable diff --git a/app/views/timeline/index.html.haml b/app/views/timeline/index.html.haml index 3285db15b..165f9f977 100644 --- a/app/views/timeline/index.html.haml +++ b/app/views/timeline/index.html.haml @@ -14,6 +14,7 @@ = link_to owner, owner = event_description(event) = render 'timeline/photos', photo: resolve_model(event) if event.event_type == 'photo' + = render 'timeline/like', like: resolve_model(event) if event.event_type == 'like' %small - if event.event_at.present? - if event.event_at.kind_of?(Date) diff --git a/app/views/timeline/likeables/_photo.html.haml b/app/views/timeline/likeables/_photo.html.haml new file mode 100644 index 000000000..1b680a22e --- /dev/null +++ b/app/views/timeline/likeables/_photo.html.haml @@ -0,0 +1 @@ += render 'timeline/photos', photo: likeable diff --git a/app/views/timeline/likeables/_post.html.haml b/app/views/timeline/likeables/_post.html.haml new file mode 100644 index 000000000..5cd54af3d --- /dev/null +++ b/app/views/timeline/likeables/_post.html.haml @@ -0,0 +1,6 @@ +.card.my-2 + .card-body + %blockquote.blockquote.mb-0 + %p= truncate(likeable.body, length: 140) + %footer.blockquote-footer + = link_to "view post", likeable diff --git a/spec/features/timeline/index_spec.rb b/spec/features/timeline/index_spec.rb index 3135bf65a..c80e74305 100644 --- a/spec/features/timeline/index_spec.rb +++ b/spec/features/timeline/index_spec.rb @@ -17,6 +17,10 @@ describe "timeline", :js do let!(:friend_harvest) { FactoryBot.create(:planting, owner: friend2, planted_at: 3.years.ago) } let!(:finished_planting) { FactoryBot.create(:finished_planting, owner: friend1) } let!(:no_planted_at_planting) { FactoryBot.create(:planting, owner: friend2, planted_at: nil) } + let!(:friend_photo) { FactoryBot.create(:photo, owner: friend1) } + let!(:friend_post) { FactoryBot.create(:post, author: friend2) } + let!(:liked_post) { FactoryBot.create(:like, likeable: friend_photo, member: friend2) } + let!(:liked_photo) { FactoryBot.create(:like, likeable: friend_post, member: friend1) } before do login_as(member) @@ -28,6 +32,8 @@ describe "timeline", :js do it { expect(page).to have_link href: planting_path(friend_harvest) } it { expect(page).to have_link href: planting_path(finished_planting) } it { expect(page).to have_no_link href: planting_path(no_planted_at_planting) } + it { expect(page).to have_link href: photo_path(friend_photo) } + it { expect(page).to have_link href: post_path(friend_post) } end describe 'shows the friends you follow' do