Skip to content
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

Add initial keyboard shortcuts #32

Merged
merged 20 commits into from
Jun 11, 2024
Merged

Add initial keyboard shortcuts #32

merged 20 commits into from
Jun 11, 2024

Conversation

keturiosakys
Copy link
Member

@keturiosakys keturiosakys commented Jun 7, 2024

related to FP-3765

Initial PR for experimenting with keyboard shortcuts in the mizu-fpx app.

It adds a generic useKeySequence hook that can be used to add keyboard shortcuts to any React component.

It also adds a basic navigation hook for up/down the request table, and enter/escape for jumping to the details and back home.

TODO:

  • [ ] I didn't add any scope yet so the keyboard shortcuts are global to the component. Probably worth figuring out some sort of scope system.
  • Currently the app will crash for the first row you attempt to navigate to..investigating

this is specifically for vim-like "gi", "go" or individual key "j" and
"k" handling. Chord combinations should probably have a different hook
without the timeout parameter
@keturiosakys keturiosakys changed the title Add initial keyboard shortcuts WIP: Add initial keyboard shortcuts Jun 7, 2024
@brettimus
Copy link
Contributor

keebs

@keturiosakys keturiosakys changed the title WIP: Add initial keyboard shortcuts Add initial keyboard shortcuts Jun 10, 2024
@brettimus
Copy link
Contributor

brettimus commented Jun 10, 2024

hmm doesn't seem to work for me when i pull it down. i only have one row in my table fwiw. it gets auto selected, but pressing enter does nothing.

then if i press j, the row gets unselected, and if i hit enter again, the app crashes (will comment on the code that crashes)

The code that causes the crash is in Requests.tsx in the <DataTable ...

      // `row` is not defined when i press enter, which causes this to crash
      handleRowClick={(row) => navigate(`/requests/${row.id}`)}

@brettimus
Copy link
Contributor

also when i navigate with enter i have to hit back twice in the browser to go back to the requests page

@keturiosakys
Copy link
Member Author

yea ran into this myself with 1 row. Think the hook + its use needs some rework.. brb

@keturiosakys
Copy link
Member Author

keturiosakys commented Jun 10, 2024

should be fixed (except the history issue) @brettimus can you give it a try?

@brettimus
Copy link
Contributor

yep seems fixed! i think i resolved the history issue, kinda hard to explain, but the gist of it is that you should avoid side-effects in a state-updater function. react got confused.

i moved the problematic logic outside of the state-updater, and put it inside its own useEffect. no more history woes but it's late and i might've borked something else 🥴

if you mouse over a row and then start using "j" and "k" to move around
it will continue from the point of where you moused
Copy link
Member

@flenter flenter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some stylistic feedback.

frontend/src/components/ui/DataTable.tsx Outdated Show resolved Hide resolved
frontend/src/components/ui/DataTable.tsx Outdated Show resolved Hide resolved
frontend/src/components/ui/DataTable.tsx Outdated Show resolved Hide resolved
@keturiosakys keturiosakys merged commit 4b6ddb4 into main Jun 11, 2024
2 checks passed
@keturiosakys keturiosakys deleted the keebs branch June 11, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants