mirror of
https://github.com/discourse/discourse.git
synced 2025-02-10 14:55:48 +08:00
32 lines
678 B
JavaScript
32 lines
678 B
JavaScript
import { createWidget } from "discourse/widgets/widget";
|
|
|
|
export default createWidget("post-gap", {
|
|
tagName: "div.gap",
|
|
buildKey: attrs => `post-gap-${attrs.pos}-${attrs.postId}`,
|
|
|
|
defaultState() {
|
|
return { loading: false };
|
|
},
|
|
|
|
html(attrs, state) {
|
|
return state.loading
|
|
? I18n.t("loading")
|
|
: I18n.t("post.gap", { count: attrs.gap.length });
|
|
},
|
|
|
|
click() {
|
|
const { attrs, state } = this;
|
|
|
|
if (state.loading) {
|
|
return;
|
|
}
|
|
state.loading = true;
|
|
|
|
const args = { gap: attrs.gap, post: this.model };
|
|
return this.sendWidgetAction(
|
|
attrs.pos === "before" ? "fillGapBefore" : "fillGapAfter",
|
|
args
|
|
);
|
|
}
|
|
});
|