mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-02 01:05:20 +03:00
searchstring improvement
This commit is contained in:
parent
e2bee3ab94
commit
a7684f3909
@ -28,21 +28,6 @@ export default function Event({ eventId, close, scrollRef }) {
|
|||||||
}
|
}
|
||||||
}, [data, scrollRef, eventId, shouldScroll]);
|
}, [data, scrollRef, eventId, shouldScroll]);
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// const checkIfClickedOutside = (e) => {
|
|
||||||
// // If the event is open and the clicked target is not within the event window or delete modal,
|
|
||||||
// // then close the menu
|
|
||||||
// if (!showDialog && eventRef.current && !eventRef.current.contains(e.target)) {
|
|
||||||
// close(null);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// document.addEventListener('mousedown', checkIfClickedOutside);
|
|
||||||
// return () => {
|
|
||||||
// // Cleanup the
|
|
||||||
// document.removeEventListener('mousedown', checkIfClickedOutside);
|
|
||||||
// };
|
|
||||||
// }, [close, showDialog]);
|
|
||||||
|
|
||||||
const handleClickDelete = () => {
|
const handleClickDelete = () => {
|
||||||
setShowDialog(true);
|
setShowDialog(true);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -28,4 +28,5 @@ const Filterable = ({ onFilter, pathname, searchParams, paramName, name, removeD
|
|||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Filterable;
|
export default Filterable;
|
||||||
|
|||||||
@ -1,2 +1,3 @@
|
|||||||
export { default as TableHead } from './tableHead';
|
export { default as TableHead } from './tableHead';
|
||||||
|
export { default as TableRow } from './tableRow';
|
||||||
export { default as Filters } from './filters';
|
export { default as Filters } from './filters';
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
import { h, Fragment } from 'preact';
|
import { h, Fragment } from 'preact';
|
||||||
import { memo } from 'preact/compat';
|
import { memo } from 'preact/compat';
|
||||||
import { useCallback, useState } from 'preact/hooks';
|
import { useCallback, useState, useMemo } from 'preact/hooks';
|
||||||
import { Tr, Td } from '../../../components/Table';
|
import { Tr, Td } from '../../../components/Table';
|
||||||
import Filterable from './filterable';
|
import Filterable from './filterable';
|
||||||
import Event from '../../Event';
|
import Event from '../../Event';
|
||||||
|
import { useSearchString } from '../hooks/useSearchString';
|
||||||
|
|
||||||
const EventsRow = memo(
|
const EventsRow = memo(
|
||||||
({
|
({
|
||||||
@ -11,26 +12,24 @@ const EventsRow = memo(
|
|||||||
apiHost,
|
apiHost,
|
||||||
start_time: startTime,
|
start_time: startTime,
|
||||||
end_time: endTime,
|
end_time: endTime,
|
||||||
reachedEnd,
|
|
||||||
scrollToRef,
|
scrollToRef,
|
||||||
searchString,
|
|
||||||
lastRowRef,
|
lastRowRef,
|
||||||
handleFilter,
|
handleFilter,
|
||||||
pathname,
|
pathname,
|
||||||
searchParams,
|
limit,
|
||||||
camera,
|
camera,
|
||||||
label,
|
label,
|
||||||
top_score: score,
|
top_score: score,
|
||||||
zones,
|
zones,
|
||||||
removeDefaultSearchKeys,
|
|
||||||
}) => {
|
}) => {
|
||||||
const [viewEvent, setViewEvent] = useState(null);
|
const [viewEvent, setViewEvent] = useState(null);
|
||||||
|
const { searchString, removeDefaultSearchKeys } = useSearchString(limit);
|
||||||
|
const searchParams = useMemo(() => new URLSearchParams(searchString), [searchString]);
|
||||||
|
|
||||||
const viewEventHandler = useCallback(
|
const viewEventHandler = useCallback(
|
||||||
(id) => {
|
(id) => {
|
||||||
//Toggle event view
|
//Toggle event view
|
||||||
if (viewEvent === id) return setViewEvent(null);
|
if (viewEvent === id) return setViewEvent(null);
|
||||||
|
|
||||||
//Set event id to be rendered.
|
//Set event id to be rendered.
|
||||||
setViewEvent(id);
|
setViewEvent(id);
|
||||||
},
|
},
|
||||||
@ -48,7 +47,7 @@ const EventsRow = memo(
|
|||||||
onClick={() => viewEventHandler(id)}
|
onClick={() => viewEventHandler(id)}
|
||||||
ref={lastRowRef}
|
ref={lastRowRef}
|
||||||
data-start-time={startTime}
|
data-start-time={startTime}
|
||||||
data-reached-end={reachedEnd}
|
// data-reached-end={reachedEnd}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
ref={(el) => (scrollToRef[id] = el)}
|
ref={(el) => (scrollToRef[id] = el)}
|
||||||
|
|||||||
@ -6,13 +6,13 @@ export const useSearchString = (limit, searchParams) => {
|
|||||||
const { searchParams: initialSearchParams } = new URL(window.location);
|
const { searchParams: initialSearchParams } = new URL(window.location);
|
||||||
const _searchParams = searchParams || initialSearchParams.toString();
|
const _searchParams = searchParams || initialSearchParams.toString();
|
||||||
|
|
||||||
const [searchString, setSearchString] = useState(`${defaultSearchString(limit)}&${_searchParams}`);
|
const [searchString, changeSearchString] = useState(`${defaultSearchString(limit)}&${_searchParams}`);
|
||||||
|
|
||||||
const changeSearchString = useCallback(
|
const setSearchString = useCallback(
|
||||||
(limit, searchString) => {
|
(limit, searchString) => {
|
||||||
setSearchString(`${defaultSearchString(limit)}&${searchString}`);
|
changeSearchString(`${defaultSearchString(limit)}&${searchString}`);
|
||||||
},
|
},
|
||||||
[setSearchString]
|
[changeSearchString]
|
||||||
);
|
);
|
||||||
|
|
||||||
const removeDefaultSearchKeys = useCallback((searchParams) => {
|
const removeDefaultSearchKeys = useCallback((searchParams) => {
|
||||||
@ -21,5 +21,5 @@ export const useSearchString = (limit, searchParams) => {
|
|||||||
searchParams.delete('before');
|
searchParams.delete('before');
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return [searchString, changeSearchString, removeDefaultSearchKeys];
|
return { searchString, setSearchString, removeDefaultSearchKeys };
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
import { h } from 'preact';
|
import { h } from 'preact';
|
||||||
import ActivityIndicator from '../../components/ActivityIndicator';
|
import ActivityIndicator from '../../components/ActivityIndicator';
|
||||||
import Heading from '../../components/Heading';
|
import Heading from '../../components/Heading';
|
||||||
import { TableHead, Filters } from './components';
|
import { TableHead, Filters, TableRow } from './components';
|
||||||
import { route } from 'preact-router';
|
import { route } from 'preact-router';
|
||||||
import TableRow from './components/tableRow';
|
|
||||||
import { FetchStatus, useApiHost, useEvents } from '../../api';
|
import { FetchStatus, useApiHost, useEvents } from '../../api';
|
||||||
import { Table, Tbody, Tfoot, Tr, Td } from '../../components/Table';
|
import { Table, Tbody, Tfoot, Tr, Td } from '../../components/Table';
|
||||||
import { useCallback, useEffect, useMemo, useReducer, useState } from 'preact/hooks';
|
import { useCallback, useEffect, useMemo, useReducer } from 'preact/hooks';
|
||||||
import { reducer, initialState } from './reducer';
|
import { reducer, initialState } from './reducer';
|
||||||
import { useSearchString } from './hooks/useSearchString';
|
import { useSearchString } from './hooks/useSearchString';
|
||||||
import { useIntersectionObserver } from '../../hooks';
|
import { useIntersectionObserver } from '../../hooks';
|
||||||
@ -15,12 +14,9 @@ const API_LIMIT = 25;
|
|||||||
|
|
||||||
export default function Events({ path: pathname, limit = API_LIMIT } = {}) {
|
export default function Events({ path: pathname, limit = API_LIMIT } = {}) {
|
||||||
const apiHost = useApiHost();
|
const apiHost = useApiHost();
|
||||||
const [searchString, setSearchString, removeDefaultSearchKeys] = useSearchString(limit);
|
const { searchString, setSearchString, removeDefaultSearchKeys } = useSearchString(limit);
|
||||||
|
|
||||||
const [{ events, reachedEnd, searchStrings, deleted }, dispatch] = useReducer(reducer, initialState);
|
const [{ events, reachedEnd, searchStrings, deleted }, dispatch] = useReducer(reducer, initialState);
|
||||||
|
|
||||||
const { data, status, deletedId } = useEvents(searchString);
|
const { data, status, deletedId } = useEvents(searchString);
|
||||||
const [counter, setCounter] = useState(0);
|
|
||||||
|
|
||||||
const scrollToRef = useMemo(() => Object, []);
|
const scrollToRef = useMemo(() => Object, []);
|
||||||
|
|
||||||
@ -76,42 +72,20 @@ export default function Events({ path: pathname, limit = API_LIMIT } = {}) {
|
|||||||
key={props.id}
|
key={props.id}
|
||||||
apiHost={apiHost}
|
apiHost={apiHost}
|
||||||
scrollToRef={scrollToRef}
|
scrollToRef={scrollToRef}
|
||||||
reachedEnd={reachedEnd}
|
|
||||||
setSearchString={setSearchString}
|
|
||||||
pathname={pathname}
|
pathname={pathname}
|
||||||
searchParams={searchParams}
|
|
||||||
limit={API_LIMIT}
|
limit={API_LIMIT}
|
||||||
searchString={searchString}
|
|
||||||
handleFilter={handleFilter}
|
handleFilter={handleFilter}
|
||||||
removeDefaultSearchKeys={removeDefaultSearchKeys}
|
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
[
|
[apiHost, handleFilter, pathname, scrollToRef]
|
||||||
reachedEnd,
|
|
||||||
apiHost,
|
|
||||||
setSearchString,
|
|
||||||
handleFilter,
|
|
||||||
pathname,
|
|
||||||
removeDefaultSearchKeys,
|
|
||||||
scrollToRef,
|
|
||||||
// searchParams,
|
|
||||||
// searchString,
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
useEffect(() => {
|
|
||||||
setInterval(() => {
|
|
||||||
setCounter((prev) => prev + 1);
|
|
||||||
}, 1000);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
console.log('main render', counter);
|
console.log('main render');
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4 w-full">
|
<div className="space-y-4 w-full">
|
||||||
<Heading>Events</Heading>
|
<Heading>Events</Heading>
|
||||||
|
|
||||||
<Filters onChange={handleFilter} searchParams={searchParams} />
|
<Filters onChange={handleFilter} searchParams={searchParams} />
|
||||||
|
|
||||||
<div className="min-w-0 overflow-auto">
|
<div className="min-w-0 overflow-auto">
|
||||||
<Table className="min-w-full table-fixed">
|
<Table className="min-w-full table-fixed">
|
||||||
<TableHead />
|
<TableHead />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user