From 63f6d838fb689983ad009e674b9a5232aba60698 Mon Sep 17 00:00:00 2001 From: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com> Date: Thu, 29 Oct 2026 21:11:19 +0000 Subject: [PATCH] refactor(browser): move the grab hook type to its owner (#36087) Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com> --- .../use-browser-page-grab-annotations.ts | 34 ++----------------- .../describe-page/browser-page-types.ts | 28 ++++++++++++++- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/renderer/src/components/browser-pane/annotate/use-browser-page-grab-annotations.ts b/src/renderer/src/components/browser-pane/annotate/use-browser-page-grab-annotations.ts index cd48ea6ed69..8c571ef02df 100644 --- a/src/renderer/src/components/browser-pane/annotate/use-browser-page-grab-annotations.ts +++ b/src/renderer/src/components/browser-pane/annotate/use-browser-page-grab-annotations.ts @@ -1,13 +1,4 @@ -import { - useCallback, - useEffect, - useLayoutEffect, - useRef, - useState, - type Dispatch, - type MutableRefObject, - type SetStateAction -} from 'react' +import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react' import { translate } from '@/i18n/i18n' import { useMountedRef } from '@/hooks/useMountedRef' import { useAppStore } from '@/store' @@ -26,6 +17,7 @@ import { import { useBrowserPageAnnotationViewportTracking } from './use-browser-page-annotation-viewport-tracking' import { runBrowserGrabActionShortcut } from './browser-page-grab-action' import type { + BrowserPageGrabAnnotations, BrowserPageGrabAnnotationsOptions, BrowserPageGrabToastState, GrabIntent @@ -58,27 +50,7 @@ export function useBrowserPageGrabAnnotations({ webviewRef, setBrowserOverlayViewport, browserAnnotationsLength -}: BrowserPageGrabAnnotationsOptions): { - grabIntent: GrabIntent - startGrabIntent: (nextIntent: GrabIntent) => void - pendingAnnotationPayload: BrowserGrabPayload | null - setPendingAnnotationPayload: Dispatch> - grabToast: BrowserPageGrabToastState | null - setGrabToast: Dispatch> - grabToastTimerRef: MutableRefObject | undefined> - dismissGrabToast: () => void - handleGrabCopy: () => void - handleGrabCopyScreenshot: () => void - grabMenuActionTakenRef: MutableRefObject - handleAddBrowserAnnotation: ( - comment: string, - intent: BrowserAnnotationIntent, - imagePaths?: string[] - ) => void - handleCancelPendingBrowserAnnotation: () => void - cancelPendingBrowserCapture: () => void - handleGrabActionShortcut: (key: 'c' | 's') => void -} { +}: BrowserPageGrabAnnotationsOptions): BrowserPageGrabAnnotations { const mountedRef = useMountedRef() const toolTargetIdRef = useRef(toolTargetId) const grabToastTimerRef = useRef>(undefined) diff --git a/src/renderer/src/components/browser-pane/describe-page/browser-page-types.ts b/src/renderer/src/components/browser-pane/describe-page/browser-page-types.ts index 1a9e121da8f..8bb7d4f8df3 100644 --- a/src/renderer/src/components/browser-pane/describe-page/browser-page-types.ts +++ b/src/renderer/src/components/browser-pane/describe-page/browser-page-types.ts @@ -1,6 +1,10 @@ import type { RuntimeBrowserClientPlacement } from '../../../../../shared/runtime-browser-placement' import type { Dispatch, MutableRefObject, SetStateAction } from 'react' -import type { BrowserGrabPayload } from '../../../../../shared/browser-grab-types' +import type { + BrowserAnnotationIntent, + BrowserGrabPayload, + GrabIntent +} from '../../../../../shared/browser-grab-types' import type { BrowserContextMenuRequestedEvent } from '../../../../../shared/browser-guest-events' import type { BrowserPage as BrowserPageState } from '../../../../../shared/browser-workspace-types' import type { GrabModeHook } from '../annotate/useGrabMode' @@ -57,6 +61,28 @@ export type BrowserPageGrabAnnotationsOptions = { browserAnnotationsLength: number } +export type BrowserPageGrabAnnotations = { + grabIntent: GrabIntent + startGrabIntent: (nextIntent: GrabIntent) => void + pendingAnnotationPayload: BrowserGrabPayload | null + setPendingAnnotationPayload: Dispatch> + grabToast: BrowserPageGrabToastState | null + setGrabToast: Dispatch> + grabToastTimerRef: MutableRefObject | undefined> + dismissGrabToast: () => void + handleGrabCopy: () => void + handleGrabCopyScreenshot: () => void + grabMenuActionTakenRef: MutableRefObject + handleAddBrowserAnnotation: ( + comment: string, + intent: BrowserAnnotationIntent, + imagePaths?: string[] + ) => void + handleCancelPendingBrowserAnnotation: () => void + cancelPendingBrowserCapture: () => void + handleGrabActionShortcut: (key: 'c' | 's') => void +} + export type BrowserPageRecoveryNavigationValidation = { committed: boolean started: boolean