Skip to content

Commit

Permalink
Fix template labels
Browse files Browse the repository at this point in the history
  • Loading branch information
radical-ube committed Feb 4, 2025
1 parent 496f298 commit 212f7e1
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 17 deletions.
16 changes: 16 additions & 0 deletions app/helpers/podcasts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,20 @@ def disable_non_compliant_language(language)
language
end
end

def subscribe_link_platform_label(link)
I18n.t("helpers.label.podcast.subscribe_link.#{link.platform}")
end

def subscribe_link_id_label(link)
if link.uses_apple_id?
I18n.t("helpers.label.podcast.subscribe_link.id.apple")
elsif link.uses_unique_id?
I18n.t("helpers.label.podcast.subscribe_link.id.unique", platform: subscribe_link_platform_label(link))
end
end

def subscribe_link_enabled_label(link)
I18n.t("helpers.label.podcast.subscribe_link.enabled", platform: subscribe_link_platform_label(link))
end
end
7 changes: 5 additions & 2 deletions app/javascript/controllers/subscribe_links_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ export default class extends Controller {

addLink(event) {
const now = new Date().getTime()
console.log(event.target.value)
const platform = event.target.value
const html = this.templateTarget.innerHTML.replaceAll("NEW_RECORD", now).replaceAll("NEW_PLATFORM", platform)

const template = this.templateTargets.filter((target) => {
return target.dataset.platform === platform
})
const html = template[0].innerHTML.replaceAll("NEW_RECORD", now).replaceAll("NEW_PLATFORM", platform)
this.templateTarget.insertAdjacentHTML("beforeBegin", html)
}
}
2 changes: 1 addition & 1 deletion app/models/podcast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def only_one_of_each_link_platform

if dupes.any?
dupes.each do |p|
errors.add(:podcast, "cannot have more than one #{p} link")
errors.add(:podcast, "cannot have more than one #{I18n.t("helpers.label.podcast.subscribe_link.#{p}")} link")
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/subscribe_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ class SubscribeLink < ApplicationRecord
scope :with_platform_id, -> { where(platform: UNIQUE_PLATFORMS) }

validates :external_id, presence: true

def uses_apple_id?
APPLE_PLATFORMS.include?(platform)
end

def uses_unique_id?
UNIQUE_PLATFORMS.include?(platform)
end
end
18 changes: 9 additions & 9 deletions app/views/podcast_engagement/_form_subscribe_link.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<div class="col-12 mb-3 d-flex gap-3 align-items-top">
<div class="col-6 d-flex align-items-center">
<div class="form-floating input-group flex-grow-1">
<%= form.text_field :external_id %>
<%= form.label :external_id, t(".ids.#{form.object.platform}") %>
<%= field_help_text t(".help.#{form.object.platform}") %>
</div>
</div>
<div class="col-12 mb-3 d-flex align-items-top">
<div class="col-6 d-flex align-items-center">
<div class="form-check flex-grow-1">
<%= form.check_box :enabled %>
<div class="d-flex align-items-center">
<%= form.label :enabled, "enabled" %>
<%= form.label :enabled, subscribe_link_enabled_label(form.object) %>
<span class="p-0 ms-1 material-icons">group</span>
</div>
</div>
</div>
<div class="col-6 d-flex align-items-center">
<div class="form-floating input-group flex-grow-1">
<%= form.text_field :external_id %>
<%= form.label :external_id, subscribe_link_id_label(form.object) %>
<%= field_help_text t(".help.#{form.object.platform}") %>
</div>
</div>
</div>
<%= form.hidden_field :type %>
<%= form.hidden_field :platform %>
12 changes: 7 additions & 5 deletions app/views/podcast_engagement/_form_subscribe_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
<%= render "form_subscribe_link", form: fields %>
<% end %>

<template data-subscribe-links-target="template">
<%= form.fields_for :subscribe_links, podcast.subscribe_links.new(platform: "NEW_PLATFORM"), child_index: "NEW_RECORD" do |fields| %>
<%= render "form_subscribe_link", form: fields %>
<% end %>
</template>
<% SubscribeLink::PLATFORMS.each do |platform| %>
<template data-subscribe-links-target="template" data-platform="<%= platform %>">
<%= form.fields_for :subscribe_links, podcast.subscribe_links.new(platform: platform), child_index: "NEW_RECORD" do |fields| %>
<%= render "form_subscribe_link", form: fields %>
<% end %>
</template>
<% end %>

<% if policy(podcast).update? %>
<div class="dropdown flex-grow-1">
Expand Down
10 changes: 10 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,16 @@ en:
serial_orders:
false: Episodic
true: Serial
subscribe_link:
apple: Apple Podcasts
spotify: Spotify
overcast: Overcast
pocketcasts: Pocket Casts
youtube: Youtube Music
id:
apple: Apple ID
unique: "%{platform} ID"
enabled: "Enable %{platform}"
subtitle: Teaser
title: Title
podcast_player:
Expand Down

0 comments on commit 212f7e1

Please sign in to comment.