mirror of
https://github.com/flarum/core.git
synced 2025-08-06 08:27:42 +02:00
fix(qa): JS issues when adding flag feature
Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
9
extensions/flags/js/src/@types/shims.d.ts
vendored
9
extensions/flags/js/src/@types/shims.d.ts
vendored
@@ -1,6 +1,7 @@
|
|||||||
import Flag from '../forum/models/Flag';
|
import type Flag from '../forum/models/Flag';
|
||||||
import FlagListState from '../forum/states/FlagListState';
|
import type FlagListState from '../forum/states/FlagListState';
|
||||||
import Mithril from 'mithril';
|
import type Mithril from 'mithril';
|
||||||
|
import type ItemList from 'flarum/common/utils/ItemList';
|
||||||
|
|
||||||
declare module 'flarum/common/models/Post' {
|
declare module 'flarum/common/models/Post' {
|
||||||
export default interface Post {
|
export default interface Post {
|
||||||
@@ -17,6 +18,8 @@ declare module 'flarum/forum/ForumApplication' {
|
|||||||
|
|
||||||
declare module 'flarum/forum/components/Post' {
|
declare module 'flarum/forum/components/Post' {
|
||||||
export default interface Post {
|
export default interface Post {
|
||||||
|
dismissFlag: (body: any) => Promise<any>;
|
||||||
|
flagActionItems: () => ItemList<Mithril.Children>;
|
||||||
flagReason: (flag: Flag) => Mithril.Children;
|
flagReason: (flag: Flag) => Mithril.Children;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,14 @@
|
|||||||
import { extend } from 'flarum/common/extend';
|
import { extend } from 'flarum/common/extend';
|
||||||
import app from 'flarum/forum/app';
|
import app from 'flarum/forum/app';
|
||||||
import Post from 'flarum/forum/components/Post';
|
import Post from 'flarum/forum/components/Post';
|
||||||
|
import CommentPost from 'flarum/forum/components/CommentPost';
|
||||||
import Button from 'flarum/common/components/Button';
|
import Button from 'flarum/common/components/Button';
|
||||||
import ItemList from 'flarum/common/utils/ItemList';
|
import ItemList from 'flarum/common/utils/ItemList';
|
||||||
import PostControls from 'flarum/forum/utils/PostControls';
|
import PostControls from 'flarum/forum/utils/PostControls';
|
||||||
import humanTime from 'flarum/common/utils/humanTime';
|
import humanTime from 'flarum/common/utils/humanTime';
|
||||||
|
import isObject from 'flarum/common/utils/isObject';
|
||||||
|
import type Flag from './models/Flag';
|
||||||
|
import type Mithril from 'mithril';
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
extend(Post.prototype, 'elementAttrs', function (attrs) {
|
extend(Post.prototype, 'elementAttrs', function (attrs) {
|
||||||
@@ -21,7 +25,7 @@ export default function () {
|
|||||||
this.subtree.invalidate();
|
this.subtree.invalidate();
|
||||||
|
|
||||||
if (app.flags.cache) {
|
if (app.flags.cache) {
|
||||||
app.flags.cache.some((flag, i) => {
|
app.flags.cache.some((flag: Flag, i: number) => {
|
||||||
if (flag.post() === post) {
|
if (flag.post() === post) {
|
||||||
app.flags.cache.splice(i, 1);
|
app.flags.cache.splice(i, 1);
|
||||||
|
|
||||||
@@ -39,6 +43,8 @@ export default function () {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,16 +56,17 @@ export default function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Post.prototype.flagActionItems = function () {
|
Post.prototype.flagActionItems = function () {
|
||||||
const items = new ItemList();
|
const items = new ItemList<Mithril.Children>();
|
||||||
|
|
||||||
const controls = PostControls.destructiveControls(this.attrs.post);
|
const controls = PostControls.destructiveControls(this.attrs.post, this);
|
||||||
|
|
||||||
Object.keys(controls.items).forEach((k) => {
|
Object.keys(controls.items).forEach((k) => {
|
||||||
const attrs = controls.get(k).attrs;
|
const item = controls.get(k);
|
||||||
|
const attrs = isObject(item) && 'attrs' in item ? item.attrs : {};
|
||||||
|
|
||||||
attrs.className = 'Button';
|
attrs.className = 'Button';
|
||||||
|
|
||||||
extend(attrs, 'onclick', () => this.dismissFlag());
|
extend(attrs, 'onclick', () => this.dismissFlag({}));
|
||||||
});
|
});
|
||||||
|
|
||||||
items.add('controls', <div className="ButtonGroup">{controls.toArray()}</div>);
|
items.add('controls', <div className="ButtonGroup">{controls.toArray()}</div>);
|
||||||
@@ -81,12 +88,16 @@ export default function () {
|
|||||||
|
|
||||||
if (!flags.length) return;
|
if (!flags.length) return;
|
||||||
|
|
||||||
if (post.isHidden()) this.revealContent = true;
|
if (post.isHidden() && this instanceof CommentPost) {
|
||||||
|
this.revealContent = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isObject(vdom) || !('unshift' in vdom)) return;
|
||||||
|
|
||||||
vdom.unshift(
|
vdom.unshift(
|
||||||
<div className="Post-flagged">
|
<div className="Post-flagged">
|
||||||
<div className="Post-flagged-flags">
|
<div className="Post-flagged-flags">
|
||||||
{flags.map((flag) => (
|
{flags.map((flag: Flag) => (
|
||||||
<div className="Post-flagged-flag">{this.flagReason(flag)}</div>
|
<div className="Post-flagged-flag">{this.flagReason(flag)}</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -111,5 +122,7 @@ export default function () {
|
|||||||
detail ? <span className="Post-flagged-detail">{detail}</span> : '',
|
detail ? <span className="Post-flagged-detail">{detail}</span> : '',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
}
|
}
|
@@ -1,4 +1,6 @@
|
|||||||
export default class FlagListState {
|
export default class FlagListState {
|
||||||
|
index = 0;
|
||||||
|
|
||||||
constructor(app) {
|
constructor(app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user