Skip to content

Commit

Permalink
articles & playlists display
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Apr 24, 2024
1 parent 2e4ca87 commit e7e652c
Show file tree
Hide file tree
Showing 17 changed files with 281 additions and 24 deletions.
17 changes: 17 additions & 0 deletions app/assets/stylesheets/application.tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@
--rau-brand-text: white;
}

.flash-error-bg,
.flash-alert-bg {
@apply bg-red-600;
}

.flash-error-text,
.flash-alert-text {
@apply text-red-100;
}

.flash-notice-bg {
@apply bg-green-600;
}
.flash-notice-text {
@apply text-green-100;
}

.post-wrapper .aspectRatioPlaceholder {
margin: 0px auto;
position: relative;
Expand Down
29 changes: 28 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def index
end

def show
@title = "Tracks"
@title = "All"
get_tracks
get_meta_tags
@as = :track
Expand All @@ -29,6 +29,28 @@ def tracks
paginated_render
end

def playlists_filter

@kind = params[:kind].present? ? params[:kind].split(",") : Category.playlist_types

@playlists = @user.playlists
.where(playlist_type: @kind)
.where(user_id: @user.id)
.with_attached_cover
.includes(user: {avatar_attachment: :blob})
.includes(tracks: {cover_attachment: :blob})

if current_user.blank? || current_user != @user
@playlists = @playlists.where(private: false)
end

@render_empty = true if params[:kind].blank? && @playlists.empty?

@playlists = @playlists.page(params[:page]).per(5)

render "playlist_cards"
end

def playlists
@title = "Playlists"
@section = "playlists"
Expand Down Expand Up @@ -106,6 +128,11 @@ def about
render "about"
end

def articles
@articles = @user.posts.order("id desc").page(params[:page]).per(10)
render "articles"
end

private

def get_meta_tags
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def reposts_preloaded
.where("reposts.user_id =?", id)
end

def is_publisher?
is_admin?
end

def is_admin?
role == "admin"
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/articles/_article_item_small.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="grid items-center py-4 mb-0 leading-8 text-black border-b border-solid cursor-pointer box-border border-stone-300 lg:clear-both lg:table xl:clear-both xl:table md:pb-0">
<div class="text-black lg:hidden xl:float-right xl:mt-0 xl:ml-4 box-border"></div>

<div class="col-span-full p-0 mb-auto text-white box-border">
<div class="col-span-full p-0 mb-auto text-default box-border">
<%= link_to article_path(post) do %>
<h2 class="mt-0 mb-2 font-sans text-base not-italic font-semibold leading-5 normal-case box-border lg:text-4xl-- lg:leading-5 md:mb-4 md:font-sans md:text-4xl-- md:font-bold md:normal-case md:not-italic md:leading-5">
<%= post.title %>
Expand Down
61 changes: 61 additions & 0 deletions app/views/playlists/_cards.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

<div class="flex justify-between items-center">
<div class="py-4">
<% Category.playlist_types.each do |item| %>
<%= link_to user_playlists_filter_path(@user.username, kind: item),
data: { turbo_frame: "playlist-cards" },
class: "bg-muted text-sm inline-flex
hover:cursor-pointer
items-center rounded-full
hover:bg-emphasis
px-3 py-1 font-medium" do %>
<%= item.humanize %>
<% end %>
<% end %>
</div>

<%= link_to user_playlists_path(@user.username), class: "text-sm font-semibold leading-6 text-brand-600" do %>
See all <span aria-hidden="true"></span>
<% end %>
</div>

<h2 class="text-md font-medium text-gray-500">Albums</h2>

<ul role="list"
class="mt-3 grid grid-cols-1 gap-5 sm:grid-cols-2 sm:gap-6 lg:grid-cols-4">
<% # pink purple yellow green %>
<% @playlists.each do |playlist| %>
<li class="col-span-1 flex rounded-md shadow-sm">
<div class="flex w-16 flex-shrink-0 items-center justify-center bg-pink-600 rounded-l-md text-sm font-medium text-default">
<%= image_tag(playlist.cover_url(:medium),
class: "object-center object-cover group-hover:opacity-75"
) %>
</div>
<div class="flex flex-1 items-center justify-between truncate rounded-r-md border-b border-r border-t border-muted bg-default">
<div class="flex-1 truncate px-4 py-2 text-sm">
<%= link_to playlist_path(playlist),
data: {turbo_frame: "_top"},
class: "font-medium text-muted hover:text-emphasis" do %>
<%= playlist.title %>
<% end %>
<p class="text-gray-500">
<%= playlist&.release_date&.year%> ·
<%= playlist.tracks.size %> Tracks
</p>
</div>
<!--<div class="flex-shrink-0 pr-2">
<button type="button"
class="inline-flex h-8 w-8 items-center
justify-center rounded-full bg-transparent
text-default hover:text-emphasis
hover:bg-brand-700
focus:outline-none focus:ring-2 focus:ring-indigo-500
focus:ring-offset-2">
<span class="sr-only">Open options</span>
<%= heroicon("play", variant: :mini) %>
</button>
</div>-->
</div>
</li>
<% end %>
</ul>
2 changes: 1 addition & 1 deletion app/views/playlists/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
<div class="flex-grow">
<div class="flex flex-col">
<div class="space-y-2">
<ul role="list" class="divide-y divide-muted">
<ul role="list" class="divide-y divide-subtle">

<% @playlist.ordered_tracks.each do |track| %>
<li>
Expand Down
10 changes: 7 additions & 3 deletions app/views/shared/_flash.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@
From: "opacity-100"
To: "opacity-0"
-->
<div class="pointer-events-auto w-full max-w-sm overflow-hidden rounded-lg bg-default shadow-lg ring-1 ring-black ring-opacity-5">
<div class="pointer-events-auto w-full max-w-sm overflow-hidden rounded-lg flash-<%= flash_type%>-bg shadow-lg ring-1 ring-black ring-opacity-5">
<div class="p-4">
<div class="flex items-start">
<div class="flex-shrink-0">
<% if flash_type.to_s == "notice" %>
<svg class="h-6 w-6 text-green-400" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<% end %>
</div>
<div class="ml-3 w-0 flex-1 pt-0.5">
<p class="text-sm font-medium text-gray-900 hidden">Successfully saved!</p>
<p class="mt-1 text-sm text-gray-500"><%= message %></p>
<p class="mt-1 text-sm flash-<%= flash_type%>-text"><%= message %></p>
</div>
<div class="ml-4 flex flex-shrink-0">
<button data-action="click->removals#hide" type="button" class="inline-flex rounded-md bg-muted text-default hover:text-subtle focus:outline-none focus:ring-2 focus:ring-brand-500 focus:ring-offset-2">
<button data-action="click->removals#hide" type="button"
class="inline-flex rounded-md text-default hover:text-subtle
focus:outline-none focus:ring-2 focus:ring-brand-500 focus:ring-offset-2">
<span class="sr-only">Close</span>
<svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
To: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
-->
<div class="relative transform overflow-hidden rounded-lg bg-default border-default px-4 pb-4 pt-5 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg sm:p-6 text-default">
<div class="absolute right-0 top-0 hidden pr-4 pt-4 sm:block">
<div class="absolute right-0 top-0 hidden-- pr-4 pt-4 sm:block">
<button type="button" data-action="click->modal#close" class="rounded-md bg-default text-muted hover:text-subtle focus:outline-none focus:ring-2 focus:ring-brand-500 focus:ring-offset-2">
<span class="sr-only">Close</span>
<svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_shared.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
To: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
-->
<div class="relative transform overflow-hidden rounded-lg bg-white px-4 pb-4 pt-5 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg sm:p-6">
<div class="absolute right-0 top-0 hidden pr-4 pt-4 sm:block">
<div class="absolute right-0 top-0 hidden-- pr-4 pt-4 sm:block">
<button type="button" data-action="click->modal#close" class="rounded-md bg-white text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-brand-500 focus:ring-offset-2" @click="open = false">
<span class="sr-only">Close</span>
<svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
Expand Down
4 changes: 2 additions & 2 deletions app/views/spotlights/_form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<% end %>
<% else %>
<% if @user.id == current_user&.id %>
<div class="flex justify-between items-center">
<div class="flex justify-between items-center mt-2">
<h1 class="font-bold text-lg">Spotlight</h1>

<%= link_to edit_spotlight_path, class: "button-sm-outline" do %>
Expand All @@ -98,7 +98,7 @@

<% if @user.present? && @user.spotlights.any? %>
<div class="px-4 py-5 sm:px-6">
<h1 class="font-bold text-4xl"><%= t("tracks.spotlight") %></h1>
<h1 class="font-bold text-2xl"><%= t("tracks.spotlight") %></h1>
</div>

<% @user.spotlights.order("position").each do |item| %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/tracks/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<!-- Profile header -->
<div>
<div class="flex flex-col sm:flex-row mb-6">
<div class="flex-grow items-center text-white">
<div class="flex-grow items-center text-default">
<% if @track.processed? %>
<%= image_tag @track.cover_url(:medium), class: "hidden h-32 w-full object-cover lg:h-48" %>

Expand Down
14 changes: 7 additions & 7 deletions app/views/user_follows/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<select
id="tabs"
name="tabs"
class="block w-full focus:ring-brand-500 focus:border-brand-500 border-gray-300 rounded-md"
class="block w-full focus:ring-brand-500 focus:border-brand-500 border-muted rounded-md"
>
<option>Likes</option>
<option>Followers</option>
Expand Down Expand Up @@ -36,13 +36,13 @@
</div>

<div class="hidden sm:block">
<div class="border-b border-gray-200">
<div class="border-b border-emphasis">
<nav class="-mb-px flex" aria-label="Tabs">
<!-- Current: "border-brand-500 text-brand-600", Default: "border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300" -->
<%= link_to t("profile.likes"), "#", class: "border-transparent dark:text-gray-200 text-gray-500 hover:text-gray-700 hover:border-gray-300 w-1/4 py-4 px-1 text-center border-b-2 font-medium text-sm" %>
<%= link_to t("profile.followings"), user_followers_path(@user.username), class: "border-transparent dark:text-gray-200 text-gray-500 hover:text-gray-700 hover:border-gray-300 w-1/4 py-4 px-1 text-center border-b-2 font-medium text-sm" %>
<%= link_to t("profile.followers"), user_followees_path(@user.username), class: "border-transparent dark:text-gray-200 text-gray-500 hover:text-gray-700 hover:border-gray-300 w-1/4 py-4 px-1 text-center border-b-2 font-medium text-sm" %>
<%= link_to t("profile.comments"), "#", class: "border-transparent dark:text-gray-200 text-gray-500 hover:text-gray-700 hover:border-gray-300 w-1/4 py-4 px-1 text-center border-b-2 font-medium text-sm" %>
<!-- Current: "border-brand-500 text-brand-600", Default: "border-transparent text-gray-500 hover:text-muted hover:border-muted" -->
<%= link_to t("profile.likes"), "#", class: "border-transparent dark:text-emphasis text-muted hover:text-muted hover:border-muted w-1/4 py-4 px-1 text-center border-b-2 font-medium text-sm" %>
<%= link_to t("profile.followings"), user_followers_path(@user.username), class: "border-transparent dark:text-emphasis text-muted hover:text-muted hover:border-muted w-1/4 py-4 px-1 text-center border-b-2 font-medium text-sm" %>
<%= link_to t("profile.followers"), user_followees_path(@user.username), class: "border-transparent dark:text-emphasis text-muted hover:text-muted hover:border-muted w-1/4 py-4 px-1 text-center border-b-2 font-medium text-sm" %>
<%= link_to t("profile.comments"), "#", class: "border-transparent dark:text-emphasis text-muted hover:text-muted hover:border-muted w-1/4 py-4 px-1 text-center border-b-2 font-medium text-sm" %>

</nav>
</div>
Expand Down
66 changes: 66 additions & 0 deletions app/views/users/_article_side.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<%
first, *rest = articles
%>

<div class="bg-default py-24 sm:py-32">
<div class="mx-auto grid max-w-7xl grid-cols-1 gap-x-8 gap-y-12 px-6 sm:gap-y-16 lg:grid-cols-2 lg:px-8">

<article class="mx-auto w-full max-w-2xl lg:mx-0 lg:max-w-lg">
<%= link_to user_path(first.user.username) do %>
<time datetime="<%= l first.created_at, format: :short %>" class="block text-sm leading-6 text-muted">
<%= l first.created_at, format: :short %>
</time>
<h2 id="featured-post" class="mt-4 text-3xl font-bold tracking-tight text-default sm:text-4xl">
<%= first.title %>
</h2>
<p class="mt-4 text-lg leading-8 text-emphasis">
<%= first.excerpt %>
</p>

<div class="mt-4 flex flex-col justify-between gap-6 sm:mt-8 sm:flex-row-reverse sm:gap-8 lg:mt-4 lg:flex-col">
<div class="flex">
<%= link_to user_articles_path(first.user.username), class: "text-sm font-semibold leading-6 text-brand-600", "aria-describedby": "featured-post" do %>
Continue reading <span aria-hidden="true">&rarr;</span>
<% end %>
</div>
<div class="flex lg:border-t lg:border-default/10 lg:pt-8">
<%= link_to user_path(first.user.username), class: "flex gap-x-2.5 text-sm font-semibold leading-6 text-default" do %>
<%= image_tag first.user.avatar_url(:small), class: "h-6 w-6 flex-none rounded-full bg-gray-50" %>
<%= first.user.first_name %> <%= first.user.last_name %>
<% end %>
</div>
</div>
<% end %>
</article>

<div class="mx-auto w-full max-w-2xl border-t border-default/10 pt-12 sm:pt-16 lg:mx-0 lg:max-w-none lg:border-t-0 lg:pt-0">
<div class="-my-12 divide-y divide-default/10">
<% rest.each do |article|%>
<article class="py-12">
<div class="group relative max-w-xl">
<time datetime="<%= l article.created_at %>" class="block text-sm leading-6 text-muted">
<%= l article.created_at, format: :short %>
</time>
<h2 class="mt-2 text-lg font-semibold text-default group-hover:text-muted">
<%= link_to article_path(article) do %>
<span class="absolute inset-0"></span>
<%= article.title %>
<% end %>
</h2>
<p class="mt-4 text-sm leading-6 text-muted">
<%= article.excerpt %>
</p>
</div>
<div class="mt-4 flex">
<%= link_to article_path(article), class: "relative flex gap-x-2.5 text-sm font-semibold leading-6 text-default" do %>
<%= image_tag article.user.avatar_url(:small), class: "h-6 w-6 flex-none rounded-full bg-gray-50" %>
<%= article.user.first_name %> <%= article.user.last_name %>
<% end %>
</div>
</article>
<% end %>
</div>
</div>

</div>
</div>
54 changes: 54 additions & 0 deletions app/views/users/articles.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<div class="bg-white py-24 sm:py-32">
<div class="mx-auto max-w-7xl px-6 lg:px-8">
<div class="mx-auto max-w-2xl">
<h2 class="text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl">
<%= @user.first_name.humanize %> <%= @user.last_name.humanize %>'s Blog
</h2>
<p class="mt-2 text-lg leading-8 text-gray-600">
<%= link_to user_path(@user.username), class: "flex items-center text-sm font-semibold leading-6 text-brand-600" do %>
<%= heroicon("chevron-left", variant: :mini)%>
back to <%= @user.username %> music
<% end %>
</p>

<div class="mt-10 space-y-16 border-t border-gray-200 pt-10 sm:mt-16 sm:pt-16">

<% @articles.each do |article| %>
<article class="flex max-w-xl flex-col items-start justify-between">
<div class="flex items-center gap-x-4 text-xs">
<time datetime="<%= l(article.created_at) %>" class="text-gray-500">
<%= l(article.created_at, format: :short) %>
</time>
<!--<a href="#" class="relative z-10 rounded-full bg-gray-50 px-3 py-1.5 font-medium text-gray-600 hover:bg-gray-100">
Marketing
</a>-->
</div>
<div class="group relative">
<h3 class="mt-3 text-lg font-semibold leading-6 text-gray-900 group-hover:text-gray-600">
<%= link_to article_path(article) do %>
<span class="absolute inset-0"></span>
<%= article.title %>
<% end %>
</h3>
<p class="mt-5 line-clamp-3 text-sm leading-6 text-gray-600">
<%= article.excerpt %>
</p>
</div>
<div class="relative mt-8 flex items-center gap-x-4">
<%= image_tag article.user.avatar_url(:small), class: "h-10 w-10 rounded-full bg-gray-50" %>
<div class="text-sm leading-6">
<p class="font-semibold text-gray-900">
<a href="#">
<span class="absolute inset-0"></span>
<%= article.user.username %>
</a>
</p>
<!--<p class="text-gray-600">Co-Founder / CTO</p>-->
</div>
</div>
</article>
<% end %>
</div>
</div>
</div>
</div>
5 changes: 5 additions & 0 deletions app/views/users/playlist_cards.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= turbo_frame_tag "playlist-cards" do %>
<% unless @render_empty %>
<%= render "playlists/cards" %>
<% end %>
<% end %>
Loading

0 comments on commit e7e652c

Please sign in to comment.