Skip to content

Commit

Permalink
refactor live idea component
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek committed Nov 7, 2024
1 parent ae4f6ac commit e5490de
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
3 changes: 1 addition & 2 deletions lib/mindwendel/brainstormings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ defmodule Mindwendel.Brainstormings do
:link,
:likes,
:idea_labels,
:files,
:comments
:files
]
)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/mindwendel/brainstormings/idea.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Mindwendel.Brainstormings.Idea do
has_one :link, Link
belongs_to :user, User
has_many :likes, Like
has_many :comments, Comment
has_many :comments, Comment, preload_order: [desc: :inserted_at]
has_many :files, File
belongs_to :brainstorming, Brainstorming
belongs_to :label, IdeaLabel, on_replace: :nilify
Expand Down
6 changes: 2 additions & 4 deletions lib/mindwendel/lanes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ defmodule Mindwendel.Lanes do
:link,
:likes,
:idea_labels,
:files,
:comments
:files
]
)
end
Expand Down Expand Up @@ -110,8 +109,7 @@ defmodule Mindwendel.Lanes do
:link,
:likes,
:idea_labels,
:files,
:comments
:files
])
)
end
Expand Down
10 changes: 9 additions & 1 deletion lib/mindwendel_web/live/comment_live/form_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,17 @@ defmodule MindwendelWeb.CommentLive.FormComponent do
|> Map.put("idea_id", socket.assigns.idea.id)

case Comments.create_comment(comment_params_merged) do
{:ok, comment} ->
{:ok, _comment} ->
# reset the form
new_comment = %Comment{
idea_id: socket.assigns.idea.id,
username: socket.assigns.current_user.username
}

{:noreply,
socket
|> assign(comment: new_comment)
|> assign(form: to_form(Comments.change_comment(new_comment)))
|> put_flash(:info, gettext("Comment created successfully"))}

{:error, %Ecto.Changeset{} = changeset} ->
Expand Down
14 changes: 7 additions & 7 deletions lib/mindwendel_web/live/lane_live/index_component.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,6 @@
>
<i class="bi bi-x text-secondary"></i>
</.link>
<.link
patch={~p"/brainstormings/#{@brainstorming.id}/ideas/#{idea.id}"}
class="float-end ms-3 mb-3"
title={gettext("Show idea")}
>
<i class="bi bi-eye text-secondary"></i>
</.link>
<.link
patch={~p"/brainstormings/#{@brainstorming.id}/ideas/#{idea.id}/edit"}
class="float-end ms-3 mb-3"
Expand All @@ -129,6 +122,13 @@
<i class="bi bi-pencil text-secondary"></i>
</.link>
<% end %>
<.link
patch={~p"/brainstormings/#{@brainstorming.id}/ideas/#{idea.id}"}
class="float-end ms-3 mb-3"
title={gettext("Show idea")}
>
<i class="bi bi-eye text-secondary"></i>
</.link>

<%= for idea_label <- Enum.sort_by(idea.idea_labels, &(&1.position_order)) do %>
<span
Expand Down

0 comments on commit e5490de

Please sign in to comment.