Add node switching to command palette
This commit is contained in:
@@ -18,11 +18,13 @@ import { toast } from "react-hot-toast";
|
|||||||
|
|
||||||
import { useDevice } from "@app/core/providers/useDevice.js";
|
import { useDevice } from "@app/core/providers/useDevice.js";
|
||||||
import { useAppStore } from "@app/core/stores/appStore.js";
|
import { useAppStore } from "@app/core/stores/appStore.js";
|
||||||
|
import { useDeviceStore } from "@app/core/stores/deviceStore.js";
|
||||||
import { GroupView } from "@components/CommandPalette/GroupView.js";
|
import { GroupView } from "@components/CommandPalette/GroupView.js";
|
||||||
import { NoResults } from "@components/CommandPalette/NoResults.js";
|
import { NoResults } from "@components/CommandPalette/NoResults.js";
|
||||||
import { PaletteTransition } from "@components/CommandPalette/PaletteTransition.js";
|
import { PaletteTransition } from "@components/CommandPalette/PaletteTransition.js";
|
||||||
import { SearchBox } from "@components/CommandPalette/SearchBox.js";
|
import { SearchBox } from "@components/CommandPalette/SearchBox.js";
|
||||||
import { SearchResult } from "@components/CommandPalette/SearchResult.js";
|
import { SearchResult } from "@components/CommandPalette/SearchResult.js";
|
||||||
|
import { Hashicon } from "@emeraldpay/hashicon-react";
|
||||||
import { Combobox, Dialog, Transition } from "@headlessui/react";
|
import { Combobox, Dialog, Transition } from "@headlessui/react";
|
||||||
import {
|
import {
|
||||||
ArchiveBoxXMarkIcon,
|
ArchiveBoxXMarkIcon,
|
||||||
@@ -57,13 +59,27 @@ export interface Group {
|
|||||||
export interface Command {
|
export interface Command {
|
||||||
name: string;
|
name: string;
|
||||||
icon: (props: React.ComponentProps<"svg">) => JSX.Element;
|
icon: (props: React.ComponentProps<"svg">) => JSX.Element;
|
||||||
|
action?: () => void;
|
||||||
|
subItems?: SubItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SubItem {
|
||||||
|
name: string;
|
||||||
|
icon: JSX.Element;
|
||||||
action: () => void;
|
action: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CommandPalette = (): JSX.Element => {
|
export const CommandPalette = (): JSX.Element => {
|
||||||
const [query, setQuery] = useState("");
|
const [query, setQuery] = useState("");
|
||||||
const { commandPaletteOpen, setCommandPaletteOpen } = useAppStore();
|
const {
|
||||||
// const [open, setOpen] = useState(false);
|
commandPaletteOpen,
|
||||||
|
setCommandPaletteOpen,
|
||||||
|
devices,
|
||||||
|
setSelectedDevice,
|
||||||
|
removeDevice,
|
||||||
|
selectedDevice
|
||||||
|
} = useAppStore();
|
||||||
|
const { getDevices } = useDeviceStore();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
setQRDialogOpen,
|
setQRDialogOpen,
|
||||||
@@ -72,7 +88,6 @@ export const CommandPalette = (): JSX.Element => {
|
|||||||
setActivePage,
|
setActivePage,
|
||||||
connection
|
connection
|
||||||
} = useDevice();
|
} = useDevice();
|
||||||
const { setSelectedDevice, removeDevice, selectedDevice } = useAppStore();
|
|
||||||
|
|
||||||
const groups: Group[] = [
|
const groups: Group[] = [
|
||||||
{
|
{
|
||||||
@@ -142,11 +157,25 @@ export const CommandPalette = (): JSX.Element => {
|
|||||||
icon: DevicePhoneMobileIcon,
|
icon: DevicePhoneMobileIcon,
|
||||||
commands: [
|
commands: [
|
||||||
{
|
{
|
||||||
name: "[WIP] Switch Node",
|
name: "Switch Node",
|
||||||
icon: ArrowsRightLeftIcon,
|
icon: ArrowsRightLeftIcon,
|
||||||
|
subItems: getDevices().map((device) => {
|
||||||
|
return {
|
||||||
|
name:
|
||||||
|
device.nodes.find(
|
||||||
|
(n) => n.data.num === device.hardware.myNodeNum
|
||||||
|
)?.data.user?.longName ?? device.hardware.myNodeNum.toString(),
|
||||||
|
icon: (
|
||||||
|
<Hashicon
|
||||||
|
size={24}
|
||||||
|
value={device.hardware.myNodeNum.toString()}
|
||||||
|
/>
|
||||||
|
),
|
||||||
action() {
|
action() {
|
||||||
alert("This feature is not implemented");
|
setSelectedDevice(device.id);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Connect New Node",
|
name: "Connect New Node",
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ export const SearchResult = ({ group }: SearchResultProps): JSX.Element => {
|
|||||||
<span className="ml-3 flex-auto truncate">{group.name}</span>
|
<span className="ml-3 flex-auto truncate">{group.name}</span>
|
||||||
</div>
|
</div>
|
||||||
{group.commands.map((command, index) => (
|
{group.commands.map((command, index) => (
|
||||||
|
<div key={index}>
|
||||||
<Combobox.Option
|
<Combobox.Option
|
||||||
key={index}
|
|
||||||
value={command}
|
value={command}
|
||||||
className={({ active }) =>
|
className={({ active }) =>
|
||||||
`mr-2 ml-4 flex cursor-pointer select-none items-center rounded-md px-3 py-1 ${
|
`mr-2 ml-4 flex cursor-pointer select-none items-center rounded-md px-3 py-1 ${
|
||||||
@@ -39,6 +39,31 @@ export const SearchResult = ({ group }: SearchResultProps): JSX.Element => {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Combobox.Option>
|
</Combobox.Option>
|
||||||
|
{command.subItems && (
|
||||||
|
<div className=" ml-9 border-l">
|
||||||
|
{command.subItems?.map((item) => (
|
||||||
|
<Combobox.Option
|
||||||
|
key={index}
|
||||||
|
value={item}
|
||||||
|
className={({ active }) =>
|
||||||
|
`mx-2 flex cursor-pointer select-none items-center rounded-md px-3 py-1 ${
|
||||||
|
active ? "bg-gray-900 bg-opacity-5 text-gray-900" : ""
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{({ active }) => (
|
||||||
|
<>
|
||||||
|
<span className="ml-3">{item.name}</span>
|
||||||
|
{active && (
|
||||||
|
<ChevronRightIcon className="ml-auto h-4 text-gray-400" />
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Combobox.Option>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user