INSERT INTO `cp_filejs` (`id`,`app`,`path`,`modul`,`file_name`,`content`) VALUES ('147','2','u6/driver','auth','js/homepage.js-','import app, {\r\n showToast\r\n} from \\\"./app.js\\\"\r\nimport store from \\\"./store.js\\\"\r\n\r\nimport {\r\n formatPostDate\r\n} from \\\\\\\'./utils.js\\\\\\\'\r\nimport {\r\n fetchComments,\r\n maybeLikePost,\r\n maybeLikeComment,\r\n addComment,\r\n deletePost,\r\n deleteComment\r\n} from \\\\\\\'./api/posts.js\\\\\\\'\r\nimport {\r\n getSessionUser\r\n} from \\\"./api/auth.js\\\"\r\nimport {\r\n renderPost\r\n} from \\\"./post-view.js\\\"\r\n\r\nvar $ = Dom7\r\nvar currentPostsPage = 1\r\nvar currentFollowingPostsPage = 1\r\n\r\nvar postsStore = store.getters.posts\r\nvar followingPostsStore = store.getters.followingPosts\r\n\r\nvar totalPostPages = 0\r\nvar totalFPostPages = 0\r\n\r\n// Infinite Scroll Event\r\nvar isFetchingPosts = false\r\nvar activeTab = \\\\\\\'latest\\\\\\\'\r\nvar refreshed = false\r\n\r\n//screen width\r\nvar containerWidth = window.innerWidth\r\n\r\npostsStore.onUpdated((data) => {\r\n totalPostPages = data.total_pages\r\n\r\n if ((data.page == data.total_pages) || (data.new_data.length == 0)) {\r\n $(\\\\\\\'.infinite-scroll-preloader.home-posts\\\\\\\').hide()\r\n\r\n if (data.data.length == 0) {\r\n $(\\\\\\\'#tab-latest .data\\\\\\\').html(\\\\\\\'
No posts
\\\\\\\')\r\n return;\r\n }\r\n }\r\n\r\n displayPosts(data.new_data)\r\n})\r\n\r\nfollowingPostsStore.onUpdated((data) => {\r\n totalFPostPages = data.total_pages\r\n\r\n if ((data.page == data.total_pages) || (data.new_data.length == 0)) {\r\n $(\\\\\\\'.infinite-scroll-preloader.home-following-posts\\\\\\\').hide()\r\n if (data.data.length == 0) {\r\n $(\\\\\\\'#tab-following .data\\\\\\\').html(\\\\\\\'
No posts
\\\\\\\')\r\n return;\r\n }\r\n }\r\n\r\n displayPosts(data.new_data, true)\r\n})\r\n\r\n$(document).on(\\\\\\\'infinite\\\\\\\', \\\\\\\'.infinite-scroll-content.home-page\\\\\\\', async function () {\r\n if (isFetchingPosts) return\r\n\r\n const totalPages = activeTab === \\\\\\\'following\\\\\\\' ? totalFPostPages : totalPostPages\r\n const storeName = activeTab === \\\\\\\'following\\\\\\\' ? \\\\\\\'getFollowingPosts\\\\\\\' : \\\\\\\'getPosts\\\\\\\'\r\n\r\n if (activeTab === \\\\\\\'following\\\\\\\') {\r\n currentFollowingPostsPage++\r\n } else {\r\n currentPostsPage++\r\n }\r\n\r\n const currentPage = activeTab === \\\\\\\'following\\\\\\\' ? currentFollowingPostsPage : currentPostsPage\r\n if (currentPage >= totalPages) {\r\n return\r\n }\r\n\r\n isFetchingPosts = true\r\n\r\n await store.dispatch(storeName, currentPage)\r\n isFetchingPosts = false\r\n})\r\n\r\n$(document).on(\\\\\\\'page:beforein\\\\\\\', \\\\\\\'.page[data-name=\\\"social\\\"]\\\\\\\', function (e) {\r\n const ptrContent = app.ptr.get(\\\\\\\'.ptr-content.home-page\\\\\\\')\r\n ptrContent.on(\\\\\\\'refresh\\\\\\\', async function () {\r\n refreshed = true\r\n const storeName = activeTab === \\\\\\\'following\\\\\\\' ? \\\\\\\'getFollowingPosts\\\\\\\' : \\\\\\\'getPosts\\\\\\\'\r\n\r\n if (isFetchingPosts) return\r\n\r\n isFetchingPosts = true\r\n\r\n if (activeTab === \\\\\\\'following\\\\\\\') {\r\n currentFollowingPostsPage = 1\r\n } else {\r\n currentPostsPage = 1\r\n }\r\n\r\n await store.dispatch(storeName, 1)\r\n\r\n isFetchingPosts = false\r\n app.ptr.done()\r\n })\r\n\r\n app.toolbar.show(\\\\\\\'.toolbar.toolbar-bottom\\\\\\\', true)\r\n})\r\n\r\n/* Based on this http://jsfiddle.net/brettwp/J4djY/*/\r\nexport function detectDoubleTapClosure(callback) {\r\n let lastTap = 0\r\n let timeout\r\n\r\n return function detectDoubleTap(event) {\r\n\r\n const curTime = new Date().getTime()\r\n const tapLen = curTime - lastTap\r\n if (tapLen < 500 && tapLen > 0) {\r\n event.preventDefault()\r\n\r\n // pass the event target to the callback\r\n callback(event.target)\r\n } else {\r\n timeout = setTimeout(() => {\r\n clearTimeout(timeout)\r\n }, 500)\r\n }\r\n\r\n lastTap = curTime\r\n }\r\n}\r\n\r\n// event listener for tab change\r\n$(document).on(\\\\\\\'click\\\\\\\', \\\\\\\'.social-tabs .tab-link\\\\\\\', async function (e) {\r\n const type = this.getAttribute(\\\\\\\'data-type\\\\\\\')\r\n activeTab = type\r\n})\r\n\r\nasync function displayPosts(posts, following = false) {\r\n const postsContainer = $(following ? \\\\\\\'#tab-following .data\\\\\\\' : \\\\\\\'#tab-latest .data\\\\\\\');\r\n\r\n if (refreshed) {\r\n postsContainer.html(\\\\\\\'\\\\\\\')\r\n refreshed = false\r\n }\r\n\r\n const user = await getSessionUser()\r\n\r\n posts.forEach(post => {\r\n let post_actions = `\r\n
\r\n
\r\n ${post.is_liked ? \\\\\\\'heart_fill\\\\\\\' : \\\\\\\'heart\\\\\\\'} \r\n
\r\n \r\n
\r\n paperplane \r\n
\r\n `;\r\n\r\n if (post.user_id == user.id) {\r\n post_actions += `\r\n
\r\n gear_alt \r\n
\r\n `;\r\n }\r\n\r\n post_actions += `
`;\r\n\r\n const date = formatPostDate(post.post_date);\r\n const maxDescriptionLength = 200; // Set your character limit here\r\n const isLongDescription = post.caption.length > maxDescriptionLength;\r\n const shortDescription = isLongDescription ? post.caption.slice(0, maxDescriptionLength) : post.caption;\r\n\r\n let imageHeight = 400;\r\n\r\n if (post.media.length > 0) {\r\n const intrinsicWidth = post.media[0].media_width;\r\n const intrinsicHeight = post.media[0].media_height;\r\n\r\n // Calculate intrinsic aspect ratio\r\n const intrinsicRatio = intrinsicWidth / intrinsicHeight;\r\n\r\n // Calculate the rendered height based on the container width\r\n const renderedHeight = containerWidth / intrinsicRatio;\r\n\r\n // Use either the rendered height or the fallback height\r\n if (renderedHeight > 0) {\r\n\r\n if (renderedHeight > 500) {\r\n imageHeight = 500\r\n } else {\r\n imageHeight = renderedHeight\r\n }\r\n }\r\n\r\n }\r\n\r\n\r\n let profile_link;\r\n\r\n if (post.user_id == user.id) {\r\n profile_link = `\r\n
\r\n
\r\n ${post.username}
\r\n ${date}
\r\n `\r\n } else {\r\n profile_link = `\r\n `\r\n }\r\n\r\n const postItem = `\r\n
\r\n
\r\n ${profile_link}\r\n
\r\n
\r\n
\r\n ${post.media.map(mediaItem => `\r\n
\r\n ${mediaItem.media_type === \\\\\\\'video\\\\\\\' ? \r\n // `\r\n //
\r\n // \r\n // \r\n // `\r\n \\\\\\\'Disabled for testing\\\\\\\'\r\n : `\r\n
\r\n `}\r\n
\r\n `).join(\\\\\\\'\\\\\\\')}\r\n
\r\n \r\n
\r\n
\r\n ${post_actions}\r\n
${post.likes_count} likes
\r\n
\r\n ${post.username} ${shortDescription} \r\n ${post.caption} \r\n ${isLongDescription ? `... more ` : \\\\\\\'\\\\\\\'}\r\n
\r\n ${post.comments_count > 0 ? `` : \\\\\\\'\\\\\\\'}\r\n
\r\n
\r\n `;\r\n\r\n postsContainer.append(postItem);\r\n });\r\n}\r\n\r\nexport function togglePostLikeV1(postId, single = false) {\r\n // Find the post element and its like icon\r\n let container = single ? `.media-post.single[data-post-id=\\\"${postId}\\\"]` : `.media-post[data-post-id=\\\"${postId}\\\"]`\r\n const postElement = document.querySelector(container)\r\n const likeIcon = postElement.querySelector(\\\\\\\'.media-post-like i\\\\\\\')\r\n const isLiked = postElement.getAttribute(\\\\\\\'data-is-liked\\\\\\\') === \\\\\\\'true\\\\\\\'\r\n const likeCountElem = postElement.querySelector(\\\\\\\'.media-post-likecount\\\\\\\')\r\n let likeCount = parseInt(likeCountElem.getAttribute(\\\\\\\'data-like-count\\\\\\\'))\r\n\r\n // Toggle the like state\r\n if (isLiked) {\r\n likeIcon.classList.remove(\\\\\\\'text-red\\\\\\\')\r\n likeIcon.innerText = \\\\\\\'heart\\\\\\\'\r\n likeCount--\r\n postElement.setAttribute(\\\\\\\'data-is-liked\\\\\\\', \\\\\\\'false\\\\\\\')\r\n } else {\r\n likeIcon.classList.add(\\\\\\\'text-red\\\\\\\')\r\n likeIcon.innerText = \\\\\\\'heart_fill\\\\\\\'\r\n likeCount++\r\n postElement.setAttribute(\\\\\\\'data-is-liked\\\\\\\', \\\\\\\'true\\\\\\\')\r\n }\r\n\r\n // Update like count\r\n likeCountElem.innerText = `${likeCount} likes`\r\n likeCountElem.setAttribute(\\\\\\\'data-like-count\\\\\\\', likeCount)\r\n\r\n // Optionally, make an API call to update the like status on the server\r\n // fetch(`/api/posts/${postId}/like`, { method: \\\\\\\'POST\\\\\\\' });\r\n maybeLikePost(postId)\r\n}\r\n\r\nexport function togglePostLike(postId, single = false) {\r\n // Find all post elements with the specified postId\r\n let container = single ? `.media-post.single[data-post-id=\\\"${postId}\\\"]` : `.media-post[data-post-id=\\\"${postId}\\\"]`\r\n const postElements = document.querySelectorAll(container)\r\n\r\n // Iterate through all matching post elements and update them\r\n postElements.forEach(postElement => {\r\n const likeIcon = postElement.querySelector(\\\\\\\'.media-post-like i\\\\\\\')\r\n const isLiked = postElement.getAttribute(\\\\\\\'data-is-liked\\\\\\\') === \\\\\\\'true\\\\\\\'\r\n const likeCountElem = postElement.querySelector(\\\\\\\'.media-post-likecount\\\\\\\')\r\n let likeCount = parseInt(likeCountElem.getAttribute(\\\\\\\'data-like-count\\\\\\\'))\r\n\r\n // Toggle the like state\r\n if (isLiked) {\r\n likeIcon.classList.remove(\\\\\\\'text-red\\\\\\\')\r\n likeIcon.innerText = \\\\\\\'heart\\\\\\\'\r\n likeCount--\r\n postElement.setAttribute(\\\\\\\'data-is-liked\\\\\\\', \\\\\\\'false\\\\\\\')\r\n } else {\r\n likeIcon.classList.add(\\\\\\\'text-red\\\\\\\')\r\n likeIcon.innerText = \\\\\\\'heart_fill\\\\\\\'\r\n likeCount++\r\n postElement.setAttribute(\\\\\\\'data-is-liked\\\\\\\', \\\\\\\'true\\\\\\\')\r\n }\r\n\r\n // Update like count\r\n likeCountElem.innerText = `${likeCount} likes`\r\n likeCountElem.setAttribute(\\\\\\\'data-like-count\\\\\\\', likeCount)\r\n })\r\n\r\n // Optionally, make an API call to update the like status on the server\r\n maybeLikePost(postId)\r\n}\r\n\r\n\r\nfunction displayComments(comments, postId) {\r\n const user = store.getters.user.value\r\n\r\n const commentsContainer = document.getElementById(\\\\\\\'comments-list\\\\\\\')\r\n // reset the comments container\r\n commentsContainer.innerHTML = \\\\\\\'\\\\\\\'\r\n const commentForm = document.getElementById(\\\\\\\'comment-form\\\\\\\')\r\n commentForm.setAttribute(\\\\\\\'data-post-id\\\\\\\', postId)\r\n\r\n if (!comments.length) {\r\n commentsContainer.innerHTML = \\\\\\\'\\\\\\\'\r\n return\r\n }\r\n\r\n comments.forEach(comment => {\r\n const replyItems = comment.replies.length > 0 ? `\r\n ` : \\\\\\\'\\\\\\\';\r\n\r\n let commenter_link = `/profile-view/${comment.user_id}`;\r\n\r\n if (comment.user_id == user.id) {\r\n commenter_link = \\\\\\\'/profile/\\\\\\\';\r\n }\r\n\r\n const deleteButton = comment.user_id == user.id ?\r\n `` : \\\\\\\'\\\\\\\';\r\n\r\n const commentItem = `\r\n \r\n `\r\n commentsContainer.insertAdjacentHTML(\\\\\\\'beforeend\\\\\\\', commentItem)\r\n })\r\n\r\n // Add click event listener for liking a comment\r\n const likeButtons = document.querySelectorAll(\\\\\\\'.comment-like\\\\\\\')\r\n likeButtons.forEach(button => {\r\n button.addEventListener(\\\\\\\'click\\\\\\\', (event) => {\r\n const commentId = event.currentTarget.closest(\\\\\\\'.comment\\\\\\\').getAttribute(\\\\\\\'data-comment-id\\\\\\\')\r\n const ownerId = event.currentTarget.closest(\\\\\\\'.comment\\\\\\\').getAttribute(\\\\\\\'data-owner-id\\\\\\\')\r\n toggleCommentLike(commentId, ownerId)\r\n })\r\n })\r\n}\r\n\r\nfunction toggleCommentLike(commentId, ownerId) {\r\n // Find the comment element and its like icon\r\n const commentElement = document.querySelector(`.comment[data-comment-id=\\\"${commentId}\\\"]`)\r\n const likeIcon = commentElement.querySelector(\\\\\\\'.comment-like i\\\\\\\')\r\n const isLiked = commentElement.getAttribute(\\\\\\\'data-is-liked\\\\\\\') === \\\\\\\'true\\\\\\\'\r\n const likeCountElem = commentElement.querySelector(\\\\\\\'.comment-likes-count\\\\\\\')\r\n let likeCount = parseInt(likeCountElem.getAttribute(\\\\\\\'data-likes-count\\\\\\\'))\r\n\r\n // Toggle the like state\r\n if (isLiked) {\r\n likeIcon.classList.remove(\\\\\\\'text-red\\\\\\\')\r\n likeIcon.innerText = \\\\\\\'heart\\\\\\\'\r\n likeCount--\r\n commentElement.setAttribute(\\\\\\\'data-is-liked\\\\\\\', \\\\\\\'false\\\\\\\')\r\n } else {\r\n likeIcon.classList.add(\\\\\\\'text-red\\\\\\\')\r\n likeIcon.innerText = \\\\\\\'heart_fill\\\\\\\'\r\n likeCount++\r\n commentElement.setAttribute(\\\\\\\'data-is-liked\\\\\\\', \\\\\\\'true\\\\\\\')\r\n }\r\n\r\n // Update like count\r\n likeCountElem.innerText = likeCount\r\n likeCountElem.setAttribute(\\\\\\\'data-likes-count\\\\\\\', likeCount)\r\n\r\n maybeLikeComment(commentId, ownerId)\r\n}\r\n\r\n$(document).on(\\\\\\\'click\\\\\\\', \\\\\\\'.media-post-readmore\\\\\\\', function () {\r\n const postDescription = this.previousElementSibling.previousElementSibling; // The short description\r\n const fullDescription = this.previousElementSibling; // The full description\r\n\r\n if (fullDescription.classList.contains(\\\\\\\'hidden\\\\\\\')) {\r\n postDescription.classList.add(\\\\\\\'hidden\\\\\\\');\r\n fullDescription.classList.remove(\\\\\\\'hidden\\\\\\\');\r\n this.textContent = \\\\\\\'... less\\\\\\\';\r\n } else {\r\n postDescription.classList.remove(\\\\\\\'hidden\\\\\\\');\r\n fullDescription.classList.add(\\\\\\\'hidden\\\\\\\');\r\n this.textContent = \\\\\\\'... more\\\\\\\';\r\n }\r\n});\r\n\r\n$(document).on(\\\\\\\'click\\\\\\\', \\\\\\\'.media-post-like i\\\\\\\', (e) => {\r\n const postId = e.target.getAttribute(\\\\\\\'data-post-id\\\\\\\')\r\n\r\n const parent = e.target.closest(\\\\\\\'.media-post\\\\\\\')\r\n const isSingle = parent.classList.contains(\\\\\\\'single\\\\\\\') ? true : false\r\n\r\n togglePostLike(postId, isSingle)\r\n})\r\n\r\n// set the post id as a data attribute from the edit post popup\r\n$(document).on(\\\\\\\'click\\\\\\\', \\\\\\\'.media-post-edit\\\\\\\', function () {\r\n const postId = $(this).closest(\\\\\\\'.media-post\\\\\\\').attr(\\\\\\\'data-post-id\\\\\\\')\r\n const isSingleView = $(this).closest(\\\\\\\'.media-post\\\\\\\').hasClass(\\\\\\\'single\\\\\\\')\r\n $(\\\\\\\'.edit-post-popup\\\\\\\').attr(\\\\\\\'data-post-id\\\\\\\', postId)\r\n $(\\\\\\\'.edit-post-popup\\\\\\\').attr(\\\\\\\'data-is-single\\\\\\\', isSingleView)\r\n})\r\n\r\n$(document).on(\\\\\\\'click\\\\\\\', \\\\\\\'#delete-post\\\\\\\', function () {\r\n var view = app.views.current\r\n\r\n // set the post id as a data attribute from the edit post popup\r\n const postId = $(\\\\\\\'.edit-post-popup\\\\\\\').attr(\\\\\\\'data-post-id\\\\\\\')\r\n const isSingleView = $(\\\\\\\'.edit-post-popup\\\\\\\').attr(\\\\\\\'data-is-single\\\\\\\')\r\n\r\n app.dialog.confirm(\\\\\\\'Are you sure you want to delete this post?\\\\\\\', \\\\\\\'Delete Post\\\\\\\', async () => {\r\n const response = await deletePost(postId)\r\n\r\n if (response) {\r\n store.dispatch(\\\\\\\'getMyPosts\\\\\\\', {\r\n page: 1,\r\n clear: true\r\n })\r\n store.dispatch(\\\\\\\'getMyTags\\\\\\\', {\r\n page: 1,\r\n clear: true\r\n })\r\n\r\n if (isSingleView) {\r\n view.router.navigate(\\\\\\\'/profile/\\\\\\\')\r\n }\r\n\r\n showToast(\\\\\\\'Post deleted successfully\\\\\\\')\r\n // remove the post from the DOM\r\n $(`.media-post[data-post-id=\\\"${postId}\\\"]`).remove()\r\n app.popup.close(\\\\\\\'.edit-post-popup\\\\\\\')\r\n } else {\r\n showToast(\\\\\\\'Failed to delete post\\\\\\\')\r\n }\r\n })\r\n})\r\n\r\n$(document).on(\\\\\\\'click\\\\\\\', \\\\\\\'#edit-post\\\\\\\', function () {\r\n var view = app.views.current\r\n\r\n // set the post id as a data attribute from the edit post popup\r\n const postId = $(\\\\\\\'.edit-post-popup\\\\\\\').attr(\\\\\\\'data-post-id\\\\\\\')\r\n view.router.navigate(`/post-edit/${postId}`, {\r\n force: true\r\n })\r\n\r\n app.popup.close(\\\\\\\'.edit-post-popup\\\\\\\')\r\n})\r\n\r\n$(document).on(\\\\\\\'touchstart\\\\\\\', \\\\\\\'.media-post-content .swiper-wrapper\\\\\\\', detectDoubleTapClosure((e) => {\r\n return // Disable double tap for now\r\n\r\n const parent = e.closest(\\\\\\\'.media-post\\\\\\\')\r\n const postId = parent.getAttribute(\\\\\\\'data-post-id\\\\\\\')\r\n const isLiked = parent.getAttribute(\\\\\\\'data-is-liked\\\\\\\') === \\\\\\\'true\\\\\\\'\r\n\r\n if (isLiked) {\r\n return\r\n }\r\n\r\n togglePostLike(postId)\r\n}), {\r\n passive: false\r\n})\r\n\r\n// media-post-video click\r\n$(document).on(\\\\\\\'click\\\\\\\', \\\\\\\'.media-post-video\\\\\\\', function () {\r\n if (this.paused) {\r\n this.play()\r\n } else {\r\n this.pause()\r\n }\r\n})\r\n\r\n// on .popup-open click\r\n$(document).on(\\\\\\\'click\\\\\\\', \\\\\\\'.media-post-comment, .media-post-commentcount\\\\\\\', async function () {\r\n const postId = this.getAttribute(\\\\\\\'data-post-id\\\\\\\')\r\n\r\n if (!postId) {\r\n return\r\n }\r\n\r\n document.getElementById(\\\\\\\'comments-list\\\\\\\').innerHTML = \\\\\\\'
\\\\\\\'\r\n document.getElementById(\\\\\\\'comment-form\\\\\\\').reset()\r\n\r\n // update the post id in the comment form\r\n document.getElementById(\\\\\\\'comment-form\\\\\\\').setAttribute(\\\\\\\'data-post-id\\\\\\\', \\\\\\\'\\\\\\\')\r\n document.getElementById(\\\\\\\'comment-form\\\\\\\').removeAttribute(\\\\\\\'data-comment-id\\\\\\\')\r\n\r\n document.getElementById(\\\\\\\'comment-form\\\\\\\').querySelector(\\\\\\\'.replying-to\\\\\\\').innerHTML = \\\\\\\'\\\\\\\'\r\n document.getElementById(\\\\\\\'comment-form\\\\\\\').querySelector(\\\\\\\'.replying-to\\\\\\\').classList.add(\\\\\\\'hidden\\\\\\\')\r\n\r\n try {\r\n const comments = await fetchComments(postId)\r\n displayComments(comments, postId)\r\n } catch (error) {\r\n app.notification.create({\r\n titleRightText: \\\\\\\'now\\\\\\\',\r\n subtitle: \\\\\\\'Oops, something went wrong\\\\\\\',\r\n text: error.message || \\\\\\\'Failed to fetch comments\\\\\\\',\r\n }).open()\r\n }\r\n})\r\n\r\n$(document).on(\\\\\\\'click\\\\\\\', \\\\\\\'.media-post-share\\\\\\\', function () {\r\n // set the post id as a data attribute \r\n const postId = $(this).closest(\\\\\\\'.media-post\\\\\\\').attr(\\\\\\\'data-post-id\\\\\\\')\r\n $(\\\\\\\'.share-popup\\\\\\\').attr(\\\\\\\'data-post-id\\\\\\\', postId)\r\n $(\\\\\\\'#copy-link\\\\\\\').attr(\\\\\\\'data-clipboard-text\\\\\\\', `${window.location.origin}/post-view/${postId}`)\r\n})\r\n\r\n$(document).on(\\\\\\\'click\\\\\\\', \\\\\\\'#share-post-email\\\\\\\', function () {\r\n const postId = $(this).closest(\\\\\\\'.popup\\\\\\\').attr(\\\\\\\'data-post-id\\\\\\\')\r\n const postLink = `${window.location.origin}/post-view/${postId}`\r\n\r\n // open the email composer\r\n window.open(`mailto:?subject=Check out this post&body=${postLink}`)\r\n})\r\n\r\n// data-clipboard-text click\r\n$(document).on(\\\\\\\'click\\\\\\\', \\\\\\\'#copy-link\\\\\\\', function () {\r\n const copyText = $(this).attr(\\\\\\\'data-clipboard-text\\\\\\\')\r\n navigator.clipboard.writeText(copyText)\r\n\r\n app.toast.create({\r\n text: \\\\\\\'Link copied to clipboard\\\\\\\',\r\n closeTimeout: 2000\r\n }).open()\r\n})\r\n\r\n// on .comment-replies-toggle click\r\n$(document).on(\\\\\\\'click\\\\\\\', \\\\\\\'.comment-replies-toggle\\\\\\\', function () {\r\n const commentRepliesContainer = this.nextElementSibling\r\n commentRepliesContainer.classList.toggle(\\\\\\\'show\\\\\\\')\r\n const repliesCount = this.getAttribute(\\\\\\\'data-replies-count\\\\\\\')\r\n\r\n this.innerText = this.innerText === `Show ${repliesCount} replies` ? `Hide ${repliesCount} replies` : `Show ${repliesCount} replies`\r\n})\r\n\r\n// on comment form submit\r\n$(\\\\\\\'#comment-form\\\\\\\').on(\\\\\\\'submit\\\\\\\', async function (e) {\r\n e.preventDefault()\r\n\r\n const postId = this.getAttribute(\\\\\\\'data-post-id\\\\\\\')\r\n const commentId = this.getAttribute(\\\\\\\'data-comment-id\\\\\\\')\r\n const comment = this.comment.value\r\n\r\n if (!comment) {\r\n // app.dialog.alert(\\\\\\\'Please enter a comment\\\\\\\')\r\n return\r\n }\r\n\r\n app.preloader.show()\r\n\r\n try {\r\n const response = await addComment(postId, comment, commentId)\r\n\r\n app.preloader.hide()\r\n\r\n if (response) {\r\n this.reset()\r\n this.removeAttribute(\\\\\\\'data-comment-id\\\\\\\')\r\n this.querySelector(\\\\\\\'.replying-to\\\\\\\').innerHTML = \\\\\\\'\\\\\\\'\r\n this.querySelector(\\\\\\\'.replying-to\\\\\\\').classList.add(\\\\\\\'hidden\\\\\\\')\r\n const comments = await fetchComments(postId)\r\n displayComments(comments, postId)\r\n } else {\r\n app.notification.create({\r\n text: \\\\\\\'Failed to add comment\\\\\\\',\r\n titleRightText: \\\\\\\'now\\\\\\\',\r\n subtitle: \\\\\\\'Oops, something went wrong\\\\\\\',\r\n }).open()\r\n }\r\n } catch (error) {\r\n app.notification.create({\r\n titleRightText: \\\\\\\'now\\\\\\\',\r\n subtitle: \\\\\\\'Oops, something went wrong\\\\\\\',\r\n text: error.message || \\\\\\\'Failed to add comment\\\\\\\',\r\n }).open()\r\n app.preloader.hide()\r\n }\r\n})\r\n\r\n//.comment-reply click\r\n$(document).on(\\\\\\\'click\\\\\\\', \\\\\\\'.comment-reply\\\\\\\', function () {\r\n // get the comment id, and comment owner id\r\n const commentId = this.closest(\\\\\\\'.comment\\\\\\\').getAttribute(\\\\\\\'data-comment-id\\\\\\\')\r\n const ownerId = this.closest(\\\\\\\'.comment\\\\\\\').getAttribute(\\\\\\\'data-owner-id\\\\\\\')\r\n const ownerName = this.closest(\\\\\\\'.comment\\\\\\\').getAttribute(\\\\\\\'data-owner-name\\\\\\\')\r\n\r\n // add something above the comment form to show the user they are replying to a comment\r\n // add the comment id to the form\r\n document.getElementById(\\\\\\\'comment-form\\\\\\\').setAttribute(\\\\\\\'data-comment-id\\\\\\\', commentId)\r\n document.getElementById(\\\\\\\'comment-form\\\\\\\').comment.focus()\r\n\r\n // add the owner name to the form\r\n //
Replying to m88xrk \r\n const replyingTo = document.getElementById(\\\\\\\'comment-form\\\\\\\').querySelector(\\\\\\\'.replying-to\\\\\\\')\r\n replyingTo.innerHTML = `Replying to
${ownerName} `\r\n replyingTo.classList.remove(\\\\\\\'hidden\\\\\\\')\r\n document.getElementById(\\\\\\\'comment-form\\\\\\\').prepend(replyingTo)\r\n})\r\n\r\n$(document).on(\\\\\\\'click\\\\\\\', \\\\\\\'.comment-delete\\\\\\\', async function () {\r\n app.dialog.confirm(\\\\\\\'Are you sure you want to delete this comment? This will remove all replies to this comment\\\\\\\', \\\\\\\'Delete Comment\\\\\\\', async () => {\r\n try {\r\n const commentId = this.getAttribute(\\\\\\\'data-comment-id\\\\\\\')\r\n const response = await deleteComment(commentId)\r\n\r\n if (response && response.success) {\r\n // remove the comment from the DOM\r\n $(`.comment[data-comment-id=\\\"${commentId}\\\"]`).remove()\r\n showToast(\\\\\\\'Comment deleted successfully\\\\\\\')\r\n }\r\n } catch (error) {\r\n app.dialog.alert(\\\\\\\'Failed to delete comment\\\\\\\')\r\n }\r\n })\r\n})\r\n\r\n$(document).on(\\\\\\\'click\\\\\\\', \\\\\\\'.comment a\\\\\\\', function (e) {\r\n var view = app.views.current\r\n // hide the comments popup\r\n app.popup.close()\r\n\r\n // get the href attribute\r\n const href = this.getAttribute(\\\\\\\'data-url\\\\\\\')\r\n\r\n if (!href || href === \\\\\\\'#\\\\\\\') {\r\n return\r\n }\r\n\r\n // prevent the default action\r\n e.preventDefault()\r\n\r\n view.router.navigate(href, {\r\n force: true\r\n })\r\n})');
Fatal error : Uncaught mysqli_sql_exception: Duplicate entry '147' for key 'PRIMARY' in /home/u340524018/domains/agniaga.com/public_html/sub/u2/cp/common.function.php:186
Stack trace:
#0 /home/u340524018/domains/agniaga.com/public_html/sub/u2/cp/common.function.php(186): mysqli_query()
#1 /home/u340524018/domains/agniaga.com/public_html/sub/u2/cp/inc.filejs.php(86): Insert()
#2 /home/u340524018/domains/agniaga.com/public_html/sub/u2/cp/index.php(286): include('/home/u34052401...')
#3 {main}
thrown in
/home/u340524018/domains/agniaga.com/public_html/sub/u2/cp/common.function.php on line
186