Files
outline/app/hooks/useCommandBarActions.ts
Saumya Pandey ad2bce9c10 fix: sync the correct collection with edit action (#3166)
* fix: sync the correct collection with edit action

* fix: remove action suggestions on undefined

* Update app/hooks/useCommandBarActions.ts

Co-authored-by: Tom Moor <tom.moor@gmail.com>
2022-02-25 20:39:03 -08:00

33 lines
856 B
TypeScript

import { useRegisterActions } from "kbar";
import { flattenDeep } from "lodash";
import { useLocation } from "react-router-dom";
import { actionToKBar } from "~/actions";
import { Action } from "~/types";
import useActionContext from "./useActionContext";
/**
* Hook to add actions to the command bar while the hook is inside a mounted
* component.
*
* @param actions actions to make available
*/
export default function useCommandBarActions(
actions: Action[],
additionalDeps: React.DependencyList = []
) {
const location = useLocation();
const context = useActionContext({
isCommandBar: true,
});
const registerable = flattenDeep(
actions.map((action) => actionToKBar(action, context))
);
useRegisterActions(registerable, [
registerable.map((r) => r.id).join(""),
location.pathname,
...additionalDeps,
]);
}