diff --git a/src/AppBody.tsx b/src/AppBody.tsx index c7c0e38..532163a 100644 --- a/src/AppBody.tsx +++ b/src/AppBody.tsx @@ -1,5 +1,4 @@ import { AppShell, useMantineTheme, } from "@mantine/core"; -import { observer } from 'mobx-react-lite'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useLocation } from "react-router-dom"; @@ -21,28 +20,27 @@ const AppBody = () => { { link: routesPath.ACCESS_PATH, label: t('header.acessSettings'), admin: true }, ] - const location = useLocation() const pathsWithLeftSidebar: string[] = [] const pathsWithRightSidebar: string[] = [routesPath.MAIN_PATH, routesPath.RECORDINGS_PATH, routesPath.EVENTS_PATH] - const [leftSideBar, setLeftSidebar] = useState(pathsWithLeftSidebar.includes(location.pathname)) - const [rightSideBar, setRightSidebar] = useState(pathsWithRightSidebar.includes(location.pathname)) + const [isLeftSideBarVisible, setVisibleLeftSidebar] = useState(pathsWithLeftSidebar.includes(location.pathname)) + const [isRightSideBarVisible, setVisibleRightSidebar] = useState(pathsWithRightSidebar.includes(location.pathname)) const handleRightSidebarChange = (isVisible: boolean) => { - setRightSidebar(isVisible); + setVisibleRightSidebar(isVisible); }; const theme = useMantineTheme(); - if (!isProduction) console.log("render Main") + if (!isProduction) console.log("render AppBody") return ( { ) }; -export default observer(AppBody); \ No newline at end of file +export default AppBody; \ No newline at end of file diff --git a/src/pages/MainPage.tsx b/src/pages/MainPage.tsx index 6b13733..078e0fe 100644 --- a/src/pages/MainPage.tsx +++ b/src/pages/MainPage.tsx @@ -115,7 +115,7 @@ const MainPage = () => { justify='center' > { className?: string; @@ -26,10 +26,13 @@ const AutoUpdatedImage = ({ const { data: imageBlob, refetch, isPending, isError } = useQuery({ queryKey: [imageUrl], - queryFn: () => proxyApi.getImageFrigate(imageUrl, 522), + queryFn: () => { + if (enabled) return proxyApi.getImageFrigate(imageUrl, 522) + return null + }, staleTime: 60 * 1000, gcTime: 5 * 60 * 1000, - refetchInterval: isVisible ? 30 * 1000 : undefined, + refetchInterval: isVisible ? 60 * 1000 : undefined, retry: 1, }); @@ -55,14 +58,15 @@ const AutoUpdatedImage = ({ } }, [imageBlob]) + if (!enabled) return Camera is disabled in config, no stream or snapshot available! + if (isPending || !imageSrc) return + if (!isProduction) console.log('AutoUpdatedImage rendered') + return ( - {enabled ? Dynamic Content - : - Camera is disabled in config, no stream or snapshot available! - } + Dynamic Content ) }; diff --git a/src/shared/components/inputs/ClearableTextInput.tsx b/src/shared/components/inputs/ClearableTextInput.tsx index b403a1f..c06cf72 100644 --- a/src/shared/components/inputs/ClearableTextInput.tsx +++ b/src/shared/components/inputs/ClearableTextInput.tsx @@ -1,18 +1,24 @@ import { CloseButton, TextInput, TextInputProps } from '@mantine/core'; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; interface ClearableTextInputProps extends TextInputProps { - clerable?: boolean + clearable?: boolean } const ClearableTextInput: React.FC = ({ value, onChange, - clerable, + clearable, ...textInputProps }) => { - const [text, setText] = useState(value) + const [text, setText] = useState(value || '') + + useEffect(() => { + if (value !== undefined) { + setText(value); + } + }, [value]); const handleClear = (event: React.MouseEvent) => { setText('') @@ -32,7 +38,7 @@ const ClearableTextInput: React.FC = ({ return ( : null} + rightSection={clearable ? : null} value={text} onChange={handleChange} {...textInputProps} diff --git a/src/shared/stores/main.store.ts b/src/shared/stores/main.store.ts index c5d2b59..474e66d 100644 --- a/src/shared/stores/main.store.ts +++ b/src/shared/stores/main.store.ts @@ -34,19 +34,25 @@ export class MainStore { } setHostId(hostId: string, navigate: (path: string, options?: NavigateOptions) => void) { - this.filters.hostId = hostId; - this.updateURL(navigate) + if (hostId !== this.filters.hostId) { + this.filters.hostId = hostId; + this.updateURL(navigate) + } } setSearchQuery(searchQuery: string, navigate: (path: string, options?: NavigateOptions) => void) { - this.filters.searchQuery = searchQuery; - this.updateURL(navigate) + if (searchQuery !== this.filters.searchQuery) { + this.filters.searchQuery = searchQuery; + this.updateURL(navigate) + } } setSelectedTags(selectedTags: string[], navigate: (path: string, options?: NavigateOptions) => void) { - if (!isProduction) console.log('MainPage set filters.selectedTags ', selectedTags) - this.filters.selectedTags = selectedTags ? selectedTags : [] - this.updateURL(navigate) + if (selectedTags !== this.filters.selectedTags) { + if (!isProduction) console.log('MainPage set filters.selectedTags ', selectedTags) + this.filters.selectedTags = selectedTags ? selectedTags : [] + this.updateURL(navigate) + } } getArrayParam = (key: string): string[] => {