forked from retoor/devplacepy
fix: correct "bugs" to "issues" in routing table and README references across multiple documentation files
This commit is contained in:
@@ -21,8 +21,33 @@ export class VoteManager extends OptimisticAction {
|
||||
|
||||
cast(form, button) {
|
||||
const action = form.getAttribute("action");
|
||||
const value = form.querySelector('input[name="value"]').value;
|
||||
return this.submit(action, { value }, button, (result) => this.render(action, result));
|
||||
const clickedValue = parseInt(form.querySelector('input[name="value"]').value, 10);
|
||||
const targetUid = action.split("/").pop();
|
||||
const prevValue = this.currentValue(action);
|
||||
const prevNet = this.currentNet(targetUid);
|
||||
const newValue = prevValue === clickedValue ? 0 : clickedValue;
|
||||
const predictedNet = prevNet + (newValue - prevValue);
|
||||
return this.submitOptimistic(
|
||||
action,
|
||||
{ value: clickedValue },
|
||||
button,
|
||||
() => this.render(action, { net: predictedNet, value: newValue }),
|
||||
() => this.render(action, { net: prevNet, value: prevValue }),
|
||||
(result) => this.render(action, result),
|
||||
);
|
||||
}
|
||||
|
||||
currentValue(action) {
|
||||
const voted = document.querySelector(`form[action="${action}"] button.voted`);
|
||||
if (!voted) return 0;
|
||||
return parseInt(voted.closest("form").querySelector('input[name="value"]').value, 10);
|
||||
}
|
||||
|
||||
currentNet(targetUid) {
|
||||
const counter = document.querySelector(`[data-vote-count="${targetUid}"]`);
|
||||
if (!counter) return 0;
|
||||
const parsed = parseInt(counter.textContent, 10);
|
||||
return Number.isNaN(parsed) ? 0 : parsed;
|
||||
}
|
||||
|
||||
render(action, result) {
|
||||
|
||||
Reference in New Issue
Block a user