icons!
This commit is contained in:
@ -99,6 +99,7 @@ defmodule SomethingErlangWeb do
|
||||
import SomethingErlangWeb.ErrorHelpers
|
||||
import SomethingErlangWeb.Gettext
|
||||
alias SomethingErlangWeb.Router.Helpers, as: Routes
|
||||
alias SomethingErlangWeb.Icons
|
||||
end
|
||||
end
|
||||
|
||||
|
37
lib/something_erlang_web/icons.ex
Normal file
37
lib/something_erlang_web/icons.ex
Normal file
@ -0,0 +1,37 @@
|
||||
defmodule SomethingErlangWeb.Icons do
|
||||
import Phoenix.LiveView.Helpers
|
||||
|
||||
@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("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
|
||||
# remove trailing semicolon
|
||||
sslice = String.slice(rest, 0..-3//1)
|
||||
# quote object keys
|
||||
quote_keys = Regex.replace(~r/([\w_]+):/, sslice, "\"\\1\":")
|
||||
# remove trailing commas
|
||||
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)
|
||||
|
||||
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 %>
|
||||
</i>
|
||||
"""
|
||||
end
|
||||
end
|
||||
end
|
@ -2,7 +2,6 @@ defmodule SomethingErlangWeb.ThreadLive.Show do
|
||||
use SomethingErlangWeb, :live_view
|
||||
on_mount SomethingErlangWeb.UserLiveAuth
|
||||
|
||||
alias SomethingErlang.Forums
|
||||
alias SomethingErlang.Grover
|
||||
|
||||
require Logger
|
||||
@ -60,11 +59,11 @@ defmodule SomethingErlangWeb.ThreadLive.Show do
|
||||
next_button_target = if page_number < page_count, do: page_number + 1, else: page_count
|
||||
|
||||
buttons = [
|
||||
%{label: "«", page: 1, special: first_page_disabled_button},
|
||||
%{label: "‹", page: prev_button_target, special: first_page_disabled_button},
|
||||
%{label: "«", page: 1, special: " btn-square" <> first_page_disabled_button},
|
||||
%{label: "‹", page: prev_button_target, special: " btn-square" <> first_page_disabled_button},
|
||||
%{label: "#{page_number}", page: page_number, special: active_page_button},
|
||||
%{label: "›", page: next_button_target, special: last_page_disabled_button},
|
||||
%{label: "»", page: page_count, special: last_page_disabled_button}
|
||||
%{label: "›", page: next_button_target, special: " btn-square" <> last_page_disabled_button},
|
||||
%{label: "»", page: page_count, special: " btn-square" <> last_page_disabled_button}
|
||||
]
|
||||
|
||||
~H"""
|
||||
@ -72,8 +71,16 @@ defmodule SomethingErlangWeb.ThreadLive.Show do
|
||||
<div class="flex-1"></div>
|
||||
<div class="flex-none btn-group">
|
||||
<%= for btn <- buttons do %>
|
||||
<%= live_redirect btn.label, class: "btn btn-sm" <> btn.special,
|
||||
to: Routes.thread_show_path(@socket, :show, @thread.id, page: btn.page) %>
|
||||
<%= live_redirect class: "btn btn-sm" <> btn.special,
|
||||
to: Routes.thread_show_path(@socket, :show, @thread.id, page: btn.page) do %>
|
||||
<%= case btn.label do %>
|
||||
<% "«" -> %><Icons.chevron_left_double />
|
||||
<% "‹" -> %><Icons.chevron_left />
|
||||
<% "›" -> %><Icons.chevron_right />
|
||||
<% "»" -> %><Icons.chevron_right_double />
|
||||
<% _ -> %><%= btn.label %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,10 +1,13 @@
|
||||
<div class="user-box">
|
||||
<%= if @current_user do %>
|
||||
<h4 class="w-full"><%= @current_user.email %></h4>
|
||||
<%= link "Settings", class: "link",
|
||||
to: Routes.user_settings_path(@conn, :edit) %>
|
||||
<%= button "Log out", class: "btn btn-sm",
|
||||
to: Routes.user_session_path(@conn, :delete), method: :delete %>
|
||||
<div class="user-box flex gap-2">
|
||||
<%= if @current_user do %>
|
||||
<h4 class=""><%= @current_user.email %></h4>
|
||||
<div class="tooltip tooltip-bottom" data-tip="Settings">
|
||||
<%= button class: "btn btn-square btn-outline btn-sm", to: Routes.user_settings_path(@conn, :edit), method: :get do %>
|
||||
<Icons.settings />
|
||||
<% end %>
|
||||
</div>
|
||||
<%= button "Log out", class: "btn btn-outline btn-sm",
|
||||
to: Routes.user_session_path(@conn, :delete), method: :delete %>
|
||||
<% else %>
|
||||
<%= link "Register", class: "link",
|
||||
to: Routes.user_registration_path(@conn, :new) %>
|
||||
|
@ -13,20 +13,24 @@
|
||||
src={Routes.static_path(@conn, "/assets/app.js")}></script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav>
|
||||
<div class="navbar">
|
||||
<div class="navbar-start"></div>
|
||||
<div class="navbar-end">
|
||||
<%= if function_exported?(Routes, :live_dashboard_path, 2) do %>
|
||||
<%= link "LiveDashboard",
|
||||
to: Routes.live_dashboard_path(@conn, :home) %>
|
||||
<% end %>
|
||||
<%= render "_user_menu.html", assigns %>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<%= @inner_content %>
|
||||
<header>
|
||||
<nav>
|
||||
<div class="navbar">
|
||||
<div class="flex-1">
|
||||
<%= if function_exported?(Routes, :live_dashboard_path, 2) do %>
|
||||
<%= link "LiveDashboard",
|
||||
to: Routes.live_dashboard_path(@conn, :home) %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="flex-none">
|
||||
<%= render "_user_menu.html", assigns %>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<%= @inner_content %>
|
||||
<footer class="footer p-10 bg-neutral text-neutral-content">
|
||||
<div class="flex flex-1"><Icons.heart /> 2022</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user