feat(docs): mobile UX improvements for docs page

On mobile (<1024px), skip auto-loading first document so users see the
sidebar category browser. Add sticky blue navigation bar showing current
document title. Expand all categories by default on mobile initial view.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
TheFlow 2026-02-23 07:44:25 +13:00
parent 8323cca70a
commit 7e0938f841

View file

@ -272,10 +272,10 @@ function updatePageUI(lang = currentLanguage) {
} }
}); });
// Update Back to Documents button // Update Back to Documents bar label
const backBtn = document.querySelector('#back-to-docs-btn span'); const backLabel = document.querySelector('#back-to-docs-btn [data-back-label]');
if (backBtn) { if (backLabel) {
backBtn.textContent = t.backToDocuments; backLabel.textContent = t.documentsHeading;
} }
// Update Select Document placeholder (if visible) // Update Select Document placeholder (if visible)
@ -706,11 +706,15 @@ async function loadDocuments() {
const t = getUITranslations(currentLanguage); const t = getUITranslations(currentLanguage);
// On mobile with no ?doc= param, expand all categories for browsing
const isMobileView = window.innerWidth < 1024;
const noDocParam = !new URLSearchParams(window.location.search).get('doc');
sortedCategories.forEach(([categoryId, category]) => { sortedCategories.forEach(([categoryId, category]) => {
const docs = grouped[categoryId] || []; const docs = grouped[categoryId] || [];
if (docs.length === 0) return; if (docs.length === 0) return;
const isCollapsed = category.collapsed || false; const isCollapsed = (isMobileView && noDocParam) ? false : (category.collapsed || false);
const categoryLabel = t.categories[categoryId] || categoryId; const categoryLabel = t.categories[categoryId] || categoryId;
// Category header // Category header
@ -838,23 +842,26 @@ async function loadDocuments() {
} }
// Priority 3: Default behavior // Priority 3: Default behavior
else { else {
// Default: Auto-load first document in "Getting Started" category (order: 1) // On mobile, show sidebar (don't auto-load) so user can browse categories
const gettingStartedDocs = grouped['getting-started'] || []; const isMobile = window.innerWidth < 1024;
if (gettingStartedDocs.length > 0) { if (!isMobile) {
// Load the first document (order: 1) if available // Desktop: auto-load first Getting Started doc as before
const firstDoc = gettingStartedDocs.find(d => d.order === 1); const gettingStartedDocs = grouped['getting-started'] || [];
if (firstDoc) { if (gettingStartedDocs.length > 0) {
loadDocument(firstDoc.slug); const firstDoc = gettingStartedDocs.find(d => d.order === 1);
} else { if (firstDoc) {
loadDocument(gettingStartedDocs[0].slug); loadDocument(firstDoc.slug);
} } else {
} else if (documents.length > 0) { loadDocument(gettingStartedDocs[0].slug);
// Fallback to first available document in any category }
const firstCategory = sortedCategories.find(([catId]) => grouped[catId] && grouped[catId].length > 0); } else if (documents.length > 0) {
if (firstCategory) { const firstCategory = sortedCategories.find(([catId]) => grouped[catId] && grouped[catId].length > 0);
loadDocument(grouped[firstCategory[0]][0].slug); if (firstCategory) {
loadDocument(grouped[firstCategory[0]][0].slug);
}
} }
} }
// Mobile: sidebar remains visible, user taps to choose a document
} }
} catch (error) { } catch (error) {
console.error('Error loading documents:', error); console.error('Error loading documents:', error);
@ -1012,6 +1019,12 @@ async function loadDocument(slug, lang = null) {
// Mobile navigation: Add document-active class to show document view // Mobile navigation: Add document-active class to show document view
document.body.classList.add('document-active'); document.body.classList.add('document-active');
// Update mobile sticky bar with current document title
const mobileDocTitle = document.getElementById('mobile-doc-title');
if (mobileDocTitle && currentDocument) {
mobileDocTitle.textContent = currentDocument.title;
}
// Scroll to top // Scroll to top
window.scrollTo({ top: 0, behavior: 'smooth' }); window.scrollTo({ top: 0, behavior: 'smooth' });