Improved state conservation in pages.meet

This commit is contained in:
Niko 2022-02-17 01:51:27 +01:00
parent 7dabf832b6
commit 870c52c7bf
1 changed files with 21 additions and 5 deletions

View File

@ -1,5 +1,8 @@
app.pages.meet = { app.pages.meet = {
data: [], data: [],
dataCurrent: function() {
return app.pages.meet.data[app.pages.meet.carousel._current];
},
isActive: function() { return (window.location.hash+'/').startsWith('#meet/') }, isActive: function() { return (window.location.hash+'/').startsWith('#meet/') },
load: function(args) { load: function(args) {
document.querySelector('#page-meet').removeAttribute('style'); document.querySelector('#page-meet').removeAttribute('style');
@ -25,8 +28,8 @@ app.pages.meet = {
}, },
_paintInterval: false, _paintInterval: false,
paintInterval: function() { paintInterval: function() {
if (app.pages.meet.data._paintInterval) return; if (app.pages.meet._paintInterval) return;
app.pages.meet.data._paintInterval = true; app.pages.meet._paintInterval = true;
setInterval(function() { setInterval(function() {
if (app.pages.meet.isActive()) if (app.pages.meet.isActive())
app.pages.meet.paint(); app.pages.meet.paint();
@ -80,7 +83,19 @@ app.pages.meet = {
var tpl = app.template.fill({}, app.template.get('meet.actions')); var tpl = app.template.fill({}, app.template.get('meet.actions'));
dom.innerHTML += tpl; 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)); app.pages.meet.carousel.set(parseInt(index));
}, },
exit: function() { exit: function() {
@ -93,8 +108,9 @@ app.pages.meet = {
_elements: function() { return app.pages.meet.carousel._parent().querySelectorAll('.meet.item') }, _elements: function() { return app.pages.meet.carousel._parent().querySelectorAll('.meet.item') },
_size: function() { return app.pages.meet.carousel._elements().length }, _size: function() { return app.pages.meet.carousel._elements().length },
_onSetEvent: function(direction) { _onSetEvent: function(direction) {
app.storage.set('status_meet_index', const current = app.pages.meet.dataCurrent();
app.pages.meet.carousel._current); if (current !== null)
app.storage.set('status_meet_index', current._id);
app.pages.meet.carousel.setDragEvent(direction); app.pages.meet.carousel.setDragEvent(direction);
}, },
set: function(i) { return app.carousel.set(app.pages.meet.carousel, i) }, set: function(i) { return app.carousel.set(app.pages.meet.carousel, i) },