2021-07-07 20:32:49 +08:00
|
|
|
defmodule LivebookWeb.SidebarHelpers do
|
|
|
|
use Phoenix.Component
|
|
|
|
|
|
|
|
import LivebookWeb.Helpers
|
|
|
|
import LivebookWeb.UserHelpers
|
|
|
|
|
|
|
|
alias LivebookWeb.Router.Helpers, as: Routes
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Renders sidebar container.
|
|
|
|
|
|
|
|
Other functions in this module render sidebar
|
|
|
|
items of various type.
|
|
|
|
"""
|
|
|
|
def sidebar(assigns) do
|
|
|
|
~H"""
|
2022-01-13 19:22:34 +08:00
|
|
|
<nav class="w-16 flex flex-col items-center space-y-4 px-3 py-7 bg-gray-900">
|
2021-11-02 02:33:43 +08:00
|
|
|
<%= render_slot(@inner_block) %>
|
2021-11-17 04:57:10 +08:00
|
|
|
</nav>
|
2021-07-07 20:32:49 +08:00
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
def logo_item(assigns) do
|
|
|
|
~H"""
|
|
|
|
<span>
|
2021-11-02 01:20:56 +08:00
|
|
|
<%= live_patch to: Routes.home_path(@socket, :page), aria_label: "go to homepage" do %>
|
|
|
|
<img src="/images/logo.png" height="40" width="40" alt="" />
|
2021-07-07 20:32:49 +08:00
|
|
|
<% end %>
|
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
def button_item(assigns) do
|
|
|
|
~H"""
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip right distant" data-tooltip={@label}>
|
2021-07-07 20:32:49 +08:00
|
|
|
<button class="text-2xl text-gray-400 hover:text-gray-50 focus:text-gray-50 rounded-xl h-10 w-10 flex items-center justify-center"
|
2021-11-02 01:20:56 +08:00
|
|
|
aria-label={@label}
|
2021-07-07 20:32:49 +08:00
|
|
|
data-element={@data_element}>
|
|
|
|
<.remix_icon icon={@icon} />
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
def link_item(assigns) do
|
|
|
|
~H"""
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip right distant" data-tooltip={@label}>
|
2021-07-07 20:32:49 +08:00
|
|
|
<%= live_patch to: @path,
|
2021-11-02 01:20:56 +08:00
|
|
|
class: "text-gray-400 hover:text-gray-50 focus:text-gray-50 rounded-xl h-10 w-10 flex items-center justify-center #{if(@active, do: "text-gray-50 bg-gray-700")}",
|
|
|
|
aria_label: @label do %>
|
2021-07-07 20:32:49 +08:00
|
|
|
<.remix_icon icon={@icon} class="text-2xl" />
|
|
|
|
<% end %>
|
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2022-01-13 19:22:34 +08:00
|
|
|
def shutdown_item(assigns) do
|
|
|
|
if :code.get_mode() == :interactive do
|
|
|
|
~H"""
|
|
|
|
<span class="tooltip right distant" data-tooltip="Shutdown">
|
|
|
|
<button class="text-2xl text-gray-400 hover:text-gray-50 focus:text-gray-50 rounded-xl h-10 w-10 flex items-center justify-center"
|
|
|
|
aria-label="shutdown"
|
|
|
|
phx-click="shutdown"
|
|
|
|
data-confirm="Are you sure you want to shutdown Livebook?">
|
|
|
|
<.remix_icon icon="shut-down-line" />
|
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
else
|
|
|
|
~H"""
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-07 20:32:49 +08:00
|
|
|
def break_item(assigns) do
|
|
|
|
~H"""
|
2021-12-30 05:06:19 +08:00
|
|
|
<div class="grow"></div>
|
2021-07-07 20:32:49 +08:00
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_item(assigns) do
|
|
|
|
~H"""
|
2021-11-02 01:20:56 +08:00
|
|
|
<span class="tooltip right distant" data-tooltip="User profile">
|
|
|
|
<%= live_patch to: @path,
|
2022-01-13 19:22:34 +08:00
|
|
|
class: "text-gray-400 rounded-xl h-8 w-8 flex items-center justify-center mt-2",
|
2021-11-02 01:20:56 +08:00
|
|
|
aria_label: "user profile" do %>
|
2021-07-07 20:32:49 +08:00
|
|
|
<.user_avatar user={@current_user} text_class="text-xs" />
|
|
|
|
<% end %>
|
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
end
|
2022-01-13 19:22:34 +08:00
|
|
|
|
|
|
|
## Shared home functionality
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
A footer shared across home, settings, explore, etc.
|
|
|
|
|
|
|
|
Note you must call `shared_home_handlers` on mount/3.
|
|
|
|
"""
|
|
|
|
def shared_home_footer(assigns) do
|
|
|
|
~H"""
|
|
|
|
<.break_item />
|
|
|
|
<.shutdown_item />
|
|
|
|
<.link_item
|
|
|
|
icon="settings-3-fill"
|
|
|
|
label="Settings"
|
|
|
|
path={Routes.settings_path(@socket, :page)}
|
|
|
|
active={false} />
|
|
|
|
<.user_item current_user={@current_user} path={@user_path} />
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
def shared_home_handlers(socket) do
|
|
|
|
attach_hook(socket, :shutdown, :handle_event, fn
|
|
|
|
"shutdown", _params, socket ->
|
|
|
|
System.stop()
|
|
|
|
{:halt, put_flash(socket, :info, "Livebook is shutting down. You can close this page.")}
|
|
|
|
|
|
|
|
_event, _params, socket ->
|
|
|
|
{:cont, socket}
|
|
|
|
end)
|
|
|
|
end
|
2021-07-07 20:32:49 +08:00
|
|
|
end
|