add followed collections to collections#index

This commit is contained in:
Andrew Brown 2020-10-01 18:10:52 -07:00
parent 35c248a419
commit 3bedd64447
3 changed files with 33 additions and 0 deletions

View File

@ -13,6 +13,8 @@ class PageCollectionsController < ApplicationController
@network_collections = PageCollection.where(user_id: followed_user_ids, privacy: 'public')
@random_collections = PageCollection.where(privacy: 'public').sample(9)
@followed_collections = current_user.followed_page_collections
end
# GET /page_collections/1

View File

@ -75,6 +75,7 @@ class User < ApplicationRecord
@published_in_page_collections ||= PageCollection.where(id: ids)
end
has_many :page_collection_followings, dependent: :destroy
has_many :followed_page_collections, through: :page_collection_followings, source: :page_collection
has_many :page_collection_reports, dependent: :destroy
has_many :votes, dependent: :destroy

View File

@ -46,6 +46,36 @@
</div>
<% end %>
<% if @followed_collections.any? %>
<div class="row">
<h1 class="center" style="font-size: 2em">
<i class="material-icons <%= PageCollection.color %>-text"><%= PageCollection.icon %></i>
Collections you follow
</h1>
<% @followed_collections.each do |collection| %>
<div class="col s12 m6 l4">
<%= link_to collection do %>
<div class="hoverable card <%= PageCollection.color %>" style="height: 250px">
<div class="card-image">
<%= image_tag collection.random_public_image, style: 'max-height: 250px;' %>
<span class="card-title bordered-text">
<%= collection.title %>
<br />
<small>
<% collection.page_types.each do |icon| %>
<% klass = icon.constantize %>
<i class="material-icons left tooltipped tiny <%= klass.color %>-text" data-tooltip="<%= icon.pluralize %>"><%= klass.icon %></i>
<% end %>
</small>
</span>
</div>
</div>
<% end %>
</div>
<% end %>
</div>
<% end %>
<% if @network_collections.any? %>
<div class="row">
<h1 class="center" style="font-size: 2em">