Skip to content

Commit

Permalink
Fixed a bug, where previously entered search string was ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
ransome1 committed Dec 18, 2023
1 parent 3a4f0ee commit 4049ed9
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 15 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.4-rc.2" date="2023-12-16"/>
<release version="2.0.4-rc.2" date="2023-12-18"/>
</releases>
<url type="homepage">https://github.com/ransome1/sleek</url>
<url type="contact">https://github.com/ransome1/sleek/issues</url>
Expand Down
4 changes: 2 additions & 2 deletions src/main/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ if(!fs.existsSync(customStylesPath)) {

filterStorage.onDidAnyChange(async () => {
try {
await processDataRequest('')
await processDataRequest()
} catch(error) {
console.error(error);
}
});

configStorage.onDidAnyChange(async () => {
try {
await processDataRequest('')
await processDataRequest()
} catch(error) {
console.error(error);
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/modules/File/Watcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ function createFileWatcher(files: FileObject[]): void {
})
.on('change', async (file) => {
console.log(`File ${file} has been changed`);

await processDataRequest('');
await processDataRequest();
})
.on('unlink', (file) => {
console.log(`FileWatcher.ts: FileObject ${file} has been unlinked`);
Expand Down
1 change: 0 additions & 1 deletion src/main/modules/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function createMenu(files: FileObject[]) {
label: 'About',
click: async () => {
const options = {
type: 'info',
title: 'About sleek',
message: `sleek v${app.getVersion()}`,
detail: description,
Expand Down
11 changes: 10 additions & 1 deletion src/main/modules/ProcessDataRequest/ProcessDataRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ const headers: HeadersObject = {
completedTodoObjects: 0,
};

async function processDataRequest(searchString: string): Promise<void> {
let searchString;

async function processDataRequest(search: string): Promise<void> {

if(search) {
searchString = search;
} else if(search === '') {
searchString = '';
}

const activeFile: FileObject | null = getActiveFile();
if(!activeFile) {
throw new Error('No active file');
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const App = () => {
const [searchString, setSearchString] = useState<string>('');
const [flattenedTodoObjects, setTodoObjects] = useState<TodoObject[] | null>(null);
const [todoObject, setTodoObject] = useState<TodoObject | null>(null);
const [headers, setHeaders] = useState<Headers | null>(null);
const [headers, setHeaders] = useState<HeadersObject | null>(null);
const [filters, setFilters] = useState<Filters | null>(null);
const [attributes, setAttributes] = useState<Attributes | null>(null);
const [sorting, setSorting] = useState<Sorting>(store.get('sorting') || null);
Expand Down Expand Up @@ -304,6 +304,7 @@ const App = () => {
isSearchOpen={isSearchOpen}
setIsSearchOpen={setIsSearchOpen}
searchFieldRef={searchFieldRef}
setTextFieldValue={setTextFieldValue}
/>
<ToolBar
isSearchOpen={isSearchOpen}
Expand Down
16 changes: 9 additions & 7 deletions src/renderer/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ const { ipcRenderer } = window.api;

interface Props extends WithTranslation {
headers: HeadersObject;
searchString: string | null;
searchString: string;
setSearchString: (searchString: string) => void;
isSearchOpen: boolean;
setIsSearchOpen: (isSearchOpen: boolean) => void;
searchFieldRef: React.RefObject<HTMLInputElement>;
setTextFieldValue: React.RefObject<string>;
t: typeof i18n.t;
}

Expand All @@ -24,11 +25,11 @@ const Search: React.FC<Props> = memo(({
isSearchOpen,
setIsSearchOpen,
searchFieldRef,
setTextFieldValue,
t,
}) => {
const handleInput = (event: ChangeEvent<HTMLInputElement>) => {
const searchString = event.target.value;
setSearchString(searchString);
setSearchString(event.target.value);
};

const handleAddTodo = () => {
Expand Down Expand Up @@ -57,13 +58,14 @@ const Search: React.FC<Props> = memo(({
});

useEffect(() => {
if(searchString === null) return;
let delayedSearch: NodeJS.Timeout;

if(!searchString) setTextFieldValue('')

const handleSearch = () => {
ipcRenderer.send('requestData', searchString);
};

delayedSearch = setTimeout(handleSearch, 200);
const delayedSearch: NodeJS.Timeout = setTimeout(handleSearch, 200);

return () => {
clearTimeout(delayedSearch);
Expand Down Expand Up @@ -91,7 +93,7 @@ const Search: React.FC<Props> = memo(({
variant='outlined'
placeholder={`${t('search.visibleTodos')} ${headers.visibleObjects}`}
inputRef={searchFieldRef}
value={searchString === null ? '' : searchString}
value={searchString}
onChange={handleInput}
InputProps={{
endAdornment: (
Expand Down
File renamed without changes.

0 comments on commit 4049ed9

Please sign in to comment.