sort notes by last change

fix delete and restore
This commit is contained in:
quenousimporte 2024-02-06 13:29:27 +01:00
parent 0d436b0516
commit 67ce656365
1 changed files with 25 additions and 31 deletions

56
main.js
View File

@ -1654,7 +1654,10 @@ function commandpalette()
suffix: [s.command]
};
}))
.concat(Object.values(metadata).map(item =>
.concat(Object.values(metadata)
.filter(item => !item.deleted)
.sort( (i,j) => j.lastchanged - i.lastchanged)
.map(item =>
{
return {
prefix: "note ",
@ -2301,9 +2304,12 @@ function toggletitle()
function selectnote()
{
// todo: sort by lastchanged
return searchinlist(
Object.values(metadata).map(item =>
Object
.values(metadata)
.filter(item => !item.deleted)
.sort( (i,j) => j.lastchanged - i.lastchanged)
.map(item =>
{
return {
text: item.title,
@ -2431,42 +2437,26 @@ function renamereferences(newname)
function restoredeleted()
{
// todo: parse local storage starting with "deleted" and reindex with a new guid
var trash = window.localStorage.getItem("trash");
if (trash)
searchinlist(Object.values(metadata).filter(i => i.deleted).sort( (i,j) => j.lastchanged - i.lastchanged).map(i => i.title))
.then(title =>
{
trash = JSON.parse(window.localStorage.getItem("trash"));
searchinlist(trash.map(note => note.title + " - deleted on " + note.deletiondate))
.then(item =>
if (confirm("Restore " + title + "?"))
{
if (confirm("Restore " + item + "?"))
{
var title = item.split(" - deleted on ").shift();
var stamp = item.split(" - deleted on ").pop();
var index = trash.findIndex(n => n.title == title && (!n.deletiondate || n.deletiondate == stamp));
if (index > -1)
{
var notetorestore = trash.splice(index, 1).pop();
notetorestore.title += " - restored on " + timestamp();
delete notetorestore.deletiondate;
localdata.unshift(notetorestore);
loadnote(notetorestore.title);
datachanged();
window.localStorage.setItem("trash", JSON.stringify(trash));
}
}
});
}
var guid = getguid(title);
metadata[guid].deleted = false;
metadata[guid].lastchanged = Date.now();
renameinternallinks(title + " (deleted)", title);
localStorage.setItem("index", JSON.stringify(metadata));
}
});
}
function deletenote(title)
{
var guid = getguid(title);
delete metadata[guid];
metadata[guid].deleted = true;
metadata[guid].lastchanged = Date.now();
renameinternallinks(title, title + " (deleted)");
var content = localStorage.getItem(guid);
localStorage.removeItem(guid);
localStorage.setItem("deleted_" + title, content);
localStorage.setItem("index", JSON.stringify(metadata));
}
@ -2692,6 +2682,10 @@ function renameinternallinks(from, to)
if (content != newcontent)
{
localStorage.setItem(guid, newcontent);
if (item.title == window.title.value)
{
seteditorcontent(newcontent);
}
}
});
}