TB54 this is the code exactly as it was at the end of the video.
You won't be able to insert it in the header directly though, you need to compile it with Webpack and the Flarum Webpack configuration.
import app from 'flarum/forum/app';
import {extend} from 'flarum/common/extend';
import IndexPage from 'flarum/forum/components/IndexPage';
import ItemList from 'flarum/common/utils/ItemList';
import TagLinkButton from 'flarum/tags/forum/components/TagLinkButton';
app.initializers.add('mysite/local-hide-secondary-tags', () => {
extend(IndexPage.prototype, 'navItems', function (items: ItemList) {
Object.keys(items.items).forEach(key => {
// Find tags based on ItemList key + store data
const match = /tag([0-9]+)/.exec(key);
if (match) {
const tag = app.store.getById('tags', match[1]);
if (tag.position() === null) {
items.remove(key);
}
}
// Find tags based on component and component attributes
/*const vdom = items.get(key);
if (vdom && vdom.tag && vdom.tag === TagLinkButton) {
if (vdom.attrs.model.position() === null) {
items.remove(key);
}
}*/
});
items.remove('moreTags');
});
});