From 0f15e92d6538f0e295b884f06aa36be7cb6e4131 Mon Sep 17 00:00:00 2001 From: luptmoor Date: Tue, 28 Apr 2026 10:21:27 +0200 Subject: [PATCH] comment counter now refreshed for each deletion or addition of comment --- public/api/contributions.php | 8 ++++++++ public/js/app.js | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/public/api/contributions.php b/public/api/contributions.php index 0e737c4..3b02068 100644 --- a/public/api/contributions.php +++ b/public/api/contributions.php @@ -664,6 +664,14 @@ function handle_delete_comment($input) { $stmt = $pdo->prepare("DELETE FROM comments WHERE comment_id = :id"); $stmt->execute([':id' => $input['comment_id']]); + $stmt2 = $pdo->prepare(" + UPDATE contributions + SET comment_count = comment_count - 1 + WHERE contribution_id = :cid; + "); + + $stmt2->execute([':cid' => $input['contribution_id']]); + json_response(['message' => 'Comment deleted successfully.']); } catch (PDOException $e) { diff --git a/public/js/app.js b/public/js/app.js index 5b2c2e4..d1fbde9 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -1105,6 +1105,14 @@ function loadComments(contributionId) { }); listContainer.innerHTML = html; + + const count = response.comments.length; + const header = document.querySelector('#comments-toggle-' + contributionId)?.closest('.popup-comments-header'); + if (header) { + header.innerHTML = ' Kommentare (' + count + ')' + + ' '; + } + }); }