bookmarks!
This commit is contained in:
@ -7,6 +7,14 @@ defmodule SomethingErlang.AwfulApi.Client do
|
||||
:unicode.characters_to_binary(resp.body, :latin1)
|
||||
end
|
||||
|
||||
def thread_lastseen_page(id, user) do
|
||||
resp = new_request(user) |> get_thread_newpost(id)
|
||||
%{status: 302, headers: headers} = resp
|
||||
{"location", redir_url} = List.keyfind(headers, "location", 0)
|
||||
[_, page] = Regex.run(~r/pagenumber=(\d+)/, redir_url)
|
||||
page |> String.to_integer()
|
||||
end
|
||||
|
||||
def bookmarks_doc(page, user) do
|
||||
resp = new_request(user) |> get_bookmarks(page)
|
||||
:unicode.characters_to_binary(resp.body, :latin1)
|
||||
@ -18,6 +26,12 @@ defmodule SomethingErlang.AwfulApi.Client do
|
||||
Req.get!(req, url: url, params: params)
|
||||
end
|
||||
|
||||
defp get_thread_newpost(req, id) do
|
||||
url = "showthread.php"
|
||||
params = [threadid: id, goto: "newpost"]
|
||||
Req.get!(req, url: url, params: params, follow_redirects: false)
|
||||
end
|
||||
|
||||
defp get_bookmarks(req, page \\ 1) do
|
||||
url = "bookmarkthreads.php"
|
||||
params = [pagenumber: page]
|
||||
|
@ -15,6 +15,10 @@ defmodule SomethingErlang.Grover do
|
||||
GenServer.call(via(self()), {:show_thread, thread_id, page_number})
|
||||
end
|
||||
|
||||
def get_bookmarks!(page_number) do
|
||||
GenServer.call(via(self()), {:show_bookmarks, page_number})
|
||||
end
|
||||
|
||||
def start_link([lv_pid, user]) do
|
||||
GenServer.start_link(
|
||||
__MODULE__,
|
||||
@ -41,6 +45,12 @@ defmodule SomethingErlang.Grover do
|
||||
{:reply, thread, state}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_call({:show_bookmarks, _page_number}, _from, state) do
|
||||
bookmarks = AwfulApi.bookmarks(state.user)
|
||||
{:reply, bookmarks, state}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({:DOWN, _ref, :process, _object, reason}, state) do
|
||||
Logger.debug "received :DOWN from: #{inspect(state.lv_pid)} reason: #{inspect(reason)}"
|
||||
|
@ -2,22 +2,23 @@ defmodule SomethingErlangWeb.BookmarksLive.Show do
|
||||
use SomethingErlangWeb, :live_view
|
||||
on_mount SomethingErlangWeb.UserLiveAuth
|
||||
|
||||
#alias SomethingErlang.Grover
|
||||
alias SomethingErlang.Grover
|
||||
|
||||
require Logger
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
#Grover.mount(socket.assigns.current_user, id)
|
||||
Grover.mount(socket.assigns.current_user)
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(%{"page" => page}, _, socket) do
|
||||
#thread = Grover.get_thread!(id, page |> String.to_integer())
|
||||
bookmarks = Grover.get_bookmarks!(page |> String.to_integer())
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:page_title, "bookmarks")}
|
||||
|> assign(:page_title, "bookmarks")
|
||||
|> assign(:bookmarks, bookmarks)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
|
@ -0,0 +1,16 @@
|
||||
<table class="table w-full">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Title</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%= for thread <- @bookmarks do %>
|
||||
<tr>
|
||||
<th><%= raw thread.icon %></th>
|
||||
<td><%= raw thread.title %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
Reference in New Issue
Block a user