import { Accordion, Flex, Text } from '@mantine/core'; import React, { Suspense, lazy, useContext, useState } from 'react'; import { host } from '../shared/env.const'; import { useQuery } from '@tanstack/react-query'; import { frigateQueryKeys, frigateApi } from '../services/frigate.proxy/frigate.api'; import { Context } from '..'; import CenterLoader from '../shared/components/CenterLoader'; import RetryError from '../pages/RetryError'; const CameraAccordion = lazy(() => import('../shared/components/accordion/CameraAccordion')); interface SelectedHostListProps { hostId: string } const SelectedHostList = ({ hostId }: SelectedHostListProps) => { const { recordingsStore: recStore } = useContext(Context) const [openCameraId, setOpenCameraId] = useState(null) const { data: host, isPending: hostPending, isError: hostError, refetch: hostRefetch } = useQuery({ queryKey: [frigateQueryKeys.getFrigateHost, hostId], queryFn: async () => { if (hostId) { return frigateApi.getHost(hostId) } return null } }) const handleOnChange = (cameraId: string | null) => { setOpenCameraId(openCameraId === cameraId ? null : cameraId) } const handleRetry = () => { if (recStore.selectedHost) hostRefetch() } if (hostPending) return if (hostError) return if (!host || host.cameras.length < 1) return null const cameras = host.cameras.slice(0, 2).map(camera => { return ( {camera.name} {openCameraId === camera.id && ( )} ) }) return ( {host.name} handleOnChange(value)}> {cameras} ) }; export default SelectedHostList;