fixes linting

This commit is contained in:
Joffrey JAFFEUX 2018-11-19 16:29:15 +01:00 committed by GitHub
parent 4459665dee
commit 95d8a421be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 41 deletions

View File

@ -12,7 +12,7 @@ const WHITELISTED_ATTRIBUTES = [
"results", "results",
"status", "status",
"step", "step",
"type", "type"
]; ];
function replaceToken(tokens, target, list) { function replaceToken(tokens, target, list) {

View File

@ -81,7 +81,7 @@ createWidget("discourse-poll-load-more", {
state.loading = true; state.loading = true;
return this.sendWidgetAction("loadMore").finally( return this.sendWidgetAction("loadMore").finally(
() => state.loading = false () => (state.loading = false)
); );
} }
}); });
@ -113,7 +113,10 @@ createWidget("discourse-poll-voters", {
state.loaded = "loaded"; state.loaded = "loaded";
state.page += 1; state.page += 1;
const newVoters = attrs.pollType === "number" ? result.voters : result.voters[attrs.optionId]; const newVoters =
attrs.pollType === "number"
? result.voters
: result.voters[attrs.optionId];
state.voters = [...new Set([...state.voters, ...newVoters])]; state.voters = [...new Set([...state.voters, ...newVoters])];
this.scheduleRerender(); this.scheduleRerender();
@ -518,21 +521,17 @@ export default createWidget("discourse-poll", {
defaultState(attrs) { defaultState(attrs) {
const { post, poll } = attrs; const { post, poll } = attrs;
const showResults = ( const showResults =
post.get("topic.archived") || post.get("topic.archived") ||
this.isClosed() || this.isClosed() ||
(poll.get("results") !== "on_close" && this.hasVoted()) (poll.get("results") !== "on_close" && this.hasVoted());
);
return { loading: false, showResults }; return { loading: false, showResults };
}, },
html(attrs, state) { html(attrs, state) {
const showResults = ( const showResults =
state.showResults || state.showResults || attrs.post.get("topic.archived") || this.isClosed();
attrs.post.get("topic.archived") ||
this.isClosed()
);
const newAttrs = jQuery.extend({}, attrs, { const newAttrs = jQuery.extend({}, attrs, {
canCastVotes: this.canCastVotes(), canCastVotes: this.canCastVotes(),
@ -542,7 +541,7 @@ export default createWidget("discourse-poll", {
isMultiple: this.isMultiple(), isMultiple: this.isMultiple(),
max: this.max(), max: this.max(),
min: this.min(), min: this.min(),
showResults, showResults
}); });
return h("div", [ return h("div", [
@ -631,21 +630,24 @@ export default createWidget("discourse-poll", {
poll_name: poll.get("name"), poll_name: poll.get("name"),
status status
} }
}).then(() => { })
poll.set("status", status); .then(() => {
if (poll.get("results") === "on_close") { poll.set("status", status);
state.showResults = status === "closed"; if (poll.get("results") === "on_close") {
} state.showResults = status === "closed";
this.scheduleRerender(); }
}).catch(error => { this.scheduleRerender();
if (error) { })
popupAjaxError(error); .catch(error => {
} else { if (error) {
bootbox.alert(I18n.t("poll.error_while_toggling_status")); popupAjaxError(error);
} } else {
}).finally(() => { bootbox.alert(I18n.t("poll.error_while_toggling_status"));
state.loading = false; }
}); })
.finally(() => {
state.loading = false;
});
} }
} }
); );
@ -698,19 +700,22 @@ export default createWidget("discourse-poll", {
poll_name: attrs.poll.get("name"), poll_name: attrs.poll.get("name"),
options: attrs.vote options: attrs.vote
} }
}).then(({ poll }) => { })
attrs.poll.setProperties(poll); .then(({ poll }) => {
if (attrs.poll.get("results") !== "on_close") { attrs.poll.setProperties(poll);
state.showResults = true; if (attrs.poll.get("results") !== "on_close") {
} state.showResults = true;
}).catch(error => { }
if (error) { })
popupAjaxError(error); .catch(error => {
} else { if (error) {
bootbox.alert(I18n.t("poll.error_while_casting_votes")); popupAjaxError(error);
} } else {
}).finally(() => { bootbox.alert(I18n.t("poll.error_while_casting_votes"));
state.loading = false; }
}); })
.finally(() => {
state.loading = false;
});
} }
}); });