DEV: Add topic-vote behavior transformer to click
DEV: remove args passed
This commit is contained in:
parent
e6dbd1f6e8
commit
1e66e60675
|
@ -0,0 +1,12 @@
|
|||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
|
||||
export default {
|
||||
name: "discourse-topic-voting-transformers",
|
||||
before: "freeze-valid-transformers",
|
||||
|
||||
initialize() {
|
||||
withPluginApi("1.35.0", (api) => {
|
||||
api.addBehaviorTransformerName("topic-vote-button-click");
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,5 +1,6 @@
|
|||
import { h } from "virtual-dom";
|
||||
import cookie from "discourse/lib/cookie";
|
||||
import { applyBehaviorTransformer } from "discourse/lib/transformer";
|
||||
import { createWidget } from "discourse/widgets/widget";
|
||||
import I18n from "I18n";
|
||||
|
||||
|
@ -71,24 +72,26 @@ export default createWidget("vote-button", {
|
|||
},
|
||||
|
||||
click() {
|
||||
if (!this.currentUser) {
|
||||
this.sendWidgetAction("showLogin");
|
||||
cookie("destination_url", window.location.href, { path: "/" });
|
||||
return;
|
||||
}
|
||||
if (
|
||||
!this.attrs.closed &&
|
||||
this.parentWidget.state.allowClick &&
|
||||
!this.attrs.user_voted &&
|
||||
!this.currentUser.votes_exceeded
|
||||
) {
|
||||
this.parentWidget.state.allowClick = false;
|
||||
this.parentWidget.state.initialVote = true;
|
||||
this.sendWidgetAction("addVote");
|
||||
}
|
||||
if (this.attrs.user_voted || this.currentUser.votes_exceeded) {
|
||||
document.querySelector(".vote-options").classList.toggle("hidden");
|
||||
}
|
||||
applyBehaviorTransformer("topic-vote-button-click", () => {
|
||||
if (!this.currentUser) {
|
||||
this.sendWidgetAction("showLogin");
|
||||
cookie("destination_url", window.location.href, { path: "/" });
|
||||
return;
|
||||
}
|
||||
if (
|
||||
!this.attrs.closed &&
|
||||
this.parentWidget.state.allowClick &&
|
||||
!this.attrs.user_voted &&
|
||||
!this.currentUser.votes_exceeded
|
||||
) {
|
||||
this.parentWidget.state.allowClick = false;
|
||||
this.parentWidget.state.initialVote = true;
|
||||
this.sendWidgetAction("addVote");
|
||||
}
|
||||
if (this.attrs.user_voted || this.currentUser.votes_exceeded) {
|
||||
document.querySelector(".vote-options").classList.toggle("hidden");
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
clickOutside() {
|
||||
|
|
Loading…
Reference in New Issue