Hi developers,
I'd like to get your feedback on the visibility logic for a modern footer extension I'm working on. This code allows me to control on which Flarum pages the footer is displayed.
Here's the a part of code:
import app from 'flarum/forum/app';
import Component from 'flarum/common/Component';
import IndexPage from 'flarum/components/IndexPage';
import DiscussionPage from 'flarum/components/DiscussionPage';
import UserPage from 'flarum/components/UserPage';
export default class CustomFooter extends Component {
oninit(vnode) {
super.oninit(vnode);
this.displayMode = parseInt(app.forum.attribute('modern-footer.display-mode'));
}
view() {
const showFooter = this.shouldShowFooter(this.displayMode);
if (!showFooter) {
return null;
}
// Footer content will go here
return (
<footer className="CustomFooter">
<div className="container">
{/* Footer content will go here */}
</div>
</footer>
);
}
shouldShowFooter(displayMode) {
const currentRoute = app.current.get('routeName');
const mainRoute = currentRoute ? currentRoute.split('.')[0] : '';
switch (displayMode) {
case 0: // show all
return true;
case 1: // hide all
return false;
case 2: // hide discussion
return mainRoute !== 'discussion';
case 3: // except index and hide all
return mainRoute === 'index';
case 4: // custom mode
default:
return true;
}
}
}
The code currently works without any problems. Moreover, during page transitions, it is hidden and shown as desired without the need to refresh the page.
I'm particularly interested in feedback on the shouldShowFooter method. I want to make sure this method is efficient, correct, and follows Flarum's best practices. Any suggestions for improvement?
Thanks!