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/loaders/CenterLoader'; import RetryErrorPage from '../pages/RetryErrorPage'; import { strings } from '../shared/strings/strings'; 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: camerasQuery, isPending: hostPending, isError: hostError, refetch: hostRefetch } = useQuery({ queryKey: [frigateQueryKeys.getCameraByHostId, hostId], queryFn: async () => { if (hostId) { return frigateApi.getCamerasByHostId(hostId) } return [] } }) const handleOnChange = (cameraId: string | null) => { setOpenCameraId(openCameraId === cameraId ? null : cameraId) recStore.openedCamera = camerasQuery?.find( camera => camera.id === cameraId) } const handleRetry = () => { if (recStore.filteredHost) hostRefetch() } if (hostPending) return if (hostError) return if (!camerasQuery || camerasQuery.length < 1) return null const camerasItems = camerasQuery.map(camera => { return ( {strings.camera}: {camera.name} {openCameraId === camera.id && ( )} ) }) return ( {strings.host}: {camerasQuery[0].frigateHost?.name} handleOnChange(value)}> {camerasItems} ) }; export default SelectedHostList;