1 import { useEffect } from 'react';
3 import { useActiveShare } from '../../../../../hooks/drive/useActiveShare';
4 import { useFolderTree } from '../../../../../store';
5 import type { Device } from '../../../../../store/_devices';
6 import ExpandButton from '../DriveSidebarFolders/DriveExpandButton';
7 import DriveSidebarSubfolders from '../DriveSidebarFolders/DriveSidebarSubfolders';
8 import DriveSidebarListItem from '../DriveSidebarListItem';
9 import { generateSidebarItemStyle } from '../utils';
11 export const SidebarDeviceItem = ({
16 setSidebarLevel: (level: number) => void;
18 const { activeFolder } = useActiveShare();
19 const { deepestOpenedLevel, rootFolder, toggleExpand } = useFolderTree(device.shareId, {
20 rootLinkId: device.linkId,
24 setSidebarLevel(deepestOpenedLevel);
25 }, [deepestOpenedLevel]);
27 const isActive = activeFolder.shareId === device.shareId && activeFolder.linkId === device.linkId;
32 to={`/${device.shareId}/folder/${device.linkId}`}
34 shareId={device.shareId}
35 isActive={() => isActive}
36 style={generateSidebarItemStyle(1)}
38 <span className="text-ellipsis" title={device.name} data-testid="sidebar-device-name">
43 expanded={Boolean(rootFolder?.isExpanded)}
44 onClick={() => toggleExpand(device.linkId)}
46 </DriveSidebarListItem>
47 <DriveSidebarSubfolders
48 shareId={device.shareId}
49 rootFolder={rootFolder}
50 toggleExpand={toggleExpand}