Skip to content

Commit

Permalink
chore: split function to get below line limit
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusds committed Dec 23, 2023
1 parent 9c45bcf commit 772b6a6
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/components/device-page/header-device-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ interface HeaderDeviceSelectorProps {
t: TFunction;
}

interface HeaderDeviceSelectorItemsProps {
devices: Devices;
dev: string;
tab?: TabName;
setSearchTerm: (value: string) => void;
}

const SearchMenu = forwardRef<HTMLDivElement, PropsWithChildren<SearchMenuProps>>(function SearchMenu(
{ children, style, className, searchTerm, setSearchTerm, t },
ref,
Expand Down Expand Up @@ -60,18 +67,26 @@ export function HeaderDeviceSelector(props: HeaderDeviceSelectorProps): JSX.Elem
</Dropdown.Toggle>

<Dropdown.Menu as={SearchMenu} searchTerm={searchTerm} t={t} setSearchTerm={setSearchTerm}>
{Object.entries(devices).map(([id, device]) => (
<Dropdown.Item
active={id === dev}
key={id}
href={`#/device/${id}/${tab}`}
onClick={() => setSearchTerm('')}
>
{device.friendly_name}
</Dropdown.Item>
))}
<HeaderDeviceSelectorItems devices={devices} dev={dev} tab={tab} setSearchTerm={setSearchTerm} />
</Dropdown.Menu>
</Dropdown>
</h1>
);
}

function HeaderDeviceSelectorItems({devices, dev, tab, setSearchTerm}: HeaderDeviceSelectorItemsProps): JSX.Element {
return (
<>
{Object.entries(devices).map(([id, device]) => (
<Dropdown.Item
active={id === dev}
key={id}
href={`#/device/${id}/${tab}`}
onClick={() => setSearchTerm('')}
>
{device.friendly_name}
</Dropdown.Item>
))}
</>
)
}

0 comments on commit 772b6a6

Please sign in to comment.