Skip to content

Commit

Permalink
chore: typescript refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideIadeluca committed Oct 16, 2024
1 parent 6c74ed9 commit 6074cc6
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 53 deletions.
File renamed without changes.
File renamed without changes.
30 changes: 0 additions & 30 deletions js/src/forum/extenders/addFrontPage.js

This file was deleted.

31 changes: 31 additions & 0 deletions js/src/forum/extenders/addFrontPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import app from 'flarum/forum/app';
import { extend } from 'flarum/common/extend';
import DiscussionControls from 'flarum/forum/utils/DiscussionControls';
import Button from 'flarum/common/components/Button';

import type Discussion from 'flarum/common/models/Discussion';
import type Mithril from 'mithril';
import type ItemList from 'flarum/common/utils/ItemList';

export default function addFrontPage() {
extend(DiscussionControls, 'moderationControls', function (items: ItemList<Mithril.Children>, discussion: Discussion) {
if (!discussion.front()) return;

let isFront = discussion.frontpage();

items.add(
'frontpage',
<Button
icon="fas fa-home"
onclick={() => {
isFront = !isFront;
discussion.save({ frontpage: isFront });
}}
>
{app.translator.trans(
discussion.frontpage() ? 'core.forum.post_controls.pull_from_front_button' : 'core.forum.post_controls.push_to_front_button'
)}
</Button>
);
});
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { extend } from 'flarum/common/extend';
import DiscussionListState from 'flarum/forum/states/DiscussionListState';

import type { PaginatedListParams } from 'flarum/common/states/PaginatedListState';

export default function () {
extend(DiscussionListState.prototype, 'requestParams', function (params) {
extend(DiscussionListState.prototype, 'requestParams', function (this: DiscussionListState, params: PaginatedListParams) {
if (this.params.sort === 'front') {
if (params.filter.q) {
params.filter.q = (params.filter.q || '') + 'is:frontpage';
Expand All @@ -12,7 +14,7 @@ export default function () {
}
});

extend(DiscussionListState.prototype, 'sortMap', function (map) {
extend(DiscussionListState.prototype, 'sortMap', function (map: Record<string, string>) {
map.front = '-frontdate';
});
}
21 changes: 0 additions & 21 deletions js/src/forum/extenders/addStickyBadge.js

This file was deleted.

15 changes: 15 additions & 0 deletions js/src/forum/extenders/addStickyBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import app from 'flarum/forum/app';
import { extend } from 'flarum/common/extend';
import Discussion from 'flarum/common/models/Discussion';
import Badge from 'flarum/common/components/Badge';

import type ItemList from 'flarum/common/utils/ItemList';
import type Mithril from 'mithril';

export default function addStickyBadge() {
extend(Discussion.prototype, 'badges', function (badges: ItemList<Mithril.Children>) {
if (!this.frontpage()) return;

badges.add('frontpage', <Badge type="frontpage" label={app.translator.trans('core.forum.badge.frontpage_tooltip')} icon="fas fa-home" />, 10);
});
}

0 comments on commit 6074cc6

Please sign in to comment.