Timeline pagination
This commit is contained in:
parent
4aa579d959
commit
ace33f3d06
|
@ -84,6 +84,10 @@ ul.status-list {
|
|||
}
|
||||
}
|
||||
|
||||
.pagination-link {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.status {
|
||||
padding: 0.5rem;
|
||||
border: 1px solid #ddd;
|
||||
|
|
|
@ -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 %>
|
||||
|
||||
|
|
|
@ -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…
Reference in New Issue