Skip to content

Commit

Permalink
Fixed a bug in todo deletion, added keyboard shortcuts for handling s…
Browse files Browse the repository at this point in the history
…earch field visibility and adding todo from search field
  • Loading branch information
ransome1 committed Oct 27, 2023
1 parent c7d7daa commit 7578703
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ npm-debug.log.*
*.dtmp
*.drawio
*.snap
*FilterLang.js
*FilterLang.js
*package-lock.json
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.0" date="2023-10-26"/>
<release version="2.0.0-dev19" date="2023-10-27"/>
</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 flatpak/com.github.ransome1.sleek.desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Desktop Entry]
Version=2.0.0
Version=2.0.0-dev19
Name=sleek
Exec=sleek
Type=Application
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"webpack-merge": "^5.9.0"
},
"build": {
"buildVersion": "27",
"buildVersion": "28",
"asar": true,
"asarUnpack": "**\\*.{node,dll}",
"files": [
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.0-dev18",
"version": "2.0.0-dev19",
"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
30 changes: 15 additions & 15 deletions release/app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@

anymatch@~3.1.2:
version "3.1.3"
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.3.tgz#790c58b19ba1720a84205b57c618d5ad8524973e"
resolved "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz"
integrity sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==
dependencies:
normalize-path "^3.0.0"
picomatch "^2.0.4"

binary-extensions@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
resolved "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz"
integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==

braces@~3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
resolved "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz"
integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==
dependencies:
fill-range "^7.0.1"

chokidar@^3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd"
resolved "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz"
integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==
dependencies:
anymatch "~3.1.2"
Expand All @@ -39,67 +39,67 @@ chokidar@^3.5.3:

fill-range@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
resolved "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz"
integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==
dependencies:
to-regex-range "^5.0.1"

fsevents@~2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz"
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==

glob-parent@~5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4"
resolved "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz"
integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==
dependencies:
is-glob "^4.0.1"

is-binary-path@~2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09"
resolved "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz"
integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==
dependencies:
binary-extensions "^2.0.0"

is-extglob@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2"
resolved "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz"
integrity sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==

is-glob@^4.0.1, is-glob@~4.0.1:
version "4.0.3"
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084"
resolved "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz"
integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==
dependencies:
is-extglob "^2.1.1"

is-number@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
resolved "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz"
integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==

normalize-path@^3.0.0, normalize-path@~3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
resolved "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz"
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==

picomatch@^2.0.4, picomatch@^2.2.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
resolved "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz"
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==

readdirp@~3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7"
resolved "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz"
integrity sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==
dependencies:
picomatch "^2.2.1"

to-regex-range@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-5.0.1.tgz#1648c44aae7c8d988a326018ed72f5b4dd0392e4"
resolved "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz"
integrity sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==
dependencies:
is-number "^7.0.0"
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: core18
version: "2.0.0"
version: "2.0.0-dev19"
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
2 changes: 1 addition & 1 deletion src/main/modules/File/Write.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function removeLineFromFile(id: number) {
const files = configStorage.get('files') as File[];
const activeFile = getActiveFile(files);

if (activeFile && activeFile.todoFilePath) { // Check if activeFile and todoFilePath are defined
if (activeFile && activeFile.todoFilePath) {
lines.splice(id, 1);
const modifiedContent = lines.join('\n');

Expand Down
12 changes: 10 additions & 2 deletions src/main/modules/Ipc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ function handleChangeDoneFilePath(event: IpcMainEvent, index: number): void {
}
}

function handleRemoveLineFromFile(event: IpcMainEvent, index: number): void {
try {
removeLineFromFile(index);
} catch (error: any) {
console.error('ipcEvents.ts:', error);
}
}

function handleSaveToClipboard(event: IpcMainEvent, string: string): void {
try {
clipboard.writeText(string);
Expand Down Expand Up @@ -138,7 +146,7 @@ function removeEventListeners(): void {
ipcMain.off('saveToClipboard', handleSaveToClipboard);
ipcMain.off('revealFile', handleRevealFile);
ipcMain.off('changeDoneFilePath', handleChangeDoneFilePath);
ipcMain.off('removeLineFromFile', removeLineFromFile);
ipcMain.off('removeLineFromFile', handleRemoveLineFromFile);
}

app.on('before-quit', removeEventListeners);
Expand All @@ -158,4 +166,4 @@ ipcMain.on('droppedFile', handleDroppedFile);
ipcMain.on('saveToClipboard', handleSaveToClipboard);
ipcMain.on('revealFile', handleRevealFile);
ipcMain.on('changeDoneFilePath', handleChangeDoneFilePath);
ipcMain.on('removeLineFromFile', removeLineFromFile);
ipcMain.on('removeLineFromFile', handleRemoveLineFromFile);
2 changes: 2 additions & 0 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ const App = () => {
sorting={sorting}
setSorting={setSorting}
attributeMapping={attributeMapping}
searchFieldRef={searchFieldRef}
/>
</>
)}
Expand All @@ -231,6 +232,7 @@ const App = () => {
setSearchString={setSearchString}
isSearchOpen={isSearchOpen}
setIsSearchOpen={setIsSearchOpen}
setIsSearchOpen={setIsSearchOpen}
searchFieldRef={searchFieldRef}
/>
<ToolBar
Expand Down
1 change: 0 additions & 1 deletion src/renderer/Drawer/Attributes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
display: none;
justify-content: center;
align-items: center;
line-height: 2.6em;
border-radius: $radius;
position: absolute;
z-index: 5;
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface Props extends WithTranslation {
attributes: Attributes;
filters: Filters;
attributeMapping: TranslatedAttributes;
searchFieldRef: React.RefObject<HTMLInputElement>;
t: typeof i18n.t;
}

Expand All @@ -28,6 +29,7 @@ const DrawerComponent: React.FC<Props> = ({
attributes,
filters,
attributeMapping,
searchFieldRef,
t
}) => {
const [activeTab, setActiveTab] = useState<string>('attributes');
Expand Down Expand Up @@ -57,7 +59,8 @@ const DrawerComponent: React.FC<Props> = ({
};

const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
const isSearchFocused = document.activeElement === searchFieldRef.current;
if (!isSearchFocused && event.key === 'Escape') {
setIsDrawerOpen(false);
}
};
Expand Down
24 changes: 21 additions & 3 deletions src/renderer/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, ChangeEvent } from 'react';
import React, { useEffect, ChangeEvent, useCallback } from 'react';
import { TextField, InputAdornment, Button, Box } from '@mui/material';
import CancelIcon from '@mui/icons-material/Cancel';
import { withTranslation, WithTranslation } from 'react-i18next';
Expand All @@ -22,6 +22,7 @@ const Search: React.FC<Props> = ({
searchString,
setSearchString,
isSearchOpen,
setIsSearchOpen,
searchFieldRef,
t,
}) => {
Expand All @@ -43,11 +44,21 @@ const Search: React.FC<Props> = ({
searchFieldRef.current?.focus();
};

const handleKeyDown = useCallback((event: KeyboardEvent) => {
const isSearchFocused = document.activeElement === searchFieldRef.current;
if(isSearchFocused && event.key === 'Escape' && searchString) {
setSearchString('');
} else if(isSearchFocused && event.key === 'Escape' && !searchString) {
setIsSearchOpen(false);
} else if(searchString && (event.metaKey || event.ctrlKey) && event.key === 'Enter') {
ipcRenderer.send('writeTodoToFile', undefined, searchString);
setSearchString('');
}
});

useEffect(() => {
if (searchString === null) return;

let delayedSearch: NodeJS.Timeout;

const handleSearch = () => {
ipcRenderer.send('requestData', searchString);
};
Expand All @@ -65,6 +76,13 @@ const Search: React.FC<Props> = ({
}
}, [isSearchOpen, searchFieldRef]);

useEffect(() => {
document.addEventListener('keydown', handleKeyDown);
return () => {
document.removeEventListener('keydown', handleKeyDown);
};
}, [handleKeyDown]);

return (
<>
{isSearchOpen && (
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/ToolBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const ToolBar: React.FC<Props> = ({
setIsSearchOpen((prevIsSearchOpen) => !prevIsSearchOpen);
};

const handleKeyDown = useCallback(
(event: KeyboardEvent) => {
const handleKeyDown = useCallback((event: KeyboardEvent) => {
const isSearchFocused = document.activeElement === searchFieldRef.current;
if ((event.metaKey || event.ctrlKey) && event.key === 'f' && isSearchOpen && !isSearchFocused) {
event.preventDefault();
Expand Down

0 comments on commit 7578703

Please sign in to comment.