Skip to content

Commit

Permalink
[BUG FIX] [NG23-206] user enables disables notes
Browse files Browse the repository at this point in the history
[BUG FIX] [NG23-206] user enables disables notes
  • Loading branch information
darrensiegel authored Jun 28, 2024
2 parents 817433f + f35b78f commit 12a4e82
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 15 deletions.
15 changes: 14 additions & 1 deletion lib/oli_web/components/delivery/layouts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ defmodule OliWeb.Components.Delivery.Layouts do
attr(:section, Section, default: nil)
attr(:active_tab, :atom)
attr(:sidebar_expanded, :boolean, default: true)
attr(:notes_enabled, :boolean, default: false)
attr(:discussions_enabled, :boolean, default: false)
attr(:preview_mode, :boolean)
attr :notification_badges, :map, default: %{}

Expand Down Expand Up @@ -147,6 +149,8 @@ defmodule OliWeb.Components.Delivery.Layouts do
section={@section}
preview_mode={@preview_mode}
sidebar_expanded={@sidebar_expanded}
notes_enabled={@notes_enabled}
discussions_enabled={@discussions_enabled}
notification_badges={@notification_badges}
/>
</div>
Expand All @@ -171,7 +175,13 @@ defmodule OliWeb.Components.Delivery.Layouts do
"
phx-click-away={JS.hide()}
>
<.sidebar_links active_tab={@active_tab} section={@section} preview_mode={@preview_mode} />
<.sidebar_links
active_tab={@active_tab}
section={@section}
preview_mode={@preview_mode}
notes_enabled={@notes_enabled}
discussions_enabled={@discussions_enabled}
/>
<div class="px-4 py-2 flex flex-row align-center justify-between border-t border-gray-300 dark:border-gray-800">
<div class="flex items-center">
<.tech_support_button id="mobile-tech-support" ctx={@ctx} />
Expand Down Expand Up @@ -214,6 +224,8 @@ defmodule OliWeb.Components.Delivery.Layouts do
attr(:active_tab, :atom)
attr(:preview_mode, :boolean)
attr(:sidebar_expanded, :boolean, default: true)
attr(:notes_enabled, :boolean, default: true)
attr(:discussions_enabled, :boolean, default: true)
attr(:notification_badges, :map, default: %{})

def sidebar_links(assigns) do
Expand Down Expand Up @@ -250,6 +262,7 @@ defmodule OliWeb.Components.Delivery.Layouts do
</.nav_link>
<.nav_link
:if={@notes_enabled || @discussions_enabled}
id="discussions_nav_link"
href={path_for(:discussions, @section, @preview_mode, @sidebar_expanded)}
is_active={@active_tab == :discussions}
Expand Down
2 changes: 2 additions & 0 deletions lib/oli_web/components/layouts/student_delivery.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
preview_mode={@preview_mode}
notification_badges={assigns[:notification_badges] || %{}}
sidebar_expanded={@sidebar_expanded}
notes_enabled={@notes_enabled}
discussions_enabled={@discussions_enabled}
/>
<div class={[
"md:w-[calc(100%-190px)] flex-1 flex flex-col md:ml-[190px] mt-14 relative",
Expand Down
26 changes: 14 additions & 12 deletions lib/oli_web/live/delivery/student/discussions_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ defmodule OliWeb.Delivery.Student.DiscussionsLive do
course_collab_space_config =
Collaboration.get_course_collab_space_config(section.root_section_resource_id)

course_discussions_enabled? =
case course_collab_space_config do
%Collaboration.CollabSpaceConfig{status: :enabled} -> true
_ -> false
end

default_posts_params =
case socket.assigns[:has_unread_discussions] do
true -> Map.merge(@default_params, %{sort_by: "unread", sort_order: :desc})
Expand All @@ -77,7 +71,7 @@ defmodule OliWeb.Delivery.Student.DiscussionsLive do
assign(socket,
is_instructor: is_instructor,
active_tab: :discussions,
active_sub_tab: :notes,
active_sub_tab: if(socket.assigns.notes_enabled, do: :notes, else: :discussions),
posts: posts,
notes: notes,
expanded_posts: %{},
Expand All @@ -87,7 +81,6 @@ defmodule OliWeb.Delivery.Student.DiscussionsLive do
more_posts_exist?: more_posts_exist?,
more_notes_exist?: more_notes_exist?,
root_curriculum_resource_id: root_curriculum_resource_id,
course_discussions_enabled?: course_discussions_enabled?,
posts_search_term: "",
posts_search_results: nil,
notes_search_term: "",
Expand All @@ -97,6 +90,10 @@ defmodule OliWeb.Delivery.Student.DiscussionsLive do
}
end

def handle_params(_params, _uri, socket) do
{:noreply, socket}
end

def handle_event("sort_posts", %{"sort_by" => sort_by}, socket) do
updated_post_params =
Map.merge(socket.assigns.post_params, %{
Expand Down Expand Up @@ -545,9 +542,14 @@ defmodule OliWeb.Delivery.Student.DiscussionsLive do
class="overflow-x-scroll md:overflow-x-auto flex flex-col py-6 px-16 mb-10 gap-6 items-start"
>
<div class="flex gap-12">
<.tab :if={not @is_instructor} label="My Notes" value={:notes} active={@active_sub_tab} />
<.tab
:if={@course_discussions_enabled?}
:if={@notes_enabled && not @is_instructor}
label="My Notes"
value={:notes}
active={@active_sub_tab}
/>
<.tab
:if={@discussions_enabled}
label="Course Discussion"
value={:discussions}
active={@active_sub_tab}
Expand All @@ -557,7 +559,7 @@ defmodule OliWeb.Delivery.Student.DiscussionsLive do
<%= case @active_sub_tab do %>
<% :notes -> %>
<.notes_section
:if={not @is_instructor}
:if={@notes_enabled && not @is_instructor}
ctx={@ctx}
section_slug={@section.slug}
current_user={@current_user}
Expand All @@ -569,7 +571,7 @@ defmodule OliWeb.Delivery.Student.DiscussionsLive do
/>
<% :discussions -> %>
<.posts_section
:if={@course_discussions_enabled?}
:if={@discussions_enabled}
posts={@posts}
ctx={@ctx}
section_slug={@section.slug}
Expand Down
36 changes: 35 additions & 1 deletion lib/oli_web/live_session_plugs/set_sidebar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ defmodule OliWeb.LiveSessionPlugs.SetSidebar do
import Phoenix.Component, only: [assign: 2]
import Phoenix.LiveView, only: [attach_hook: 4, connected?: 1]

def on_mount(:default, _params, _session, socket) do
alias Oli.Resources.Collaboration.CollabSpaceConfig
alias Oli.Resources.Collaboration
alias Oli.Publishing.{DeliveryResolver}

def on_mount(:default, _params, session, socket) do
socket =
socket
|> assign_notes_and_discussions_enabled(session["section_slug"])

if connected?(socket) do
socket =
socket
Expand All @@ -26,4 +34,30 @@ defmodule OliWeb.LiveSessionPlugs.SetSidebar do
|> assign(sidebar_expanded: true)}
end
end

defp assign_notes_and_discussions_enabled(socket, nil),
do: assign(socket, notes_enabled: false, discussions_enabled: false)

defp assign_notes_and_discussions_enabled(socket, section_slug) do
{collab_space_pages_count, _pages_count} =
Collaboration.count_collab_spaces_enabled_in_pages_for_section(section_slug)

notes_enabled = collab_space_pages_count > 0

%{slug: revision_slug} = DeliveryResolver.root_container(section_slug)

discussions_enabled =
case Collaboration.get_collab_space_config_for_page_in_section(
revision_slug,
section_slug
) do
{:ok, %CollabSpaceConfig{status: :enabled}} ->
true

_ ->
false
end

assign(socket, notes_enabled: notes_enabled, discussions_enabled: discussions_enabled)
end
end
8 changes: 7 additions & 1 deletion test/oli_web/live/delivery/student/learn_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2770,8 +2770,14 @@ defmodule OliWeb.Delivery.Student.ContentLiveTest do

test "redirects and ensures navigation to the preview Notes page", %{
conn: conn,
section: section
author: author,
section: section,
page_1: page_1,
page_2: page_2,
page_3: page_3
} do
enable_all_sidebar_links(section, author, page_1, page_2, page_3)

stub_current_time(~U[2023-11-04 20:00:00Z])
{:ok, view, _html} = live(conn, "/sections/#{section.slug}/preview")

Expand Down

0 comments on commit 12a4e82

Please sign in to comment.