mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-01 16:55:21 +03:00
fix for version 0.10
This commit is contained in:
parent
f5e298184d
commit
5e9cc7130a
@ -18,7 +18,8 @@ export const useSearchString = (limit, searchParams) => {
|
|||||||
const removeDefaultSearchKeys = useCallback((searchParams) => {
|
const removeDefaultSearchKeys = useCallback((searchParams) => {
|
||||||
searchParams.delete('limit');
|
searchParams.delete('limit');
|
||||||
searchParams.delete('include_thumbnails');
|
searchParams.delete('include_thumbnails');
|
||||||
searchParams.delete('before');
|
// removed deletion of "before" as its used by DatePicker
|
||||||
|
// searchParams.delete('before');
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return { searchString, setSearchString, removeDefaultSearchKeys };
|
return { searchString, setSearchString, removeDefaultSearchKeys };
|
||||||
|
|||||||
@ -1,31 +1,29 @@
|
|||||||
import { h } from 'preact';
|
import { h } from 'preact';
|
||||||
import Select from '../../../components/Select';
|
import Select from '../../../components/Select';
|
||||||
import { useCallback, useMemo } from 'preact/hooks';
|
import { useCallback } from 'preact/hooks';
|
||||||
|
|
||||||
const Filter = ({ onChange, searchParams, paramName, options }) => {
|
function Filter({ onChange, searchParams, paramName, options, type, ...rest }) {
|
||||||
const handleSelect = useCallback(
|
const handleSelect = useCallback(
|
||||||
(key) => {
|
(key) => {
|
||||||
const newParams = new URLSearchParams(searchParams.toString());
|
const newParams = new URLSearchParams(searchParams.toString());
|
||||||
if (key !== 'all') {
|
Object.keys(key).map((entries) => {
|
||||||
newParams.set(paramName, key);
|
if (key[entries] !== 'all') {
|
||||||
} else {
|
newParams.set(entries, key[entries]);
|
||||||
newParams.delete(paramName);
|
} else {
|
||||||
}
|
paramName.map((p) => newParams.delete(p));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
onChange(newParams);
|
onChange(newParams);
|
||||||
},
|
},
|
||||||
[searchParams, paramName, onChange]
|
[searchParams, paramName, onChange]
|
||||||
);
|
);
|
||||||
|
|
||||||
const selectOptions = useMemo(() => ['all', ...options], [options]);
|
let obj = {};
|
||||||
|
paramName.map((p) => Object.assign(obj, { [p]: searchParams.get(p) }), [searchParams]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Select
|
<Select onChange={handleSelect} options={options} selected={obj} paramName={paramName} type={type} {...rest} />
|
||||||
label={`${paramName.charAt(0).toUpperCase()}${paramName.substr(1)}`}
|
|
||||||
onChange={handleSelect}
|
|
||||||
options={selectOptions}
|
|
||||||
selected={searchParams.get(paramName) || 'all'}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
export default Filter;
|
export default Filter;
|
||||||
|
|||||||
@ -3,13 +3,19 @@ import { useCallback, useMemo } from 'preact/hooks';
|
|||||||
import Link from '../../../components/Link';
|
import Link from '../../../components/Link';
|
||||||
import { route } from 'preact-router';
|
import { route } from 'preact-router';
|
||||||
|
|
||||||
const Filterable = ({ onFilter, pathname, searchParams, paramName, name, removeDefaultSearchKeys }) => {
|
function Filterable({ onFilter, pathname, searchParams, paramName, name }) {
|
||||||
|
const removeDefaultSearchKeys = useCallback((searchParams) => {
|
||||||
|
searchParams.delete('limit');
|
||||||
|
searchParams.delete('include_thumbnails');
|
||||||
|
// searchParams.delete('before');
|
||||||
|
}, []);
|
||||||
|
|
||||||
const href = useMemo(() => {
|
const href = useMemo(() => {
|
||||||
const params = new URLSearchParams(searchParams.toString());
|
const params = new URLSearchParams(searchParams.toString());
|
||||||
params.set(paramName, name);
|
params.set(paramName, name);
|
||||||
removeDefaultSearchKeys(params);
|
removeDefaultSearchKeys(params);
|
||||||
return `${pathname}?${params.toString()}`;
|
return `${pathname}?${params.toString()}`;
|
||||||
}, [searchParams, paramName, pathname, name, removeDefaultSearchKeys]);
|
}, [searchParams, paramName, pathname, name]);
|
||||||
|
|
||||||
const handleClick = useCallback(
|
const handleClick = useCallback(
|
||||||
(event) => {
|
(event) => {
|
||||||
@ -27,6 +33,6 @@ const Filterable = ({ onFilter, pathname, searchParams, paramName, name, removeD
|
|||||||
{name}
|
{name}
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
export default Filterable;
|
export default Filterable;
|
||||||
|
|||||||
@ -2,10 +2,10 @@ import { h } from 'preact';
|
|||||||
import Filter from './filter';
|
import Filter from './filter';
|
||||||
import { useConfig } from '../../../api';
|
import { useConfig } from '../../../api';
|
||||||
import { useMemo } from 'preact/hooks';
|
import { useMemo } from 'preact/hooks';
|
||||||
|
import { DateFilterOptions } from '../../../components/DatePicker';
|
||||||
|
|
||||||
const Filters = ({ onChange, searchParams }) => {
|
const Filters = ({ onChange, searchParams }) => {
|
||||||
const { data } = useConfig();
|
const { data } = useConfig();
|
||||||
|
|
||||||
const cameras = useMemo(() => Object.keys(data.cameras), [data]);
|
const cameras = useMemo(() => Object.keys(data.cameras), [data]);
|
||||||
|
|
||||||
const zones = useMemo(
|
const zones = useMemo(
|
||||||
@ -30,9 +30,38 @@ const Filters = ({ onChange, searchParams }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex space-x-4">
|
<div className="flex space-x-4">
|
||||||
<Filter onChange={onChange} options={cameras} paramName="camera" searchParams={searchParams} />
|
<Filter
|
||||||
<Filter onChange={onChange} options={zones} paramName="zone" searchParams={searchParams} />
|
type="dropdown"
|
||||||
<Filter onChange={onChange} options={labels} paramName="label" searchParams={searchParams} />
|
onChange={onChange}
|
||||||
|
options={['all', ...cameras]}
|
||||||
|
paramName={['camera']}
|
||||||
|
label="Camera"
|
||||||
|
searchParams={searchParams}
|
||||||
|
/>
|
||||||
|
<Filter
|
||||||
|
type="dropdown"
|
||||||
|
onChange={onChange}
|
||||||
|
options={['all', ...zones]}
|
||||||
|
paramName={['zone']}
|
||||||
|
label="Zone"
|
||||||
|
searchParams={searchParams}
|
||||||
|
/>
|
||||||
|
<Filter
|
||||||
|
type="dropdown"
|
||||||
|
onChange={onChange}
|
||||||
|
options={['all', ...labels]}
|
||||||
|
paramName={['label']}
|
||||||
|
label="Label"
|
||||||
|
searchParams={searchParams}
|
||||||
|
/>
|
||||||
|
<Filter
|
||||||
|
type="datepicker"
|
||||||
|
onChange={onChange}
|
||||||
|
options={DateFilterOptions}
|
||||||
|
paramName={['before', 'after']}
|
||||||
|
label="DatePicker"
|
||||||
|
searchParams={searchParams}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user