This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/widgets/post-gap.js
2020-03-12 13:29:55 -04:00

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
);
}
});