mirror of
https://github.com/ash-project/ash_hq.git
synced 2024-09-19 12:53:49 +12:00
WIP
This commit is contained in:
parent
877e960bce
commit
0dba60de36
7 changed files with 103 additions and 26 deletions
|
@ -163,6 +163,12 @@ window.addEventListener("phx:js:scroll-to", (e) => {
|
|||
});
|
||||
});
|
||||
|
||||
window.addEventListener("phx:sidebar-state", (e) => {
|
||||
const cookie = Object.keys(e.detail).map((key) => `${key}:${e.detail[key]}`).join(',');
|
||||
document.cookie = 'sidebar_state' + '=' + cookie + ';path=/';
|
||||
})
|
||||
|
||||
|
||||
let scrolled = false;
|
||||
|
||||
window.addEventListener("phx:page-loading-start", () => {
|
||||
|
|
|
@ -5,10 +5,18 @@ defmodule AshHq.Docs.Importer do
|
|||
|
||||
alias AshHq.Docs.LibraryVersion
|
||||
require Logger
|
||||
require Ash.Query
|
||||
|
||||
def import(only \\ nil) do
|
||||
query =
|
||||
if only do
|
||||
AshHq.Docs.Library |> Ash.Query.filter(name in ^only)
|
||||
else
|
||||
AshHq.Docs.Library
|
||||
end
|
||||
|
||||
def import() do
|
||||
for %{name: name, latest_version: latest_version} = library <-
|
||||
AshHq.Docs.Library.read!(load: :latest_version) do
|
||||
AshHq.Docs.Library.read!(load: :latest_version, query: query) do
|
||||
latest_version =
|
||||
if latest_version do
|
||||
Version.parse!(latest_version)
|
||||
|
|
|
@ -14,6 +14,9 @@ defmodule AshHqWeb.Components.DocSidebar do
|
|||
prop id, :string, required: true
|
||||
prop dsl, :any, required: true
|
||||
prop module, :any, required: true
|
||||
prop sidebar_state, :map, required: true
|
||||
prop collapse_sidebar, :event, required: true
|
||||
prop expand_sidebar, :event, required: true
|
||||
|
||||
def render(assigns) do
|
||||
~F"""
|
||||
|
@ -115,10 +118,16 @@ defmodule AshHqWeb.Components.DocSidebar do
|
|||
<li class="border-l pl-1 border-orange-600 border-opacity-30">
|
||||
<div class="flex flex-row items-center">
|
||||
{#if Enum.any?(dsls, &(List.starts_with?(&1.path, dsl.path ++ [dsl.name])))}
|
||||
{#if @dsl && List.starts_with?(@dsl.path ++ [@dsl.name], path ++ [dsl.name])}
|
||||
<Heroicons.Outline.ChevronDownIcon class="w-3 h-3"/>
|
||||
{#else}
|
||||
<Heroicons.Outline.ChevronRightIcon class="w-3 h-3"/>
|
||||
{#if !(@dsl && List.starts_with?(@dsl.path ++ [@dsl.name], path ++ [dsl.name]))}
|
||||
{#if @sidebar_state[dsl.id] == "open"}
|
||||
<button :on-click={@collapse_sidebar} phx-value-id={dsl.id}>
|
||||
<Heroicons.Outline.ChevronDownIcon class="w-3 h-3"/>
|
||||
</button>
|
||||
{#else}
|
||||
<button :on-click={@expand_sidebar} phx-value-id={dsl.id}>
|
||||
<Heroicons.Outline.ChevronRightIcon class="w-3 h-3"/>
|
||||
</button>
|
||||
{/if}
|
||||
{/if}
|
||||
{/if}
|
||||
<LivePatch
|
||||
|
@ -131,7 +140,7 @@ defmodule AshHqWeb.Components.DocSidebar do
|
|||
{dsl.name}
|
||||
</LivePatch>
|
||||
</div>
|
||||
{#if @dsl && List.starts_with?(@dsl.path ++ [@dsl.name], path ++ [dsl.name])}
|
||||
{#if @sidebar_state[dsl.id] == "open" || (@dsl && List.starts_with?(@dsl.path ++ [@dsl.name], path ++ [dsl.name]))}
|
||||
{render_dsls(assigns, dsls, path ++ [dsl.name])}
|
||||
{/if}
|
||||
</li>
|
||||
|
|
|
@ -5,22 +5,25 @@ defmodule AshHqWeb.Pages.Docs do
|
|||
alias AshHqWeb.Components.{CalloutText, DocSidebar, RightNav, Tag}
|
||||
alias AshHqWeb.Routes
|
||||
|
||||
prop(params, :map, required: true)
|
||||
prop(change_versions, :event, required: true)
|
||||
prop(selected_versions, :map, required: true)
|
||||
prop(libraries, :list, default: [])
|
||||
prop(uri, :string)
|
||||
prop params, :map, required: true
|
||||
prop change_versions, :event, required: true
|
||||
prop selected_versions, :map, required: true
|
||||
prop libraries, :list, default: []
|
||||
prop uri, :string
|
||||
prop sidebar_state, :map, required: true
|
||||
prop collapse_sidebar, :event, required: true
|
||||
prop expand_sidebar, :event, required: true
|
||||
|
||||
data(library, :any)
|
||||
data(extension, :any)
|
||||
data(docs, :any)
|
||||
data(library_version, :any)
|
||||
data(guide, :any)
|
||||
data(doc_path, :list, default: [])
|
||||
data(dsls, :list, default: [])
|
||||
data(dsl, :any)
|
||||
data(options, :list, default: [])
|
||||
data(module, :any)
|
||||
data library, :any
|
||||
data extension, :any
|
||||
data docs, :any
|
||||
data library_version, :any
|
||||
data guide, :any
|
||||
data doc_path, :list, default: []
|
||||
data dsls, :list, default: []
|
||||
data dsl, :any
|
||||
data options, :list, default: []
|
||||
data module, :any
|
||||
|
||||
@spec render(any) :: Phoenix.LiveView.Rendered.t()
|
||||
def render(assigns) do
|
||||
|
@ -57,6 +60,9 @@ defmodule AshHqWeb.Pages.Docs do
|
|||
id="mobile-sidebar"
|
||||
libraries={@libraries}
|
||||
extension={@extension}
|
||||
sidebar_state={@sidebar_state}
|
||||
collapse_sidebar={@collapse_sidebar}
|
||||
expand_sidebar={@expand_sidebar}
|
||||
module={@module}
|
||||
guide={@guide}
|
||||
library={@library}
|
||||
|
@ -73,6 +79,9 @@ defmodule AshHqWeb.Pages.Docs do
|
|||
module={@module}
|
||||
libraries={@libraries}
|
||||
extension={@extension}
|
||||
sidebar_state={@sidebar_state}
|
||||
collapse_sidebar={@collapse_sidebar}
|
||||
expand_sidebar={@expand_sidebar}
|
||||
guide={@guide}
|
||||
library={@library}
|
||||
library_version={@library_version}
|
||||
|
@ -227,8 +236,14 @@ defmodule AshHqWeb.Pages.Docs do
|
|||
end
|
||||
)
|
||||
|
||||
assign(
|
||||
socket,
|
||||
new_state = Map.put(socket.assigns.sidebar_state, dsl.id, "open")
|
||||
|
||||
unless socket.assigns.sidebar_state[dsl.id] == "open" do
|
||||
send(self(), {:new_sidebar_state, new_state})
|
||||
end
|
||||
|
||||
socket
|
||||
|> assign(
|
||||
:dsl,
|
||||
dsl
|
||||
)
|
||||
|
|
|
@ -5,6 +5,7 @@ defmodule AshHqWeb.SessionPlug do
|
|||
@cookies_to_replicate [
|
||||
"theme",
|
||||
"selected_versions",
|
||||
"sidebar_state",
|
||||
"selected_types"
|
||||
]
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ defmodule AshHqWeb.AppViewLive do
|
|||
data selected_versions, :map, default: %{}
|
||||
data libraries, :list, default: []
|
||||
data selected_types, :map, default: %{}
|
||||
data sidebar_state, :map, default: %{}
|
||||
|
||||
def render(assigns) do
|
||||
~F"""
|
||||
|
@ -78,6 +79,9 @@ defmodule AshHqWeb.AppViewLive do
|
|||
id="docs"
|
||||
params={@params}
|
||||
uri={@uri}
|
||||
collapse_sidebar="collapse_sidebar"
|
||||
expand_sidebar="expand_sidebar"
|
||||
sidebar_state={@sidebar_state}
|
||||
change_versions="change-versions"
|
||||
selected_versions={@selected_versions}
|
||||
libraries={@libraries}
|
||||
|
@ -92,6 +96,20 @@ defmodule AshHqWeb.AppViewLive do
|
|||
{:noreply, assign(socket, params: params, uri: uri)}
|
||||
end
|
||||
|
||||
def handle_event("collapse_sidebar", %{"id" => id}, socket) do
|
||||
new_state = Map.put(socket.assigns.sidebar_state, id, "closed")
|
||||
|
||||
{:noreply,
|
||||
socket |> assign(:sidebar_state, new_state) |> push_event("js:sidebar-state", new_state)}
|
||||
end
|
||||
|
||||
def handle_event("expand_sidebar", %{"id" => id}, socket) do
|
||||
new_state = Map.put(socket.assigns.sidebar_state, id, "open")
|
||||
|
||||
{:noreply,
|
||||
socket |> assign(:sidebar_state, new_state) |> push_event("sidebar-state", new_state)}
|
||||
end
|
||||
|
||||
def handle_event("change-versions", %{"versions" => versions}, socket) do
|
||||
{:noreply,
|
||||
socket
|
||||
|
@ -133,6 +151,11 @@ defmodule AshHqWeb.AppViewLive do
|
|||
|> push_event("set_theme", %{theme: theme})}
|
||||
end
|
||||
|
||||
def handle_info({:new_sidebar_state, new_state}, socket) do
|
||||
{:noreply,
|
||||
socket |> assign(:sidebar_state, new_state) |> push_event("sidebar-state", new_state)}
|
||||
end
|
||||
|
||||
defp load_docs(socket) do
|
||||
new_libraries =
|
||||
socket.assigns.libraries
|
||||
|
@ -203,6 +226,21 @@ defmodule AshHqWeb.AppViewLive do
|
|||
|> Enum.filter(&(&1 in all_types))
|
||||
end
|
||||
|
||||
sidebar_state =
|
||||
case session["sidebar_state"] do
|
||||
nil ->
|
||||
%{}
|
||||
|
||||
value ->
|
||||
value
|
||||
|> String.split(",")
|
||||
|> Map.new(fn str ->
|
||||
str
|
||||
|> String.split(":")
|
||||
|> List.to_tuple()
|
||||
end)
|
||||
end
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> assign(:selected_versions, configured_library_versions)
|
||||
|
@ -244,7 +282,7 @@ defmodule AshHqWeb.AppViewLive do
|
|||
)
|
||||
|> load_docs()
|
||||
|
||||
{:ok, assign(socket, configured_theme: configured_theme)}
|
||||
{:ok, assign(socket, configured_theme: configured_theme, sidebar_state: sidebar_state)}
|
||||
end
|
||||
|
||||
def toggle_search(js \\ %JS{}) do
|
||||
|
|
|
@ -108,7 +108,7 @@ defmodule Utils do
|
|||
_ -> "No Documentation"
|
||||
end
|
||||
|
||||
def build_function({{type, name, arity}, _, heads, %{"en" => docs}, _}, order) do
|
||||
def build_function({{type, name, arity}, _, heads, %{"en" => docs}, _}, order) when not(is_nil(type)) and not(is_nil(name)) and not(is_nil(arity)) do
|
||||
[%{
|
||||
name: to_string(name),
|
||||
type: type,
|
||||
|
|
Loading…
Reference in a new issue