Skip to content

Commit

Permalink
feat: add button to return to channels in mobile boards page
Browse files Browse the repository at this point in the history
  • Loading branch information
dy0gu committed Jan 9, 2025
1 parent 9f3370b commit cf1d7da
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions web/src/scripts/boards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Adds a button to return to the channels page from the mobile boards page
function handleButton() {
const sidebar = document.querySelector(".Sidebar.octo-sidebar");
if (!sidebar || sidebar.closest("#focalboard-app") === null) {
return;
}
if (window.innerWidth < 770) {
// Look for the expected HTML structure
const workspaceTitle = document.querySelector(".WorkspaceTitle");
if (workspaceTitle && !sidebar.classList.contains("hidden")) {
const sidebarSwitcher = workspaceTitle.querySelector(".sidebarSwitcher");
if (sidebarSwitcher) {
// Check if the button is already appended
if (!workspaceTitle.querySelector(".back-button-freemium")) {
const backButton = document.createElement("button");
backButton.textContent = "🏠";
backButton.className = "back-button-freemium";
backButton.style.backgroundColor = "transparent";
backButton.style.border = "none";
backButton.style.marginLeft = "10px";

backButton.addEventListener("click", () => {
window.location.href = window.location.origin;
});

// Append the button as a sibling of the sidebarSwitcher
const last = sidebarSwitcher.parentNode.lastChild;
if (last) {
sidebarSwitcher.parentNode.insertBefore(backButton, last);
}
}
}
}
}
if (window.innerWidth >= 770 || sidebar.classList.contains("hidden")) {
const backButton = document.querySelector(".back-button-freemium");
if (backButton) {
backButton.remove();
}
}
}

export default function main() {
// Use mutation observer to detect sidebar opening
const target = document.body;
const callback = (mutations: MutationRecord[]) => {
for (const mutation of mutations) {
if (mutation.type === "childList" || mutation.type === "attributes") {
handleButton();
}
}
};
const observer = new MutationObserver(callback);
const config = {
childList: true,
attributes: true,
subtree: true,
};
observer.observe(target, config);
}

0 comments on commit cf1d7da

Please sign in to comment.