Skip to content

Commit e173a76

Browse files
claudesimonw
authored andcommitted
Add URL parameter for view mode in Bluesky thread viewer
The view mode (thread/recent) is now persisted in the URL as a `view` parameter. This allows users to refresh the page and maintain their selected view mode. Changes: - Tab clicks update URL with current view - Form submission preserves view mode in URL - Page load reads view parameter to restore state
1 parent 92786b6 commit e173a76

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

bluesky-thread.html

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ <h1>Bluesky Thread Viewer</h1>
330330
currentView = view;
331331
viewTabs.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
332332
e.target.classList.add('active');
333+
// Update URL with current view
334+
const newUrl = new URL(window.location);
335+
newUrl.searchParams.set('view', view);
336+
history.replaceState(null, '', newUrl);
333337
renderCurrentView();
334338
}
335339
}
@@ -368,14 +372,10 @@ <h1>Bluesky Thread Viewer</h1>
368372
viewTabs.style.display = 'none';
369373
lastThread = null;
370374
allPosts = [];
371-
currentView = 'thread';
372-
// Reset tabs to default
373-
viewTabs.querySelectorAll('.tab').forEach(t => {
374-
t.classList.toggle('active', t.dataset.view === 'thread');
375-
});
376-
// Update URL with the submitted post URL
375+
// Update URL with the submitted post URL and current view
377376
const newUrl = new URL(window.location);
378377
newUrl.searchParams.set('url', postUrl.value.trim());
378+
newUrl.searchParams.set('view', currentView);
379379
history.replaceState(null, '', newUrl);
380380
try {
381381
const url = new URL(postUrl.value.trim());
@@ -413,9 +413,17 @@ <h1>Bluesky Thread Viewer</h1>
413413
}
414414
});
415415

416-
// Check for ?url= query parameter on page load
416+
// Check for query parameters on page load
417417
const params = new URLSearchParams(window.location.search);
418418
const urlParam = params.get('url');
419+
const viewParam = params.get('view');
420+
// Initialize view from URL parameter if valid
421+
if (viewParam === 'thread' || viewParam === 'recent') {
422+
currentView = viewParam;
423+
viewTabs.querySelectorAll('.tab').forEach(t => {
424+
t.classList.toggle('active', t.dataset.view === viewParam);
425+
});
426+
}
419427
if (urlParam) {
420428
postUrl.value = urlParam;
421429
form.requestSubmit();

0 commit comments

Comments
 (0)