aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunasSudo <runassudo@yingtongli.me>2021-10-29 20:28:25 +1100
committerRunasSudo <runassudo@yingtongli.me>2021-10-29 20:28:50 +1100
commitba8282804639c4a9274c31f61757be34927070ab (patch)
tree64370063b6a2d7226f4f8c6a1a68fe9b1b8eae0e
parent5a652cb46638ba42a0eb31a0295873c192bd8a11 (diff)
Fix web UI crash when tie requires manual intervention in first stage
-rw-r--r--html/worker.js15
-rw-r--r--src/stv/gregory/transfers.rs8
2 files changed, 14 insertions, 9 deletions
diff --git a/html/worker.js b/html/worker.js
index 95a96eb..fe4daeb 100644
--- a/html/worker.js
+++ b/html/worker.js
@@ -64,13 +64,7 @@ onmessage = function(evt) {
// Step election
state = wasm['CountState' + numbers].new(election);
- wasm['count_init_' + numbers](state, opts);
-
- postMessage({'type': 'updateResultsTable', 'result': wasm['update_results_table_' + numbers](1, state, opts, reportStyle)});
- postMessage({'type': 'updateStageComments', 'comment': wasm['update_stage_comments_' + numbers](state)});
-
- stageNum = 2;
-
+ stageNum = 1;
resumeCount();
} else if (evt.data.type == 'userInput') {
@@ -92,7 +86,12 @@ onmessage = function(evt) {
function resumeCount() {
for (;; stageNum++) {
- let isDone = wasm['count_one_stage_' + numbers](state, opts);
+ let isDone;
+ if (stageNum <= 1) {
+ isDone = wasm['count_init_' + numbers](state, opts);
+ } else {
+ isDone = wasm['count_one_stage_' + numbers](state, opts);
+ }
if (wasmRaw.asyncify_get_state() !== 0) {
// This stage caused a stack unwind in get_user_input so ignore the result
diff --git a/src/stv/gregory/transfers.rs b/src/stv/gregory/transfers.rs
index 88338af..6eb5d52 100644
--- a/src/stv/gregory/transfers.rs
+++ b/src/stv/gregory/transfers.rs
@@ -455,7 +455,13 @@ impl<'e, N: Number> TransferTable<'e, N> {
}
/// Render table as plain text
- //#[cfg(not(target_arch = "wasm32"))]
+ #[cfg(not(target_arch = "wasm32"))]
+ pub fn render_text(&self, opts: &STVOptions) -> String {
+ return self.render(opts).to_string();
+ }
+
+ /// Render table as HTML
+ #[cfg(target_arch = "wasm32")]
pub fn render_text(&self, opts: &STVOptions) -> String {
return self.render(opts).to_html();
}
Contact (issues, pull requests, etc.) at git@yingtongli.me. Generated by cgit.