Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded player for social media #221

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/controllers/tracks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class TracksController < ApplicationController
before_action :set_track, only: %i[move_higher move_lower]
before_action :set_track, only: %i[move_higher move_lower player]

def move_higher
authorize @track
Expand All @@ -19,6 +19,12 @@ def move_lower
redirect_to artist_album_path(@track.artist, @track.album)
end

def player
authorize @track
@album = @track.album
render layout: false
end

private

def set_track
Expand Down
4 changes: 4 additions & 0 deletions app/policies/track_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ def move_lower?
def reorder?
record.unpublished? && move_lower? && move_higher?
end

def player?
true
end
end
42 changes: 42 additions & 0 deletions app/views/tracks/player.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= display_meta_tags site: "jam.coop" %>
<%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %>

<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
<%= hotwire_livereload_tags if Rails.env.development? %>
</head>

<style>
.player {
width: 100vw;
height: 100vh;
background-image: url('<%= cdn_url(@album.cover.representation(resize_to_limit: [750, 750])) %>');
background-size: cover;
background-position: 50% 50%;
}

.footer {
position: absolute;
right: 0;
bottom: 3%;
left: 3%;
}
</style>

<body>
<div class="player">
<div class="footer">
<span class="text-white bg-slate-600 px-2 py-1">
<%= text_link_to @album.title, artist_album_url(@album.artist, @album) %> by <%= @album.artist.name %>
</span>
<span></span>
</div>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
member do
post 'move_higher'
post 'move_lower'
get 'player'
end
end

Expand Down