DEV: Remove jquery from votes (#206)

This commit is contained in:
Isaac Janzen 2024-08-14 11:55:29 -05:00 committed by GitHub
parent 54d6607bf0
commit e6dbd1f6e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 8 deletions

View File

@ -1,5 +1,5 @@
import $ from "jquery";
import { h } from "virtual-dom";
import cookie from "discourse/lib/cookie";
import { createWidget } from "discourse/widgets/widget";
import I18n from "I18n";
@ -73,7 +73,7 @@ export default createWidget("vote-button", {
click() {
if (!this.currentUser) {
this.sendWidgetAction("showLogin");
$.cookie("destination_url", window.location.href);
cookie("destination_url", window.location.href, { path: "/" });
return;
}
if (
@ -87,12 +87,12 @@ export default createWidget("vote-button", {
this.sendWidgetAction("addVote");
}
if (this.attrs.user_voted || this.currentUser.votes_exceeded) {
$(".vote-options").toggleClass("hidden");
document.querySelector(".vote-options").classList.toggle("hidden");
}
},
clickOutside() {
$(".vote-options").addClass("hidden");
document.querySelector(".vote-options").classList.add("hidden");
this.parentWidget.state.initialVote = false;
},
});

View File

@ -1,6 +1,6 @@
import $ from "jquery";
import { h } from "virtual-dom";
import { ajax } from "discourse/lib/ajax";
import cookie from "discourse/lib/cookie";
import { createWidget } from "discourse/widgets/widget";
import getURL from "discourse-common/lib/get-url";
@ -43,7 +43,7 @@ export default createWidget("vote-count", {
click() {
if (!this.currentUser) {
this.sendWidgetAction("showLogin");
$.cookie("destination_url", window.location.href);
cookie("destination_url", window.location.href, { path: "/" });
return;
}
@ -54,13 +54,18 @@ export default createWidget("vote-count", {
if (this.state.whoVotedUsers === null) {
return this.getWhoVoted();
} else {
$(".who-voted").toggle();
const whoVotedElement = document.querySelector(".who-voted");
whoVotedElement.style.display =
whoVotedElement.style.display === "none" ? "block" : "none";
}
}
},
clickOutside() {
$(".who-voted").hide();
const whoVotedElement = document.querySelector(".who-voted");
if (whoVotedElement) {
whoVotedElement.style.display = "none";
}
},
getWhoVoted() {