Skip to content

Commit 65232a8

Browse files
committed
handle drawer events in preview nav
1 parent 685078a commit 65232a8

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

lib/algora_web/live/org/preview_nav.ex

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ defmodule AlgoraWeb.Org.PreviewNav do
3131
|> assign(:current_user_role, :admin)
3232
|> assign(:nav, nav_items(repo_owner, repo_name))
3333
|> assign(:contacts, [])
34-
|> attach_hook(:active_tab, :handle_params, &handle_active_tab_params/3)}
34+
|> attach_hook(:active_tab, :handle_params, &handle_active_tab_params/3)
35+
|> attach_hook(:handle_event, :handle_event, &handle_event/3)}
3536

3637
{:error, reason} ->
3738
Logger.error("Failed to restore preview state for #{repo_owner}/#{repo_name}: #{inspect(reason)}")
@@ -53,6 +54,7 @@ defmodule AlgoraWeb.Org.PreviewNav do
5354
|> assign(:nav, nav_items(repo_owner, repo_name))
5455
|> assign(:contacts, [])
5556
|> attach_hook(:active_tab, :handle_params, &handle_active_tab_params/3)
57+
|> attach_hook(:handle_event, :handle_event, &handle_event/3)
5658

5759
# checking if the socket is connected to avoid redirect loop that prevents og image from being fetched
5860
if (current_context && current_context.last_context == "repo/#{repo_owner}/#{repo_name}") ||
@@ -97,6 +99,34 @@ defmodule AlgoraWeb.Org.PreviewNav do
9799
end
98100
end
99101

102+
defp handle_event("create_contract_main", %{"contract_form" => _params}, socket) do
103+
{:cont, put_flash(socket, :warning, "Please sign in to create your contract")}
104+
end
105+
106+
defp handle_event("create_bounty_main", %{"bounty_form" => _params}, socket) do
107+
{:cont, put_flash(socket, :warning, "Please sign in to create your bounty")}
108+
end
109+
110+
defp handle_event("open_main_bounty_form", _params, socket) do
111+
{:cont, assign(socket, :main_bounty_form_open?, true)}
112+
end
113+
114+
defp handle_event("close_main_bounty_form", _params, socket) do
115+
{:cont, assign(socket, :main_bounty_form_open?, false)}
116+
end
117+
118+
defp handle_event("open_main_contract_form", _params, socket) do
119+
{:cont, assign(socket, :main_contract_form_open?, true)}
120+
end
121+
122+
defp handle_event("close_main_contract_form", _params, socket) do
123+
{:cont, assign(socket, :main_contract_form_open?, false)}
124+
end
125+
126+
defp handle_event(_event, _params, socket) do
127+
{:cont, socket}
128+
end
129+
100130
defp handle_active_tab_params(_params, _url, socket) do
101131
active_tab =
102132
case {socket.view, socket.assigns.live_action} do

0 commit comments

Comments
 (0)