Skip to content

add toggle to switch between old and new UI#410

Open
hannessolo wants to merge 3 commits into
mainfrom
ew-toggle
Open

add toggle to switch between old and new UI#410
hannessolo wants to merge 3 commits into
mainfrom
ew-toggle

Conversation

@hannessolo
Copy link
Copy Markdown
Contributor

@aem-code-sync
Copy link
Copy Markdown

aem-code-sync Bot commented Apr 30, 2026

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-sync branch
Commits

Comment thread nx/blocks/nav/toggle.js
import { daFetch } from '../../utils/daFetch.js';

const TOGGLE_MAP = { '/edit': '/canvas', '/canvas': '/edit', '/browse': '/', '/': '/browse' };
const cache = {};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this grow for ever? if a user navigates through many org/site combos, entries accumulate for the session lifetime. not critical, but worth noting and also for me to better understand the da architecture in general.

Comment thread nx/blocks/nav/toggle.js
};

check();
window.addEventListener('hashchange', check);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never removed? if the nav component disconnects and reconnects, we get duplicate listeners. we need cleanup in disconnectedCallback.

Comment thread nx/blocks/nav/toggle.js
.then((r) => (r?.ok ? r.json() : null))
.then((json) => {
const sheet = json?.data?.data ?? json?.data;
return !!sheet?.find(({ key: k, value }) => k === 'nx-toggle' && value === 'true');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this may be nit, because I genuinely dislike single letter named vars. I understand that in sheet?.find(({ key: k, value }) => ...). k is used to avoid shadowing the outer key param. fair reason but confusing to read. why not rename the outer const to cacheKey?

Comment thread nx/blocks/nav/nav.css
height: 20px;
}

.nx-nav-toggle {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So many magic numbers....

Comment thread nx/blocks/nav/nav.css
}

.nx-nav-toggle:hover {
background: #e1e1e1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

background: #e1e1e1. no token, no light-dark(). won't this look wrong in the dark mode?

Comment thread nx/blocks/nav/toggle.js
btn.className = 'nx-nav-toggle';
btn.innerHTML = `<svg class="icon"><use href="#S2IconLayout20N-icon"/></svg><span>${label}</span>`;
btn.addEventListener('click', () => {
const { pathname: p, hash: h, search } = window.location;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the listener closure captures pathname at call time via window.location. that's fine. but if the toggle is created once and the user navigates, the label ("Old UI"/"New UI") goes stale. is the toggle re-created on every hashchange? (looks like yes, via remove + re-add, so probably ok.)

Comment thread nx/blocks/nav/toggle.js
const label = (pathname === '/canvas' || pathname === '/browse') ? 'Old UI' : 'New UI';
const btn = document.createElement('button');
btn.className = 'nx-nav-toggle';
btn.innerHTML = `<svg class="icon"><use href="#S2IconLayout20N-icon"/></svg><span>${label}</span>`;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btn.innerHTML = <svg...>${label}is safe here sincelabel is from a hardcoded ternary. but innerHTML with dynamic content is a pattern to generally avoid..

Comment thread nx/blocks/nav/nav.js
}

class Nav extends HTMLElement {
constructor() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async connectedCallback() is risky... if loadNav() throws, the rejection is unhandled (no caller awaits the lifecycle method). also, setupToggle now runs only after loadNav finishes, meaning the toggle won't show until nav fully loads. is that intentional? why not fire-and-forget setupToggle independently?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants