mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
+ remember last opened list in browser storage (closes GH-39)
This commit is contained in:
parent
6888b0ade0
commit
60797ffdb8
1 changed files with 39 additions and 15 deletions
|
|
@ -729,26 +729,28 @@ var mytinytodo = window.mytinytodo = _mtt = {
|
|||
{
|
||||
var ti = '';
|
||||
var openListId = 0;
|
||||
if(res && res.total && res.list)
|
||||
|
||||
if (res && res.total && res.list)
|
||||
{
|
||||
// open required or first non-hidden list
|
||||
for(var i=0; i<res.list.length; i++) {
|
||||
if(_mtt.options.openList) {
|
||||
if(_mtt.options.openList == res.list[i].id) {
|
||||
openListId = res.list[i].id;
|
||||
break;
|
||||
}
|
||||
// open required or last opened or first non-hidden list
|
||||
let list;
|
||||
if (_mtt.options.openList) {
|
||||
list = res.list.find( item => _mtt.options.openList == item.id );
|
||||
}
|
||||
else {
|
||||
const lastOpenList = getLocalStorageItem('lastList');
|
||||
if (lastOpenList) {
|
||||
list = res.list.find( item => !item.hidden && lastOpenList == item.id );
|
||||
}
|
||||
else if(!res.list[i].hidden) {
|
||||
openListId = res.list[i].id;
|
||||
break;
|
||||
if (!list) {
|
||||
list = res.list.find( item => !item.hidden );
|
||||
}
|
||||
}
|
||||
if (list) {
|
||||
openListId = list.id;
|
||||
}
|
||||
|
||||
// open all tasks tab
|
||||
if(_mtt.options.openList == -1) openListId = -1;
|
||||
|
||||
$.each(res.list, function(i, item) {
|
||||
res.list.forEach( (item) => {
|
||||
if ( item.id == -1 ) {
|
||||
tabLists._alltasks = item;
|
||||
ti += prepareListHtml(item);
|
||||
|
|
@ -1524,6 +1526,7 @@ function tabSelect(elementOrId)
|
|||
var newTitle = curList.name + ' - ' + _mtt.options.title;
|
||||
var isFirstLoad = flag.firstLoad;
|
||||
updateHistoryState( { list:id }, _mtt.urlForList(curList), newTitle );
|
||||
setLocalStorageItem('lastList', ''+id);
|
||||
|
||||
if (curList.hidden && flag.readOnly != true) {
|
||||
curList.hidden = false;
|
||||
|
|
@ -2512,6 +2515,27 @@ function hideList(listId)
|
|||
}
|
||||
}
|
||||
|
||||
function getLocalStorageItem(key)
|
||||
{
|
||||
try {
|
||||
return localStorage.getItem(key);
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function setLocalStorageItem(key, value)
|
||||
{
|
||||
try {
|
||||
localStorage.setItem(key, value);
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Errors and Info messages
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue