Skip to content

Commit

Permalink
Refactored the groups in renderer. Fixed bug in markdown parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
ransome1 committed Feb 8, 2024
1 parent 729c139 commit 8d63c9c
Show file tree
Hide file tree
Showing 23 changed files with 350 additions and 315 deletions.
2 changes: 1 addition & 1 deletion flatpak/com.github.ransome1.sleek.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<developer_name>Robin Ahle</developer_name>
<content_rating type="oars-1.1"/>
<releases>
<release version="2.0.9-rc.1" date="2024-02-03"/>
<release version="2.0.9-rc.2" date="2024-02-08"/>
</releases>
<url type="homepage">https://github.com/ransome1/sleek</url>
<url type="contact">https://github.com/ransome1/sleek/issues</url>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sleek",
"version": "2.0.9-rc.1",
"version": "2.0.9-rc.2",
"main": "./src/main/main.tsx",
"scripts": {
"build": "concurrently \"yarn run peggy\" \"yarn run build:main\" \"yarn run build:renderer\"",
Expand Down
2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sleek",
"version": "2.0.9-rc.1",
"version": "2.0.9-rc.2",
"description": "todo.txt manager for Linux, Windows and MacOS, free and open-source (FOSS)",
"synopsis": "todo.txt manager for Linux, Windows and MacOS, free and open-source (FOSS)",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: sleek
base: core20
version: "2.0.9-rc.1"
version: "2.0.9-rc.2"
summary: todo.txt manager for Linux, free and open-source (FOSS)
description: |
sleek is an open-source (FOSS) todo manager based on the todo.txt syntax. Stripped down to only the most necessary features, and with a clean and simple interface, sleek aims to help you focus on getting things done.
Expand Down
28 changes: 14 additions & 14 deletions src/__tests__/__mock__/recurrence.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

2024-02-03 Line 1 rec:1d due:2024-02-04
2024-02-03 Line 1 rec:w due:2024-02-10
2024-02-03 Line 1 rec:2m due:2024-04-03
2024-02-03 Line 1 rec:+1d due:2024-02-05
2024-02-03 Line 1 rec:7w due:2024-03-23
2024-02-03 Line 1 due:2023-07-24 rec:+1b
2024-02-03 taxes are due in one year t:2022-03-30 due:2022-04-30 rec:+1y
2024-02-03 Water plants @home +quick due:2024-02-10 t:2024-01-31 rec:1w
2024-02-03 Line 1 rec:+1d t:2023-09-20
2024-02-03 Line 1 rec:1d pri:A due:2024-02-04
2024-02-03 (A) Do something rec:d t:2024-02-04 @SomeContext
2024-02-03 Do something rec:0d
2024-02-03 Do something rec:0d due:2024-02-03
2024-02-03 Do something rec:0d due:2024-02-03 t:2024-02-03
2024-02-08 Line 1 rec:1d due:2024-02-09
2024-02-08 Line 1 rec:w due:2024-02-15
2024-02-08 Line 1 rec:2m due:2024-04-08
2024-02-08 Line 1 rec:+1d due:2024-02-10
2024-02-08 Line 1 rec:7w due:2024-03-28
2024-02-08 Line 1 due:2023-07-24 rec:+1b
2024-02-08 taxes are due in one year t:2022-03-30 due:2022-04-30 rec:+1y
2024-02-08 Water plants @home +quick due:2024-02-15 t:2024-02-05 rec:1w
2024-02-08 Line 1 rec:+1d t:2023-09-20
2024-02-08 Line 1 rec:1d pri:A due:2024-02-09
2024-02-08 (A) Do something rec:d t:2024-02-09 @SomeContext
2024-02-08 Do something rec:0d
2024-02-08 Do something rec:0d due:2024-02-08
2024-02-08 Do something rec:0d due:2024-02-08 t:2024-02-08
4 changes: 4 additions & 0 deletions src/__tests__/main/CreateTodoObjects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('Create todo objects', () => {
pm: "4",
string: '(B) Test +project @context todo 1 due:2023-12-31 t:2024-03-24 h:1 test @anotherContext pm:4 and a strict rec:+2w',
notify: false,
visible: true,
});
});

Expand All @@ -68,6 +69,7 @@ describe('Create todo objects', () => {
pm: null,
string: 'x 2023-07-23 2023-07-21 Test todo 2',
notify: false,
visible: true,
});
});

Expand All @@ -91,6 +93,7 @@ describe('Create todo objects', () => {
pm: null,
string: 'Test todo 3 due:end of the year',
notify: false,
visible: true,
});
});

Expand All @@ -114,6 +117,7 @@ describe('Create todo objects', () => {
pm: null,
string: 'Test todo 4 t:first day of next year',
notify: false,
visible: true,
});
});
});
18 changes: 16 additions & 2 deletions src/__tests__/main/ProcessTodoObjects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const todoObjects: any =
hidden: false,
pm: null,
string: '(C) 2025-12-09 +testProject5 test0 @testContext due:2023-01-02',
notify: false,
visible: true,
},
{
id: 1,
Expand All @@ -86,6 +88,8 @@ const todoObjects: any =
hidden: false,
pm: null,
string: '(B) 2023-12-01 test1 +testProject7 @testContext7 t:2023-12-15',
notify: false,
visible: true,
},
{
id: 2,
Expand All @@ -102,6 +106,8 @@ const todoObjects: any =
hidden: false,
pm: null,
string: 'x (C) 2025-12-08 2023-12-01 test2 +testProject1 @testContext due:2023-01-01',
notify: false,
visible: true,
},
{
id: 3,
Expand All @@ -118,6 +124,8 @@ const todoObjects: any =
hidden: false,
pm: null,
string: '(A) 2023-06-24 test3 +testProject6 @testContext6 due:2023-12-03',
notify: false,
visible: true,
},
{
id: 4,
Expand All @@ -134,6 +142,8 @@ const todoObjects: any =
hidden: false,
pm: null,
string: '(C) 2025-12-06 test3 +testProject3 @testContext due:2023-01-03',
notify: false,
visible: true,
},
{
id: 5,
Expand All @@ -150,6 +160,8 @@ const todoObjects: any =
hidden: false,
pm: null,
string: '(C) 2025-12-05 test3 +testProject2 @testContext due:2023-01-05',
notify: false,
visible: true,
},
{
id: 6,
Expand All @@ -165,7 +177,9 @@ const todoObjects: any =
rec: null,
hidden: false,
pm: null,
string: '(C) 2025-12-07 test3 +testProject4 @testContext due:2023-01-04'
string: '(C) 2025-12-07 test3 +testProject4 @testContext due:2023-01-04',
notify: false,
visible: true,
}
];

Expand All @@ -176,7 +190,7 @@ describe('Process todo.txt objects', () => {
});

test('Objects are counted correctly', () => {
const count: number = countTodoObjects(todoObjects, true);
const count: number = countTodoObjects(todoObjects, true, false);
expect(count).toEqual(1);
});

Expand Down
1 change: 1 addition & 0 deletions src/main/modules/Attributes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function updateAttributes(todoObjects: TodoObject[], sorting: Sorting[], reset:
(reset) ? attributes[key] = {} : attributes[key][attributeKey].count = 0
});
todoObjects.forEach((todoObject: TodoObject) => {
if(!todoObject.visible) return;
const value = todoObject[key as keyof TodoObject];
const notify: boolean = (key === 'due') ? !!todoObject?.notify : false;

Expand Down
10 changes: 2 additions & 8 deletions src/main/modules/IpcMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,9 @@ function handleSaveToClipboard(event: IpcMainEvent, string: string): void {
}
}

function handleOpenInBrowser(event: IpcMainEvent, url: string): void {
async function handleOpenInBrowser(event: IpcMainEvent, url: string): Promise<void> {
try {
if(url) {
shell?.openExternal(url);
}
await shell?.openExternal(url);
} catch (error: any) {
console.error(error);
event.reply('responseFromMainProcess', error);
Expand All @@ -212,9 +210,7 @@ function removeEventListeners(): void {
ipcMain.off('storeGetConfig', handleStoreGetConfig);
ipcMain.off('storeSetConfig', handleStoreSetConfig);
ipcMain.off('storeSetFilters', handleStoreSetFilters);

ipcMain.off('storeGetFilters', handleStoreGetFilters);

ipcMain.off('storeSetNotifiedTodoObjects', handleStoreSetNotifiedTodoObjects);
ipcMain.off('setFile', handleSetFile);
ipcMain.off('removeFile', handleRemoveFile);
Expand All @@ -239,9 +235,7 @@ app.on('before-quit', () => removeEventListeners);
ipcMain.on('storeGetConfig', handleStoreGetConfig);
ipcMain.on('storeSetConfig', handleStoreSetConfig);
ipcMain.on('storeSetFilters', handleStoreSetFilters);

ipcMain.on('storeGetFilters', handleStoreGetFilters);

ipcMain.on('storeSetNotifiedTodoObjects', handleStoreSetNotifiedTodoObjects);
ipcMain.on('setFile', handleSetFile);
ipcMain.on('removeFile', handleRemoveFile);
Expand Down
1 change: 1 addition & 0 deletions src/main/modules/ProcessDataRequest/CreateTodoObjects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function createTodoObject(index: number, string: string, attributeType?: string,
rec,
hidden,
pm,
visible: true,
string: content,
};
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/modules/ProcessDataRequest/ProcessDataRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ async function processDataRequest(search?: string): Promise<void> {

const fileContent = await readFileContent(activeFile.todoFilePath, activeFile.todoFileBookmark);
let todoObjects: TodoObject[] | [] = await createTodoObjects(fileContent);

todoObjects = handleTodoObjectsDates(todoObjects);
headers.availableObjects = countTodoObjects(todoObjects, false);
headers.completedTodoObjects = countTodoObjects(todoObjects, true);
todoObjects = handleCompletedTodoObjects(todoObjects);

updateAttributes(todoObjects, sorting, true);
Expand All @@ -41,7 +38,9 @@ async function processDataRequest(search?: string): Promise<void> {
if(filters) todoObjects = applyFilters(todoObjects, filters);
if(searchString) todoObjects = applySearchString(searchString, todoObjects);

headers.visibleObjects = countTodoObjects(todoObjects, false);
headers.visibleObjects = countTodoObjects(todoObjects, false, true);
headers.availableObjects = countTodoObjects(todoObjects, false);
headers.completedTodoObjects = countTodoObjects(todoObjects, true);

updateAttributes(todoObjects, sorting, false);

Expand Down
62 changes: 36 additions & 26 deletions src/main/modules/ProcessDataRequest/ProcessTodoObjects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { runQuery } from '../Filters/FilterQuery';
import { createTodoObject } from './CreateTodoObjects';
import { config } from '../../config';

function countTodoObjects(todoObjects: TodoObject[], completed: boolean): number {
function countTodoObjects(todoObjects: TodoObject[], completed: boolean, visible?: boolean): number {
const filteredTodoObjects: TodoObject[] = todoObjects.filter((todoObject: TodoObject) => {
if(completed) {
return todoObject.complete;
} else if(visible) {
return todoObject.visible;
} else {
return todoObject;
}
Expand All @@ -28,45 +30,59 @@ function checkForSearchMatches(todoString: string, searchString: string) {
function applySearchString(searchString: string, todoObjects: TodoObject[]): TodoObject[] {
try {
const query = FilterLang.parse(searchString);
return todoObjects.filter(todoObject => runQuery(todoObject, query));
return todoObjects.map(todoObject => {
if(!todoObject.visible) return todoObject;
todoObject.visible = runQuery(todoObject, query);
return todoObject;
});
} catch (error) {
const lowerSearchString = searchString.toLowerCase();
return Object.values(todoObjects)
.flat()
.filter(todoObject => todoObject?.string?.toLowerCase().includes(lowerSearchString)) as TodoObject[];
.map(todoObject => {
if(!todoObject.visible) return todoObject;
todoObject.visible = todoObject?.string?.toLowerCase().includes(lowerSearchString) || false;
return todoObject;
}) as TodoObject[];
}
}

function handleCompletedTodoObjects(todoObjects: TodoObject[]): TodoObject[] {
const showCompleted: boolean = config.get('showCompleted');
return todoObjects.filter((todoObject: TodoObject) => {
if(showCompleted) {
return true;
} else {
return !todoObject.complete;
return todoObjects.map((todoObject: TodoObject) => {
if(todoObject.complete && !showCompleted) {
todoObject.visible = false;
}
return todoObject;
});
}

function handleHiddenTodoObjects(todoObjects: TodoObject[]): TodoObject[] {
return Object.values(todoObjects)
.flat()
.filter((object: TodoObject | null) =>
object && !object.hidden
);
return todoObjects.map((todoObject: TodoObject) => {
if(!todoObject.visible) return todoObject;
todoObject.visible = todoObject.visible && !todoObject.hidden;
return todoObject;
});
}

function handleTodoObjectsDates(todoObjects: TodoObject[]): TodoObject[] {
const thresholdDateInTheFuture: boolean = config.get('thresholdDateInTheFuture');
const dueDateInTheFuture: boolean = config.get('dueDateInTheFuture');

return todoObjects.flat().filter((todoObject) => {
const tDate = dayjs(todoObject?.t);
return todoObjects.map((todoObject: TodoObject) => {

if(!todoObject.visible) return todoObject;

const thresholdDate = dayjs(todoObject?.t);
const dueDate = dayjs(todoObject?.due);
if(!dueDateInTheFuture && dueDate && dueDate.isAfter(dayjs())) {
return false;

if(thresholdDate && thresholdDate.isAfter(dayjs()) && !thresholdDateInTheFuture) {
todoObject.visible = false;
} else if(dueDate && dueDate.isAfter(dayjs()) && !dueDateInTheFuture) {
todoObject.visible = false;
}
return !(!thresholdDateInTheFuture && tDate && tDate.isAfter(dayjs()));

return todoObject;
});
}

Expand Down Expand Up @@ -125,8 +141,8 @@ function sortAndGroupTodoObjects(todoObjects: TodoObject[], sorting: Sorting[]):
return sortAndGroupObjects(sortedTodoObjects, 0, sorting);
}

function flattenTodoObjects(todoObjects: TodoObject[], topLevelGroup: string): any {
const flattenedObjects = [];
function flattenTodoObjects(todoObjects: TodoObject[], topLevelGroup: string): TodoObject[] {
const flattenedObjects: TodoObject[] = [];
const flatten = (todoObject: any, sortingKey: string) => {
if(typeof todoObject === 'object' && todoObject !== null) {
if('id' in todoObject) {
Expand All @@ -140,12 +156,6 @@ function flattenTodoObjects(todoObjects: TodoObject[], topLevelGroup: string): a
}
}
for (const key in todoObjects) {
if(topLevelGroup) {
flattenedObjects.push({
group: topLevelGroup,
value: key,
});
}
flatten(todoObjects[key], topLevelGroup);
}
return flattenedObjects;
Expand Down
1 change: 1 addition & 0 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const App = () => {
setSearchString={setSearchString}
headers={headers}
settings={settings}
todoObjects={todoObjects}
/>
</div>
</div>
Expand Down
Loading

0 comments on commit 8d63c9c

Please sign in to comment.