Skip to content

Commit 412e178

Browse files
committed
Rejigger the bubbles upvote component
1 parent ded35e5 commit 412e178

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

assets/js/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ function initializeCodeCopy() {
6363
}
6464

6565
function initializeBubblesVotes() {
66-
document.querySelectorAll('[data-url]').forEach(el => {
66+
document.querySelectorAll('#vote-on-bubbles').forEach(el => {
6767
const url = el.getAttribute('data-url');
6868
fetch(`https://bubbles.town/api/vote-count?url=${encodeURIComponent(url)}`)
6969
.then(r => r.json())
7070
.then(d => {
7171
if (!d.id) return
72-
el.outerHTML = `
72+
el.innerHTML = `
7373
<a href="https://bubbles.town/entry/${d.id}" class="underline" style="color: #4ecdc4" target="_blank">
74-
vote on Bubbles ▲<span class="bubbles-count text-foreground">${d.count ? d.count : ''}</span>
74+
Vote on Bubbles ▲<span class="bubbles-count text-foreground">${d.count ? d.count : ''}</span>
7575
</a>
7676
`
7777
})

lib/jola_dev_web/components/core_components.ex

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ defmodule JolaDevWeb.CoreComponents do
295295
end
296296

297297
attr :author, :string, required: true
298-
attr :url, :string, required: true
299298
attr :class, :string, default: nil
300299

301300
def author(assigns) do
@@ -312,7 +311,7 @@ defmodule JolaDevWeb.CoreComponents do
312311
>
313312
@jola.dev
314313
</.link>
315-
or why not give it a <span class="vote-on-bubbles" data-url={@url}> vote on <.link href="https://bubbles.town/" class="underline">Bubbles</.link></span>.
314+
.
316315
</p>
317316
"""
318317
end
@@ -322,7 +321,7 @@ defmodule JolaDevWeb.CoreComponents do
322321

323322
def sponsor(assigns) do
324323
~H"""
325-
<aside class={["mt-12", @class]}>
324+
<aside class={["mt-8", @class]}>
326325
<div class="rounded-lg border border-accent/30 bg-accent/5 p-6 md:p-8">
327326
<p class="text-lg font-semibold text-foreground mb-2">
328327
{assigns.title}
@@ -792,4 +791,12 @@ defmodule JolaDevWeb.CoreComponents do
792791
</div>
793792
"""
794793
end
794+
795+
attr :url, :string, required: true
796+
797+
def bubbles_vote(assigns) do
798+
~H"""
799+
<div id="vote-on-bubbles" data-url={@url} class="mt-2" />
800+
"""
801+
end
795802
end

lib/jola_dev_web/controllers/blog_html/show.html.heex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
{raw(@post.body)}
2727
</div>
2828

29+
<.bubbles_vote url={Phoenix.Controller.current_url(@conn)} />
30+
2931
<.author
3032
author={@post.author}
31-
url={Phoenix.Controller.current_url(@conn)}
3233
/>
3334

3435
<.sponsor title="Like this post?" />

0 commit comments

Comments
 (0)