Repository navigation
day308 Grida Canvas - UX / Icons Library - #466
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughThis pull request introduces a complete floating window system with dragging, boundary constraints, and portal support. It includes wrapper components, a demo page, and a new IconsBrowser component that enables searching, filtering, and inserting icons from multiple vendors into the editor. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant UI as UI (Trigger)
participant Window as FloatingWindowRoot
participant Browser as IconsBrowser
participant API as Icons API
participant Canvas as Canvas/Editor
User->>UI: Click "Open Icons Browser"
UI->>Window: trigger open via controls.openWindow()
Window->>Window: Show window (CSS transform)
User->>Browser: Type search query
Browser->>API: Fetch icons (vendor + query)
API-->>Browser: Return icons array
Browser->>Browser: Render virtualized grid
User->>Browser: Click icon
Browser->>Browser: Show loading toast
Browser->>API: Fetch SVG (download URL)
API-->>Browser: Return SVG blob
Browser->>Canvas: Call onInsert callback
Canvas->>Canvas: Fetch SVG, create node, set name
Canvas->>Browser: Success
Browser->>Browser: Show success toast
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Areas requiring extra attention:
Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }); | ||
| setVendorsLoaded(true); | ||
| } catch (e) { | ||
| console.warn("Failed to load icon vendors", e); |
There was a problem hiding this comment.
Handle vendor fetch failures so icons can load
When the vendors request fails (network or non-2xx), vendorsLoaded is never set and fetchIcons exits early whenever vendorsLoaded is false. That leaves loading stuck true and the icon list never fetches, even if the vendor endpoint recovers later. The catch block should mark vendors as handled or trigger an icon fetch fallback so users aren’t left with a permanent spinner after a transient vendor error.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (6)
editor/grida-canvas-hosted/playground/icons-browser.tsx (1)
242-244: Missing cleanup for fetchIcons effect.The effect at lines 242-244 triggers
fetchIconsbut doesn't handle component unmount during the async operation. While the hook's internal state updates won't crash, responses from stale requests could update state unexpectedly.Consider adding an AbortController for request cancellation:
useEffect(() => { - void fetchIcons(); - }, [fetchIcons, vendorsLoaded]); + const controller = new AbortController(); + void fetchIcons(controller.signal); + return () => controller.abort(); + }, [fetchIcons, vendorsLoaded]);This would require updating
fetchIconsto accept and use the signal. This is a minor concern since React state updates on unmounted components are safe in React 18+, but cleaner for request lifecycle management.editor/components/floating-window/primitives.tsx (5)
241-255: Optional: Consider reacting to boundary position changes, not just size
useElementRecttracks the boundary’sDOMRect, but the clamping/layout effect here only depends onboundarySizeandwindowSize. If the boundary moves (e.g., layout shift) without resizing, windows won’t be re-offset to the new location until some other trigger causesapplyPositionto run.If you expect the boundary to move independently of its size, consider including something derived from
boundaryRect(e.g.,boundaryRect?.left,boundaryRect?.top) in this effect’s dependencies, or adding a small effect that callsapplyPosition(positionRef.current)wheneverboundaryRectchanges. This would keep portalled windows perfectly aligned during layout shifts.
362-377: Ordering of spreads may allow consumer props to override drag handlersIn
FloatingWindowTitleBaryou spreaddragHandlePropsbefore{...rest}:<div {...dragHandleProps} {...rest} data-floating-window-titlebar className={className} >This means any event handlers or pointer props passed in
restcan override the drag handlers, potentially disabling dragging if a consumer supplies their ownonPointerDown, etc.If you’d prefer drag behavior to always be wired and still allow consumers to augment handlers, you could instead:
- Either spread
restfirst anddragHandlePropslast, or- Merge handlers explicitly (e.g., wrap both in a combined handler).
Right now it’s not wrong, but worth being aware of this precedence.
418-464: Improve disabled semantics for Trigger/Close when no controls are available
FloatingWindowTriggerandFloatingWindowClosesetaria-disabled={!getControls()}, but they always render an enabled<button>and still attachonClick. IfgetControls()returnsundefined, clicks become no-ops but the element is still focusable and announced as a normal button by some assistive tech.To tighten this up:
- Also set the actual
disabledattribute when!getControls():- <button - type="button" - onClick={handleClick} - aria-disabled={!getControls()} - {...rest} - > + <button + type="button" + onClick={handleClick} + aria-disabled={!getControls()} + disabled={!getControls()} + {...rest} + >Same for
FloatingWindowClose.This keeps the ARIA state and actual interactivity in sync and improves keyboard / AT behavior.
Also applies to: 466-512
532-552: Optional: Make measurement hooks resilient to ref target changesBoth
useElementSizeanduseElementRectdepend on[ref]and captureconst el = ref.currentonce when the effect runs. If the samerefobject gets re-attached to a different DOM node later (common with conditional rendering), the observers will continue to track the old node and ignore the new one.If you expect the referenced elements to change over time, consider:
- Depending on
ref.currentinstead ofref(with a small guard fornull), or- Using a callback ref that wires/unwires observers as the element instance changes.
Example tweak for
useElementSize:- useEffect(() => { - const el = ref.current; - if (!el) return; + useEffect(() => { + const el = ref.current; + if (!el) return; @@ - observer.observe(el); - return () => observer.disconnect(); - }, [ref]); + observer.observe(el); + return () => observer.disconnect(); + }, [ref.current]);(Same idea for
useElementRect.) Not mandatory given your current usage, but it makes these hooks more generally robust.Also applies to: 554-585
380-416: Minor:togglecaptures stale state; prefer functional updates for React 19 concurrent rendering
useFloatingWindowControlscapturesstatein thetoggleclosure, which could behave unexpectedly under concurrent rendering or with rapid successive calls. React 19 best practice recommends using functional updaters when new state depends on prior state.To implement this properly,
setOpenwould need to support both boolean and functional updates:export type FloatingWindowControls = { open: boolean; - setOpen: (next: boolean) => void; + setOpen: (next: boolean | ((prev: boolean) => boolean)) => void; toggle: () => void; openWindow: () => void; closeWindow: () => void; }; export function useFloatingWindowControls( config: FloatingWindowControlsConfig = {} ): FloatingWindowControls { const { open, defaultOpen = true, onOpenChange } = config; const [uncontrolled, setUncontrolled] = useState(defaultOpen); const isControlled = typeof open === "boolean"; const state = isControlled ? open : uncontrolled; const setOpen = (next: boolean | ((prev: boolean) => boolean)) => { const nextValue = typeof next === "function" ? next(state) : next; if (!isControlled) { setUncontrolled(nextValue); } onOpenChange?.(nextValue); }; return { open: state, setOpen, toggle: () => setOpen((prev) => !prev), openWindow: () => setOpen(true), closeWindow: () => setOpen(false), }; }This ensures
togglederives the next state from the current value rather than relying on a captured closure, improving robustness under concurrent rendering.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
editor/app/(dev)/ui/floating-window/page.tsx(1 hunks)editor/components/floating-window/floating-window.tsx(1 hunks)editor/components/floating-window/index.ts(1 hunks)editor/components/floating-window/primitives.tsx(1 hunks)editor/grida-canvas-hosted/playground/icons-browser.tsx(1 hunks)editor/grida-canvas-hosted/playground/playground.tsx(5 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx}: Use TypeScript 5 as the main language for most apps
Use Lucide or Radix Icons for icons
Files:
editor/components/floating-window/index.tseditor/app/(dev)/ui/floating-window/page.tsxeditor/components/floating-window/floating-window.tsxeditor/grida-canvas-hosted/playground/playground.tsxeditor/components/floating-window/primitives.tsxeditor/grida-canvas-hosted/playground/icons-browser.tsx
**/*.{ts,tsx,css}
📄 CodeRabbit inference engine (AGENTS.md)
Use Tailwind CSS 4 for styling
Files:
editor/components/floating-window/index.tseditor/app/(dev)/ui/floating-window/page.tsxeditor/components/floating-window/floating-window.tsxeditor/grida-canvas-hosted/playground/playground.tsxeditor/components/floating-window/primitives.tsxeditor/grida-canvas-hosted/playground/icons-browser.tsx
**/components/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use Shadcn UI for reusable UI components
Files:
editor/components/floating-window/index.tseditor/components/floating-window/floating-window.tsxeditor/components/floating-window/primitives.tsx
**/*.{tsx,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use React.js 19 for web UI development
Files:
editor/app/(dev)/ui/floating-window/page.tsxeditor/components/floating-window/floating-window.tsxeditor/grida-canvas-hosted/playground/playground.tsxeditor/components/floating-window/primitives.tsxeditor/grida-canvas-hosted/playground/icons-browser.tsx
{editor,apps}/**/app/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use Next.js 15 as the web framework
Files:
editor/app/(dev)/ui/floating-window/page.tsx
🧠 Learnings (6)
📚 Learning: 2025-12-01T00:21:48.564Z
Learnt from: CR
Repo: gridaco/grida PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-01T00:21:48.564Z
Learning: Use DOM as canvas backend for website builder canvas bound with React
Applied to files:
editor/app/(dev)/ui/floating-window/page.tsxeditor/components/floating-window/primitives.tsx
📚 Learning: 2025-12-01T00:21:48.564Z
Learnt from: CR
Repo: gridaco/grida PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-01T00:21:48.564Z
Learning: Applies to **/components/**/*.{ts,tsx} : Use Shadcn UI for reusable UI components
Applied to files:
editor/grida-canvas-hosted/playground/playground.tsxeditor/grida-canvas-hosted/playground/icons-browser.tsx
📚 Learning: 2025-12-01T00:22:56.899Z
Learnt from: CR
Repo: gridaco/grida PR: 0
File: editor/app/(tools)/tools/halftone/AGENTS.md:0-0
Timestamp: 2025-12-01T00:22:56.899Z
Learning: Applies to editor/app/(tools)/tools/halftone/app/(tools)/tools/halftone/_page.tsx : Use React hooks for state management (imageSrc, shape, grid, maxRadius, gamma, jitter, opacity, color, customShapeImage, imageDataRef, sizeRef)
Applied to files:
editor/grida-canvas-hosted/playground/playground.tsx
📚 Learning: 2025-12-01T00:22:19.083Z
Learnt from: CR
Repo: gridaco/grida PR: 0
File: crates/grida-canvas-wasm/AGENTS.md:0-0
Timestamp: 2025-12-01T00:22:19.083Z
Learning: Applies to crates/grida-canvas-wasm/**/main.rs : Update `grida-canvas-wasm.d.ts` TypeScript definitions file when new APIs are introduced via `main.rs`
Applied to files:
editor/grida-canvas-hosted/playground/icons-browser.tsx
📚 Learning: 2025-12-01T00:21:48.564Z
Learnt from: CR
Repo: gridaco/grida PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-01T00:21:48.564Z
Learning: Applies to **/*.{ts,tsx} : Use Lucide or Radix Icons for icons
Applied to files:
editor/grida-canvas-hosted/playground/icons-browser.tsx
📚 Learning: 2025-12-01T00:22:56.899Z
Learnt from: CR
Repo: gridaco/grida PR: 0
File: editor/app/(tools)/tools/halftone/AGENTS.md:0-0
Timestamp: 2025-12-01T00:22:56.899Z
Learning: Applies to editor/app/(tools)/tools/halftone/app/(tools)/tools/halftone/_page.tsx : When adding new shape types, update the Shape type union, add cases in drawShape() function, add cases in shapeToSVG() function, and add SelectItem in UI
Applied to files:
editor/grida-canvas-hosted/playground/icons-browser.tsx
🧬 Code graph analysis (3)
editor/grida-canvas-hosted/playground/playground.tsx (2)
editor/components/floating-window/floating-window.tsx (7)
FloatingWindowHost(31-33)FloatingWindowBounds(35-45)FloatingWindowRoot(47-59)FloatingWindowTitleBar(61-72)FloatingWindowClose(87-89)FloatingWindowBody(74-81)FloatingWindowTrigger(83-85)editor/grida-canvas-hosted/playground/icons-browser.tsx (2)
IconsBrowserItem(43-49)IconsBrowser(491-708)
editor/components/floating-window/primitives.tsx (1)
editor/components/floating-window/floating-window.tsx (13)
FloatingWindowBoundsProps(26-26)FloatingWindowPortal(91-95)FloatingWindowBounds(35-45)FloatingWindowHost(31-33)FloatingWindowRootProps(24-24)FloatingWindowRoot(47-59)TitleBarProps(25-25)FloatingWindowTitleBar(61-72)TriggerProps(27-27)FloatingWindowTrigger(83-85)CloseProps(28-28)FloatingWindowClose(87-89)FloatingWindowBody(74-81)
editor/grida-canvas-hosted/playground/icons-browser.tsx (4)
editor/components/ui-editor/popover.tsx (3)
Popover(62-62)PopoverTrigger(62-62)PopoverContent(62-62)editor/components/ui/badge.tsx (1)
Badge(46-46)editor/components/ui/command.tsx (6)
Command(175-175)CommandInput(177-177)CommandList(178-178)CommandEmpty(179-179)CommandGroup(180-180)CommandItem(181-181)editor/components/ui/input-group.tsx (3)
InputGroup(164-164)InputGroupAddon(165-165)InputGroupInput(168-168)
🪛 Biome (2.1.2)
editor/app/(dev)/ui/floating-window/page.tsx
[error] 120-120: Wrap comments inside children within braces.
Unsafe fix: Wrap the comments with braces
(lint/suspicious/noCommentText)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: cargo test
🔇 Additional comments (13)
editor/components/floating-window/index.ts (1)
1-4: LGTM!Clean barrel export pattern with appropriate
"use client"directive. The namespace export for primitives provides good flexibility for consumers who need lower-level access.editor/app/(dev)/ui/floating-window/page.tsx (1)
19-172: Well-structured demo page.Good use of accessibility patterns (
sr-onlyfor screen reader text,aria-hiddenon decorative icons). The demo effectively showcases multi-window coordination with drag boundaries.editor/grida-canvas-hosted/playground/playground.tsx (3)
369-393: Icon insertion flow looks good.The
handleInsertIconcallback properly handles the async flow with toast feedback for loading, success, and error states. Thecache: "no-store"ensures fresh icon data.
449-541: Clean floating window integration.The
FloatingWindowHostwrapping andFloatingWindowBoundswith boundary ref properly coordinate the UI. The icons browser window is well-configured with appropriate initial position, dimensions, and z-index for overlay behavior.
621-670: Simplified sidebar with floating trigger.Good refactor from modal dialog to floating window trigger. The
asChildpattern with the Button component follows Radix UI conventions correctly.editor/components/floating-window/floating-window.tsx (1)
47-95: Well-designed wrapper components.Sensible defaults for transitions, styling, and cursor feedback. The consistent use of
cn()for className merging allows consumers to override styles while preserving base behavior.editor/grida-canvas-hosted/playground/icons-browser.tsx (2)
450-489: Good lazy loading pattern.The
IconGridCellcomponent implements a clean skeleton-to-image transition with appropriate loading state management. The tooltip with icon name and primary tag provides helpful context.
491-708: Well-implemented virtualized icon grid.The
IconsBrowsercomponent effectively combines:
- Responsive cell sizing via ResizeObserver
- Row virtualization with @tanstack/react-virtual
- Vendor/variant filtering with searchable dropdowns
- Horizontal scrollable vendor pills with fade edges
The overall structure is clean and handles loading/error/empty states appropriately.
editor/components/floating-window/primitives.tsx (5)
26-49: Portal implementation and SSR guard look solidThe client-only mount guard (
mounted+typeof document !== "undefined") and portal wrapper with a fixed, pointer-events-none overlay are appropriate for avoiding SSR mismatches and keeping windows above the app chrome. No issues here.
51-80: Bounds container API and render-prop pattern look good
FloatingWindowBoundscorrectly normalizes its children to either static content or a render-prop with aboundaryRef, and it enforces a relative, overflow-hidden 100%×100% container suitable as a drag boundary. This is a clean primitive for the higher-level wrapper to style.
95-127: Registry / host lifecycle is well-structuredThe registry context +
FloatingWindowHostimplementation withMap<string, FloatingWindowControls>and guardedunregister(identity check) is a good pattern to avoid stale removals when controls objects change between renders, while still cleaning up on unmount.
284-297: Drag bindings and render-prop helpers are well-factoredThe
useDragconfiguration (offset-based,fromseeded bypositionRef.current, scroll prevention, pointer capture) combined with the memoizedhelpersobject anddragHandlePropslooks solid. The render prop /renderAPI flexibility is nice and keeps the primitive unopinionated.Also applies to: 299-318
514-529: Body primitive is fine as a thin passthrough
FloatingWindowBodyis a minimal wrapper adding only adata-floating-window-bodyattribute and forwardingclassName/style. That matches the “primitive” intent and lets the higher-level wrapper control Tailwind/shadcn styling. No issues.
| export function FloatingWindowBounds(props: FloatingWindowBoundsProps) { | ||
| return ( | ||
| <PrimitiveBounds | ||
| {...props} | ||
| className={cn( | ||
| "relative w-full h-full overflow-hidden data-[floating-window-bounds]", | ||
| props.className | ||
| )} | ||
| /> | ||
| ); | ||
| } |
There was a problem hiding this comment.
Invalid data attribute syntax.
data-[floating-window-bounds] uses Tailwind's conditional selector notation, which expects an existing attribute to apply styles conditionally. To define a data attribute, remove the brackets.
<PrimitiveBounds
{...props}
className={cn(
- "relative w-full h-full overflow-hidden data-[floating-window-bounds]",
+ "relative w-full h-full overflow-hidden",
props.className
)}
+ data-floating-window-bounds=""
/>Alternatively, if this is meant as a Tailwind variant selector, ensure the primitive sets the attribute and use proper conditional syntax like data-[floating-window-bounds]:some-style.
🤖 Prompt for AI Agents
editor/components/floating-window/floating-window.tsx lines 35-45: the JSX uses
Tailwind's conditional selector syntax `data-[floating-window-bounds]` but you
intended to set a data attribute; change the prop to a normal data attribute
name (e.g., data-floating-window-bounds) on the PrimitiveBounds so Tailwind can
match it, or if you meant to apply Tailwind variant styles instead, leave the
selector in className but ensure the PrimitiveBounds actually renders that data
attribute and use the full variant syntax (e.g.,
data-[floating-window-bounds]:<utility>) in className.
| const applyPosition = (pos: { x: number; y: number }) => { | ||
| const el = windowRef.current; | ||
| if (!el) return; | ||
| const offsetX = boundaryRect?.left ?? 0; | ||
| const offsetY = boundaryRect?.top ?? 0; | ||
| el.style.setProperty("--floating-window-x", `${pos.x + offsetX}px`); | ||
| el.style.setProperty("--floating-window-y", `${pos.y + offsetY}px`); | ||
| }; |
There was a problem hiding this comment.
Bug: Non-portal windows are mis-positioned due to unconditional boundary offset
applyPosition always adds boundaryRect.left/top to the logical {x, y} position before setting the CSS variables, but the render-time transform always interprets those CSS variables in the local coordinate space of the window’s containing element.
- For
portal={true}, the window is rendered inside a fixed, full-screen portal; addingboundaryRect.left/topis correct to map boundary-relative coords into viewport space. - For
portal={false}, the window is rendered inside the boundary container; addingboundaryRect.left/topdouble-applies the offset (once from normal layout of the boundary in the page, once from the transform), so the window ends up shifted too far from the top-left of its bounds.
This means the portal flag does not behave correctly today: non-portal windows won’t align to the expected 0…width / 0…height coordinate system of the boundary.
You can fix this by conditioning the offset on portal so local (non-portal) windows use pure boundary-relative coordinates:
@@
- const applyPosition = (pos: { x: number; y: number }) => {
- const el = windowRef.current;
- if (!el) return;
- const offsetX = boundaryRect?.left ?? 0;
- const offsetY = boundaryRect?.top ?? 0;
- el.style.setProperty("--floating-window-x", `${pos.x + offsetX}px`);
- el.style.setProperty("--floating-window-y", `${pos.y + offsetY}px`);
- };
+ const applyPosition = (pos: { x: number; y: number }) => {
+ const el = windowRef.current;
+ if (!el) return;
+
+ // For portalled windows, translate boundary-relative coords into viewport space.
+ // For non-portal windows, stay in the boundary’s local coordinate system.
+ const offsetX = portal ? boundaryRect?.left ?? 0 : 0;
+ const offsetY = portal ? boundaryRect?.top ?? 0 : 0;
+
+ el.style.setProperty("--floating-window-x", `${pos.x + offsetX}px`);
+ el.style.setProperty("--floating-window-y", `${pos.y + offsetY}px`);
+ };With this change, portal={false} will keep window motion correctly clamped and aligned within the boundary, and portal={true} will continue to align to the viewport overlay.
Also applies to: 324-341
🤖 Prompt for AI Agents
In editor/components/floating-window/primitives.tsx around lines 194-201 (and
likewise update the block at 324-341), applyPosition is always adding
boundaryRect.left/top to the logical pos which double-offsets non-portal
windows; change the logic to only add the boundary offsets when the window is
rendered in a portal (portal === true) and otherwise set the CSS vars to the raw
boundary-relative pos (falling back to 0 if boundaryRect is undefined). Update
both occurrences to branch on the portal flag, keep null-safe reads of
boundaryRect, and set "--floating-window-x" and "--floating-window-y"
accordingly so portal windows map to viewport coordinates and non-portal windows
remain in local boundary coordinates.
| const handleInsert = useCallback( | ||
| async (icon: IconsBrowserItem) => { | ||
| if (!onInsert) return; | ||
| const task = Promise.resolve(onInsert(icon)); | ||
| toast.promise(task, { | ||
| loading: "Loading icon...", | ||
| success: "Icon inserted", | ||
| error: "Failed to insert icon", | ||
| }); | ||
| }, | ||
| [onInsert] | ||
| ); |
There was a problem hiding this comment.
Double toast notifications on icon insert.
Both IconsBrowser.handleInsert (here) and playground.tsx:handleInsertIcon (lines 386-390) wrap the insert operation with toast.promise. This results in duplicate toast messages for each icon insertion.
Remove the toast wrapper here since the parent component already handles user feedback:
const handleInsert = useCallback(
async (icon: IconsBrowserItem) => {
if (!onInsert) return;
- const task = Promise.resolve(onInsert(icon));
- toast.promise(task, {
- loading: "Loading icon...",
- success: "Icon inserted",
- error: "Failed to insert icon",
- });
+ await onInsert(icon);
},
[onInsert]
);Alternatively, keep toasts here and remove them from the consuming components to centralize the feedback logic.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const handleInsert = useCallback( | |
| async (icon: IconsBrowserItem) => { | |
| if (!onInsert) return; | |
| const task = Promise.resolve(onInsert(icon)); | |
| toast.promise(task, { | |
| loading: "Loading icon...", | |
| success: "Icon inserted", | |
| error: "Failed to insert icon", | |
| }); | |
| }, | |
| [onInsert] | |
| ); | |
| const handleInsert = useCallback( | |
| async (icon: IconsBrowserItem) => { | |
| if (!onInsert) return; | |
| await onInsert(icon); | |
| }, | |
| [onInsert] | |
| ); |
🤖 Prompt for AI Agents
In editor/grida-canvas-hosted/playground/icons-browser.tsx around lines 517 to
528, this handleInsert callback wraps onInsert(icon) with toast.promise causing
duplicate toasts because the parent already shows feedback; remove the
toast.promise wrapper and simply call (and await if onInsert returns a promise)
onInsert(icon) directly inside the useCallback so only the parent handles user
notifications.
day308 Grida Canvas - UX / Icons Library
day-308-grida-canvas-ux-icons-browser.mp4
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.