fix add observer

This commit is contained in:
NlightN22 2024-02-28 16:12:41 +07:00
parent 505dd09b43
commit e45ec6595f
22 changed files with 49 additions and 53 deletions

View File

@ -5,6 +5,7 @@ import { strings } from '../shared/strings/strings';
import { redirect, useNavigate } from 'react-router-dom'; import { redirect, useNavigate } from 'react-router-dom';
import { routesPath } from '../router/routes.path'; import { routesPath } from '../router/routes.path';
import { Context } from '..'; import { Context } from '..';
import { observer } from 'mobx-react-lite';
const Forbidden = () => { const Forbidden = () => {
@ -29,4 +30,4 @@ const Forbidden = () => {
); );
}; };
export default Forbidden; export default observer(Forbidden);

View File

@ -5,6 +5,7 @@ import { strings } from '../shared/strings/strings';
import { redirect, useNavigate } from 'react-router-dom'; import { redirect, useNavigate } from 'react-router-dom';
import { routesPath } from '../router/routes.path'; import { routesPath } from '../router/routes.path';
import { Context } from '..'; import { Context } from '..';
import { observer } from 'mobx-react-lite';
const NotFound = () => { const NotFound = () => {
@ -29,4 +30,4 @@ const NotFound = () => {
); );
}; };
export default NotFound; export default observer(NotFound);

View File

@ -12,6 +12,7 @@ import { Context } from '..';
import { strings } from '../shared/strings/strings'; import { strings } from '../shared/strings/strings';
import { useAdminRole } from '../hooks/useAdminRole'; import { useAdminRole } from '../hooks/useAdminRole';
import Forbidden from './403'; import Forbidden from './403';
import { observer } from 'mobx-react-lite';
const AccessSettings = () => { const AccessSettings = () => {
const { data, isPending, isError, refetch } = useQuery({ const { data, isPending, isError, refetch } = useQuery({
@ -64,4 +65,4 @@ const AccessSettings = () => {
); );
}; };
export default AccessSettings; export default observer(AccessSettings);

View File

@ -12,7 +12,7 @@ import { observer } from 'mobx-react-lite'
import { useAdminRole } from '../hooks/useAdminRole'; import { useAdminRole } from '../hooks/useAdminRole';
import Forbidden from './403'; import Forbidden from './403';
const FrigateHostsPage = observer(() => { const FrigateHostsPage = () => {
const queryClient = useQueryClient() const queryClient = useQueryClient()
const { isPending: hostsPending, error: hostsError, data } = useQuery({ const { isPending: hostsPending, error: hostsError, data } = useQuery({
queryKey: [frigateQueryKeys.getFrigateHosts], queryKey: [frigateQueryKeys.getFrigateHosts],
@ -89,6 +89,6 @@ const FrigateHostsPage = observer(() => {
</Flex> </Flex>
</div> </div>
); );
}) }
export default FrigateHostsPage; export default observer(FrigateHostsPage);

View File

@ -11,6 +11,7 @@ import CenterLoader from '../shared/components/loaders/CenterLoader';
import RetryErrorPage from './RetryErrorPage'; import RetryErrorPage from './RetryErrorPage';
import { useAdminRole } from '../hooks/useAdminRole'; import { useAdminRole } from '../hooks/useAdminRole';
import Forbidden from './403'; import Forbidden from './403';
import { observer } from 'mobx-react-lite';
const HostConfigPage = () => { const HostConfigPage = () => {
@ -115,4 +116,4 @@ const HostConfigPage = () => {
} }
export default HostConfigPage; export default observer(HostConfigPage);

View File

@ -3,6 +3,7 @@ import { useParams } from 'react-router-dom';
import { Context } from '..'; import { Context } from '..';
import { useAdminRole } from '../hooks/useAdminRole'; import { useAdminRole } from '../hooks/useAdminRole';
import Forbidden from './403'; import Forbidden from './403';
import { observer } from 'mobx-react-lite';
const HostStoragePage = () => { const HostStoragePage = () => {
let { id } = useParams<'id'>() let { id } = useParams<'id'>()
@ -25,4 +26,4 @@ const HostStoragePage = () => {
); );
}; };
export default HostStoragePage; export default observer(HostStoragePage);

View File

@ -3,6 +3,7 @@ import { useParams } from 'react-router-dom';
import { Context } from '..'; import { Context } from '..';
import { useAdminRole } from '../hooks/useAdminRole'; import { useAdminRole } from '../hooks/useAdminRole';
import Forbidden from './403'; import Forbidden from './403';
import { observer } from 'mobx-react-lite';
const HostSystemPage = () => { const HostSystemPage = () => {
let { id } = useParams<'id'>() let { id } = useParams<'id'>()
@ -24,4 +25,4 @@ const HostSystemPage = () => {
); );
}; };
export default HostSystemPage; export default observer(HostSystemPage);

View File

@ -12,7 +12,7 @@ import { strings } from '../shared/strings/strings';
import { routesPath } from '../router/routes.path'; import { routesPath } from '../router/routes.path';
import { recordingsPageQuery } from './RecordingsPage'; import { recordingsPageQuery } from './RecordingsPage';
const LiveCameraPage = observer(() => { const LiveCameraPage = () => {
const navigate = useNavigate() const navigate = useNavigate()
let { id: cameraId } = useParams<'id'>() let { id: cameraId } = useParams<'id'>()
if (!cameraId) throw Error('Camera id does not exist') if (!cameraId) throw Error('Camera id does not exist')
@ -52,6 +52,6 @@ const LiveCameraPage = observer(() => {
<Player camera={camera} /> <Player camera={camera} />
</Flex> </Flex>
); );
}) }
export default LiveCameraPage; export default observer(LiveCameraPage)

View File

@ -6,6 +6,7 @@ import { proxyURL } from '../shared/env.const';
import { proxyApi } from '../services/frigate.proxy/frigate.api'; import { proxyApi } from '../services/frigate.proxy/frigate.api';
import NotFound from './404'; import NotFound from './404';
import { Context } from '..'; import { Context } from '..';
import { observer } from 'mobx-react-lite';
export const playRecordPageQuery = { export const playRecordPageQuery = {
link: 'link', link: 'link',
@ -33,4 +34,4 @@ const PlayRecordPage = () => {
); );
}; };
export default PlayRecordPage; export default observer(PlayRecordPage);

View File

@ -20,7 +20,7 @@ export const recordingsPageQuery = {
hour: 'hour', hour: 'hour',
} }
const RecordingsPage = observer(() => { const RecordingsPage = () => {
const { sideBarsStore, recordingsStore: recStore } = useContext(Context) const { sideBarsStore, recordingsStore: recStore } = useContext(Context)
const location = useLocation() const location = useLocation()
@ -123,6 +123,6 @@ const RecordingsPage = observer(() => {
} }
</Flex> </Flex>
) )
}) }
export default RecordingsPage export default observer(RecordingsPage)

View File

@ -5,6 +5,7 @@ import { strings } from '../shared/strings/strings';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { ExclamationCogWheel } from '../shared/components/svg/ExclamationCogWheel'; import { ExclamationCogWheel } from '../shared/components/svg/ExclamationCogWheel';
import { Context } from '..'; import { Context } from '..';
import { observer } from 'mobx-react-lite';
interface RetryErrorPageProps { interface RetryErrorPageProps {
onRetry?: () => void onRetry?: () => void
@ -14,8 +15,6 @@ const RetryErrorPage = ({ onRetry }: RetryErrorPageProps) => {
const navigate = useNavigate() const navigate = useNavigate()
const { sideBarsStore } = useContext(Context) const { sideBarsStore } = useContext(Context)
useEffect(() => { useEffect(() => {
sideBarsStore.setLeftChildren(null) sideBarsStore.setLeftChildren(null)
sideBarsStore.setRightChildren(null) sideBarsStore.setRightChildren(null)
@ -48,4 +47,4 @@ const RetryErrorPage = ({ onRetry }: RetryErrorPageProps) => {
); );
}; };
export default RetryErrorPage; export default observer(RetryErrorPage);

View File

@ -16,6 +16,7 @@ import { GetConfig } from '../services/frigate.proxy/frigate.schema';
import { Context } from '..'; import { Context } from '..';
import { useAdminRole } from '../hooks/useAdminRole'; import { useAdminRole } from '../hooks/useAdminRole';
import Forbidden from './403'; import Forbidden from './403';
import { observer } from 'mobx-react-lite';
const SettingsPage = () => { const SettingsPage = () => {
const queryClient = useQueryClient() const queryClient = useQueryClient()
@ -133,4 +134,4 @@ const SettingsPage = () => {
); );
}; };
export default SettingsPage; export default observer(SettingsPage);

View File

@ -27,8 +27,9 @@ instanceApi.interceptors.request.use(
config => { config => {
const token = getToken(); const token = getToken();
if (token) { if (token) {
config.headers.Authorization = `Bearer ${token}`; config.headers.Authorization = `Bearer ${token}`
} }
config.timeout = 60 * 1000
return config; return config;
}, },
error => Promise.reject(error) error => Promise.reject(error)
@ -40,7 +41,6 @@ export const frigateApi = {
getHosts: () => instanceApi.get<GetFrigateHost[]>('apiv1/frigate-hosts').then(res => { getHosts: () => instanceApi.get<GetFrigateHost[]>('apiv1/frigate-hosts').then(res => {
return res.data return res.data
}), }),
// TODO change request to cameras
getHost: (id: string) => instanceApi.get<GetFrigateHost>(`apiv1/frigate-hosts/${id}`).then(res => { getHost: (id: string) => instanceApi.get<GetFrigateHost>(`apiv1/frigate-hosts/${id}`).then(res => {
return res.data return res.data
}), }),
@ -100,7 +100,10 @@ export const proxyApi = {
cameraName: string, cameraName: string,
timezone: string, timezone: string,
) => ) =>
instanceApi.get<RecordSummary[]>(`proxy/${hostName}/api/${cameraName}/recordings/summary`, { params: { timezone } }).then(res => res.data), instanceApi.get<RecordSummary[]>(`proxy/${hostName}/api/${cameraName}/recordings/summary`, {
params: { timezone },
timeout: 5 * 60 * 1000
}).then(res => res.data),
// E.g. http://127.0.0.1:5000/api/events?before=1708534799&after=1708448400&camera=CameraName&has_clip=1&include_thumbnails=0&limit=5000 // E.g. http://127.0.0.1:5000/api/events?before=1708534799&after=1708448400&camera=CameraName&has_clip=1&include_thumbnails=0&limit=5000
getEvents: ( getEvents: (
@ -133,7 +136,6 @@ export const proxyApi = {
getEventsSummary: (hostName: string, cameraName: string) => getEventsSummary: (hostName: string, cameraName: string) =>
instanceApi.get(`proxy/${hostName}/api/${cameraName}/events/summary`).then(res => res.data), instanceApi.get(`proxy/${hostName}/api/${cameraName}/events/summary`).then(res => res.data),
getEventsInProgress: (hostName: string) => instanceApi.get(`proxy/${hostName}/api/events?in_progress=1&include_thumbnails=0`),
cameraWsURL: (hostName: string, cameraName: string) => cameraWsURL: (hostName: string, cameraName: string) =>
`ws://${proxyURL.host}/proxy-ws/${hostName}/live/jsmpeg/${cameraName}`, `ws://${proxyURL.host}/proxy-ws/${hostName}/live/jsmpeg/${cameraName}`,
cameraImageURL: (hostName: string, cameraName: string) => cameraImageURL: (hostName: string, cameraName: string) =>
@ -154,10 +156,8 @@ export const proxyApi = {
}, },
getExportedVideoList: (hostName: string) => instanceApi.get<GetExportedFile[]>(`proxy/${hostName}/exports/`).then(res => res.data), getExportedVideoList: (hostName: string) => instanceApi.get<GetExportedFile[]>(`proxy/${hostName}/exports/`).then(res => res.data),
getVideoUrl: (hostName: string, fileName: string) => `${proxyPrefix}${hostName}/exports/${fileName}`, getVideoUrl: (hostName: string, fileName: string) => `${proxyPrefix}${hostName}/exports/${fileName}`,
deleteExportedVideo: (hostName: string, videoName: string) => instanceApi.delete(`proxy/${hostName}/api/export/${videoName}`).then(res => res.data)
// filename example Home_1_Backyard_2024_02_26_16_25__2024_02_26_16_26.mp4 // filename example Home_1_Backyard_2024_02_26_16_25__2024_02_26_16_26.mp4
deleteExportedVideo: (hostName: string, videoName: string) => instanceApi.delete(`proxy/${hostName}/api/export/${videoName}`).then(res => res.data)
} }
export const mapCamerasFromConfig = (config: FrigateConfig): string[] => { export const mapCamerasFromConfig = (config: FrigateConfig): string[] => {

View File

@ -1,4 +1,4 @@
import { any, z } from "zod"; import { z } from "zod";
import { CameraConfig, FrigateConfig } from "../../types/frigateConfig"; import { CameraConfig, FrigateConfig } from "../../types/frigateConfig";
export const putConfigSchema = z.object({ export const putConfigSchema = z.object({

View File

@ -42,7 +42,6 @@ const SideBar = ({ isHidden, side, children }: SideBarProps) => {
} }
const { sideBarsStore } = useContext(Context) const { sideBarsStore } = useContext(Context)
useEffect(() => { useEffect(() => {
if (sideBarsStore.rightVisible && side === 'right' && !visible) { if (sideBarsStore.rightVisible && side === 'right' && !visible) {
open() open()

View File

@ -1,11 +1,10 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Avatar, createStyles, Group, Menu, UnstyledButton, Text, Button, Flex } from "@mantine/core"; import { Avatar, Group, Menu, Text, Button, Flex } from "@mantine/core";
import { useAuth } from 'react-oidc-context'; import { useAuth } from 'react-oidc-context';
import { strings } from '../strings/strings'; import { strings } from '../strings/strings';
import { useMediaQuery } from '@mantine/hooks'; import { useMediaQuery } from '@mantine/hooks';
import { dimensions } from '../dimensions/dimensions'; import { dimensions } from '../dimensions/dimensions';
import ColorSchemeToggle from './buttons/ColorSchemeToggle'; import ColorSchemeToggle from './buttons/ColorSchemeToggle';
import { useNavigate } from 'react-router-dom';
import { keycloakConfig } from '../..'; import { keycloakConfig } from '../..';
interface UserMenuProps { interface UserMenuProps {
@ -16,10 +15,9 @@ const UserMenu = ({ user }: UserMenuProps) => {
const [userMenuOpened, setUserMenuOpened] = useState(false); const [userMenuOpened, setUserMenuOpened] = useState(false);
const auth = useAuth() const auth = useAuth()
const isMiddleScreen = useMediaQuery(dimensions.middleScreenSize) const isMiddleScreen = useMediaQuery(dimensions.middleScreenSize)
const navigate = useNavigate()
const handleAboutMe = () => { const handleAboutMe = () => {
navigate(`USER_DETAILED_PATH`) throw Error('Not yet implemented')
} }
const handleLogout = async () => { const handleLogout = async () => {
@ -56,12 +54,12 @@ const UserMenu = ({ user }: UserMenuProps) => {
: :
<></> <></>
} }
<Menu.Item> {/* <Menu.Item>
{strings.settings} {strings.settings}
</Menu.Item> </Menu.Item>
<Menu.Item onClick={handleAboutMe}> <Menu.Item onClick={handleAboutMe}>
{strings.aboutMe} {strings.aboutMe}
</Menu.Item> </Menu.Item> */}
<Menu.Item onClick={handleLogout}> <Menu.Item onClick={handleLogout}>
{strings.logout} {strings.logout}
</Menu.Item> </Menu.Item>

View File

@ -12,13 +12,9 @@ import { strings } from '../../strings/strings';
import { RecordSummary } from '../../../types/record'; import { RecordSummary } from '../../../types/record';
interface CameraAccordionProps { interface CameraAccordionProps {
// camera: GetCameraWHostWConfig,
// host: GetFrigateHost
} }
const CameraAccordion = ({ const CameraAccordion = ({
// camera,
// host
}: CameraAccordionProps) => { }: CameraAccordionProps) => {
const { recordingsStore: recStore } = useContext(Context) const { recordingsStore: recStore } = useContext(Context)

View File

@ -1,4 +1,4 @@
import { Flex, Group, Button, Text, Image } from '@mantine/core'; import { Flex, Button, Text } from '@mantine/core';
import { IconExternalLink } from '@tabler/icons-react'; import { IconExternalLink } from '@tabler/icons-react';
import React from 'react'; import React from 'react';
import { proxyApi } from '../../../services/frigate.proxy/frigate.api'; import { proxyApi } from '../../../services/frigate.proxy/frigate.api';

View File

@ -36,7 +36,7 @@ interface EventsAccordionProps {
* @param cameraName e.g Backyard * @param cameraName e.g Backyard
* @param hostName proxy format, e.g hostName: localhost:4000 * @param hostName proxy format, e.g hostName: localhost:4000
*/ */
const EventsAccordion = observer(({ const EventsAccordion = ({
day, day,
hour, hour,
// TODO labels, score // TODO labels, score
@ -184,6 +184,6 @@ const EventsAccordion = observer(({
))} ))}
</Accordion> </Accordion>
); );
}) }
export default EventsAccordion; export default observer(EventsAccordion);

View File

@ -1,6 +1,5 @@
import { Box, Burger, Button, Center, Collapse, Divider, Drawer, Flex, Group, Menu, ScrollArea, UnstyledButton, createStyles, rem, useMantineTheme } from '@mantine/core'; import { Burger, Drawer, Flex, UnstyledButton, createStyles } from '@mantine/core';
import { useDisclosure } from '@mantine/hooks'; import { useDisclosure } from '@mantine/hooks';
import { IconChevronDown } from '@tabler/icons-react';
import React from 'react'; import React from 'react';
import { LinkItem } from '../../../widgets/header/HeaderAction'; import { LinkItem } from '../../../widgets/header/HeaderAction';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
@ -42,8 +41,6 @@ const DrawerMenu = ({
const { classes } = useStyles(); const { classes } = useStyles();
const [drawerOpened, { toggle: toggleDrawer, close: closeDrawer }] = useDisclosure(false) const [drawerOpened, { toggle: toggleDrawer, close: closeDrawer }] = useDisclosure(false)
const theme = useMantineTheme();
const handleNavigate = (link: string) => { const handleNavigate = (link: string) => {
navigate(link) navigate(link)

View File

@ -1,14 +1,12 @@
import { Center, Flex, Text } from '@mantine/core'; import { Flex, Text } from '@mantine/core';
import React, { Suspense, useContext } from 'react'; import React, { Suspense, useContext } from 'react';
import CameraAccordion from '../shared/components/accordion/CameraAccordion'; import CameraAccordion from '../shared/components/accordion/CameraAccordion';
import { GetCameraWHostWConfig, GetFrigateHost } from '../services/frigate.proxy/frigate.schema';
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { Context } from '..'; import { Context } from '..';
import { frigateQueryKeys, frigateApi } from '../services/frigate.proxy/frigate.api'; import { frigateQueryKeys, frigateApi } from '../services/frigate.proxy/frigate.api';
import { host } from '../shared/env.const';
import CogwheelLoader from '../shared/components/loaders/CogwheelLoader';
import RetryErrorPage from '../pages/RetryErrorPage'; import RetryErrorPage from '../pages/RetryErrorPage';
import CenterLoader from '../shared/components/loaders/CenterLoader'; import CenterLoader from '../shared/components/loaders/CenterLoader';
import { observer } from 'mobx-react-lite';
interface SelectedCameraListProps { interface SelectedCameraListProps {
} }
@ -47,4 +45,4 @@ const SelectedCameraList = ({
) )
}; };
export default SelectedCameraList; export default observer(SelectedCameraList);

View File

@ -7,6 +7,7 @@ import { Context } from '..';
import CenterLoader from '../shared/components/loaders/CenterLoader'; import CenterLoader from '../shared/components/loaders/CenterLoader';
import RetryErrorPage from '../pages/RetryErrorPage'; import RetryErrorPage from '../pages/RetryErrorPage';
import { strings } from '../shared/strings/strings'; import { strings } from '../shared/strings/strings';
import { observer } from 'mobx-react-lite';
const CameraAccordion = lazy(() => import('../shared/components/accordion/CameraAccordion')); const CameraAccordion = lazy(() => import('../shared/components/accordion/CameraAccordion'));
@ -74,4 +75,4 @@ const SelectedHostList = ({
) )
}; };
export default SelectedHostList; export default observer(SelectedHostList);