Skip to content

Commit e6247cf

Browse files
committed
Update view templates
The variable tracking the side panel navigation headings has been renamed, to more accurately reflect what it represents. We now show a basic title or heading on each page in each of the main categories. Lastly, the 'Tutorial' and 'Examples' categories have been disabled as adding pages to those categories requires more work, which will not be done unless future discussions confirm this Phoenix app as the right approach.
1 parent 7699e51 commit e6247cf

File tree

9 files changed

+35
-31
lines changed

9 files changed

+35
-31
lines changed

etc/docs/lib/docs_web/live/page_live/components/content_component.ex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ defmodule DocsWeb.PageLive.ContentComponent do
22
use DocsWeb, :live_component
33

44
@impl true
5-
def update(%{content: content, active_tab: active_tab}, socket) do
6-
{:ok, assign(socket, content: content, active_tab: active_tab)}
5+
def update(%{content: content, active_tab: active_tab, active_page: active_page}, socket) do
6+
{:ok, assign(socket, content: content, active_tab: active_tab, active_page: active_page)}
77
end
88

99
@impl true
1010
def render(assigns) when assigns.active_tab == :fx or assigns.active_tab == :synths do
11-
#test = Map.take(assigns.content, [:doc])
1211
Phoenix.View.render(DocsWeb.PageView, "components/synths_or_fx_component.html", assigns)
1312
end
1413

15-
# TODO: Store active_page per tab? this would allow us to check whether a page has been chosen on each tab,
16-
# and if not, render a default. (Also to render the last active page per tab when switching between them).
17-
@impl true
18-
def render(assigns) when assigns.active_tab == nil do
19-
Phoenix.View.render(DocsWeb.PageView, "components/welcome_component.html", %{})
14+
def render(assigns) when assigns.active_tab == :samples do
15+
Phoenix.View.render(DocsWeb.PageView, "components/samples_component.html", assigns)
16+
end
17+
18+
def render(assigns) when assigns.active_tab == :lang do
19+
Phoenix.View.render(DocsWeb.PageView, "components/lang_component.html", assigns)
2020
end
2121
end

etc/docs/lib/docs_web/live/page_live/components/side_nav_component.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ defmodule DocsWeb.PageLive.SideNavComponent do
99
end
1010

1111
@impl true
12-
def update(%{active_page: active_page, active_tab: active_tab, active_pages: active_pages, page_titles: page_titles}, socket) do
12+
def update(%{active_page: active_page, active_tab: active_tab, active_pages: active_pages, page_keys: page_keys}, socket) do
1313
case active_tab do
14-
nil -> {:ok, assign(socket, active_pages: active_pages, page_titles: page_titles)}
15-
_ -> {:ok, assign(socket, active_page: active_page, active_pages: %{active_pages | active_tab => active_page}, page_titles: page_titles)}
14+
nil -> {:ok, assign(socket, active_pages: active_pages, page_keys: page_keys)}
15+
_ -> {:ok, assign(socket, active_page: active_page, active_pages: %{active_pages | active_tab => active_page}, page_keys: page_keys)}
1616
end
1717
end
1818
end

etc/docs/lib/docs_web/live/page_live/page_live.ex

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ defmodule DocsWeb.PageLive do
66
@impl true
77
def mount(_params, %{"metadata" => metadata}, socket) do
88
metadata = Enum.reject(metadata, fn {k, _v} -> k == :_build end)
9-
page_titles = Enum.into(metadata, %{}, fn {k, v} -> {k, Enum.flat_map(v, fn x -> Map.keys(x) end)} end)
9+
page_keys = Enum.into(metadata, %{}, fn {k, v} -> {k, Enum.flat_map(v, fn x -> Map.keys(x) end)} end)
1010
active_pages = Enum.into(metadata, %{}, fn {k, v} -> {k, hd(Enum.flat_map(v, fn x -> Map.keys(x) end))} end)
11-
{:ok, assign(socket, metadata: metadata, active_tab: :fx, active_page: :bitcrusher, active_pages: active_pages, page_titles: page_titles[:fx], content: nil)}
11+
content = Enum.find(metadata[:synths], fn p -> Enum.member?(Map.keys(p), :dull_bell) end)
12+
%{dull_bell: data} = content
13+
{:ok, assign(socket, metadata: metadata, active_tab: :synths, active_page: :dull_bell, active_pages: active_pages, page_keys: page_keys[:synths], content: data)}
1214
end
1315

1416
@impl true
@@ -19,21 +21,21 @@ defmodule DocsWeb.PageLive do
1921
@impl true
2022
def handle_event("change_tab", %{"active_tab" => active_tab}, socket) do
2123
active_tab = String.to_atom(active_tab)
22-
page_titles = socket.assigns.metadata[active_tab]
23-
|> Enum.flat_map(&Map.keys/1)
24-
|> Enum.uniq
25-
26-
{:noreply, assign(socket, active_tab: active_tab, active_pages: socket.assigns.active_pages, page_titles: page_titles)}
24+
page_keys = Enum.into(socket.assigns.metadata, %{}, fn {k, v} -> {k, Enum.flat_map(v, fn x -> Map.keys(x) end)} end)[active_tab]
25+
active_page = socket.assigns.active_pages[active_tab]
26+
pages = socket.assigns.metadata[active_tab]
27+
content = Enum.find(pages, fn p -> Enum.member?(Map.keys(p), active_page) end)
28+
%{^active_page => data} = content
29+
{:noreply, assign(socket, active_tab: active_tab, active_pages: socket.assigns.active_pages, page_keys: page_keys, content: data)}
2730
end
2831

2932
@impl true
3033
def handle_event("change_page", %{"active_page" => active_page}, socket) do
3134
active_tab = socket.assigns.active_tab
3235
pages = socket.assigns.metadata[active_tab]
33-
page = String.to_atom(active_page)
34-
content = Enum.find(pages, fn p -> Enum.member?(Map.keys(p), page) end)
35-
%{^page => data} = content
36-
{:noreply, assign(socket, active_pages: %{socket.assigns.active_pages | active_tab => page}, content: data)}
36+
active_page = String.to_atom(active_page)
37+
content = Enum.find(pages, fn p -> Enum.member?(Map.keys(p), active_page) end)
38+
%{^active_page => data} = content
39+
{:noreply, assign(socket, active_pages: %{socket.assigns.active_pages | active_tab => active_page}, content: data)}
3740
end
38-
3941
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<h1><%= inspect(@content) %></h1>
1+
<h1><%= @content[:summary] %></h1>

etc/docs/lib/docs_web/templates/page/components/navbar_component.html.heex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
<ul class="nav nav-pills justify-content-center">
22
<li class="nav-item">
33
<button
4-
class={is_active(@active_tab, :tutorial)}
4+
class={["disabled", is_active(@active_tab, :tutorial)]}
55
phx-click="change_tab"
66
phx-value-active_tab={:tutorial}
77
aria-current="page"
8+
disabled
89
>
910
Tutorial
1011
</button>
1112
</li>
1213
<li class="nav-item">
1314
<button
14-
class={is_active(@active_tab, :examples)}
15+
class={["disabled", is_active(@active_tab, :examples)]}
1516
phx-click="change_tab"
1617
phx-value-active_tab={:examples}
18+
disabled
1719
>
1820
Examples
1921
</button>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<h1><%= inspect(@content) %></h1>
1+
<h1><%= String.capitalize(Atom.to_string(@active_page)) %> sounds</h1>

etc/docs/lib/docs_web/templates/page/components/side_nav_component.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ul class="nav nav-pills flex-column">
2-
<%= for title <- @page_titles do %>
2+
<%= for title <- @page_keys do %>
33
<li class="nav-item">
44
<button
55
class={is_active(@active_page, title)}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<h1><%= inspect(@content) %></h1>
1+
<h1><%= @content.name %></h1>

etc/docs/lib/docs_web/templates/page/page.html.heex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<div class="container-fluid">
33
<div class="row">
44
<div class="col-2">
5-
<%= live_component(@socket, DocsWeb.PageLive.SideNavComponent, active_tab: @active_tab, active_pages: @active_pages, active_page: @active_pages[@active_tab], page_titles: @page_titles) %>
5+
<%= live_component(@socket, DocsWeb.PageLive.SideNavComponent, active_tab: @active_tab, active_pages: @active_pages, active_page: @active_pages[@active_tab], page_keys: @page_keys) %>
66
</div>
77
<div class="col-10">
8-
<%= live_component(@socket, DocsWeb.PageLive.ContentComponent, active_tab: @active_tab, content: @content) %>
8+
<%= live_component(@socket, DocsWeb.PageLive.ContentComponent, active_tab: @active_tab, active_page: @active_pages[@active_tab], content: @content) %>
99
</div>
1010
</div>
1111
</div>

0 commit comments

Comments
 (0)