Skip to content

Commit

Permalink
Fix import of SearchBackground class in search-injection logic
Browse files Browse the repository at this point in the history
- Was only being used as a type, but not sure if our webpack setup is smart enough to pick that up and not actually include it in the search injection CS bundle.
- Regardless, it was the wrong type being used. RemoteSearchInterface has the RPCs, following the same pattern as most of our BG classes
- Also removed the `requestSearcher` param as it can be gotten from `searchBG`
  • Loading branch information
poltak committed Jun 25, 2024
1 parent daff4c6 commit a9b2084
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/content-scripts/content_script/in-page-ui-injections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { ContentScriptRegistry, InPageUIInjectionsMain } from './types'
import { renderUpgradeModal } from 'src/search-injection/upgrade-modal-display'
import { handleRenderPDFOpenButton } from 'src/search-injection/pdf-open-button'
import { handleRenderImgActionButtons } from 'src/search-injection/img-action-buttons'
import type { SearchEngineName } from 'src/search-injection/types'

export const main: InPageUIInjectionsMain = async ({
inPageUI,
Expand Down Expand Up @@ -60,7 +61,7 @@ export const main: InPageUIInjectionsMain = async ({
)
} else if (component === 'search-engine-integration') {
const url = window.location.href
const matched = utils.matchURL(url)
const matched = utils.matchURL(url) as SearchEngineName | false

if (matched) {
const searchInjection =
Expand All @@ -73,7 +74,6 @@ export const main: InPageUIInjectionsMain = async ({

await handleRenderSearchInjection(
query,
searchDisplayProps.searchBG.unifiedSearch,
matched,
syncSettings,
() =>
Expand Down
9 changes: 2 additions & 7 deletions src/search-injection/components/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,20 @@ import strictUriEncode from 'strict-uri-encode'
import ResultItem from './ResultItem'
import RemovedText from './RemovedText'
import * as constants from '../constants'
import { getLocalStorage } from '../utils'
import Notification from './Notification'
import { UPDATE_NOTIFS } from '../../notifications/notifications'
import * as actionTypes from '../../notifications/action-types'
import ActionButton from '../../notifications/components/ActionButton'
import OptIn from '../../notifications/components/OptIn'
import ToggleSwitch from '../../common-ui/components/ToggleSwitch'
import type { SearchEngineName, ResultItemProps } from '../types'
import CloudUpgradeBanner from 'src/personal-cloud/ui/components/cloud-upgrade-banner'
import { STORAGE_KEYS as CLOUD_STORAGE_KEYS } from 'src/personal-cloud/constants'
import type { SyncSettingsStore } from 'src/sync-settings/util'
import { OVERVIEW_URL } from 'src/constants'
import { sleepPromise } from 'src/util/promises'
import styled from 'styled-components'
import LoadingIndicator from '@worldbrain/memex-common/lib/common-ui/components/loading-indicator'
import Icon from '@worldbrain/memex-common/lib/common-ui/components/icon'
import IconBox from '@worldbrain/memex-common/lib/common-ui/components/icon-box'
import { UITaskState } from '@worldbrain/memex-common/lib/main-ui/types'
import SearchBackground from 'src/search/background'
import type { RemoteSearchInterface } from 'src/search/background/types'

const search = browser.runtime.getURL('/img/search.svg')

Expand All @@ -39,7 +34,7 @@ export interface Props {
updateQuery: (query: string) => Promise<void>
query: string
openSettings: () => void
searchBG: SearchBackground
searchBG: RemoteSearchInterface
openPDFinViewer: (url: string) => Promise<void>
}

Expand Down
24 changes: 8 additions & 16 deletions src/search-injection/searchInjection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ import {
} from 'src/common-ui/components/design-library/theme'
import type { MemexThemeVariant } from '@worldbrain/memex-common/lib/common-ui/styles/types'
import type { ResultItemProps, SearchEngineName } from './types'
import { SyncSettingsStore } from 'src/sync-settings/util'
import type { SyncSettingsStore } from 'src/sync-settings/util'
import type { RemoteSearchInterface } from 'src/search/background/types'
import { ContentIdentifier } from 'src/search/types'
import { isMemexPageAPdf } from '@worldbrain/memex-common/lib/page-indexing/utils'
import SearchBackground from 'src/search/background'

interface RootProps {
rootEl: HTMLElement
query: string
requestSearcher: RemoteSearchInterface['unifiedSearch']
renderComponent: () => Promise<void>
searchEngine: SearchEngineName
syncSettings: SyncSettingsStore<
Expand All @@ -36,7 +33,7 @@ interface RootProps {
>
position: 'side' | 'above'
openSettings: () => void
searchBG: SearchBackground
searchBG: RemoteSearchInterface
openPDFinViewer: (url: string) => Promise<void>
}

Expand All @@ -62,9 +59,8 @@ class Root extends React.Component<RootProps, RootState> {
}

private executeSearch = async (query: string) => {
const { requestSearcher } = this.props
const limit = 100
const searchRes = await requestSearcher({
const searchRes = await this.props.searchBG.unifiedSearch({
query,
limit,
skip: 0,
Expand Down Expand Up @@ -103,8 +99,6 @@ class Root extends React.Component<RootProps, RootState> {
searchResDocsProcessedPromises,
)

console.log('searchResDocsProcessed', searchResDocsProcessed)

this.setState({
searchResDocsProcessed: searchResDocsProcessed,
})
Expand Down Expand Up @@ -148,9 +142,8 @@ class Root extends React.Component<RootProps, RootState> {

// TODO: Type this
export const handleRenderSearchInjection = async (
query,
requestSearcher,
searchEngine,
query: string,
searchEngine: SearchEngineName,
syncSettings: SyncSettingsStore<
| 'extension'
| 'inPageUI'
Expand All @@ -159,9 +152,9 @@ export const handleRenderSearchInjection = async (
| 'searchInjection'
| 'dashboard'
>,
openSettings,
searchBG,
openPDFinViewer,
openSettings: () => void,
searchBG: RemoteSearchInterface,
openPDFinViewer: (url: string) => Promise<void>,
) => {
// docs: (array of objects) returned by the search.
// totalCount: (int) number of results found
Expand Down Expand Up @@ -376,7 +369,6 @@ export const handleRenderSearchInjection = async (
syncSettings={syncSettings}
searchEngine={searchEngine}
renderComponent={renderComponent}
requestSearcher={requestSearcher}
openSettings={openSettings}
searchBG={searchBG}
openPDFinViewer={openPDFinViewer}
Expand Down

0 comments on commit a9b2084

Please sign in to comment.