diff --git a/app/static/js/gallery-infinite.js b/app/static/js/gallery-infinite.js index e1d03d4..5a67473 100644 --- a/app/static/js/gallery-infinite.js +++ b/app/static/js/gallery-infinite.js @@ -20,7 +20,8 @@ isLoading: false, hasMore: true, cursor: null, - activeTag: null, + activeTag: null, // display string, used for human-facing bits + activeTagId: null, // integer id, authoritative for filter API calls loadedSections: new Set(), // year_month keys of loaded sections timelineData: [], currentVisibleSection: null, @@ -53,6 +54,16 @@ state.activeTag = window.galleryState.activeTag; } + // Read tag_id from the current URL — that's what the backend filtered by + // for the initial render, and what the scroll/timeline/jump APIs now + // expect after the ?tag= -> ?tag_id= switch. + const urlParams = new URLSearchParams(window.location.search); + const tagIdRaw = urlParams.get('tag_id'); + if (tagIdRaw) { + const n = parseInt(tagIdRaw, 10); + if (!isNaN(n)) state.activeTagId = n; + } + // Track initially loaded sections parseInitialSections(); @@ -93,8 +104,8 @@ if (state.cursor) { params.set('cursor', state.cursor); } - if (state.activeTag) { - params.set('tag', state.activeTag); + if (state.activeTagId) { + params.set('tag_id', String(state.activeTagId)); } const response = await fetch(`/api/gallery/scroll?${params}`); @@ -289,7 +300,7 @@ // Timeline functions async function loadTimeline() { try { - const params = state.activeTag ? `?tag=${encodeURIComponent(state.activeTag)}` : ''; + const params = state.activeTagId ? `?tag_id=${state.activeTagId}` : ''; const response = await fetch(`/api/gallery/timeline${params}`); const data = await response.json(); @@ -386,8 +397,8 @@ limit: CONFIG.BATCH_SIZE }); - if (state.activeTag) { - params.set('tag', state.activeTag); + if (state.activeTagId) { + params.set('tag_id', String(state.activeTagId)); } const response = await fetch(`/api/gallery/jump?${params}`);