meeseeks bookmarks; also bookmarks

This commit is contained in:
Rüdiger Diedrich
2024-08-12 15:46:13 +02:00
parent 2ab3f7ba7f
commit fede012e44
6 changed files with 114 additions and 50 deletions

View File

@ -0,0 +1,42 @@
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

View File

@ -28,6 +28,8 @@ defmodule SomethingErlangWeb.Router do
on_mount: [{SomethingErlangWeb.UserAuth, :ensure_authenticated}] do
live("/thread", ThreadLive)
live("/thread/:id", ThreadLive)
live("/bookmarks", BookmarksLive)
live("/bookmarks/:id", BookmarksLive)
end
end