Repo maintenance (#30)

* Bump deps; add TS support; use Prettier

* Format

* Update js/package.json

Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>

* Update lockfile

Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
David Wheatley 2021-09-20 16:06:32 +01:00 committed by GitHub
parent 3e962c5e0f
commit 3e3fa6535d
8 changed files with 4317 additions and 2543 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,21 @@
{ {
"private": true, "private": true,
"name": "@flarum/sticky", "name": "@flarum/sticky",
"prettier": "@flarum/prettier-config",
"dependencies": { "dependencies": {
"flarum-webpack-config": "0.1.0-beta.10", "flarum-webpack-config": "^1.0.0",
"webpack": "^4.43.0", "webpack": "^4.46.0",
"webpack-cli": "^3.3.11" "webpack-cli": "^4.7.2"
}, },
"scripts": { "scripts": {
"dev": "webpack --mode development --watch", "dev": "webpack --mode development --watch",
"build": "webpack --mode production" "build": "webpack --mode production",
"format": "prettier --write src",
"format-check": "prettier --check src"
},
"devDependencies": {
"@flarum/prettier-config": "^1.0.0",
"flarum-tsconfig": "^1.0.0",
"prettier": "^2.3.2"
} }
} }

View File

@ -1,11 +1,13 @@
import app from 'flarum/app'; import app from 'flarum/app';
app.initializers.add('flarum-sticky', () => { app.initializers.add('flarum-sticky', () => {
app.extensionData app.extensionData.for('flarum-sticky').registerPermission(
.for('flarum-sticky') {
.registerPermission({
icon: 'fas fa-thumbtack', icon: 'fas fa-thumbtack',
label: app.translator.trans('flarum-sticky.admin.permissions.sticky_discussions_label'), label: app.translator.trans('flarum-sticky.admin.permissions.sticky_discussions_label'),
permission: 'discussion.sticky' permission: 'discussion.sticky',
}, 'moderate', 95); },
'moderate',
95
);
}); });

View File

@ -3,13 +3,17 @@ import Discussion from 'flarum/models/Discussion';
import Badge from 'flarum/components/Badge'; import Badge from 'flarum/components/Badge';
export default function addStickyBadge() { export default function addStickyBadge() {
extend(Discussion.prototype, 'badges', function(badges) { extend(Discussion.prototype, 'badges', function (badges) {
if (this.isSticky()) { if (this.isSticky()) {
badges.add('sticky', Badge.component({ badges.add(
type: 'sticky', 'sticky',
label: app.translator.trans('flarum-sticky.forum.badge.sticky_tooltip'), Badge.component({
icon: 'fas fa-thumbtack' type: 'sticky',
}), 10); label: app.translator.trans('flarum-sticky.forum.badge.sticky_tooltip'),
icon: 'fas fa-thumbtack',
}),
10
);
} }
}); });
} }

View File

@ -4,17 +4,27 @@ import DiscussionPage from 'flarum/components/DiscussionPage';
import Button from 'flarum/components/Button'; import Button from 'flarum/components/Button';
export default function addStickyControl() { export default function addStickyControl() {
extend(DiscussionControls, 'moderationControls', function(items, discussion) { extend(DiscussionControls, 'moderationControls', function (items, discussion) {
if (discussion.canSticky()) { if (discussion.canSticky()) {
items.add('sticky', Button.component({ items.add(
icon: 'fas fa-thumbtack', 'sticky',
onclick: this.stickyAction.bind(discussion) Button.component(
}, app.translator.trans(discussion.isSticky() ? 'flarum-sticky.forum.discussion_controls.unsticky_button' : 'flarum-sticky.forum.discussion_controls.sticky_button'))); {
icon: 'fas fa-thumbtack',
onclick: this.stickyAction.bind(discussion),
},
app.translator.trans(
discussion.isSticky()
? 'flarum-sticky.forum.discussion_controls.unsticky_button'
: 'flarum-sticky.forum.discussion_controls.sticky_button'
)
)
);
} }
}); });
DiscussionControls.stickyAction = function() { DiscussionControls.stickyAction = function () {
this.save({isSticky: !this.isSticky()}).then(() => { this.save({ isSticky: !this.isSticky() }).then(() => {
if (app.current.matches(DiscussionPage)) { if (app.current.matches(DiscussionPage)) {
app.current.get('stream').update(); app.current.get('stream').update();
} }

View File

@ -6,13 +6,13 @@ import IndexPage from 'flarum/components/IndexPage';
import { truncate } from 'flarum/utils/string'; import { truncate } from 'flarum/utils/string';
export default function addStickyControl() { export default function addStickyControl() {
extend(DiscussionListState.prototype, 'requestParams', function(params) { extend(DiscussionListState.prototype, 'requestParams', function (params) {
if (app.current.matches(IndexPage) || app.current.matches(DiscussionPage)) { if (app.current.matches(IndexPage) || app.current.matches(DiscussionPage)) {
params.include.push('firstPost'); params.include.push('firstPost');
} }
}); });
extend(DiscussionListItem.prototype, 'infoItems', function(items) { extend(DiscussionListItem.prototype, 'infoItems', function (items) {
const discussion = this.attrs.discussion; const discussion = this.attrs.discussion;
if (discussion.isSticky() && !this.attrs.params.q && !discussion.lastReadPostNumber()) { if (discussion.isSticky() && !this.attrs.params.q && !discussion.lastReadPostNumber()) {

View File

@ -19,4 +19,3 @@ app.initializers.add('flarum-sticky', () => {
addStickyExcerpt(); addStickyExcerpt();
addStickyClass(); addStickyClass();
}); });

View File

@ -0,0 +1,14 @@
{
// Use Flarum's tsconfig as a starting point
"extends": "flarum-tsconfig",
// This will match all .ts, .tsx, .d.ts, .js, .jsx files
"include": ["src/**/*"],
"compilerOptions": {
// This will output typings to `dist-typings`
"declarationDir": "./dist-typings",
"baseUrl": ".",
"paths": {
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
}
}
}