mix format

This commit is contained in:
2022-11-07 13:49:31 +01:00
parent 51b9cc7f76
commit 0e74b0e1e0
16 changed files with 137 additions and 110 deletions

View File

@ -7,11 +7,14 @@ defmodule SomethingErlangWeb.PageController do
def to_forum_path(conn, %{"to" => redir_params} = _params) do
%{"forum_path" => path} = redir_params
with [_, thread] <- Regex.run(~r{threadid=(\d+)}, path),
[_, page] <- Regex.run(~r{pagenumber=(\d+)}, path) do
redirect(conn,
to: Routes.thread_show_path(conn, :show, thread, page: page))
to: Routes.thread_show_path(conn, :show, thread, page: page)
)
end
put_flash(conn, :error, "Could not resolve URL")
render(conn, "index.html")
end

View File

@ -4,12 +4,12 @@ defmodule SomethingErlangWeb.Icons do
@priv_dir Path.join(:code.priv_dir(:something_erlang), "icons")
@repo_url "https://github.com/CoreyGinnivan/system-uicons.git"
System.cmd("rm", ["-rf", Path.join(@priv_dir, "system-uicons")])
System.cmd("rm", ["-rf", Path.join(@priv_dir, "system-uicons")])
System.cmd("git", ["clone", "--depth=1", @repo_url, Path.join(@priv_dir, "system-uicons")])
source_data = File.read!(Path.join(@priv_dir, "system-uicons/src/js/data.js"))
<<"var sourceData = "::utf8 , rest::binary>> = source_data
<<"var sourceData = "::utf8, rest::binary>> = source_data
# remove trailing semicolon
sslice = String.slice(rest, 0..-3//1)
# quote object keys
@ -18,15 +18,18 @@ defmodule SomethingErlangWeb.Icons do
rm_trailing_commas = Regex.replace(~r/,\s+(}|])/, quote_keys, "\\1")
icon_data = Jason.decode!(rm_trailing_commas)
icon_map = Enum.map(icon_data, fn %{"icon_path" => path} = icon ->
svg = File.read!(Path.join(@priv_dir, "system-uicons/src/images/icons/#{path}.svg"))
Map.put_new(icon, "icon_svg", svg)
|> Map.new(fn {k, v} -> {String.to_atom(k), v} end)
end)
icon_map =
Enum.map(icon_data, fn %{"icon_path" => path} = icon ->
svg = File.read!(Path.join(@priv_dir, "system-uicons/src/images/icons/#{path}.svg"))
Map.put_new(icon, "icon_svg", svg)
|> Map.new(fn {k, v} -> {String.to_atom(k), v} end)
end)
for %{icon_path: path, icon_svg: svg} <- icon_map do
def unquote(String.to_atom(path))(assigns) do
svg = unquote(svg)
~H"""
<i class={"icon"}>
<%= Phoenix.HTML.raw svg %>

View File

@ -15,6 +15,7 @@ defmodule SomethingErlangWeb.BookmarksLive.Show do
@impl true
def handle_params(%{"page" => page}, _, socket) do
bookmarks = Grover.get_bookmarks!(page |> String.to_integer())
{:noreply,
socket
|> assign(:page_title, "bookmarks")
@ -23,8 +24,9 @@ defmodule SomethingErlangWeb.BookmarksLive.Show do
@impl true
def handle_params(_, _, socket) do
{:noreply, push_redirect(socket,
to: Routes.bookmarks_show_path(socket, :show, page: 1))}
{:noreply,
push_redirect(socket,
to: Routes.bookmarks_show_path(socket, :show, page: 1)
)}
end
end

View File

@ -15,6 +15,7 @@ defmodule SomethingErlangWeb.ThreadLive.Show do
@impl true
def handle_params(%{"id" => id, "page" => page}, _, socket) do
thread = Grover.get_thread!(id, page |> String.to_integer())
{:noreply,
socket
|> assign(:page_title, thread.title)
@ -23,8 +24,10 @@ defmodule SomethingErlangWeb.ThreadLive.Show do
@impl true
def handle_params(%{"id" => id}, _, socket) do
{:noreply, push_redirect(socket,
to: Routes.thread_show_path(socket, :show, id, page: 1))}
{:noreply,
push_redirect(socket,
to: Routes.thread_show_path(socket, :show, id, page: 1)
)}
end
def post(assigns) do
@ -61,10 +64,10 @@ defmodule SomethingErlangWeb.ThreadLive.Show do
%{page: page_number, page_count: page_count} = assigns.thread
first_page_disabled_button = if page_number == 1, do: " btn-disabled", else: ""
last_page_disabled_button = if page_number == page_count, do: " btn-disabled", else: ""
last_page_disabled_button = if page_number == page_count, do: " btn-disabled", else: ""
active_page_button = " btn-active"
prev_button_target = if page_number >= 1, do: page_number - 1, else: 1
prev_button_target = if page_number > 1, do: page_number - 1, else: 1
next_button_target = if page_number < page_count, do: page_number + 1, else: page_count
buttons = [
@ -78,16 +81,16 @@ defmodule SomethingErlangWeb.ThreadLive.Show do
~H"""
<div class="navbar my-4 bg-base-200">
<div class="flex-1"></div>
<div class="pagination flex-none btn-group">
<div class="pagination flex-none btn-group grid grid-cols-5">
<%= for btn <- buttons do %>
<%= live_redirect class: "btn btn-sm" <> btn.special,
<%= live_redirect class: "btn btn-sm btn-ghost" <> btn.special,
to: Routes.thread_show_path(@socket, :show, @thread.id, page: btn.page) do %>
<%= case btn.label do %>
<% "«" -> %>1 <Icons.chevron_left_double />
<% "" -> %><Icons.chevron_left />
<% "" -> %><Icons.chevron_right />
<% "»" -> %><Icons.chevron_right_double /> <%= page_count %>
<% _ -> %><%= btn.label %>
<% "«" -> %><Icons.chevron_left_double /><%= btn.page %>
<% "" -> %><Icons.chevron_left /><%= btn.page %>
<% "" -> %><%= btn.page %><Icons.chevron_right />
<% "»" -> %><%= btn.page %><Icons.chevron_right_double />
<% _ -> %><%= btn.page %>
<% end %>
<% end %>
<% end %>

View File

@ -3,7 +3,6 @@ defmodule SomethingErlangWeb.UserLiveAuth do
alias SomethingErlang.Accounts
def on_mount(:default, _params, %{"user_token" => user_token} = _session, socket) do
user = Accounts.get_user_by_session_token(user_token)
socket = assign_new(socket, :current_user, fn -> user end)