Skip to content

Commit b9f7d08

Browse files
committed
full fledge formatting
1 parent 09cd0dd commit b9f7d08

File tree

9 files changed

+1350
-1636
lines changed

9 files changed

+1350
-1636
lines changed

website/templates/comments2.html

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ <h2 class="text-2xl font-bold text-gray-900 dark:text-gray-100">Comments ({{ all
133133
<div class="flex justify-between items-start mb-4">
134134
<div class="flex items-center space-x-3">
135135
<img class="w-8 h-8 rounded-full object-cover"
136-
{% if child_comment.author_fk.user_avatar %} src="{{ MEDIA_URL }}{{ child_comment.author_fk.user_avatar }}" {% else %} src="{% static 'images/dummy-user.webp' %}" {% endif %}
136+
{% if user.userprofile.user_avatar %} src="{{ MEDIA_URL }}{{ user.userprofile.user_avatar }}" {% else %} src="{% static 'images/dummy-user.webp' %}" {% endif %}
137137
alt="{{ child_comment.author }} profile"
138138
width="32"
139139
height="32">
@@ -187,22 +187,22 @@ <h2 class="text-2xl font-bold text-gray-900 dark:text-gray-100">Comments ({{ all
187187
{% endfor %}
188188
</div>
189189
<script>
190-
function initDropDown() {
190+
function initDropDown(){
191191
document.querySelectorAll("[data-dropdown-toggle]").forEach((toggle) => {
192192
toggle.addEventListener("click", (e) => {
193193
e.stopPropagation();
194194
const { dropdownToggle } = toggle.dataset;
195195
const dropdown = document.getElementById(dropdownToggle);
196-
196+
197197
// Close all other dropdowns first
198198
document.querySelectorAll('[id^="dropdownComment"]').forEach(menu => {
199199
if (menu.id !== dropdownToggle && !menu.classList.contains('hidden')) {
200200
menu.classList.add('hidden');
201201
}
202202
});
203-
203+
204204
dropdown.classList.toggle("hidden");
205-
205+
206206
if (!dropdown.classList.contains("hidden")) {
207207
const rect = toggle.getBoundingClientRect();
208208
dropdown.style.position = "absolute";
@@ -211,7 +211,7 @@ <h2 class="text-2xl font-bold text-gray-900 dark:text-gray-100">Comments ({{ all
211211
}
212212
});
213213
});
214-
214+
215215
// Close dropdowns when clicking outside
216216
document.addEventListener('click', () => {
217217
document.querySelectorAll('[id^="dropdownComment"]').forEach(menu => {
@@ -222,13 +222,13 @@ <h2 class="text-2xl font-bold text-gray-900 dark:text-gray-100">Comments ({{ all
222222
});
223223
}
224224

225-
function remove_reply() {
225+
function remove_reply(){
226226
document.getElementById("replying_to_cont").remove();
227227
document.getElementById("replying_to_input").value = "";
228228
}
229229

230-
function add_reply(comment_id, comment_author) {
231-
let replying_to_root = document.getElementById("replying_to_root");
230+
function add_reply(comment_id, comment_author){
231+
let replying_to_root = document.getElementById("replying_to_root");
232232
let reply_text = "@" + comment_author + "#" + comment_id;
233233

234234
replying_to_root.innerHTML = `
@@ -242,29 +242,29 @@ <h2 class="text-2xl font-bold text-gray-900 dark:text-gray-100">Comments ({{ all
242242
</div>
243243
`;
244244
document.getElementById("replying_to_input").value = reply_text;
245-
245+
246246
// Focus on the comment textarea
247247
document.getElementById("comment").focus();
248248
}
249249

250-
function see_replies(comment_id) {
250+
function see_replies(comment_id){
251251
let id = "comment_replies_" + comment_id;
252252
let comment_container = document.getElementById(id);
253253
comment_container.toggleAttribute('hidden');
254254
}
255255

256-
function comment_on_content(e) {
256+
function comment_on_content(e){
257257
e.preventDefault();
258258
let content_pk = '{{ object.pk|safe }}';
259259
let content_type = '{{ content_type }}';
260260
var csrftoken = $("[name=csrfmiddlewaretoken]").val();
261261

262262
let replying_to_input = document.getElementById("replying_to_input").value;
263263
let comment = document.getElementById("comment").value;
264-
if (comment == "") {
264+
if(comment == ""){
265265
return;
266266
}
267-
267+
268268
// Show loading state
269269
const btn = document.getElementById('post_comment_btn');
270270
const originalText = btn.textContent;
@@ -276,7 +276,7 @@ <h2 class="text-2xl font-bold text-gray-900 dark:text-gray-100">Comments ({{ all
276276
</svg>
277277
Posting...
278278
`;
279-
279+
280280
$.ajax({
281281
type: 'POST',
282282
url: '/content/' + content_pk + '/comment/',
@@ -285,34 +285,34 @@ <h2 class="text-2xl font-bold text-gray-900 dark:text-gray-100">Comments ({{ all
285285
"comment": comment,
286286
"content_type": content_type
287287
},
288-
beforeSend: function (xhr, settings) {
288+
beforeSend: function(xhr, settings) {
289289
xhr.setRequestHeader("X-CSRFToken", csrftoken);
290290
},
291291
success: function (data) {
292292
$('#comment_root').replaceWith(data);
293293
location.reload();
294294
},
295-
error: function () {
295+
error: function() {
296296
// Restore button state on error
297297
btn.disabled = false;
298298
btn.textContent = originalText;
299299
}
300300
});
301301
}
302-
302+
303303
$('#post_comment_btn').click((e) => comment_on_content(e));
304-
305-
function update_comment(e, comment_id) {
304+
305+
function update_comment(e, comment_id){
306306
e.preventDefault();
307307
let content_pk = '{{ object.pk|safe }}';
308308
let content_type = '{{ content_type }}';
309309
var csrftoken = $("[name=csrfmiddlewaretoken]").val();
310310

311311
let comment = document.getElementById("comment").value;
312-
if (comment == "") {
312+
if(comment == ""){
313313
return;
314314
}
315-
315+
316316
// Show loading state
317317
const btn = document.getElementById('update_comment_btn');
318318
const originalText = btn.textContent;
@@ -324,30 +324,30 @@ <h2 class="text-2xl font-bold text-gray-900 dark:text-gray-100">Comments ({{ all
324324
</svg>
325325
Updating...
326326
`;
327-
327+
328328
$.ajax({
329329
type: 'POST',
330330
url: '/content/' + content_pk + '/comment/update/' + comment_id + '/',
331331
data: {
332332
"comment": comment,
333333
"content_type": content_type
334334
},
335-
beforeSend: function (xhr, settings) {
335+
beforeSend: function(xhr, settings) {
336336
xhr.setRequestHeader("X-CSRFToken", csrftoken);
337337
},
338338
success: function (data) {
339339
$('#comment_root').replaceWith(data);
340340
location.reload();
341341
},
342-
error: function () {
342+
error: function() {
343343
// Restore button state on error
344344
btn.disabled = false;
345345
btn.textContent = originalText;
346346
}
347347
});
348348
}
349-
350-
function remove_update_label() {
349+
350+
function remove_update_label(){
351351
let add_update_label = document.getElementById("add_update_label");
352352
add_update_label.innerHTML = "";
353353
$('#comment').val("");
@@ -356,7 +356,7 @@ <h2 class="text-2xl font-bold text-gray-900 dark:text-gray-100">Comments ({{ all
356356
$('#update_comment_btn').off('click');
357357
$('#post_comment_btn').off('click').on('click', (e) => comment_on_content(e));
358358
}
359-
359+
360360
$('body').on('click', '.edit_comment', function (e) {
361361
e.preventDefault();
362362
let comment_id = $(this).data('name');
@@ -365,7 +365,7 @@ <h2 class="text-2xl font-bold text-gray-900 dark:text-gray-100">Comments ({{ all
365365
$('#comment').val(comment_text);
366366
$('#post_comment_btn').text('Update comment');
367367
$('#post_comment_btn').attr('id', 'update_comment_btn');
368-
368+
369369
let add_update_label = document.getElementById("add_update_label");
370370
add_update_label.innerHTML = `
371371
<div class="flex items-center bg-blue-50 text-blue-800 rounded-md p-2 max-w-max">
@@ -377,18 +377,18 @@ <h2 class="text-2xl font-bold text-gray-900 dark:text-gray-100">Comments ({{ all
377377
</button>
378378
</div>
379379
`;
380-
380+
381381
$('#update_comment_btn').off('click').on('click', (e) => update_comment(e, comment_id));
382-
382+
383383
// Scroll to comment form
384384
document.getElementById('comments').scrollIntoView({ behavior: 'smooth' });
385385
});
386-
386+
387387
$('body').off('click', '.del_comment').on('click', '.del_comment', function (e) {
388388
e.preventDefault();
389389

390390
var clickedElement = $(this);
391-
391+
392392
// Create a confirmation dialog
393393
const confirmDialog = document.createElement('div');
394394
confirmDialog.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50';
@@ -402,20 +402,20 @@ <h3 class="text-lg font-medium text-gray-900 dark:text-gray-100 mb-4">Delete Com
402402
</div>
403403
</div>
404404
`;
405-
405+
406406
document.body.appendChild(confirmDialog);
407407
document.body.style.overflow = 'hidden';
408-
408+
409409
// Handle cancel
410-
document.getElementById('cancel-delete').addEventListener('click', function () {
410+
document.getElementById('cancel-delete').addEventListener('click', function() {
411411
document.body.removeChild(confirmDialog);
412412
document.body.style.overflow = '';
413413
});
414-
414+
415415
// Handle confirm
416-
document.getElementById('confirm-delete').addEventListener('click', function () {
416+
document.getElementById('confirm-delete').addEventListener('click', function() {
417417
var csrftoken = $("[name=csrfmiddlewaretoken]").val();
418-
418+
419419
// Show loading state
420420
this.disabled = true;
421421
this.innerHTML = `
@@ -441,15 +441,15 @@ <h3 class="text-lg font-medium text-gray-900 dark:text-gray-100 mb-4">Delete Com
441441
$('#comment_root').replaceWith(data);
442442
location.reload();
443443
},
444-
error: function () {
444+
error: function() {
445445
document.body.removeChild(confirmDialog);
446446
document.body.style.overflow = '';
447447
}
448448
});
449449
});
450450
});
451451

452-
$(document).ready(function () {
452+
$(document).ready(function(){
453453
initDropDown();
454454
});
455455
</script>

0 commit comments

Comments
 (0)