-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor clipboard actions to use useClipboard hook #613
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
Conversation
… for clipboard actions
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
… for clipboard actions feat: add error callback to useClipboard.write and restore error handling in ItemGroupListView/ItemListView
…l using useCopyPasteActions
…alContext in MealEditView
…alContext in RecipeEditView
…d remove utility file
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.
Pull Request Overview
This PR refactors the clipboard copy/paste logic across recipe, meal, item-group, and food-item components to use shared hooks, improving code reuse, error handling, and schema validation.
- Introduces
useCopyPasteActionsfor unified copy/paste flows inRecipeEditViewandMealEditView. - Replaces direct
navigator.clipboardcalls inItemGroupListViewandItemListViewwith theuseClipboardhook. - Enhances
useClipboardto accept an error callback and ignoreNotAllowedError.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/sections/recipe/components/RecipeEditView.tsx | Switched to useCopyPasteActions, removed duplicated code |
| src/sections/meal/components/MealEditView.tsx | Same refactor for meal editor |
| src/sections/item-group/components/ItemGroupListView.tsx | Replaced inline clipboard with useClipboard |
| src/sections/item-group/components/ItemGroupEditModal.tsx | Integrated useCopyPasteActions; removed custom clipboard code |
| src/sections/food-item/components/ItemListView.tsx | Replaced inline clipboard in item list with useClipboard |
| src/sections/common/hooks/useCopyPasteActions.ts | New shared hook for copy/paste operations |
| src/sections/common/hooks/useClipboard.tsx | Expanded write API to accept error callback |
| package.json | Bumped version to match issue #472 |
| .github/copilot-instructions.md | Added static import guideline under Imports |
Comments suppressed due to low confidence (5)
src/sections/item-group/components/ItemGroupListView.tsx:18
- [nitpick] Naming the entire hook result as
clipboardcan be confusing; destructure only the needed methods (e.g.,const { write, clear } = useClipboard()) for clarity.
const clipboard = useClipboard()
src/sections/food-item/components/ItemListView.tsx:43
- [nitpick] To improve readability, destructure the hook return value instead of using a generic
clipboardobject, e.g.,const { write } = useClipboard().
const clipboard = useClipboard()
src/sections/common/hooks/useCopyPasteActions.ts:1
- The new
useCopyPasteActionshook encapsulates important logic but currently has no unit tests; consider adding tests forhandleCopy,handlePaste, and validation flows.
import { useClipboard, createClipboardSchemaFilter } from '~/sections/common/hooks/useClipboard'
src/sections/common/hooks/useCopyPasteActions.ts:5
- Add JSDoc descriptions for the returned properties (
handleCopy,handlePaste, etc.) so consumers know their purpose and return types.
/**
src/sections/item-group/components/ItemGroupEditModal.tsx:473
- Missing import for
useConfirmModalContext, which will cause a runtime error. Please addimport { useConfirmModalContext } from '~/sections/common/context/ConfirmModalContext'at the top of the file.
const { show: showConfirmModal } = useConfirmModalContext()
Refactor clipboard actions in ItemGroupListView and ItemListView to utilize the useClipboard hook, streamlining the copy functionality and improving error handling.
Closes #472