-
Notifications
You must be signed in to change notification settings - Fork 62
front: allow users to copy and paste timetables #13943
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
base: dev
Are you sure you want to change the base?
Conversation
7c7b708 to
f4ebfc7
Compare
| if (!timetableItems) return; | ||
|
|
||
| const jsonString = timetableItemsToJson(selectedTimeTableIdsFromClick, timetableItems); | ||
| navigator.clipboard.writeText(jsonString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use ClipboardItem + clipboard.write() instead of text, to indicate that a JSON blob is being copied? Could also set disposition as attachment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately from what I saw, the clipboard doesn't support writing JSON, it can only write plain text, html or png. :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, what do you mean? Does it throw an error? Does it silently do nothing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It throw an error (DOMException with not supported type to be more specific).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, ClipboardItem.supports('application/json') returns false… It seems like we'd need to use a custom web MIME type if we wanted to assign a different MIME type…
|
|
||
| const ctrlV = useCallback( | ||
| async (event: KeyboardEvent) => { | ||
| if (!event.repeat && event.ctrlKey && event.key === 'v') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use the paste event instead of catching a specific combination of keypresses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
|
||
| const ctrlC = useCallback( | ||
| (event: KeyboardEvent) => { | ||
| if (!event.repeat && event.ctrlKey && event.key === 'c') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use the copy event here instead too (together with event.preventDefault() to disable the built-in copy behavior).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
f4ebfc7 to
c11bacc
Compare
Signed-off-by: Martin Bourbier <[email protected]>
Signed-off-by: Martin Bourbier <[email protected]>
Signed-off-by: Angelina Kuntz <[email protected]>
…g (ctrl+x) Signed-off-by: Angelina Kuntz <[email protected]>
e1d1f08 to
1b945a3
Compare
Signed-off-by: Martin Bourbier <[email protected]>
1b945a3 to
0cbf0ea
Compare
This PR allows users to copy and paste timetables using simple standard shortcuts (ctrl+c, ctrl+v, ctrl+x).
Closes #13902