cleanup search documents action

This commit is contained in:
Tom Moor
2022-03-14 17:41:55 -07:00
parent 40e84ed481
commit 1633bbf5aa
6 changed files with 23 additions and 42 deletions

View File

@@ -48,9 +48,7 @@ function CommandBar() {
t("Type a command or search")
}`}
/>
<CommandBarResults
prioritizeSearchResults={ui.commandBarOpenedFromSidebar}
/>
<CommandBarResults />
{ui.commandBarOpenedFromSidebar && (
<Hint size="small" type="tertiary">
<QuestionMarkIcon size={18} color="currentColor" />

View File

@@ -1,27 +1,14 @@
import { useMatches, KBarResults } from "kbar";
import { orderBy } from "lodash";
import * as React from "react";
import styled from "styled-components";
import CommandBarItem from "~/components/CommandBarItem";
import { SearchSection } from "~/actions/sections";
type Props = {
prioritizeSearchResults: boolean;
};
export default function CommandBarResults(props: Props) {
export default function CommandBarResults() {
const { results, rootActionId } = useMatches();
return (
<KBarResults
items={orderBy(results, (item) =>
// this is an unfortunate hack until kbar supports priority internally
typeof item !== "string" &&
item.section === SearchSection &&
props.prioritizeSearchResults
? -1
: 1
)}
items={results}
maxHeight={400}
onRender={({ item, active }) =>
typeof item === "string" ? (

View File

@@ -1,9 +1,8 @@
import { useKBar } from "kbar";
import * as React from "react";
import {
navigateToRecentSearchQuery,
navigateToSearchQuery,
} from "~/actions/definitions/navigation";
import { searchDocumentsForQuery } from "~/actions/definitions/documents";
import { navigateToRecentSearchQuery } from "~/actions/definitions/navigation";
import useCommandBarActions from "~/hooks/useCommandBarActions";
import useStores from "~/hooks/useStores";
@@ -18,7 +17,9 @@ export default function SearchActions() {
searchQuery: state.searchQuery,
}));
useCommandBarActions(searchQuery ? [navigateToSearchQuery(searchQuery)] : []);
useCommandBarActions(
searchQuery ? [searchDocumentsForQuery(searchQuery)] : []
);
useCommandBarActions(searches.recent.map(navigateToRecentSearchQuery));