defmodule SomethingErlangWeb.BookmarksLive do use SomethingErlangWeb, :live_view alias SomethingErlang.Grover def render(assigns) do assigns.bookmarks |> dbg() ~H"""
<.bookmark :for={thread <- bookmarks} id={thread.id} title={thread.title.thread_title} post_count={thread.replies} />
""" end defp bookmark(assigns) do assigns = assign(assigns, :pages, ceil(assigns.post_count / 40)) ~H"""
<.link href={~p"/thread/#{@id}"}><%= @title %> <.link href={~p"/thread/#{@id}?page=#{@pages}"}><%= @pages %>
""" end def mount(_params, session, socket) do user = socket.assigns.current_user |> Map.put(:bbpassword, session["bbpassword"]) {:ok, pid} = Grover.start_link(user) |> dbg() {:ok, socket |> assign(:page_title, "Bookmarks") |> assign_async(:bookmarks, fn -> {:ok, bookmarks} = get_bookmarks(pid) {:ok, %{bookmarks: bookmarks}} end)} end defp get_bookmarks(pid) do case Grover.get_bookmarks!(pid, 1) do bookmarks when is_list(bookmarks) -> {:ok, bookmarks} _ -> {:error, "Failed getting bookmarks"} end end end