From d7221d79bcaa0cadf5efe36bbf6077fcbac8cb02 Mon Sep 17 00:00:00 2001 From: tiddlygit-test Date: Fri, 5 Feb 2021 00:57:34 +0800 Subject: [PATCH] refactor: Find In Page --- src/components/main/find-in-page.tsx | 26 +++++----- src/components/main/workspace-selector.tsx | 12 +++-- src/listeners/index.ts | 4 +- src/services/windows/index.ts | 55 +++++++++++----------- src/services/windows/interface.ts | 4 ++ 5 files changed, 54 insertions(+), 47 deletions(-) diff --git a/src/components/main/find-in-page.tsx b/src/components/main/find-in-page.tsx index 0a25dfef..03035808 100644 --- a/src/components/main/find-in-page.tsx +++ b/src/components/main/find-in-page.tsx @@ -4,7 +4,7 @@ import TextField from '@material-ui/core/TextField'; import Typography from '@material-ui/core/Typography'; import connectComponent from '../../helpers/connect-component'; import { closeFindInPage, updateFindInPageText } from '../../state/find-in-page/actions'; -import { requestFindInPage, requestStopFindInPage } from '../../senders'; + const styles = (theme: any) => ({ root: { background: theme.palette.background.default, @@ -37,9 +37,7 @@ const FindInPage = (props: FindInPageProps) => { // Event handler utilizing useCallback ... // ... so that reference never changes. const handleOpenFindInPage = useCallback(() => { - // @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'. inputReference.current.focus(); - // @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'. inputReference.current.select(); }, [inputReference]); useEffect(() => { @@ -74,20 +72,18 @@ const FindInPage = (props: FindInPageProps) => { const value = e.target.value; onUpdateFindInPageText(value); if (value.length > 0) { - requestFindInPage(value, true); + void window.service.window.findInPage(value, true); } else { - // @ts-expect-error ts-migrate(2554) FIXME: Expected 1 arguments, but got 0. - requestStopFindInPage(); + void window.service.window.stopFindInPage(); } }} onInput={(e) => { const value = (e.target as any).value; onUpdateFindInPageText(value); if (value.length > 0) { - requestFindInPage(value, true); + void window.service.window.findInPage(value, true); } else { - // @ts-expect-error ts-migrate(2554) FIXME: Expected 1 arguments, but got 0. - requestStopFindInPage(); + void window.service.window.stopFindInPage(); } }} onKeyDown={(e) => { @@ -95,12 +91,12 @@ const FindInPage = (props: FindInPageProps) => { // Enter const value = (e.target as any).value; if (value.length > 0) { - requestFindInPage(value, true); + void window.service.window.findInPage(value, true); } } if ((e.keyCode || e.which) === 27) { // Escape - requestStopFindInPage(true); + void window.service.window.stopFindInPage(true); onCloseFindInPage(); } }} @@ -111,7 +107,7 @@ const FindInPage = (props: FindInPageProps) => { disabled={text.length < 1 || matches < 1} onClick={() => { if (text.length > 0) { - requestFindInPage(text, false); + void window.service.window.findInPage(text, false); } }}> Previous @@ -121,7 +117,7 @@ const FindInPage = (props: FindInPageProps) => { disabled={text.length < 1 || matches < 1} onClick={() => { if (text.length > 0) { - requestFindInPage(text, true); + void window.service.window.findInPage(text, true); } }}> Next @@ -131,7 +127,7 @@ const FindInPage = (props: FindInPageProps) => { disabled={text.length < 1} onClick={() => { if (text.length > 0) { - requestFindInPage(text, true); + void window.service.window.findInPage(text, true); } }}> Find @@ -139,7 +135,7 @@ const FindInPage = (props: FindInPageProps) => {