chore: Move to Typescript (#2783)
This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously. closes #1282
This commit is contained in:
31
app/hooks/useCommandBarActions.ts
Normal file
31
app/hooks/useCommandBarActions.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { useRegisterActions } from "kbar";
|
||||
import { flattenDeep } from "lodash";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useLocation } from "react-router-dom";
|
||||
import { actionToKBar } from "~/actions";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { Action } from "~/types";
|
||||
|
||||
export default function useCommandBarActions(actions: Action[]) {
|
||||
const stores = useStores();
|
||||
const { t } = useTranslation();
|
||||
const location = useLocation();
|
||||
const context = {
|
||||
t,
|
||||
isCommandBar: true,
|
||||
isContextMenu: false,
|
||||
activeCollectionId: stores.ui.activeCollectionId,
|
||||
activeDocumentId: stores.ui.activeDocumentId,
|
||||
location,
|
||||
stores,
|
||||
};
|
||||
|
||||
const registerable = flattenDeep(
|
||||
actions.map((action) => actionToKBar(action, context))
|
||||
);
|
||||
|
||||
useRegisterActions(registerable, [
|
||||
registerable.map((r) => r.id).join(""),
|
||||
location.pathname,
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user