Skip to content

Commit

Permalink
player sharer
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Aug 18, 2023
1 parent 45139f5 commit 4cf1413
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 23 deletions.
2 changes: 2 additions & 0 deletions app/controllers/player_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class PlayerController < ApplicationController

def update
@tracks = Track.where(id: params[:player][:ids])
.with_attached_cover
.includes(user: { avatar_attachment: :blob })
end

def show
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/sharer_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ def new
@resource, @resource_path = find_resource

@button_class = "button"

@share_url = private_track_url(@resource.signed_id, utm_source: 'clipboard', utm_campaign: 'social_sharing', utm_medium: 'text')
#@share_url = #if @resource.private?
# private_track_url(@resource.signed_id, utm_source: 'clipboard', utm_campaign: 'social_sharing', utm_medium: 'text')
#else
# track_url(@resource, utm_source: 'clipboard', utm_campaign: 'social_sharing', utm_medium: 'text')
#end
end

def find_resource
Expand Down
24 changes: 17 additions & 7 deletions app/controllers/tracks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class TracksController < ApplicationController

before_action :authenticate_user!, except: [:index, :show ]
before_action :authenticate_user!, except: [:index, :show, :private_access ]

def index
@tracks = Track.published.order("id desc")
Expand Down Expand Up @@ -53,8 +53,23 @@ def update
flash.now[:notice] = "Track was successfully updated."
end

def private_access
@track = Track.find_signed(params[:id])
get_meta_tags
render "show"
end

def show
@track = Track.friendly.find(params[:id])
get_meta_tags
end

def destroy
@track = current_user.tracks.friendly.find(params[:id])
@track.destroy
end

def get_meta_tags
@supporters = []
set_meta_tags(
# title: @track.title,
Expand All @@ -76,12 +91,7 @@ def show
}
)

@oembed_json = oembed_show_url(track_id: @track, format: :json)
end

def destroy
@track = current_user.tracks.friendly.find(params[:id])
@track.destroy
@oembed_json = private_oembed_track_url(track_id: @track, format: :json)
end

def track_params
Expand Down
27 changes: 24 additions & 3 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,45 @@ def tracks
get_tracks
# @collection = @user.tracks.page(params[:page]).per(5)
@as = :track
@title = "Tracks"
@section = "tracks/track_item"

paginated_render
end

def playlists
@title = "Playlists"
@section = "playlists"
@collection = @user.playlists.page(params[:page]).per(5)
@collection = @user.playlists
.where.not(playlist_type: ["album", "ep"])
.where(user_id: @user.id )
.with_attached_cover
.includes(user: { avatar_attachment: :blob })
.includes(tracks: {cover_attachment: :blob})
.page(params[:page]).per(5)
@as = :playlist
@section = "playlists/playlist_item"
render "show"
end

def reposts
@title = "Reposts"
@collection = @user.reposts_preloaded.page(params[:page]).per(5)
@as = :track
@section = "tracks/track_item"
render "show"
end

def albums
@title = "Albums"
@section = "albums"
@collection = @user.playlists.where(playlist_type: "album").page(params[:page]).per(5)
@collection = @user.playlists
.where(playlist_type: ["album", "ep"])
.where(user_id: @user.id )
.with_attached_cover
.includes(user: { avatar_attachment: :blob })
.includes(tracks: {cover_attachment: :blob})
.page(params[:page]).per(5)
@as = :playlist
@section = "playlists/playlist_item"
render "show"
Expand All @@ -47,10 +63,15 @@ def get_tracks
if current_user
@collection = User.track_preloaded_by_user(current_user&.id)
.where(user_id: @user.id )
.with_attached_cover
.includes(user: { avatar_attachment: :blob })
.order("id desc")
.page(params[:page]).per(6)
else
@collection = @user.tracks.published.order("id desc").page(params[:page]).per(6)
@collection = @user.tracks.published
.with_attached_cover
.includes(user: { avatar_attachment: :blob })
.order("id desc").page(params[:page]).per(6)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/likes/_like_button.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</svg>
<span class="flex space-x-1">
<span><%= resource.likes.count %></span>
<span class="hidden sm:block">Me gusta</span>
<span class="hidden sm:block"><%= t("likes") %></span>
</span>
<% end %>
<% end %>
7 changes: 5 additions & 2 deletions app/views/sharer/new.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
<div class="flex items-center space-x-3">
<input
type="text"
value="<%= track_url(@resource, format: :private, utm_source: 'clipboard', utm_campaign: 'social_sharing', utm_medium: 'text') %>"
value="<%= @share_url %>"
class="shadow-sm focus:ring-brand-500 focus:border-brand-500 block w-full sm:text-sm border-gray-300 rounded-md dark:bg-gray-900 dark:text-gray-100"
readonly="readonly"
/>
<!--
<label class="flex items-center space-x-2">
<input
type="checkbox"
Expand All @@ -53,11 +55,12 @@
/>
<span class=""><%= t("sharer.at") %></span>
</label>
<input
type="text"
value="0:00"
class="w-1/4 shadow-sm focus:ring-brand-500 focus:border-brand-500 block w-full sm:text-sm border-gray-300 rounded-md dark:bg-gray-900 dark:text-gray-100"
/>
/>-->
</div>
</div>
<div class="text-sm text-gray-700 dark:text-gray-300 py-2">
Expand Down
10 changes: 2 additions & 8 deletions app/views/tracks/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,8 @@


<div class="mt-6 flex items-center justify-stretch space-x-2 sm:flex-row sm:space-y-0 sm:space-x-4">
<div>
<%= link_to "#", class: "button" do %>
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" viewBox="0 0 20 20" fill="currentColor">
<path d="M15 8a3 3 0 10-2.977-2.63l-4.94 2.47a3 3 0 100 4.319l4.94 2.47a3 3 0 10.895-1.789l-4.94-2.47a3.027 3.027 0 000-.74l4.94-2.47C13.456 7.68 14.19 8 15 8z"></path>
</svg>
<span class="hidden sm:block">Compartir</span>
<% end %>
</div>

<%= render "sharer/share_button", resource: @track %>
<%= render "likes/like_button", resource: @track, button_class: liked?(@track) ? "button-active" : "button" %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<div class="border-r-2--">
<div class="px-4 py-5 sm:px-6">
<div class="flex justify-between items-center">
<h1 class="font-bold text-4xl">all</h1>
<h1 class="font-bold text-4xl"><%= @title %></h1>


<a href="/tracks/new" data-phx-link="redirect" data-phx-link-state="push" class="button-large-outline">
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ en:
loading: Loading...
repost: Repost
like: Like
likes: Likes

menu:
music: Music
Expand Down
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

get "/embed/:track_id", to: "embeds#show"
get "/oembed/:track_id", to: "embeds#oembed_show", as: :oembed_show
get "/oembed/:track_id/private", to: "embeds#oembed_private_show"
get "/oembed/:track_id/private", to: "embeds#oembed_private_show", as: :private_oembed_track
get "/embed/:track_id/private", to: "embeds#private_track", as: :private_embed
get "/embed/sets/:playlist_id", to: "embeds#show_playlist"
get "/embed/sets/:playlist_id/private", to: "embeds#private_playlist"
Expand Down Expand Up @@ -91,6 +91,9 @@
resources :comments
resource :embed, only: :show
resource :sharer, controller: "sharer"
member do
get :private , to: "tracks#private_access"
end
resources :track_purchases do
member do
get :success
Expand Down

0 comments on commit 4cf1413

Please sign in to comment.