From fd5cf639a15fb77c6d24afa540ecd1c07ec1c9b5 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Wed, 16 Feb 2022 17:15:59 +0000 Subject: [PATCH] central handling of new list version --- public/javascripts/lsl.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/public/javascripts/lsl.js b/public/javascripts/lsl.js index 851d709..ef6f9a8 100644 --- a/public/javascripts/lsl.js +++ b/public/javascripts/lsl.js @@ -20,6 +20,11 @@ function got_lists_version(new_version) { if (new_version != lists_version) window.setTimeout(load_lists); } +function got_list_version(new_version) { + var id_data = selected_list.data('id'); + if (new_version != id_data.version) + window.setTimeout(() => load_list_items(id_data.uri, selected_list)); +} function load_list_items(uri, target) { $.get(uri) .done(item_data => { @@ -99,17 +104,10 @@ function handle_new_list_submission(){ return false; } function new_list_item_submission_done(data) { - if (data.lists_version != lists_version) { - load_lists(); - return; - } + got_list_version(data.list_version); var item_data = selected_list.data('items'); - if (data.list_version != item_data.version + 1) { - load_list_items(current_list); - } - else { var new_item = { description: $('#new-list-item input[type="text"]').val().trim(), done: $('#new-list-item input[type="checkbox"]').prop('checked'), @@ -118,7 +116,6 @@ function new_list_item_submission_done(data) { item_data.items.push(new_item); item_data.version = data.list_version; add_list_item(new_item); - } $('#new-list-item input').val(''); } -- 2.39.5