fix search params at events page
This commit is contained in:
parent
cc410d548a
commit
e2bd0c20c5
@ -1,17 +1,29 @@
|
|||||||
import { Flex, Text } from '@mantine/core';
|
import { Flex, Text } from '@mantine/core';
|
||||||
import { notifications } from '@mantine/notifications';
|
import { notifications } from '@mantine/notifications';
|
||||||
|
import { IconAlertCircle } from '@tabler/icons-react';
|
||||||
import { t } from 'i18next';
|
import { t } from 'i18next';
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
import { useContext, useEffect, useState } from 'react';
|
import { useContext, useEffect, useMemo } from 'react';
|
||||||
import { Context } from '..';
|
import { Context } from '..';
|
||||||
import { isStartBiggerThanEndTime } from '../shared/utils/dateUtil';
|
import { isStartBiggerThanEndTime } from '../shared/utils/dateUtil';
|
||||||
import EventsBody from '../widgets/EventsBody';
|
import EventsBody from '../widgets/EventsBody';
|
||||||
import EventsRightFilters from '../widgets/sidebars/EventsRightFilters';
|
import EventsRightFilters from '../widgets/sidebars/EventsRightFilters';
|
||||||
import { SideBarContext } from '../widgets/sidebars/SideBarContext';
|
import { SideBarContext } from '../widgets/sidebars/SideBarContext';
|
||||||
import { IconAlertCircle } from '@tabler/icons-react';
|
import { useLocation, useSearchParams } from 'react-router-dom';
|
||||||
|
|
||||||
|
export const eventsQueryParams = {
|
||||||
|
hostId: 'hostId',
|
||||||
|
cameraId: 'cameraId',
|
||||||
|
startDate: 'startDate',
|
||||||
|
endDate: 'endDate',
|
||||||
|
startTime: 'startTime',
|
||||||
|
endTime: 'endTime',
|
||||||
|
}
|
||||||
|
|
||||||
const EventsPage = () => {
|
const EventsPage = () => {
|
||||||
|
|
||||||
|
const [searchParams] = useSearchParams()
|
||||||
|
|
||||||
const { setRightChildren } = useContext(SideBarContext)
|
const { setRightChildren } = useContext(SideBarContext)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -20,8 +32,20 @@ const EventsPage = () => {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const { eventsStore } = useContext(Context)
|
const { eventsStore } = useContext(Context)
|
||||||
|
|
||||||
|
|
||||||
const { hostId, cameraId, period, startTime, endTime } = eventsStore.filters
|
const { hostId, cameraId, period, startTime, endTime } = eventsStore.filters
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const paramHostId = searchParams.get(eventsQueryParams.hostId) || undefined
|
||||||
|
const paramCameraId = searchParams.get(eventsQueryParams.cameraId) || undefined
|
||||||
|
const paramStartDate = searchParams.get(eventsQueryParams.startDate) || undefined
|
||||||
|
const paramEndDate = searchParams.get(eventsQueryParams.endDate) || undefined
|
||||||
|
const paramStartTime = searchParams.get(eventsQueryParams.startTime) || undefined
|
||||||
|
const paramEndTime = searchParams.get(eventsQueryParams.endTime) || undefined
|
||||||
|
eventsStore.loadFiltersFromPage(paramHostId, paramCameraId, paramStartDate, paramEndDate, paramStartTime, paramEndTime)
|
||||||
|
}, [searchParams])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (startTime && endTime) {
|
if (startTime && endTime) {
|
||||||
if (isStartBiggerThanEndTime(startTime, endTime)) {
|
if (isStartBiggerThanEndTime(startTime, endTime)) {
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
import { makeAutoObservable } from "mobx";
|
import { makeAutoObservable } from "mobx";
|
||||||
|
import { eventsQueryParams } from "../../pages/EventsPage";
|
||||||
|
import { NavigateOptions } from "react-router-dom";
|
||||||
|
|
||||||
interface Filters {
|
interface Filters {
|
||||||
hostId?: string
|
hostId?: string
|
||||||
@ -8,21 +10,12 @@ interface Filters {
|
|||||||
endTime?: string
|
endTime?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const eventsQueryParams = {
|
|
||||||
hostId: 'hostId',
|
|
||||||
cameraId: 'cameraId',
|
|
||||||
startDate: 'startDate',
|
|
||||||
endDate: 'endDate',
|
|
||||||
startTime: 'startTime',
|
|
||||||
endTime: 'endTime',
|
|
||||||
}
|
|
||||||
|
|
||||||
export class EventsStore {
|
export class EventsStore {
|
||||||
filters: Filters = {}
|
filters: Filters = {}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
makeAutoObservable(this);
|
makeAutoObservable(this);
|
||||||
this.loadFiltersFromURL();
|
// this.loadFiltersFromURL();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadFiltersFromURL() {
|
loadFiltersFromURL() {
|
||||||
@ -38,32 +31,48 @@ export class EventsStore {
|
|||||||
this.filters.endTime = params.get(eventsQueryParams.endTime) || undefined
|
this.filters.endTime = params.get(eventsQueryParams.endTime) || undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
setHostId(hostId: string, navigate: (path: string) => void) {
|
loadFiltersFromPage(
|
||||||
|
paramHostId: string | undefined,
|
||||||
|
paramCameraId: string | undefined,
|
||||||
|
paramStartDate: string | undefined,
|
||||||
|
paramEndDate: string | undefined,
|
||||||
|
paramStartTime: string | undefined,
|
||||||
|
paramEndTime: string | undefined) {
|
||||||
|
this.filters.hostId = paramHostId
|
||||||
|
this.filters.cameraId = paramCameraId
|
||||||
|
if (paramStartDate && paramEndDate) {
|
||||||
|
this.filters.period = [new Date(paramStartDate), new Date(paramEndDate)]
|
||||||
|
}
|
||||||
|
this.filters.startTime = paramStartTime
|
||||||
|
this.filters.endTime = paramEndTime
|
||||||
|
}
|
||||||
|
|
||||||
|
setHostId(hostId: string, navigate: (path: string, options?: NavigateOptions) => void) {
|
||||||
this.filters.hostId = hostId;
|
this.filters.hostId = hostId;
|
||||||
this.updateURL(navigate)
|
this.updateURL(navigate)
|
||||||
}
|
}
|
||||||
|
|
||||||
setCameraId(cameraId: string, navigate: (path: string) => void) {
|
setCameraId(cameraId: string, navigate: (path: string, options?: NavigateOptions) => void) {
|
||||||
this.filters.cameraId = cameraId;
|
this.filters.cameraId = cameraId;
|
||||||
this.updateURL(navigate)
|
this.updateURL(navigate)
|
||||||
}
|
}
|
||||||
|
|
||||||
setPeriod(period: [Date | null, Date | null], navigate: (path: string) => void) {
|
setPeriod(period: [Date | null, Date | null], navigate: (path: string, options?: NavigateOptions) => void) {
|
||||||
this.filters.period = period;
|
this.filters.period = period;
|
||||||
this.updateURL(navigate)
|
this.updateURL(navigate)
|
||||||
}
|
}
|
||||||
|
|
||||||
setStartTime(startTime: string, navigate: (path: string) => void) {
|
setStartTime(startTime: string, navigate: (path: string, options?: NavigateOptions) => void) {
|
||||||
this.filters.startTime = startTime
|
this.filters.startTime = startTime
|
||||||
this.updateURL(navigate)
|
this.updateURL(navigate)
|
||||||
}
|
}
|
||||||
|
|
||||||
setEndTime(endTime: string, navigate: (path: string) => void) {
|
setEndTime(endTime: string, navigate: (path: string, options?: NavigateOptions) => void) {
|
||||||
this.filters.endTime = endTime
|
this.filters.endTime = endTime
|
||||||
this.updateURL(navigate)
|
this.updateURL(navigate)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateURL(navigate: (path: string) => void) {
|
updateURL(navigate: (path: string, options?: NavigateOptions) => void) {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
if (this.filters.hostId) params.set('hostId', this.filters.hostId);
|
if (this.filters.hostId) params.set('hostId', this.filters.hostId);
|
||||||
if (this.filters.cameraId) params.set('cameraId', this.filters.cameraId);
|
if (this.filters.cameraId) params.set('cameraId', this.filters.cameraId);
|
||||||
@ -80,7 +89,7 @@ export class EventsStore {
|
|||||||
if (this.filters.startTime) params.set('startTime', this.filters.startTime)
|
if (this.filters.startTime) params.set('startTime', this.filters.startTime)
|
||||||
if (this.filters.endTime) params.set('endTime', this.filters.endTime)
|
if (this.filters.endTime) params.set('endTime', this.filters.endTime)
|
||||||
|
|
||||||
navigate(`?${params.toString()}`);
|
navigate(`?${params.toString()}`, { replace: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
isPeriodSet() {
|
isPeriodSet() {
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import { mapHostToHostname, proxyApi } from '../services/frigate.proxy/frigate.a
|
|||||||
import { GetCameraWHostWConfig } from '../services/frigate.proxy/frigate.schema';
|
import { GetCameraWHostWConfig } from '../services/frigate.proxy/frigate.schema';
|
||||||
import AutoUpdatedImage from '../shared/components/images/AutoUpdatedImage';
|
import AutoUpdatedImage from '../shared/components/images/AutoUpdatedImage';
|
||||||
import CameraTagsList from './CameraTagsList';
|
import CameraTagsList from './CameraTagsList';
|
||||||
import { eventsQueryParams } from '../shared/stores/events.store';
|
import { eventsQueryParams } from '../pages/EventsPage';
|
||||||
|
|
||||||
const useStyles = createStyles((theme) => ({
|
const useStyles = createStyles((theme) => ({
|
||||||
mainCard: {
|
mainCard: {
|
||||||
@ -53,9 +53,8 @@ const CameraCard = ({
|
|||||||
const imageUrl = hostName ? proxyApi.cameraImageURL(hostName, camera.name) : '' //todo implement get URL from live cameras
|
const imageUrl = hostName ? proxyApi.cameraImageURL(hostName, camera.name) : '' //todo implement get URL from live cameras
|
||||||
const { isAdmin } = useAdminRole()
|
const { isAdmin } = useAdminRole()
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (entry?.isIntersecting)
|
if (entry && entry.isIntersecting)
|
||||||
setRenderImage(true)
|
setRenderImage(true)
|
||||||
}, [entry?.isIntersecting])
|
}, [entry?.isIntersecting])
|
||||||
|
|
||||||
@ -83,7 +82,7 @@ const CameraCard = ({
|
|||||||
<Grid.Col md={6} lg={3} p='0.2rem'>
|
<Grid.Col md={6} lg={3} p='0.2rem'>
|
||||||
<Card ref={ref} h='100%' radius="lg" padding='0.5rem' className={classes.mainCard}>
|
<Card ref={ref} h='100%' radius="lg" padding='0.5rem' className={classes.mainCard}>
|
||||||
<Text align='center' size='md' className={classes.headText} >{camera.name} / {camera.frigateHost?.name}</Text>
|
<Text align='center' size='md' className={classes.headText} >{camera.name} / {camera.frigateHost?.name}</Text>
|
||||||
{!renderImage ? '' :
|
{!renderImage ? null :
|
||||||
<AutoUpdatedImage onClick={handleOpenLiveView} enabled={camera.config?.enabled} imageUrl={imageUrl} />
|
<AutoUpdatedImage onClick={handleOpenLiveView} enabled={camera.config?.enabled} imageUrl={imageUrl} />
|
||||||
}
|
}
|
||||||
<Group
|
<Group
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user