diff --git a/js/src/forum/components/SolvedFilter.tsx b/js/src/forum/components/SolvedFilter.tsx index ec60528..f3060d0 100644 --- a/js/src/forum/components/SolvedFilter.tsx +++ b/js/src/forum/components/SolvedFilter.tsx @@ -3,10 +3,16 @@ import Component, { ComponentAttrs } from 'flarum/common/Component'; import Dropdown from 'flarum/common/components/Dropdown'; import Button from 'flarum/common/components/Button'; -export interface SolvedFilterAttrs extends ComponentAttrs {} +import type Mithril from 'mithril'; +import type Tag from 'flarum/tags/common/models/Tag'; +export interface SolvedFilterAttrs extends ComponentAttrs { + alwaysShow?: boolean; +} export default class SolvedFilter extends Component { view() { + if (!this.shouldShowFilter()) return null; + const selected = app.discussions.bestAnswer as unknown as number; const options = ['all', 'solved', 'unsolved']; @@ -39,4 +45,24 @@ export default class SolvedFilter extends Component { }) ); } + + shouldShowFilter() { + const { alwaysShow } = this.attrs; + + if (alwaysShow) return true; + + if (!app.forum.attribute('showBestAnswerFilterUi')) return false; + + const tag: Tag = app.current.get('tag'); + + if (!tag?.isQnA?.()) { + if (app.discussions.bestAnswer) { + delete app.discussions.bestAnswer; + app.discussions.refresh(); + } + return false; + } + + return true; + } } diff --git a/js/src/forum/extenders/extendIndexPage.tsx b/js/src/forum/extenders/extendIndexPage.tsx index aa12ca9..f769d08 100644 --- a/js/src/forum/extenders/extendIndexPage.tsx +++ b/js/src/forum/extenders/extendIndexPage.tsx @@ -21,21 +21,6 @@ export default function extendIndexPage() { }); extend(IndexPage.prototype, 'viewItems', function (items) { - if (!app.forum.attribute('showBestAnswerFilterUi')) { - return; - } - - const tag = this.currentTag(); - - if (!tag?.isQnA?.()) { - if (app.discussions.bestAnswer) { - delete app.discussions.bestAnswer; - app.discussions.refresh(); - } - - return; - } - items.add('solved-filter', ); }); }