feat: rebuild command menu
This commit is contained in:
1 parent
ec295fe26e
commit
769204ca3b
53 files changed
+1188
-667
No files matched your search
@@ -7,6 +7,7 @@ import { useI18n } from "@homarr/translation/client";
|
||||
import { createChildrenOptions } from "../../lib/children";
|
||||
import { createGroup } from "../../lib/group";
|
||||
import { interaction } from "../../lib/interaction";
|
||||
import { useRemoteQuery } from "../../lib/remote-query";
|
||||
|
||||
// This has to be type so it can be interpreted as Record<string, unknown>.
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
@@ -71,6 +72,7 @@ const groupChildrenOptions = createChildrenOptions<Group>({
|
||||
export const groupsSearchGroup = createGroup<Group>({
|
||||
keyPath: "id",
|
||||
title: (t) => t("common.entity.groups"),
|
||||
source: { kind: "remote", source: "groups" },
|
||||
Component: ({ name }) => (
|
||||
<Group px="md" py="sm">
|
||||
<Text>{name}</Text>
|
||||
@@ -78,6 +80,7 @@ export const groupsSearchGroup = createGroup<Group>({
|
||||
),
|
||||
useInteraction: interaction.children(groupChildrenOptions),
|
||||
useQueryOptions(query) {
|
||||
return clientApi.group.search.useQuery({ query, limit: 5 });
|
||||
const remoteQuery = useRemoteQuery(query, "groups");
|
||||
return clientApi.group.search.useQuery({ query: remoteQuery.query, limit: 8 }, { enabled: remoteQuery.enabled });
|
||||
},
|
||||
});
|
||||
@@ -1,9 +1,17 @@
|
||||
import { useSession } from "@homarr/auth/client";
|
||||
|
||||
import type { SearchMode } from "../../lib/mode";
|
||||
import { groupsSearchGroup } from "./groups-search-group";
|
||||
import { usersSearchGroup } from "./users-search-group";
|
||||
|
||||
export const userGroupMode = {
|
||||
modeKey: "userGroup",
|
||||
mode: "userGroup",
|
||||
character: "@",
|
||||
groups: [usersSearchGroup, groupsSearchGroup],
|
||||
label: (t) => t("search.modePicker.userGroup.label"),
|
||||
placeholder: (t) => t("search.modePicker.userGroup.placeholder"),
|
||||
useGroups() {
|
||||
const { data: session } = useSession();
|
||||
if (!session?.user.permissions.includes("admin")) return [];
|
||||
return [usersSearchGroup, groupsSearchGroup];
|
||||
},
|
||||
} satisfies SearchMode;
|
||||
@@ -8,6 +8,7 @@ import { UserAvatar } from "@homarr/ui";
|
||||
import { createChildrenOptions } from "../../lib/children";
|
||||
import { createGroup } from "../../lib/group";
|
||||
import { interaction } from "../../lib/interaction";
|
||||
import { useRemoteQuery } from "../../lib/remote-query";
|
||||
|
||||
// This has to be type so it can be interpreted as Record<string, unknown>.
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
||||
@@ -49,6 +50,7 @@ const userChildrenOptions = createChildrenOptions<User>({
|
||||
export const usersSearchGroup = createGroup<User>({
|
||||
keyPath: "id",
|
||||
title: (t) => t("common.entity.users"),
|
||||
source: { kind: "remote", source: "users" },
|
||||
Component: (user) => (
|
||||
<Group px="md" py="sm">
|
||||
<UserAvatar user={user} size="sm" />
|
||||
@@ -57,6 +59,7 @@ export const usersSearchGroup = createGroup<User>({
|
||||
),
|
||||
useInteraction: interaction.children(userChildrenOptions),
|
||||
useQueryOptions(query) {
|
||||
return clientApi.user.search.useQuery({ query, limit: 5 });
|
||||
const remoteQuery = useRemoteQuery(query, "users");
|
||||
return clientApi.user.search.useQuery({ query: remoteQuery.query, limit: 8 }, { enabled: remoteQuery.enabled });
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user