43 lines
949 B
Elixir
43 lines
949 B
Elixir
![]() |
defmodule SomethingErlangWeb.BookmarksLive do
|
||
|
use SomethingErlangWeb, :live_view
|
||
|
|
||
|
alias SomethingErlang.Grover
|
||
|
|
||
|
def render(assigns) do
|
||
|
~H"""
|
||
|
<div :if={@bookmarks}>
|
||
|
<.bookmark
|
||
|
:for={thread <- @bookmarks}
|
||
|
id={thread.id}
|
||
|
title={thread.title.thread_title}
|
||
|
post_count={thread.replies}
|
||
|
/>
|
||
|
</div>
|
||
|
"""
|
||
|
end
|
||
|
|
||
|
defp bookmark(assigns) do
|
||
|
assigns = assign(assigns, :pages, trunc(assigns.post_count / 40))
|
||
|
|
||
|
~H"""
|
||
|
<div>
|
||
|
<.link href={~p"/thread/#{@id}"}><%= @title %></.link>
|
||
|
<.link href={~p"/thread/#{@id}?page=#{@pages}"}><%= @pages %></.link>
|
||
|
</div>
|
||
|
"""
|
||
|
end
|
||
|
|
||
|
def mount(_params, session, socket) do
|
||
|
user =
|
||
|
socket.assigns.current_user
|
||
|
|> Map.put(:bbpassword, session["bbpassword"])
|
||
|
|
||
|
Grover.mount(user)
|
||
|
|
||
|
{:ok,
|
||
|
socket
|
||
|
|> assign(:page_title, "Bookmarks")
|
||
|
|> assign(:bookmarks, Grover.get_bookmarks!(1) |> dbg())}
|
||
|
end
|
||
|
end
|