Commit 2e5ec0be authored by ransome1's avatar ransome1
Browse files

Fixed group header issue on lazy loading

parent f95f6d91
{ {
"name": "sleek", "name": "sleek",
"productName": "sleek", "productName": "sleek",
"version": "1.1.1", "version": "1.1.2-rc.1",
"description": "Todo app based on todo.txt for Linux, Windows and MacOS, free and open-source", "description": "Todo app based on todo.txt for Linux, Windows and MacOS, free and open-source",
"synopsis": "Todo app based on todo.txt for Linux, Windows and MacOS, free and open-source", "synopsis": "Todo app based on todo.txt for Linux, Windows and MacOS, free and open-source",
"category": "ProjectManagement", "category": "ProjectManagement",
......
...@@ -55,11 +55,11 @@ function selectFileFromList(index) { ...@@ -55,11 +55,11 @@ function selectFileFromList(index) {
handleError(error); handleError(error);
}); });
resetModal().then(response => { resetModal().then(response => {
window.api.send("startFileWatcher", [userData.files[index][1], 1]);
console.info(response); console.info(response);
}).catch(error => { }).catch(error => {
handleError(error); handleError(error);
}); });
window.api.send("startFileWatcher", [userData.files[index][1], 1]);
return Promise.resolve("Success: File selected"); return Promise.resolve("Success: File selected");
} catch (error) { } catch (error) {
return Promise.reject(error); return Promise.reject(error);
......
...@@ -56,16 +56,16 @@ const todoTableBodyCellHiddenTemplate = document.createElement("span"); ...@@ -56,16 +56,16 @@ const todoTableBodyCellHiddenTemplate = document.createElement("span");
const item = { previous: "" } const item = { previous: "" }
let let
items, items,
clusterCounter, clusterCounter = 0,
clusterSize = Math.ceil(window.innerHeight/30), // 35 being the pixel height of one todo in compact mode clusterSize = Math.ceil(window.innerHeight/32), // 32 being the pixel height of one todo in compact mode
clusterThreshold = 0, clusterThreshold = clusterSize,
//stopBuilding = false, visibleRows,
visibleRows = 0; todoRows;
todoTableWrapper.addEventListener("scroll", function(event) { todoTableWrapper.addEventListener("scroll", function(event) {
if(visibleRows>=items.filtered.length) return false; if(clusterThreshold>=items.filtered.length) return false;
if(Math.floor(event.target.scrollHeight - event.target.scrollTop) <= event.target.clientHeight) { if(Math.floor(event.target.scrollHeight - event.target.scrollTop) <= event.target.clientHeight) {
//stopBuilding = false; //clusterThreshold = clusterThreshold + clusterCounter;
startBuilding(true); startBuilding(true);
} }
}); });
...@@ -89,15 +89,8 @@ function showResultStats() { ...@@ -89,15 +89,8 @@ function showResultStats() {
return Promise.reject(error); return Promise.reject(error);
} }
} }
function configureTodoTableTemplate(append) { function configureTodoTableTemplate() {
try { try {
// setting up for the first cluster
if(!append) {
todoTable.innerHTML = "";
visibleRows = 0;
clusterThreshold = 0;
//stopBuilding = false;
}
todoTableBodyRowTemplate.setAttribute("class", "todo"); todoTableBodyRowTemplate.setAttribute("class", "todo");
todoTableBodyCellCheckboxTemplate.setAttribute("class", "cell checkbox"); todoTableBodyCellCheckboxTemplate.setAttribute("class", "cell checkbox");
todoTableBodyCellTextTemplate.setAttribute("class", "cell text"); todoTableBodyCellTextTemplate.setAttribute("class", "cell text");
...@@ -166,19 +159,19 @@ function generateGroups(items) { ...@@ -166,19 +159,19 @@ function generateGroups(items) {
}); });
return Promise.resolve(items) return Promise.resolve(items)
} }
async function generateTable(groups, append, loadAll) { async function generateTable(groups, loadAll) {
try { try {
todoRows = new Array;
// TODO Overthink due to performance reasons
todoTable.textContent = "";
// configure stats // configure stats
showResultStats(); showResultStats();
// prepare the templates for the table // prepare the templates for the table
await configureTodoTableTemplate(append); await configureTodoTableTemplate();
// reset cluster count for this run // reset cluster count for this run
clusterCounter = 0;
for (let group in groups) { for (let group in groups) {
// if(stopBuilding) {
// stopBuilding = false;
// break;
// }
// create a divider row // create a divider row
let dividerRow; let dividerRow;
// completed todos // completed todos
...@@ -202,19 +195,9 @@ async function generateTable(groups, append, loadAll) { ...@@ -202,19 +195,9 @@ async function generateTable(groups, append, loadAll) {
} else { } else {
dividerRow = document.createRange().createContextualFragment("<div class=\"group\"></div>") dividerRow = document.createRange().createContextualFragment("<div class=\"group\"></div>")
} }
// add divider row only if it doesn't exist yet if(!document.getElementById(userData.sortBy[0] + groups[group][0]) && dividerRow) todoRows.push(dividerRow);
if(!append && !document.getElementById(userData.sortBy[0] + groups[group][0]) && dividerRow) tableContainerContent.appendChild(dividerRow);
for (let item in groups[group][1]) { for (let item in groups[group][1]) {
let todo = groups[group][1][item]; let todo = groups[group][1][item];
//TODO: Explain this, maybe refactor
if(!loadAll && clusterCounter<clusterThreshold) {
clusterCounter++;
continue;
} else if(!loadAll && (visibleRows===clusterSize+clusterThreshold) || visibleRows===items.filtered.length ) {
clusterThreshold = visibleRows;
//stopBuilding = true;
break;
}
// if this todo is not a recurring one the rec value will be set to null // if this todo is not a recurring one the rec value will be set to null
if(!todo.rec) todo.rec = null; if(!todo.rec) todo.rec = null;
// incompleted todos with due date // incompleted todos with due date
...@@ -234,8 +217,20 @@ async function generateTable(groups, append, loadAll) { ...@@ -234,8 +217,20 @@ async function generateTable(groups, append, loadAll) {
}); });
} }
} }
tableContainerContent.appendChild(generateTableRow(todo)); todoRows.push(generateTableRow(todo));
}
}
for (let row in todoRows) {
clusterCounter++;
visibleRows++;
if(clusterCounter === clusterThreshold) {
clusterThreshold = clusterThreshold + clusterCounter;
clusterCounter = 0;
break;
} else if(visibleRows < clusterThreshold) {
continue;
} }
tableContainerContent.appendChild(todoRows[row]);
} }
todoTable.appendChild(tableContainerContent); todoTable.appendChild(tableContainerContent);
return Promise.resolve("Success: Todo table generated"); return Promise.resolve("Success: Todo table generated");
...@@ -246,8 +241,6 @@ async function generateTable(groups, append, loadAll) { ...@@ -246,8 +241,6 @@ async function generateTable(groups, append, loadAll) {
} }
function generateTableRow(todo) { function generateTableRow(todo) {
try { try {
clusterCounter++;
visibleRows++;
// create nodes from templates // create nodes from templates
let todoTableBodyRow = todoTableBodyRowTemplate.cloneNode(true); let todoTableBodyRow = todoTableBodyRowTemplate.cloneNode(true);
let todoTableBodyCellCheckbox = todoTableBodyCellCheckboxTemplate.cloneNode(true); let todoTableBodyCellCheckbox = todoTableBodyCellCheckboxTemplate.cloneNode(true);
...@@ -647,4 +640,4 @@ function generateHash(string) { ...@@ -647,4 +640,4 @@ function generateHash(string) {
(((prevHash << 5) - prevHash) + currVal.charCodeAt(0))|0, 0); (((prevHash << 5) - prevHash) + currVal.charCodeAt(0))|0, 0);
} }
export { generateItems, generateGroups, generateTable, items, item, visibleRows, setTodoComplete, archiveTodos, addTodo }; export { generateItems, generateGroups, generateTable, items, item, setTodoComplete, archiveTodos, addTodo };
...@@ -167,7 +167,7 @@ const createWindow = async function() { ...@@ -167,7 +167,7 @@ const createWindow = async function() {
break; break;
} }
} }
const startFileWatcher = function(file, isTabItem) { const startFileWatcher = function(file, isTabItem, resetTab) {
try { try {
if(!fs.existsSync(file)) throw("Error: File not found on disk") if(!fs.existsSync(file)) throw("Error: File not found on disk")
// skip persisted files and go with ENV if set // skip persisted files and go with ENV if set
......
...@@ -785,7 +785,7 @@ function getBadgeCount() { ...@@ -785,7 +785,7 @@ function getBadgeCount() {
}); });
return count; return count;
} }
async function startBuilding(append, loadAll) { async function startBuilding(loadAll) {
try { try {
t0 = performance.now(); t0 = performance.now();
...@@ -798,7 +798,7 @@ async function startBuilding(append, loadAll) { ...@@ -798,7 +798,7 @@ async function startBuilding(append, loadAll) {
userData = await getUserData(); userData = await getUserData();
await todos.generateTable(groups, append, loadAll); await todos.generateTable(groups, loadAll);
configureMainView(); configureMainView();
......
...@@ -8,3 +8,4 @@ x 2021-07-15 2021-07-15 test todo ...@@ -8,3 +8,4 @@ x 2021-07-15 2021-07-15 test todo
x 2021-07-17 2021-07-17 test todo x 2021-07-17 2021-07-17 test todo
x 2021-07-25 2021-07-25 test todo x 2021-07-25 2021-07-25 test todo
x 2021-07-27 2021-07-27 test todo x 2021-07-27 2021-07-27 test todo
x 2021-09-24 2021-09-24 test todo
{"theme":"light","width":1538,"height":863,"horizontal":145,"vertical":548,"maximizeWindow":false,"notifications":true,"useTextarea":false,"compactView":false,"matomoEvents":false,"drawerWidth":"500","showDueIsPast":true,"showDueIsFuture":true,"showDueIsToday":true,"showHidden":false,"showCompleted":true,"sortCompletedLast":false,"sortBy":["priority","dueString","contexts","projects"],"zoom":"100","tray":false,"showEmptyFilters":true,"dismissedNotifications":[-1319247018],"dismissedMessages":[],"hideFilterCategories":[],"language":"en","uid":"TESTING","path":"test/preferences_empty/todo.txt","files":[[1,"test/preferences_empty/todo.txt"]],"file":"test/preferences_empty/todo.txt","filterDrawer":false,"selectedFilters":[],"viewDrawer":false,"sortByLevel":["priority","dueString","contexts","projects"],"deferredTodos":true,"fileTabs":true} {"theme":"light","width":1538,"height":863,"horizontal":145,"vertical":577,"maximizeWindow":false,"notifications":true,"useTextarea":false,"compactView":false,"matomoEvents":false,"drawerWidth":"500","showDueIsPast":true,"showDueIsFuture":true,"showDueIsToday":true,"showHidden":false,"showCompleted":true,"sortCompletedLast":false,"sortBy":["priority","dueString","contexts","projects"],"zoom":"100","tray":false,"showEmptyFilters":true,"dismissedNotifications":[-1319247018],"dismissedMessages":[],"hideFilterCategories":[],"language":"en","uid":"TESTING","path":"test/preferences_empty/todo.txt","files":[[1,"test/preferences_empty/todo.txt"]],"file":"test/preferences_empty/todo.txt","filterDrawer":false,"selectedFilters":[],"viewDrawer":false,"sortByLevel":["priority","dueString","contexts","projects"],"deferredTodos":true,"fileTabs":true}
\ No newline at end of file \ No newline at end of file
{"theme":"light","width":1538,"height":863,"horizontal":46,"vertical":29,"maximizeWindow":true,"notifications":true,"useTextarea":false,"compactView":false,"matomoEvents":false,"drawerWidth":"500","showDueIsPast":true,"showDueIsFuture":true,"showDueIsToday":true,"showHidden":false,"showCompleted":true,"sortCompletedLast":false,"sortBy":["priority","dueString","contexts","projects"],"zoom":"100","tray":false,"showEmptyFilters":true,"dismissedNotifications":[-1319247018],"dismissedMessages":[],"hideFilterCategories":[],"language":"en","uid":"TESTING","path":"test/preferences_existent/todo.txt","files":[[1,"test/preferences_existent/todo.txt"]],"file":"test/preferences_existent/todo.txt","filterDrawer":false,"selectedFilters":[],"viewDrawer":false,"sortByLevel":["priority","dueString","contexts","projects"],"deferredTodos":true,"fileTabs":true} {"theme":"light","width":1538,"height":863,"horizontal":46,"vertical":389,"maximizeWindow":true,"notifications":true,"useTextarea":false,"compactView":false,"matomoEvents":false,"drawerWidth":"500","showDueIsPast":true,"showDueIsFuture":true,"showDueIsToday":true,"showHidden":false,"showCompleted":true,"sortCompletedLast":false,"sortBy":["priority","dueString","contexts","projects"],"zoom":"100","tray":false,"showEmptyFilters":true,"dismissedNotifications":[-1319247018],"dismissedMessages":[],"hideFilterCategories":[],"language":"en","uid":"TESTING","path":"test/preferences_existent/todo.txt","files":[[1,"test/preferences_existent/todo.txt"]],"file":"test/preferences_existent/todo.txt","filterDrawer":false,"selectedFilters":[],"viewDrawer":false,"sortByLevel":["priority","dueString","contexts","projects"],"deferredTodos":true,"fileTabs":true}
\ No newline at end of file \ No newline at end of file
{"theme":"light","width":1100,"height":700,"horizontal":129,"vertical":525,"maximizeWindow":false,"notifications":true,"useTextarea":false,"compactView":false,"matomoEvents":false,"drawerWidth":"500","showDueIsPast":true,"showDueIsFuture":true,"showDueIsToday":true,"showHidden":false,"showCompleted":true,"sortCompletedLast":false,"sortBy":["priority","dueString","contexts","projects"],"zoom":"100","tray":false,"showEmptyFilters":true,"hideFilterCategories":[],"language":"en","dismissedNotifications":[],"dismissedMessages":[],"sortByLevel":["priority","dueString","contexts","projects"],"deferredTodos":true,"fileTabs":true} {"theme":"light","width":1100,"height":700,"horizontal":129,"vertical":670,"maximizeWindow":false,"notifications":true,"useTextarea":false,"compactView":false,"matomoEvents":false,"drawerWidth":"500","showDueIsPast":true,"showDueIsFuture":true,"showDueIsToday":true,"showHidden":false,"showCompleted":true,"sortCompletedLast":false,"sortBy":["priority","dueString","contexts","projects"],"zoom":"100","tray":false,"showEmptyFilters":true,"hideFilterCategories":[],"language":"en","dismissedNotifications":[],"dismissedMessages":[],"sortByLevel":["priority","dueString","contexts","projects"],"deferredTodos":true,"fileTabs":true}
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment