-
Notifications
You must be signed in to change notification settings - Fork 68
feat:extend-shortcuts #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
its-me-abhishek
merged 8 commits into
CCExtractor:main
from
Neeraj-gagat:feat/extend-shortcuts
Jan 9, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9c92318
add shortcts keys in taskdialog
Neeraj-gagat d5e5a1c
resolved conflicts
Neeraj-gagat 8dd2880
feat:extend-shortcuts
Neeraj-gagat 2e962df
Merge branch 'main' into feat/extend-shortcuts
Neeraj-gagat ee15fc4
feat:extends-shortcuts
Neeraj-gagat ffaa0ef
feat:extends-shortcuts
Neeraj-gagat 6d7d1a4
feat:extend-shortcuts
Neeraj-gagat 2ef0273
feat:extend-shortcuts
Neeraj-gagat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
264 changes: 245 additions & 19 deletions
264
frontend/src/components/HomeComponents/Tasks/TaskDialog.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
frontend/src/components/HomeComponents/Tasks/UseTaskDialogFocusMap.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { UseTaskDialogFocusMapProps } from '@/components/utils/types'; | ||
| import React from 'react'; | ||
|
|
||
| export function useTaskDialogFocusMap<F extends readonly string[]>({ | ||
| fields, | ||
| inputRefs, | ||
| }: UseTaskDialogFocusMapProps<F>) { | ||
| return React.useCallback( | ||
| (field: F[number]) => { | ||
| const element = inputRefs.current[field]; | ||
| if (!element) return; | ||
|
|
||
| element.focus(); | ||
|
|
||
| if ( | ||
| field === 'due' || | ||
| field === 'start' || | ||
| field === 'end' || | ||
| field === 'wait' || | ||
| field === 'entry' | ||
| ) { | ||
| element.click(); | ||
| } | ||
| }, | ||
| [fields, inputRefs] | ||
| ); | ||
| } | ||
57 changes: 57 additions & 0 deletions
57
frontend/src/components/HomeComponents/Tasks/UseTaskDialogKeyboard.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { UseTaskDialogKeyboardProps } from '@/components/utils/types'; | ||
| import React from 'react'; | ||
|
|
||
| export function useTaskDialogKeyboard<F extends readonly string[]>({ | ||
| fields, | ||
| focusedFieldIndex, | ||
| setFocusedFieldIndex, | ||
| isEditingAny, | ||
| triggerEditForField, | ||
| stopEditing, | ||
| }: UseTaskDialogKeyboardProps<F>) { | ||
| return React.useCallback( | ||
| (e: React.KeyboardEvent) => { | ||
| const target = e.target as HTMLElement; | ||
|
|
||
| const isTyping = | ||
| target.tagName === 'INPUT' || | ||
| target.tagName === 'TEXTAREA' || | ||
| target.isContentEditable; | ||
|
|
||
| if (isTyping) return; | ||
|
|
||
| switch (e.key) { | ||
| case 'ArrowDown': | ||
| e.preventDefault(); | ||
| if (isEditingAny) return; | ||
| setFocusedFieldIndex((i) => Math.min(i + 1, fields.length - 1)); | ||
| break; | ||
|
|
||
| case 'ArrowUp': | ||
| e.preventDefault(); | ||
| if (isEditingAny) return; | ||
| setFocusedFieldIndex((i) => Math.max(i - 1, 0)); | ||
| break; | ||
|
|
||
| case 'Enter': | ||
| if (isEditingAny) return; | ||
| e.preventDefault(); | ||
| triggerEditForField(fields[focusedFieldIndex]); | ||
| break; | ||
|
|
||
| case 'Escape': | ||
| e.preventDefault(); | ||
| stopEditing(); | ||
| break; | ||
| } | ||
| }, | ||
| [ | ||
| fields, | ||
| focusedFieldIndex, | ||
| isEditingAny, | ||
| setFocusedFieldIndex, | ||
| stopEditing, | ||
| triggerEditForField, | ||
| ] | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
frontend/src/components/HomeComponents/Tasks/__tests__/UseTaskDialogFocusMap.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { act, renderHook } from '@testing-library/react'; | ||
| import { useTaskDialogFocusMap } from '../UseTaskDialogFocusMap'; | ||
|
|
||
| describe('UseTaskDialogFocusMap', () => { | ||
| test('focus is being called for any field with an element', () => { | ||
| const focus = jest.fn(); | ||
| const click = jest.fn(); | ||
|
|
||
| const inputrefs = { | ||
| current: { | ||
| description: { focus, click }, | ||
| }, | ||
| }; | ||
|
|
||
| const { result } = renderHook(() => | ||
| useTaskDialogFocusMap({ | ||
| fields: ['description'], | ||
| inputRefs: inputrefs as any, | ||
| }) | ||
| ); | ||
|
|
||
| act(() => { | ||
| result.current('description'); | ||
| }); | ||
|
|
||
| expect(focus).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('click is being called for date field', () => { | ||
| const focus = jest.fn(); | ||
| const click = jest.fn(); | ||
|
|
||
| const inputrefs = { | ||
| current: { | ||
| due: { focus, click }, | ||
| }, | ||
| }; | ||
|
|
||
| const { result } = renderHook(() => | ||
| useTaskDialogFocusMap({ | ||
| fields: ['due'], | ||
| inputRefs: inputrefs as any, | ||
| }) | ||
| ); | ||
|
|
||
| act(() => { | ||
| result.current('due'); | ||
| }); | ||
|
|
||
| expect(focus).toHaveBeenCalled(); | ||
| expect(click).toHaveBeenCalled(); | ||
| }); | ||
| }); |
128 changes: 128 additions & 0 deletions
128
frontend/src/components/HomeComponents/Tasks/__tests__/UseTaskDialogKeyboard.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import { act, renderHook } from '@testing-library/react'; | ||
| import { useTaskDialogKeyboard } from '../UseTaskDialogKeyboard'; | ||
|
|
||
| const FIELDS = ['Description', 'start', 'due'] as const; | ||
| const setFocusedFieldIndex = jest.fn(); | ||
| const triggerEditForField = jest.fn(); | ||
| const stopEditing = jest.fn(); | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe('UseTaskDialogKeyboard', () => { | ||
| test('ArrowDown increments focusFieldsIndex', () => { | ||
| const { result } = renderHook(() => | ||
| useTaskDialogKeyboard({ | ||
| fields: FIELDS, | ||
| focusedFieldIndex: 0, | ||
| setFocusedFieldIndex, | ||
| stopEditing, | ||
| isEditingAny: false, | ||
| triggerEditForField, | ||
| }) | ||
| ); | ||
|
|
||
| act(() => { | ||
| result.current({ | ||
| key: 'ArrowDown', | ||
| preventDefault: jest.fn(), | ||
| target: document.body, | ||
| } as any); | ||
| }); | ||
|
|
||
| expect(setFocusedFieldIndex).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('ArrowUp decrement focusFieldsIndex', () => { | ||
| const { result } = renderHook(() => | ||
| useTaskDialogKeyboard({ | ||
| fields: FIELDS, | ||
| focusedFieldIndex: 1, | ||
| setFocusedFieldIndex, | ||
| stopEditing, | ||
| isEditingAny: false, | ||
| triggerEditForField, | ||
| }) | ||
| ); | ||
|
|
||
| act(() => { | ||
| result.current({ | ||
| key: 'ArrowUp', | ||
| preventDefault: jest.fn(), | ||
| target: document.body, | ||
| } as any); | ||
| }); | ||
|
|
||
| expect(setFocusedFieldIndex).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('Enter key trigger edit for focusfield', () => { | ||
| const { result } = renderHook(() => | ||
| useTaskDialogKeyboard({ | ||
| fields: FIELDS, | ||
| focusedFieldIndex: 2, | ||
| setFocusedFieldIndex: jest.fn(), | ||
| stopEditing: jest.fn(), | ||
| isEditingAny: false, | ||
| triggerEditForField, | ||
| }) | ||
| ); | ||
|
|
||
| act(() => { | ||
| result.current({ | ||
| key: 'Enter', | ||
| preventDefault: jest.fn(), | ||
| target: document.body, | ||
| } as any); | ||
| }); | ||
|
|
||
| expect(triggerEditForField).toHaveBeenCalledWith('due'); | ||
| }); | ||
|
|
||
| test('Escape key exit editing mode', () => { | ||
| const { result } = renderHook(() => | ||
| useTaskDialogKeyboard({ | ||
| fields: FIELDS, | ||
| focusedFieldIndex: 1, | ||
| setFocusedFieldIndex: jest.fn(), | ||
| stopEditing, | ||
| isEditingAny: false, | ||
| triggerEditForField: jest.fn(), | ||
| }) | ||
| ); | ||
|
|
||
| act(() => { | ||
| result.current({ | ||
| key: 'Escape', | ||
| preventDefault: jest.fn(), | ||
| target: document.body, | ||
| } as any); | ||
| }); | ||
|
|
||
| expect(stopEditing).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('prevent navigating when editing', () => { | ||
| const { result } = renderHook(() => | ||
| useTaskDialogKeyboard({ | ||
| fields: FIELDS, | ||
| focusedFieldIndex: 0, | ||
| setFocusedFieldIndex, | ||
| stopEditing, | ||
| isEditingAny: true, | ||
| triggerEditForField, | ||
| }) | ||
| ); | ||
|
|
||
| act(() => { | ||
| result.current({ | ||
| key: 'ArrowDown', | ||
| preventDefault: jest.fn(), | ||
| target: document.createElement('div'), | ||
| } as any); | ||
| }); | ||
|
|
||
| expect(setFocusedFieldIndex).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| export const FIELDS = [ | ||
| 'description', | ||
| 'due', | ||
| 'start', | ||
| 'end', | ||
| 'wait', | ||
| 'depends', | ||
| 'priority', | ||
| 'project', | ||
| 'tags', | ||
| 'entry', | ||
| 'recur', | ||
| 'annotations', | ||
| ] as const; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.