feat: show/hide categories on world page, #13255

This commit is contained in:
Julian Lam
2025-04-09 11:50:24 -04:00
parent d58d5861d9
commit 804208b7b5
2 changed files with 38 additions and 1 deletions

View File

@@ -14,5 +14,8 @@
"onboard.title": "Your window to the fediverse...", "onboard.title": "Your window to the fediverse...",
"onboard.what": "This is your personalized category made up of only content found outside of this forum. Whether something shows up in this page depends on whether you follow them, or whether that post was shared by someone you follow.", "onboard.what": "This is your personalized category made up of only content found outside of this forum. Whether something shows up in this page depends on whether you follow them, or whether that post was shared by someone you follow.",
"onboard.why": "There's a lot that goes on outside of this forum, and not all of it is relevant to your interests. That's why following people is the best way to signal that you want to see more from someone.", "onboard.why": "There's a lot that goes on outside of this forum, and not all of it is relevant to your interests. That's why following people is the best way to signal that you want to see more from someone.",
"onboard.how": "In the meantime, you can click on the shortcut buttons at the top to see what else this forum knows about, and start discovering some new content!" "onboard.how": "In the meantime, you can click on the shortcut buttons at the top to see what else this forum knows about, and start discovering some new content!",
"show-categories": "Show categories",
"hide-categories": "Hide categories"
} }

View File

@@ -11,6 +11,7 @@ define('forum/world', ['topicList', 'search', 'sort', 'hooks', 'alerts', 'api',
handleIgnoreWatch(-1); handleIgnoreWatch(-1);
handleHelp(); handleHelp();
handleCategories();
search.enableQuickSearch({ search.enableQuickSearch({
searchElements: { searchElements: {
@@ -81,5 +82,38 @@ define('forum/world', ['topicList', 'search', 'sort', 'hooks', 'alerts', 'api',
}); });
} }
function handleCategories() {
// const optionsEl = document.getElementById('category-options');
// const dropdownEl = optionsEl.querySelector('ul');
const showEl = document.getElementById('show-categories');
const hideEl = document.getElementById('hide-categories');
const categoriesEl = document.querySelector('.categories-list');
if (![showEl, hideEl, categoriesEl].every(Boolean)) {
return;
}
const update = () => {
showEl.classList.toggle('hidden', visibility);
hideEl.classList.toggle('hidden', !visibility);
categoriesEl.classList.toggle('hidden', !visibility);
localStorage.setItem('world:show-categories', visibility);
}
let visibility = localStorage.getItem('world:show-categories');
console.log('got value', visibility);
visibility = visibility ? visibility === 'true' : true; // localStorage values are strings
update();
showEl.addEventListener('click', () => {
visibility = true;
update();
});
hideEl.addEventListener('click', () => {
visibility = false;
update();
});
}
return World; return World;
}); });