1 Commits

Author SHA1 Message Date
24b0942a13 grover without dynamicsupervisor? 2024-08-13 09:48:50 +02:00
6 changed files with 29 additions and 62 deletions

View File

@ -5,7 +5,7 @@
/* This file is for your main application CSS */
body {
@apply bg-base-300 font-['Inter'] text-[18px] leading-6 overflow-x-hidden;
@apply bg-base-300 text-[14pt] leading-8 overflow-x-hidden;
}
.post {
@ -36,14 +36,11 @@ body {
.post .code pre:before { @apply mr-0; }
.post .code h5 { @apply hidden; }
.post a[href] { @apply link; }
.post .bbc-block a[href] { @apply link; }
.post .editedby { @apply text-sm italic opacity-70 mt-4; }
.post .title :where(img[src*="gangtags"]) + * {
@apply mb-1;
}
.post i, .post .bbc-spoiler, .post a[href] { @apply inline-block mx-1; }
.pagination a svg {
@apply h-5;
}

View File

@ -34,8 +34,7 @@ if config_env() == :prod do
# ssl: true,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
socket_options: maybe_ipv6,
prepare: :unnamed
socket_options: maybe_ipv6
# The secret key base is used to sign/encrypt cookies and other secrets.
# A default value is used in config/dev.exs and config/test.exs but you
@ -49,11 +48,7 @@ if config_env() == :prod do
You can generate one by calling: mix phx.gen.secret
"""
host =
System.get_env("PHX_HOST") ||
"example.com"
|> IO.inspect()
host = System.get_env("PHX_HOST") || "example.com"
port = String.to_integer(System.get_env("PORT") || "4000")
config :something_erlang, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY")
@ -68,7 +63,6 @@ if config_env() == :prod do
ip: {0, 0, 0, 0, 0, 0, 0, 0},
port: port
],
check_origin: [host],
secret_key_base: secret_key_base
# ## SSL Support

View File

@ -35,11 +35,7 @@ defmodule SomethingErlang.AwfulApi.Thread do
end
posts =
for post <- Meeseeks.all(thread, css("table.post")),
post
|> Meeseeks.attr("class")
|> String.contains?("ignored")
|> Kernel.not() do
for post <- Meeseeks.all(thread, css("table.post:not(.ignored)")) do
%{
userinfo: userinfo(post),
postdate: postdate(post),

View File

@ -4,48 +4,30 @@ defmodule SomethingErlang.Grover do
alias SomethingErlang.AwfulApi
require Logger
def mount(user) do
grover =
DynamicSupervisor.start_child(
SomethingErlang.Supervisor.Grovers,
{__MODULE__, [self(), user]}
)
case grover do
{:ok, pid} -> pid
{:error, {:already_started, pid}} -> pid
{:error, error} -> {:error, error}
end
end
def get_thread!(thread_id, page_number) do
GenServer.call(via(self()), {:show_thread, thread_id, page_number})
GenServer.call(__MODULE__, {:show_thread, thread_id, page_number})
end
def get_bookmarks!(page_number) do
GenServer.call(via(self()), {:show_bookmarks, page_number})
def get_bookmarks!(pid, page_number) do
GenServer.call(pid, {:show_bookmarks, page_number})
end
def start_link([lv_pid, user]) do
def start_link(user) do
GenServer.start_link(
__MODULE__,
[lv_pid, user],
name: via(lv_pid)
[user]
)
end
@impl true
def init([pid, user]) do
def init([user]) do
%{bbuserid: userid, bbpassword: userhash} = user
initial_state = %{
lv_pid: pid,
user: %{id: userid, hash: userhash}
}
Logger.debug("init #{userid} #{inspect(pid)}")
Process.monitor(pid)
{:ok, initial_state}
{:ok, initial_state} |> dbg()
end
@impl true
@ -57,20 +39,6 @@ defmodule SomethingErlang.Grover do
@impl true
def handle_call({:show_bookmarks, page_number}, _from, state) do
bookmarks = AwfulApi.bookmarks(page_number, 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)}")
case reason do
{:shutdown, _} -> {:stop, :normal, state}
:killed -> {:stop, :normal, state}
_ -> {:noreply, state}
{:reply, bookmarks, state} |> dbg()
end
end
defp via(lv_pid),
do: {:via, Registry, {SomethingErlang.Registry.Grovers, lv_pid}}
end

View File

@ -4,10 +4,12 @@ defmodule SomethingErlangWeb.BookmarksLive do
alias SomethingErlang.Grover
def render(assigns) do
assigns.bookmarks |> dbg()
~H"""
<div :if={@bookmarks}>
<div :if={bookmarks = @bookmarks.ok? && @bookmarks.result}>
<.bookmark
:for={thread <- @bookmarks}
:for={thread <- bookmarks}
id={thread.id}
title={thread.title.thread_title}
post_count={thread.replies}
@ -32,11 +34,21 @@ defmodule SomethingErlangWeb.BookmarksLive do
socket.assigns.current_user
|> Map.put(:bbpassword, session["bbpassword"])
Grover.mount(user)
{:ok, pid} = Grover.start_link(user) |> dbg()
{:ok,
socket
|> assign(:page_title, "Bookmarks")
|> assign(:bookmarks, Grover.get_bookmarks!(1))}
|> 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

View File

@ -14,7 +14,7 @@
"finch": {:hex, :finch, "0.18.0", "944ac7d34d0bd2ac8998f79f7a811b21d87d911e77a786bc5810adb75632ada4", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6 or ~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "69f5045b042e531e53edc2574f15e25e735b522c37e2ddb766e15b979e03aa65"},
"floki": {:hex, :floki, "0.36.2", "a7da0193538c93f937714a6704369711998a51a6164a222d710ebd54020aa7a3", [:mix], [], "hexpm", "a8766c0bc92f074e5cb36c4f9961982eda84c5d2b8e979ca67f5c268ec8ed580"},
"gettext": {:hex, :gettext, "0.24.0", "6f4d90ac5f3111673cbefc4ebee96fe5f37a114861ab8c7b7d5b30a1108ce6d8", [:mix], [{:expo, "~> 0.5.1", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "bdf75cdfcbe9e4622dd18e034b227d77dd17f0f133853a1c73b97b3d6c770e8b"},
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized", depth: 1]},
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized"]},
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
"meeseeks": {:hex, :meeseeks, "0.17.0", "8a41ceccd2365476c2b779292e7649fb25f0a9735030905941f1244d2095c8a6", [:mix], [{:meeseeks_html5ever, "~> 0.14.3", [hex: :meeseeks_html5ever, repo: "hexpm", optional: false]}], "hexpm", "13efaf321a1517dea046cb48ff9baa9dc0604d9afd82c57501bc01dc45a5e309"},