From 870c52c7bf084f312365f06264ddd2f3f910b3d5 Mon Sep 17 00:00:00 2001 From: Niko Date: Thu, 17 Feb 2022 01:51:27 +0100 Subject: [PATCH] Improved state conservation in pages.meet --- web/src/app/js/pages/meet.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/web/src/app/js/pages/meet.js b/web/src/app/js/pages/meet.js index 526abb5..07a9d86 100644 --- a/web/src/app/js/pages/meet.js +++ b/web/src/app/js/pages/meet.js @@ -1,5 +1,8 @@ app.pages.meet = { data: [], + dataCurrent: function() { + return app.pages.meet.data[app.pages.meet.carousel._current]; + }, isActive: function() { return (window.location.hash+'/').startsWith('#meet/') }, load: function(args) { document.querySelector('#page-meet').removeAttribute('style'); @@ -25,8 +28,8 @@ app.pages.meet = { }, _paintInterval: false, paintInterval: function() { - if (app.pages.meet.data._paintInterval) return; - app.pages.meet.data._paintInterval = true; + if (app.pages.meet._paintInterval) return; + app.pages.meet._paintInterval = true; setInterval(function() { if (app.pages.meet.isActive()) app.pages.meet.paint(); @@ -80,7 +83,19 @@ app.pages.meet = { var tpl = app.template.fill({}, app.template.get('meet.actions')); dom.innerHTML += tpl; }; _(); - var index = app.storage.get('status_meet_index') || 0; + var index = app.storage.get('status_meet_index') || null; + if (index !== null) { + for (var j = 0; j < app.pages.meet.data.length; j++) { + console.log(app.pages.meet.data[j]._id) + console.log(index) + console.log('---') + if (app.pages.meet.data[j]._id === index) { + app.pages.meet.carousel._current = j; + index = j; + break; + } + } + } else index = 0; app.pages.meet.carousel.set(parseInt(index)); }, exit: function() { @@ -93,8 +108,9 @@ app.pages.meet = { _elements: function() { return app.pages.meet.carousel._parent().querySelectorAll('.meet.item') }, _size: function() { return app.pages.meet.carousel._elements().length }, _onSetEvent: function(direction) { - app.storage.set('status_meet_index', - app.pages.meet.carousel._current); + const current = app.pages.meet.dataCurrent(); + if (current !== null) + app.storage.set('status_meet_index', current._id); app.pages.meet.carousel.setDragEvent(direction); }, set: function(i) { return app.carousel.set(app.pages.meet.carousel, i) },