Skip to content

Commit

Permalink
Remove unneccessary code that caused conflicts with other extensions …
Browse files Browse the repository at this point in the history
…also extending viewItems (#52)
  • Loading branch information
imorland committed Nov 1, 2021
1 parent c6ee131 commit 7122f1e
Showing 1 changed file with 0 additions and 53 deletions.
53 changes: 0 additions & 53 deletions js/src/forum/addHotnessSort.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,9 @@
import { extend } from 'flarum/common/extend';
import IndexPage from 'flarum/forum/components/IndexPage';
import ItemList from 'flarum/common/utils/ItemList';
import DiscussionListState from 'flarum/forum/states/DiscussionListState';
import Dropdown from 'flarum/common/components/Dropdown';
import Button from 'flarum/common/components/Button';
import LinkButton from 'flarum/common/components/LinkButton';

export default function () {
IndexPage.prototype.viewItems = function () {
const items = new ItemList();
const sortMap = app.discussions.sortMap();

const sortOptions = {};
for (const i in sortMap) {
sortOptions[i] = app.translator.trans('core.forum.index_sort.' + i + '_button');
}

let dropDownLabel = sortOptions[app.search.params().sort] || Object.keys(sortMap).map((key) => sortOptions[key])[0];

if (/^.*?\/hot/.test(m.route.get())) {
dropDownLabel = app.translator.trans('core.forum.index_sort.hot_button');
}

items.add(
'sort',
Dropdown.component(
{
buttonClassName: 'Button',
label: dropDownLabel,
},
Object.keys(sortOptions).map((value) => {
const label = sortOptions[value];
let active = (app.search.params().sort || Object.keys(sortMap)[0]) === value;

if (/^.*?\/hot/.test(m.route.get()) && value === 'hot') {
active = true;
}

if (/^.*?\/hot/.test(m.route.get()) && value === 'latest') {
active = false;
m.redraw();
}

return Button.component(
{
icon: active ? 'fas fa-check' : true,
onclick: app.search.changeSort.bind(app.search, value),
active: active,
},
label
);
})
)
);

return items;
};

extend(IndexPage.prototype, 'navItems', function (items) {
if (!app.session.user || app.session.user.data.attributes.canViewRankingPage !== true) {
return;
Expand Down

0 comments on commit 7122f1e

Please sign in to comment.