From ff422ab7e239f8fc20a86f33c20314d92694f4e8 Mon Sep 17 00:00:00 2001 From: flashwave Date: Tue, 6 Dec 2016 15:40:12 +0100 Subject: [PATCH] fixed friends and comments (for the most part) do you ever just... --- app/Controllers/CommentsController.php | 2 +- app/Controllers/FriendsController.php | 4 +- resources/views/yuuno/elements/comments.twig | 82 +++++++------------- 3 files changed, 33 insertions(+), 55 deletions(-) diff --git a/app/Controllers/CommentsController.php b/app/Controllers/CommentsController.php index ea1d9b0..3a9749d 100644 --- a/app/Controllers/CommentsController.php +++ b/app/Controllers/CommentsController.php @@ -26,7 +26,7 @@ class CommentsController extends Controller public function post(string $category = '', int $reply = 0): string { // Check if the user can comment - if (session_check()) { + if (!session_check()) { $error = "Your session expired, refresh the page!"; return $this->json(compact('error')); } diff --git a/app/Controllers/FriendsController.php b/app/Controllers/FriendsController.php index 8ba6cdf..419c919 100644 --- a/app/Controllers/FriendsController.php +++ b/app/Controllers/FriendsController.php @@ -49,7 +49,7 @@ class FriendsController extends Controller $user = CurrentSession::$user; // Check if the user can comment - if (session_check()) { + if (!session_check()) { $error = "Your session expired, refresh the page!"; return $this->json(compact('error')); } @@ -110,7 +110,7 @@ class FriendsController extends Controller $user = CurrentSession::$user; // Check if the user can comment - if (session_check()) { + if (!session_check()) { $error = "Your session expired, refresh the page!"; return $this->json(compact('error')); } diff --git a/resources/views/yuuno/elements/comments.twig b/resources/views/yuuno/elements/comments.twig index 17a7574..42c21d9 100644 --- a/resources/views/yuuno/elements/comments.twig +++ b/resources/views/yuuno/elements/comments.twig @@ -70,100 +70,78 @@ function commentAdd(obj) { var container = document.createElement('li'); container.id = "comment-" + obj.id; + container.className = 'comment-container'; var inner = document.createElement('div'); inner.className = 'comment'; var avatar = document.createElement('a'); - avatar.className = 'comment-avatar clean'; + avatar.className = 'avatar avatar--border comment__avatar'; + + if (!obj.reply) { + avatar.className += ' comment__avatar--big'; + } + avatar.href = "{{ route('user.profile', 1) }}".replace(1, obj.user); avatar.style.backgroundImage = "url('{{ route('user.avatar', 1) }}')".replace(1, obj.user); inner.appendChild(avatar); var pointer = document.createElement('div'); - pointer.className = 'comment-pointer'; + pointer.className = 'comment__pointer'; inner.appendChild(pointer); var content = document.createElement('div'); - content.className = 'comment-content'; + content.className = 'comment__content'; var controls = document.createElement('div'); - controls.className = 'comment-controls'; + controls.className = 'comment__controls'; var controlsInner = document.createElement('ul'); - if (Sakura.Cookies.Get(sakuraVars.cookie.prefix + 'id') == obj.user) { - var controlsTrashContainer = document.createElement('li'); - var controlsTrash = document.createElement('a'); - controlsTrash.href = 'javascript:void(0);'; + if (Sakura.Config.LoggedIn && Sakura.Config.UserId === obj.user) { + var controlsTrash = document.createElement('div'); controlsTrash.title = 'Delete'; - controlsTrash.className = 'clean fa fa-trash-o'; + controlsTrash.className = 'fa fa-trash-o comment__control'; controlsTrash.setAttribute('onclick', 'commentDelete(' + obj.id + ');'); - controlsTrashContainer.appendChild(controlsTrash); - controlsInner.appendChild(controlsTrashContainer); - } else { - var controlsReportContainer = document.createElement('li'); - var controlsReport = document.createElement('a'); - controlsReport.href = '#'; - controlsReport.title = 'Report'; - controlsReport.className = 'clean fa fa-trash-o'; - controlsReportContainer.appendChild(controlsReport); - controlsInner.appendChild(controlsReportContainer); + controls.appendChild(controlsTrash); } - var controlsReplyContainer = document.createElement('li'); - var controlsReply = document.createElement('a'); - controlsReply.href = 'javascript:void(0);'; + var controlsReply = document.createElement('div'); controlsReply.title = 'Reply'; - controlsReply.className = 'clean fa fa-reply'; + controlsReply.className = 'fa fa-reply comment__control'; controlsReply.setAttribute('onclick', 'commentReply(' + obj.id + ', "{{ session_id() }}", "{{ route("user.avatar", user.id) }}");'); - controlsReplyContainer.appendChild(controlsReply); - controlsInner.appendChild(controlsReplyContainer); + controls.appendChild(controlsReply); - var controlsLikeContainer = document.createElement('li'); - controlsLikeContainer.className = 'shown voting like'; - var controlsLike = document.createElement('a'); - controlsLike.href = 'javascript:void(0);'; + var controlsLike = document.createElement('div'); controlsLike.setAttribute('onclick', 'commentVote(' + obj.id + ', 1);'); - controlsLike.className = 'clean'; + controlsLike.className = 'comment__control comment__control--vote comment__control--vote-up'; var controlsLikeIcon = document.createElement('span'); - controlsLikeIcon.className = 'fa fa-thumbs-up'; + controlsLikeIcon.className = 'fa fa-chevron-up'; controlsLike.appendChild(controlsLikeIcon); controlsLike.innerHTML += "\r\n"; var controlsLikeCount = document.createElement('span'); controlsLikeCount.id = 'comment-' + obj.id + '-likes'; controlsLikeCount.innerText = obj.upvotes; controlsLike.appendChild(controlsLikeCount); - controlsLikeContainer.appendChild(controlsLike); - controlsInner.appendChild(controlsLikeContainer); + controls.appendChild(controlsLike); - var controlsDislikeContainer = document.createElement('li'); - controlsDislikeContainer.className = 'shown voting dislike'; - var controlsDislike = document.createElement('a'); - controlsDislike.href = 'javascript:void(0);'; + var controlsDislike = document.createElement('div'); controlsDislike.setAttribute('onclick', 'commentVote(' + obj.id + ', 0);'); - controlsDislike.className = 'clean'; + controlsDislike.className = 'comment__control comment__control--vote comment__control--vote-down'; var controlsDislikeIcon = document.createElement('span'); - controlsDislikeIcon.className = 'fa fa-thumbs-down'; + controlsDislikeIcon.className = 'fa fa-chevron-down'; controlsDislike.appendChild(controlsDislikeIcon); controlsDislike.innerHTML += "\r\n"; var controlsDislikeCount = document.createElement('span'); controlsDislikeCount.id = 'comment-' + obj.id + '-dislikes'; controlsDislikeCount.innerText = obj.upvotes; controlsDislike.appendChild(controlsDislikeCount); - controlsDislikeContainer.appendChild(controlsDislike); - controlsInner.appendChild(controlsDislikeContainer); - - controls.appendChild(controlsInner); - - var clear = document.createElement('div'); - clear.className = 'clear'; - controls.appendChild(clear); + controls.appendChild(controlsDislike); content.appendChild(controls); var text = document.createElement('text'); - text.className = 'comment-text'; + text.className = 'comment__text'; text.innerHTML = obj.text; content.appendChild(text); @@ -171,7 +149,7 @@ container.appendChild(inner); var replies = document.createElement('ul'); - replies.className = 'comment-replies'; + replies.className = 'comment__replies'; container.appendChild(replies); var discussion = document.getElementById('comments').querySelector('.comments__list'); @@ -248,10 +226,10 @@ replyContainer.appendChild(replyDiv); // Insert the HTML - if (replyingTo.querySelector('.comment-replies').children.length > 0) { - replyingTo.querySelector('.comment-replies').insertBefore(replyContainer, replyingTo.querySelector('.comment-replies').firstChild); + if (replyingTo.querySelector('.comment__replies').children.length > 0) { + replyingTo.querySelector('.comment__replies').insertBefore(replyContainer, replyingTo.querySelector('.comment__replies').firstChild); } else { - replyingTo.querySelector('.comment-replies').appendChild(replyContainer); + replyingTo.querySelector('.comment__replies').appendChild(replyContainer); } }