diff --git a/pkg/interface/src/logic/lib/omnibox.js b/pkg/interface/src/logic/lib/omnibox.ts similarity index 92% rename from pkg/interface/src/logic/lib/omnibox.js rename to pkg/interface/src/logic/lib/omnibox.ts index 1870db33f3..e20fd22a77 100644 --- a/pkg/interface/src/logic/lib/omnibox.js +++ b/pkg/interface/src/logic/lib/omnibox.ts @@ -10,8 +10,18 @@ const makeIndexes = () => new Map([ ['other', []] ]); +export interface OmniboxItem { + title: string; + link: string; + app: string; + host: string; + description: string; + shiftLink: string; + shiftDescription: string; +} + // result schematic -const result = function(title, link, app, host, description = 'Open', shiftLink = null, shiftDescription = null) { +const result = function(title: string, link: string, app: string, host: string, description = 'Open', shiftLink = null as string | null, shiftDescription = null as string | null): OmniboxItem { return { 'title': title, 'link': link, @@ -93,7 +103,7 @@ const otherIndex = function(config) { return other; }; -export default function index(contacts, associations, apps, currentGroup, groups, hide) { +export default function index(contacts, associations, apps, currentGroup, groups, hide): Map { const indexes = makeIndexes(); indexes.set('ships', shipIndex(contacts)); // all metadata from all apps is indexed @@ -117,7 +127,7 @@ export default function index(contacts, associations, apps, currentGroup, groups let app = each['app-name']; if (each['app-name'] === 'contacts') { app = 'groups'; - }; + } if (each['app-name'] === 'graph') { app = each.metadata.config.graph; @@ -159,4 +169,4 @@ export default function index(contacts, associations, apps, currentGroup, groups indexes.set('other', otherIndex(hide)); return indexes; -}; +} diff --git a/pkg/interface/src/views/components/leap/Omnibox.tsx b/pkg/interface/src/views/components/leap/Omnibox.tsx index d50cbdeb06..363abcf48b 100644 --- a/pkg/interface/src/views/components/leap/Omnibox.tsx +++ b/pkg/interface/src/views/components/leap/Omnibox.tsx @@ -13,7 +13,7 @@ import React, { import { useHistory, useLocation } from 'react-router-dom'; import * as ob from 'urbit-ob'; import defaultApps from '~/logic/lib/default-apps'; -import makeIndex from '~/logic/lib/omnibox'; +import makeIndex, { OmniboxItem } from '~/logic/lib/omnibox'; import { useOutsideClick } from '~/logic/lib/useOutsideClick'; import { deSig } from '~/logic/lib/util'; import useContactState from '~/logic/state/contact'; @@ -114,7 +114,7 @@ export function Omnibox(props: OmniboxProps): ReactElement { }, [props.show]); const initialResults = useMemo(() => { - return new Map( + return new Map( SEARCHED_CATEGORIES.map((category) => { if (category === 'other') { return [ @@ -132,7 +132,7 @@ export function Omnibox(props: OmniboxProps): ReactElement { return initialResults; } const q = query.toLowerCase(); - const resultsMap = new Map(); + const resultsMap = new Map(); SEARCHED_CATEGORIES.map((category) => { const categoryIndex = index.get(category); resultsMap.set( @@ -317,7 +317,7 @@ export function Omnibox(props: OmniboxProps): ReactElement { borderBottomRightRadius={2} > {SEARCHED_CATEGORIES.map(category => - Object({ + ({ category, categoryResults: _.take(results.get(category).sort(sortResults), CAT_LIMIT) })