Skip to content

Commit

Permalink
add count of comments to idea cards (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek authored Nov 12, 2024
1 parent 9be977e commit afd6137
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 45 deletions.
10 changes: 9 additions & 1 deletion lib/mindwendel/ideas.ex
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,15 @@ defmodule Mindwendel.Ideas do
"""
def decrement_comment_count(idea_id) do
idea = Repo.get!(Idea, idea_id)
changeset = Idea.changeset(idea, %{comments_count: idea.comments_count - 1})

new_comments_count =
if idea.comments_count - 1 >= 0 do
idea.comments_count - 1
else
0
end

changeset = Idea.changeset(idea, %{comments_count: new_comments_count})
Repo.update(changeset)
end

Expand Down
64 changes: 35 additions & 29 deletions lib/mindwendel_web/live/lane_live/index_component.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -175,36 +175,16 @@
</div>

<div class="card-footer-mindwendel">
<small class="text-muted">
<%= gettext("By") %> <%= Gettext.gettext(MindwendelWeb.Gettext, idea.username) %> <%= Timex.format!(
idea.inserted_at,
"{relative}",
:relative
) %>
</small>
<div class="float-end">
<span class="me-1"><%= length(idea.likes) %></span>
<%= unless Mindwendel.Likes.exists_like_for_idea?(idea.id, @current_user.id) do %>
<.link
phx-click="like"
phx-target={@myself}
phx-value-id={idea.id}
title="Like"
>
<i class="bi-arrow-up-circle"></i>
</.link>
<% else %>
<.link
phx-click="unlike"
phx-target={@myself}
phx-value-id={idea.id}
title="Unlike"
>
<i class="bi-arrow-up-circle-fill"></i>
</.link>
<% end %>
<div class="d-block">
<small class="text-muted">
<%= gettext("By") %> <%= Gettext.gettext(MindwendelWeb.Gettext, idea.username) %> <%= Timex.format!(
idea.inserted_at,
"{relative}",
:relative
) %>
</small>
</div>
<div class="IndexComponent__IdeaLabelSection">
<div class="d-inline IndexComponent__IdeaLabelSection">
<%= for brainstorming_idea_label <- @brainstorming.labels do %>
<%= unless Enum.find(idea.idea_labels, fn idea_label -> idea_label.id == brainstorming_idea_label.id end) do %>
<.link
Expand Down Expand Up @@ -247,6 +227,32 @@
<% end %>
<% end %>
</div>
<div class="float-end ms-2">
<span>
<%= idea.comments_count %>
<i class="bi-chat"></i>
</span>
<span class="me-1"><%= length(idea.likes) %></span>
<%= unless Mindwendel.Likes.exists_like_for_idea?(idea.id, @current_user.id) do %>
<.link
phx-click="like"
phx-target={@myself}
phx-value-id={idea.id}
title="Like"
>
<i class="bi-arrow-up-circle"></i>
</.link>
<% else %>
<.link
phx-click="unlike"
phx-target={@myself}
phx-value-id={idea.id}
title="Unlike"
>
<i class="bi-arrow-up-circle-fill"></i>
</.link>
<% end %>
</div>
</div>
</div>
<% end %>
Expand Down
10 changes: 5 additions & 5 deletions priv/gettext/de/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ msgstr "Neues Brainstorming"
msgid "New idea"
msgstr "Neue Idee"

#: lib/mindwendel_web/live/lane_live/index_component.html.heex:257
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:263
#, elixir-autogen, elixir-format
msgid "No ideas brainstormed"
msgstr "Bisher keine Ideen vorhanden"
Expand Down Expand Up @@ -202,7 +202,7 @@ msgstr "Nutzername"

#: lib/mindwendel_web/controllers/admin/brainstorming_html/export.html.heex:3
#: lib/mindwendel_web/live/comment_live/show_component.html.heex:40
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:179
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:180
#, elixir-autogen, elixir-format
msgid "By"
msgstr "Von"
Expand Down Expand Up @@ -421,7 +421,7 @@ msgstr "Name"
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:26
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:28
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:114
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:278
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:284
#, elixir-autogen, elixir-format
msgid "New lane"
msgstr "Neue Spalte"
Expand Down Expand Up @@ -455,7 +455,7 @@ msgstr "Spalte aktualisiert"

#: lib/mindwendel_web/live/lane_live/index_component.html.heex:10
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:13
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:262
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:268
#, elixir-autogen, elixir-format, fuzzy
msgid "Add idea"
msgstr "Neue Idee"
Expand All @@ -465,7 +465,7 @@ msgstr "Neue Idee"
msgid "Default lane"
msgstr "Eine Spalte"

#: lib/mindwendel_web/live/lane_live/index_component.html.heex:273
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:279
#, elixir-autogen, elixir-format
msgid "No lanes available"
msgstr "Keine Spalten vorhanden"
Expand Down
10 changes: 5 additions & 5 deletions priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ msgstr ""
msgid "New idea"
msgstr ""

#: lib/mindwendel_web/live/lane_live/index_component.html.heex:257
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:263
#, elixir-autogen, elixir-format
msgid "No ideas brainstormed"
msgstr ""
Expand Down Expand Up @@ -201,7 +201,7 @@ msgstr ""

#: lib/mindwendel_web/controllers/admin/brainstorming_html/export.html.heex:3
#: lib/mindwendel_web/live/comment_live/show_component.html.heex:40
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:179
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:180
#, elixir-autogen, elixir-format
msgid "By"
msgstr ""
Expand Down Expand Up @@ -420,7 +420,7 @@ msgstr ""
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:26
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:28
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:114
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:278
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:284
#, elixir-autogen, elixir-format
msgid "New lane"
msgstr ""
Expand Down Expand Up @@ -454,7 +454,7 @@ msgstr ""

#: lib/mindwendel_web/live/lane_live/index_component.html.heex:10
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:13
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:262
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:268
#, elixir-autogen, elixir-format
msgid "Add idea"
msgstr ""
Expand All @@ -464,7 +464,7 @@ msgstr ""
msgid "Default lane"
msgstr ""

#: lib/mindwendel_web/live/lane_live/index_component.html.heex:273
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:279
#, elixir-autogen, elixir-format
msgid "No lanes available"
msgstr ""
Expand Down
10 changes: 5 additions & 5 deletions priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ msgstr ""
msgid "New idea"
msgstr ""

#: lib/mindwendel_web/live/lane_live/index_component.html.heex:257
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:263
#, elixir-autogen, elixir-format
msgid "No ideas brainstormed"
msgstr ""
Expand Down Expand Up @@ -202,7 +202,7 @@ msgstr ""

#: lib/mindwendel_web/controllers/admin/brainstorming_html/export.html.heex:3
#: lib/mindwendel_web/live/comment_live/show_component.html.heex:40
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:179
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:180
#, elixir-autogen, elixir-format
msgid "By"
msgstr ""
Expand Down Expand Up @@ -421,7 +421,7 @@ msgstr ""
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:26
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:28
#: lib/mindwendel_web/live/brainstorming_live/show.html.heex:114
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:278
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:284
#, elixir-autogen, elixir-format
msgid "New lane"
msgstr ""
Expand Down Expand Up @@ -455,7 +455,7 @@ msgstr ""

#: lib/mindwendel_web/live/lane_live/index_component.html.heex:10
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:13
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:262
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:268
#, elixir-autogen, elixir-format, fuzzy
msgid "Add idea"
msgstr ""
Expand All @@ -465,7 +465,7 @@ msgstr ""
msgid "Default lane"
msgstr ""

#: lib/mindwendel_web/live/lane_live/index_component.html.heex:273
#: lib/mindwendel_web/live/lane_live/index_component.html.heex:279
#, elixir-autogen, elixir-format
msgid "No lanes available"
msgstr ""
Expand Down

0 comments on commit afd6137

Please sign in to comment.