From 155f9a2ae9e0a13992104a090fe5ddae580166d9 Mon Sep 17 00:00:00 2001 From: Jannik Streek Date: Tue, 12 Nov 2024 14:42:51 +0100 Subject: [PATCH] add count of comments to idea cards --- lib/mindwendel/ideas.ex | 10 ++- .../live/lane_live/index_component.html.heex | 64 ++++++++++--------- priv/gettext/de/LC_MESSAGES/default.po | 10 +-- priv/gettext/default.pot | 10 +-- priv/gettext/en/LC_MESSAGES/default.po | 10 +-- 5 files changed, 59 insertions(+), 45 deletions(-) diff --git a/lib/mindwendel/ideas.ex b/lib/mindwendel/ideas.ex index d581ee7e..e09f8835 100644 --- a/lib/mindwendel/ideas.ex +++ b/lib/mindwendel/ideas.ex @@ -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 diff --git a/lib/mindwendel_web/live/lane_live/index_component.html.heex b/lib/mindwendel_web/live/lane_live/index_component.html.heex index aca3f900..1c3ef08b 100644 --- a/lib/mindwendel_web/live/lane_live/index_component.html.heex +++ b/lib/mindwendel_web/live/lane_live/index_component.html.heex @@ -175,36 +175,16 @@