Skip to content

Commit 673da97

Browse files
committed
Show oldest unread entry at the top
1 parent 6f77b48 commit 673da97

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

config/dev.exs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ config :ex_rss, ExRssWeb.Endpoint,
3636
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
3737
~r{priv/gettext/.*(po)$},
3838
~r{lib/ex_rss_web/views/.*(ex)$},
39-
~r{lib/ex_rss_web/templates/.*(eex)$}
39+
~r{lib/ex_rss_web/templates/.*(eex)$},
40+
# TODO
41+
# 2024-12-04
42+
# This pattern is more generic than the one generated by Phoenix 1.7.
43+
#
44+
# This is due to a different folder structure. It is probably a good idea
45+
# to move files around to match the expectations of Phoenix 1.7.
46+
~r{lib/ex_rss_web/.*(heex)$}
4047
]
4148
]
4249

lib/ex_rss/user.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ defmodule ExRss.User do
44
alias Ecto.Changeset
55

66
alias ExRss.Feed
7+
alias ExRss.Repo
78
alias ExRss.User
89

910
@timestamps_opts [type: :utc_datetime]
@@ -33,4 +34,16 @@ defmodule ExRss.User do
3334
def verify_remember_me_token(token) do
3435
Phoenix.Token.verify(@context, @salt, token, max_age: @max_age)
3536
end
37+
38+
def oldest_unread_entry(user_id) do
39+
user = Repo.get!(User, user_id)
40+
41+
from(e in assoc(user, :entries),
42+
where: e.read == false,
43+
order_by: [asc: :posted_at],
44+
limit: 1
45+
)
46+
|> Repo.all()
47+
|> List.first()
48+
end
3649
end

lib/ex_rss_web/feed_live/index.ex

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
defmodule ExRssWeb.FeedLive.Index do
22
use ExRssWeb, :live_view
33

4-
def mount(_params, %{"api_token" => api_token} = _session, socket) do
5-
{:ok, assign(socket, :api_token, api_token)}
4+
alias ExRss.User
5+
6+
def mount(
7+
_params,
8+
%{"api_token" => api_token, "current_user" => current_user} = _session,
9+
socket
10+
) do
11+
oldest_unread_entry = User.oldest_unread_entry(current_user.id)
12+
13+
socket =
14+
socket
15+
|> assign(:api_token, api_token)
16+
|> assign(:oldest_unread_entry, oldest_unread_entry)
17+
18+
{:ok, socket}
619
end
720

821
# 2024-12-03
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
<h1 class="mb-2 font-bold">Oldest unread entry</h1>
2+
3+
<ul class="mb-6 flex flex-col">
4+
<li class="flex flex-col md:flex-row mt-4">
5+
<div class="flex flex-col">
6+
<a href={@oldest_unread_entry.url} target="_blank"><%= @oldest_unread_entry.title %></a>
7+
<span><%= @oldest_unread_entry.posted_at %></span>
8+
</div>
9+
10+
<div class="md:shrink-0 flex self-start mt-1 ml-auto space-x-4">
11+
<a target="_blank" aria-label={"View entry #{@oldest_unread_entry.title}"}>View</a>
12+
<button aria-label="Mark as read">Mark as read</button>
13+
</div>
14+
</li>
15+
</ul>
16+
117
<%=
218
elm_module("App.Feeds", %{apiToken: @api_token})
319
%>

0 commit comments

Comments
 (0)