Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions src/components/patterns/Sidebar/SidebarVersionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ export class SidebarVersionManager {
}

setup(): void {
const versionSwitchers = this.sidebar.querySelectorAll(
'[data-version-switcher] select, [data-version-select]'
);
const versionSwitchers = this.sidebar.querySelectorAll('[data-version-switcher]');

versionSwitchers.forEach((switcher) => {
switcher.addEventListener('change', (e) => {
const select = e.target as HTMLSelectElement;
this.handleVersionChange(select.value);
});
switcher.addEventListener('select-change', ((e: CustomEvent<{ value: string }>) => {
this.handleVersionChange(e.detail.value);
}) as EventListener);
});
}

Expand Down Expand Up @@ -129,17 +126,4 @@ export class SidebarVersionManager {
updatePath(path: string[]): void {
this.activeSubmenuPath = path;
}

getVersion(): string {
return this.currentVersion;
}

setVersion(version: string): void {
const versionSelects =
this.sidebar.querySelectorAll<HTMLSelectElement>('[data-version-select]');
versionSelects.forEach((select) => {
select.value = version;
});
this.handleVersionChange(version);
}
Comment on lines -133 to -144

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These are unused, so I removed them.

}
36 changes: 0 additions & 36 deletions src/components/patterns/VersionSwitcher/VersionSwitcher.astro
Original file line number Diff line number Diff line change
Expand Up @@ -72,42 +72,6 @@ const selectOptions: SelectOption[] = versions.map((version) => ({
size="md"
variant="default"
fullWidth
data-version-select
aria-label={t('version.selectLabel')}
/>
</Flex>

<script>
function handleVersionChange(event: Event) {
const customEvent = event as CustomEvent<{ value: string }>;
const newVersion = customEvent.detail.value;
const currentPath = window.location.pathname;

const pathParts = currentPath.split('/').filter(Boolean);

const versionIndex = pathParts.findIndex((part) => /^\d+x$/.test(part));

if (versionIndex !== -1) {
pathParts[versionIndex] = newVersion;
} else if (pathParts.length >= 2) {
pathParts.splice(1, 0, newVersion);
}

window.location.href = '/' + pathParts.join('/');
}

function initVersionSwitcher() {
const versionSwitchers = document.querySelectorAll('[data-version-switcher]');

versionSwitchers.forEach((versionSwitcher) => {
const selectContainer = versionSwitcher.querySelector('[data-select-container]');
if (!selectContainer) return;

selectContainer.removeEventListener('select-change', handleVersionChange);
selectContainer.addEventListener('select-change', handleVersionChange);
});
}

initVersionSwitcher();
document.addEventListener('astro:page-load', initVersionSwitcher);
</script>
Loading