Skip to content

Commit

Permalink
[FEATURE] [NG23-206] User enables/disables both Notes and Course Disc…
Browse files Browse the repository at this point in the history
…ussions

[FEATURE] [NG23-206] User enables/disables both Notes and Course Discussions
  • Loading branch information
darrensiegel authored Jun 24, 2024
2 parents edd8755 + cea0e90 commit 65e28c4
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 58 deletions.
131 changes: 78 additions & 53 deletions lib/oli_web/live/delivery/student/discussions_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ defmodule OliWeb.Delivery.Student.DiscussionsLive do
assign(socket,
is_instructor: is_instructor,
active_tab: :discussions,
active_sub_tab: :notes,
posts: posts,
notes: notes,
expanded_posts: %{},
Expand All @@ -96,10 +97,6 @@ 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 @@ -480,6 +477,10 @@ defmodule OliWeb.Delivery.Student.DiscussionsLive do
end
end

def handle_event("select_tab", %{"tab" => tab}, socket) do
{:noreply, assign(socket, active_sub_tab: String.to_existing_atom(tab))}
end

def handle_info({:discussion_created, new_post}, socket) do
{:noreply, assign(socket, :posts, [new_post | socket.assigns.posts])}
end
Expand Down Expand Up @@ -543,30 +544,66 @@ defmodule OliWeb.Delivery.Student.DiscussionsLive do
id="discussions_content"
class="overflow-x-scroll md:overflow-x-auto flex flex-col py-6 px-16 mb-10 gap-6 items-start"
>
<.posts_section
:if={@course_discussions_enabled?}
posts={@posts}
ctx={@ctx}
section_slug={@section.slug}
expanded_posts={@expanded_posts}
current_user={@current_user}
course_collab_space_config={@course_collab_space_config}
post_params={@post_params}
more_posts_exist?={@more_posts_exist?}
posts_search_term={@posts_search_term}
posts_search_results={@posts_search_results}
/>
<.notes_section
:if={not @is_instructor}
ctx={@ctx}
section_slug={@section.slug}
current_user={@current_user}
notes={@notes}
note_params={@note_params}
more_notes_exist?={@more_notes_exist?}
notes_search_term={@notes_search_term}
notes_search_results={@notes_search_results}
/>
<div class="flex gap-12">
<.tab :if={not @is_instructor} label="My Notes" value={:notes} active={@active_sub_tab} />
<.tab
:if={@course_discussions_enabled?}
label="Course Discussion"
value={:discussions}
active={@active_sub_tab}
/>
</div>
<%= case @active_sub_tab do %>
<% :notes -> %>
<.notes_section
:if={not @is_instructor}
ctx={@ctx}
section_slug={@section.slug}
current_user={@current_user}
notes={@notes}
note_params={@note_params}
more_notes_exist?={@more_notes_exist?}
notes_search_term={@notes_search_term}
notes_search_results={@notes_search_results}
/>
<% :discussions -> %>
<.posts_section
:if={@course_discussions_enabled?}
posts={@posts}
ctx={@ctx}
section_slug={@section.slug}
expanded_posts={@expanded_posts}
current_user={@current_user}
course_collab_space_config={@course_collab_space_config}
post_params={@post_params}
more_posts_exist?={@more_posts_exist?}
posts_search_term={@posts_search_term}
posts_search_results={@posts_search_results}
/>
<% end %>
</div>
"""
end

attr :label, :string, required: true
attr :value, :atom, required: true
attr :active, :atom, required: true

def tab(assigns) do
~H"""
<div
class={[
"text-lg font-semibold py-2 border-b-2 cursor-pointer transition-colors duration-200",
if(@active == @value,
do: "text-gray-900 py-2 border-gray-900",
else: "text-gray-500 border-transparent hover:border-gray-500"
)
]}
phx-click="select_tab"
phx-value-tab={@value}
>
<%= @label %>
</div>
"""
end
Expand Down Expand Up @@ -665,12 +702,6 @@ defmodule OliWeb.Delivery.Student.DiscussionsLive do
defp posts_section(assigns) do
~H"""
<section id="posts" class="container mx-auto flex flex-col items-start w-full gap-6">
<div role="posts header" class="flex justify-between items-center w-full self-stretch">
<h3 class="text-2xl tracking-[0.02px] font-semibold dark:text-white">
Course Discussions
</h3>
</div>
<.posts_actions
post_params={@post_params}
course_collab_space_config={@course_collab_space_config}
Expand Down Expand Up @@ -728,12 +759,6 @@ defmodule OliWeb.Delivery.Student.DiscussionsLive do
defp notes_section(assigns) do
~H"""
<section id="notes" class="container mx-auto flex flex-col items-start w-full gap-6">
<div role="notes header" class="flex justify-between items-center w-full self-stretch">
<h3 class="text-2xl tracking-[0.02px] font-semibold dark:text-white">
My Notes
</h3>
</div>
<.notes_actions note_params={@note_params} notes_search_term={@notes_search_term} />
<%= case @notes_search_results do %>
Expand Down Expand Up @@ -786,8 +811,8 @@ defmodule OliWeb.Delivery.Student.DiscussionsLive do

defp posts_actions(assigns) do
~H"""
<div role="posts actions" class="w-full flex gap-6">
<div class="flex flex-1 space-x-3 justify-between">
<div role="posts actions" class="w-full flex">
<div class="flex flex-1 gap-6">
<Annotations.search_box
class="flex-1 max-w-[600px]"
search_term={@posts_search_term}
Expand Down Expand Up @@ -836,16 +861,16 @@ defmodule OliWeb.Delivery.Student.DiscussionsLive do
<span class="text-[14px] leading-[20px] mr-2">Sort</span>
<Icons.chevron_down />
</.dropdown>
</div>
<button
:if={@course_collab_space_config && @course_collab_space_config.status == :enabled}
role="new discussion"
phx-click={Modal.show_modal("new-discussion-modal")}
class="rounded-[3px] py-[10px] pl-[18px] pr-6 flex justify-center items-center whitespace-nowrap text-[14px] leading-[20px] font-normal text-white bg-[#0F6CF5] hover:bg-blue-600"
>
<Icons.plus class="w-6 h-6 mr-[10px]" /> New Discussion
</button>
<button
:if={@course_collab_space_config && @course_collab_space_config.status == :enabled}
role="new discussion"
phx-click={Modal.show_modal("new-discussion-modal")}
class="rounded-[3px] py-[10px] pl-[18px] pr-6 flex justify-center items-center whitespace-nowrap text-[14px] leading-[20px] font-normal text-white bg-[#0F6CF5] hover:bg-blue-600"
>
<Icons.plus class="w-6 h-6 mr-[10px]" /> New Discussion
</button>
</div>
</div>
"""
end
Expand All @@ -855,8 +880,8 @@ defmodule OliWeb.Delivery.Student.DiscussionsLive do

defp notes_actions(assigns) do
~H"""
<div role="notes actions" class="w-full flex gap-6">
<div class="flex flex-1 space-x-3 justify-between">
<div role="notes actions" class="w-full flex">
<div class="flex flex-1 gap-6">
<Annotations.search_box
class="flex-1 max-w-[600px]"
search_term={@notes_search_term}
Expand Down
57 changes: 54 additions & 3 deletions test/oli_web/live/delivery/student/discussions_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ defmodule OliWeb.Delivery.Student.DiscussionsLiveTest do

assert has_element?(
view,
~s{section[id="posts"] div[role="posts header"] h3},
"Course Discussions"
~s{div[id="discussions_content"] div[phx-value-tab='discussions']},
"Course Discussion"
)
end

Expand Down Expand Up @@ -250,6 +250,11 @@ defmodule OliWeb.Delivery.Student.DiscussionsLiveTest do

{:ok, view, _html} = live(conn, live_view_discussions_live_route(section.slug))

# select course discussions tab
view
|> element("div[phx-click='select_tab'][phx-value-tab='discussions']")
|> render_click

# page posts are not shown in discussions view
refute view
|> has_element?("div[id=\"post-#{page_post.id}\"]")
Expand Down Expand Up @@ -309,6 +314,11 @@ defmodule OliWeb.Delivery.Student.DiscussionsLiveTest do

{:ok, view, _html} = live(conn, live_view_discussions_live_route(section.slug))

# select course discussions tab
view
|> element("div[phx-click='select_tab'][phx-value-tab='discussions']")
|> render_click

## post header
# student name (Me)
assert view
Expand Down Expand Up @@ -344,6 +354,11 @@ defmodule OliWeb.Delivery.Student.DiscussionsLiveTest do

{:ok, view, _html} = live(conn, live_view_discussions_live_route(section.slug))

# select course discussions tab
view
|> element("div[phx-click='select_tab'][phx-value-tab='discussions']")
|> render_click

refute render(view) =~ "My first discussion :)"

form(view, "form[id=\"new_discussion_form\"]")
Expand Down Expand Up @@ -373,6 +388,11 @@ defmodule OliWeb.Delivery.Student.DiscussionsLiveTest do

{:ok, view, _html} = live(conn, live_view_discussions_live_route(section.slug))

# select course discussions tab
view
|> element("div[phx-click='select_tab'][phx-value-tab='discussions']")
|> render_click

refute render(view) =~ "My first anon discussion :)"

form(view, "form[id=\"new_discussion_form\"]")
Expand Down Expand Up @@ -427,6 +447,11 @@ defmodule OliWeb.Delivery.Student.DiscussionsLiveTest do

{:ok, view, _html} = live(conn, live_view_discussions_live_route(section.slug))

# select course discussions tab
view
|> element("div[phx-click='select_tab'][phx-value-tab='discussions']")
|> render_click

assert render(view) =~ "My first discussion"
refute render(view) =~ "This is a reply to the first discussion"

Expand Down Expand Up @@ -478,6 +503,11 @@ defmodule OliWeb.Delivery.Student.DiscussionsLiveTest do

{:ok, view, _html} = live(conn, live_view_discussions_live_route(section.slug))

# select course discussions tab
view
|> element("div[phx-click='select_tab'][phx-value-tab='discussions']")
|> render_click

assert render(view) =~ "My first discussion"
refute render(view) =~ "This is a reply to the first discussion"
refute render(view) =~ "This is a reply to the reply"
Expand Down Expand Up @@ -514,10 +544,16 @@ defmodule OliWeb.Delivery.Student.DiscussionsLiveTest do
content: %{message: "My first anonymous discussion"},
inserted_at: ~U[2023-12-01 00:00:00Z],
updated_at: ~U[2023-12-01 00:00:00Z],
anonymous: true
anonymous: true,
status: :approved
})

{:ok, view, _html} = live(conn, live_view_discussions_live_route(section.slug))

view
|> element("div[phx-click='select_tab'][phx-value-tab='discussions']")
|> render_click

assert render(view) =~ "My first anonymous discussion"
assert render(view) =~ "Anonymous"
refute render(view) =~ student_2.name
Expand All @@ -534,6 +570,11 @@ defmodule OliWeb.Delivery.Student.DiscussionsLiveTest do

{:ok, view, _html} = live(conn, live_view_discussions_live_route(section.slug))

# select course discussions tab
view
|> element("div[phx-click='select_tab'][phx-value-tab='discussions']")
|> render_click

assert render(view) =~ "There are no discussions to show."
end

Expand Down Expand Up @@ -563,6 +604,11 @@ defmodule OliWeb.Delivery.Student.DiscussionsLiveTest do

{:ok, view, _html} = live(conn, live_view_discussions_live_route(section.slug))

# select course discussions tab
view
|> element("div[phx-click='select_tab'][phx-value-tab='discussions']")
|> render_click

refute render(view) =~ "Discussion 1 :)"
refute render(view) =~ "Discussion 2 :)"
refute render(view) =~ "Discussion 3 :)"
Expand Down Expand Up @@ -624,6 +670,11 @@ defmodule OliWeb.Delivery.Student.DiscussionsLiveTest do

{:ok, view, _html} = live(conn, live_view_discussions_live_route(section.slug))

# select course discussions tab
view
|> element("div[phx-click='select_tab'][phx-value-tab='discussions']")
|> render_click

assert has_element?(view, "button[role=\"new discussion\"]", "New Discussion")

{:ok, _root_container_sr} =
Expand Down
4 changes: 2 additions & 2 deletions test/oli_web/live/delivery/student/learn_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2779,7 +2779,7 @@ defmodule OliWeb.Delivery.Student.ContentLiveTest do
{:ok, view, _html} = live(conn, redirect_path)

assert view |> element(~s{#header span}) |> render() =~ "(Preview Mode)"
assert view |> element(~s{h3)}) |> render() =~ "My Notes"
assert view |> has_element?(~s{h1}, "Notes")
end

test "redirects and ensures navigation to the preview Practice page", %{
Expand All @@ -2804,7 +2804,7 @@ defmodule OliWeb.Delivery.Student.ContentLiveTest do
{:ok, view, _html} = live(conn, redirect_path)

assert view |> element(~s{#header span}) |> render() =~ "(Preview Mode)"
assert view |> element(~s{h1)}) |> render() =~ "Your Practice Pages"
assert view |> element(~s{h1}) |> render() =~ "Your Practice Pages"
end
end

Expand Down

0 comments on commit 65e28c4

Please sign in to comment.