Browse Source

Timeline pagination

master
Shadowfacts 1 year ago
parent
commit
ace33f3d06
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
3 changed files with 43 additions and 3 deletions
  1. +4
    -0
      assets/css/clacks.scss
  2. +15
    -0
      lib/clacks_web/templates/frontend/_timeline.html.eex
  3. +24
    -3
      lib/clacks_web/views/frontend_view.ex

+ 4
- 0
assets/css/clacks.scss View File

@ -84,6 +84,10 @@ ul.status-list {
}
}
.pagination-link {
text-align: center;
}
.status {
padding: 0.5rem;
border: 1px solid #ddd;


+ 15
- 0
lib/clacks_web/templates/frontend/_timeline.html.eex View File

@ -1,3 +1,10 @@
<% newer = prev_page_path(@conn, @statuses_with_authors) %>
<%= if newer do %>
<p class="pagination-link">
<a href="<%= newer %>">Newer</a>
</p>
<% end %>
<ul class="status-list">
<%= for {status, author} <- @statuses_with_authors do %>
<li>
@ -5,3 +12,11 @@
</li>
<% end %>
</ul>
<% older = next_page_path(@conn, @statuses_with_authors) %>
<%= if older do %>
<p class="pagination-link">
<a href="<%= older %>">Older</a>
</p>
<% end %>

+ 24
- 3
lib/clacks_web/views/frontend_view.ex View File

@ -1,6 +1,6 @@
defmodule ClacksWeb.FrontendView do
use ClacksWeb, :view
alias Clacks.Actor
alias Clacks.{Actor, Activity}
@spec display_username(actor :: Actor.t()) :: String.t()
@ -13,8 +13,6 @@ defmodule ClacksWeb.FrontendView do
"@" <> name <> "@" <> host
end
@absolute_timestamp_threshold 24 * 60 * 60
def display_timestamp(str) when is_binary(str) do
display_timestamp(Timex.parse!(str, "{ISO:Extended}"))
end
@ -43,4 +41,27 @@ defmodule ClacksWeb.FrontendView do
Timex.format!(datetime, "%FT%T%:z", :strftime)
end
end
def prev_page_path(conn, activities) do
if Map.has_key?(conn.query_params, "max_id") do
Phoenix.Controller.current_path(conn, %{
since_id: activities |> List.first() |> activity_id()
})
else
nil
end
end
def next_page_path(conn, activities) do
if length(activities) < 20 do
nil
else
Phoenix.Controller.current_path(conn, %{
max_id: activities |> List.last() |> activity_id()
})
end
end
defp activity_id(%Activity{id: id}), do: id
defp activity_id({%Activity{id: id}, _}), do: id
end

Loading…
Cancel
Save