Skip to content

Add loading state to entry #487

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

Merged
merged 1 commit into from
Jan 4, 2025
Merged
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
17 changes: 11 additions & 6 deletions lib/ex_rss_web/feed_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ defmodule ExRssWeb.FeedLive.Index do
end

attr :entry, Entry, required: true
attr :dom_id, :string, required: true

def entry(assigns) do
~H"""
<ul class="flex flex-col">
<ul id={@dom_id} class="flex flex-col phx-click-loading:opacity-50">
<li class="flex flex-col md:flex-row">
<div class="flex flex-col">
<a href={@entry.url} target="_blank">{@entry.title}</a>
Expand All @@ -201,12 +202,16 @@ defmodule ExRssWeb.FeedLive.Index do
href={@entry.url}
target="_blank"
aria-label={"View entry #{@entry.title}"}
phx-click="mark_as_read"
phx-click={JS.push("mark_as_read", loading: "##{@dom_id}")}
phx-value-entry-id={@entry.id}
>
<.icon name="hero-arrow-top-right-on-square-solid" />
</a>
<button aria-label="Mark as read" phx-click="mark_as_read" phx-value-entry-id={@entry.id}>
<button
aria-label="Mark as read"
phx-click={JS.push("mark_as_read", loading: "##{@dom_id}")}
phx-value-entry-id={@entry.id}
>
<.icon name="hero-check-circle-solid" />
</button>
</div>
Expand All @@ -228,19 +233,19 @@ defmodule ExRssWeb.FeedLive.Index do
~H"""
<ul class="mb-6 flex flex-col space-y-4">
<li :for={entry <- @head_entries}>
<.entry entry={entry} />
<.entry entry={entry} dom_id={"entry-#{entry.id}"} />
</li>
<div>{@number_of_entries_not_shown} entries not shown</div>
<li :for={entry <- @tail_entries}>
<.entry entry={entry} />
<.entry entry={entry} dom_id={"entry-#{entry.id}"} />
</li>
</ul>
"""
else
~H"""
<ul class="mb-6 flex flex-col space-y-4">
<li :for={entry <- @entries}>
<.entry entry={entry} />
<.entry entry={entry} dom_id={"entry-#{entry.id}"} />
</li>
</ul>
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/ex_rss_web/feed_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

<div class="mb-6">
<%= if @oldest_unread_entry do %>
<.entry entry={@oldest_unread_entry} />
<.entry entry={@oldest_unread_entry} dom_id="entry-oldest-unread" />
<% else %>
<div>No entry found</div>
<% end %>
Expand Down
Loading