From dc94262bfb0c8b071544200ee73535de993264c3 Mon Sep 17 00:00:00 2001 From: Asaf Gartner Date: Sun, 7 Aug 2022 00:45:07 +0300 Subject: [PATCH] Snippets edited on a project page can't be disassociated from that project on that page. --- public/js/snippetedit.js | 18 +++++++++++------- src/templates/src/project_homepage.html | 4 ++-- src/templates/src/user_profile.html | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/public/js/snippetedit.js b/public/js/snippetedit.js index 6cc81ed5..10950327 100644 --- a/public/js/snippetedit.js +++ b/public/js/snippetedit.js @@ -16,7 +16,7 @@ function readableByteSize(numBytes) { return new Intl.NumberFormat([], { maximumFractionDigits: (scale > 0 ? 2 : 0) }).format(numBytes) + scales[scale]; } -function makeSnippetEdit(ownerName, ownerAvatar, ownerUrl, date, text, attachmentElement, projectIds, snippetId, originalSnippetEl) { +function makeSnippetEdit(ownerName, ownerAvatar, ownerUrl, date, text, attachmentElement, projectIds, stickyProjectId, snippetId, originalSnippetEl) { let snippetEdit = snippetEditTemplate(); let projectSelector = null; let originalAttachment = null; @@ -60,10 +60,14 @@ function makeSnippetEdit(ownerName, ownerAvatar, ownerUrl, date, text, attachmen projEl.projectId.value = proj.id; projEl.projectLogo.src = proj.logo; projEl.projectName.textContent = proj.name; - projEl.removeButton.addEventListener("click", function(ev) { - projEl.root.remove(); - updateProjectSelector(); - }); + if (proj.id == stickyProjectId) { + projEl.removeButton.remove(); + } else { + projEl.removeButton.addEventListener("click", function(ev) { + projEl.root.remove(); + updateProjectSelector(); + }); + } snippetEdit.projectList.appendChild(projEl.root); } @@ -338,7 +342,7 @@ function makeSnippetEdit(ownerName, ownerAvatar, ownerUrl, date, text, attachmen return snippetEdit; } -function editTimelineSnippet(timelineItemEl) { +function editTimelineSnippet(timelineItemEl, stickyProjectId) { let ownerName = timelineItemEl.querySelector(".user")?.textContent; let ownerUrl = timelineItemEl.querySelector(".user")?.href; let ownerAvatar = timelineItemEl.querySelector(".avatar-icon")?.src; @@ -353,7 +357,7 @@ function editTimelineSnippet(timelineItemEl) { projectIds.push(projid); } } - let snippetEdit = makeSnippetEdit(ownerName, ownerAvatar, ownerUrl, creationDate, rawDesc, attachment, projectIds, timelineItemEl.getAttribute("data-id"), timelineItemEl); + let snippetEdit = makeSnippetEdit(ownerName, ownerAvatar, ownerUrl, creationDate, rawDesc, attachment, projectIds, stickyProjectId, timelineItemEl.getAttribute("data-id"), timelineItemEl); timelineItemEl.parentElement.insertBefore(snippetEdit.root, timelineItemEl); timelineItemEl.remove(); } diff --git a/src/templates/src/project_homepage.html b/src/templates/src/project_homepage.html index bca81d95..b7ff3d99 100644 --- a/src/templates/src/project_homepage.html +++ b/src/templates/src/project_homepage.html @@ -103,7 +103,7 @@ const currentProjectId = {{ .Project.ID }}; document.querySelector(".create_snippet_link")?.addEventListener("click", function() { - let snippetEdit = makeSnippetEdit(userName, userAvatar, userUrl, new Date(), "", null, [currentProjectId], null, null); + let snippetEdit = makeSnippetEdit(userName, userAvatar, userUrl, new Date(), "", null, [currentProjectId], currentProjectId, null, null); document.querySelector(".timeline").insertBefore(snippetEdit.root, document.querySelector(".timeline").children[0]); document.querySelector(".create_snippet_link")?.remove(); }); @@ -115,7 +115,7 @@ parent = parent.parentElement; } if (parent && parent.classList.contains("timeline-item")) { - editTimelineSnippet(parent); + editTimelineSnippet(parent, currentProjectId); } } }); diff --git a/src/templates/src/user_profile.html b/src/templates/src/user_profile.html index d6a99ad3..7994c850 100644 --- a/src/templates/src/user_profile.html +++ b/src/templates/src/user_profile.html @@ -175,7 +175,7 @@ {{ if .OwnProfile }} document.querySelector(".create_snippet_link")?.addEventListener("click", function() { - let snippetEdit = makeSnippetEdit(userName, userAvatar, userUrl, new Date(), "", null, [], null, null); + let snippetEdit = makeSnippetEdit(userName, userAvatar, userUrl, new Date(), "", null, [], null, null, null); document.querySelector(".timeline").insertBefore(snippetEdit.root, document.querySelector(".timeline").children[0]); document.querySelector(".create_snippet_link")?.remove(); }); @@ -188,7 +188,7 @@ parent = parent.parentElement; } if (parent && parent.classList.contains("timeline-item")) { - editTimelineSnippet(parent); + editTimelineSnippet(parent, null); } } });