forked from Github/frigate
Search UI tweaks (#13965)
* Prevent keyboard shortcuts from running when input is focused * fix reset button and update time pickers when using input * simplify css * consistent button order and spacing
This commit is contained in:
@@ -430,6 +430,13 @@ function TimeRangeFilterButton({
|
||||
const formattedSelectedAfter = useFormattedHour(config, selectedAfterHour);
|
||||
const formattedSelectedBefore = useFormattedHour(config, selectedBeforeHour);
|
||||
|
||||
useEffect(() => {
|
||||
setSelectedAfterHour(afterHour);
|
||||
setSelectedBeforeHour(beforeHour);
|
||||
// only refresh when state changes
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [timeRange]);
|
||||
|
||||
const trigger = (
|
||||
<Button
|
||||
size="sm"
|
||||
@@ -447,18 +454,8 @@ function TimeRangeFilterButton({
|
||||
</Button>
|
||||
);
|
||||
const content = (
|
||||
<div
|
||||
className={cn(
|
||||
"scrollbar-container flex h-auto max-h-[80dvh] flex-col overflow-y-auto overflow-x-hidden",
|
||||
isDesktop ? "w-64" : "w-full gap-2 pt-2",
|
||||
)}
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"mt-3 flex w-full items-center rounded-lg text-secondary-foreground",
|
||||
isDesktop ? "mx-6 gap-2 px-2" : "justify-center gap-2",
|
||||
)}
|
||||
>
|
||||
<div className="scrollbar-container h-auto max-h-[80dvh] overflow-y-auto overflow-x-hidden">
|
||||
<div className="my-5 flex flex-row items-center justify-center gap-2">
|
||||
<Popover
|
||||
open={startOpen}
|
||||
onOpenChange={(open) => {
|
||||
@@ -480,7 +477,7 @@ function TimeRangeFilterButton({
|
||||
{formattedSelectedAfter}
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="flex flex-col items-center">
|
||||
<PopoverContent className="flex flex-row items-center justify-center">
|
||||
<input
|
||||
className="text-md mx-4 w-full border border-input bg-background p-1 text-secondary-foreground hover:bg-accent hover:text-accent-foreground dark:[color-scheme:dark]"
|
||||
id="startTime"
|
||||
@@ -534,8 +531,8 @@ function TimeRangeFilterButton({
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<DropdownMenuSeparator />
|
||||
</div>
|
||||
<DropdownMenuSeparator />
|
||||
<div className="flex items-center justify-evenly p-2">
|
||||
<Button
|
||||
variant="select"
|
||||
@@ -558,6 +555,7 @@ function TimeRangeFilterButton({
|
||||
onClick={() => {
|
||||
setSelectedAfterHour(DEFAULT_TIME_RANGE_AFTER);
|
||||
setSelectedBeforeHour(DEFAULT_TIME_RANGE_BEFORE);
|
||||
updateTimeRange(undefined);
|
||||
}}
|
||||
>
|
||||
Reset
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useRef, useEffect, useCallback } from "react";
|
||||
import React, { useState, useRef, useEffect, useCallback } from "react";
|
||||
import {
|
||||
LuX,
|
||||
LuFilter,
|
||||
@@ -45,6 +45,8 @@ import useSWR from "swr";
|
||||
import { FrigateConfig } from "@/types/frigateConfig";
|
||||
|
||||
type InputWithTagsProps = {
|
||||
inputFocused: boolean;
|
||||
setInputFocused: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
filters: SearchFilter;
|
||||
setFilters: (filter: SearchFilter) => void;
|
||||
search: string;
|
||||
@@ -55,6 +57,8 @@ type InputWithTagsProps = {
|
||||
};
|
||||
|
||||
export default function InputWithTags({
|
||||
inputFocused,
|
||||
setInputFocused,
|
||||
filters,
|
||||
setFilters,
|
||||
search,
|
||||
@@ -69,7 +73,6 @@ export default function InputWithTags({
|
||||
const [currentFilterType, setCurrentFilterType] = useState<FilterType | null>(
|
||||
null,
|
||||
);
|
||||
const [inputFocused, setInputFocused] = useState(false);
|
||||
const [isSimilaritySearch, setIsSimilaritySearch] = useState(false);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const commandRef = useRef<HTMLDivElement>(null);
|
||||
@@ -381,7 +384,7 @@ export default function InputWithTags({
|
||||
|
||||
const handleInputFocus = useCallback(() => {
|
||||
setInputFocused(true);
|
||||
}, []);
|
||||
}, [setInputFocused]);
|
||||
|
||||
const handleClearInput = useCallback(() => {
|
||||
setInputFocused(false);
|
||||
@@ -392,16 +395,19 @@ export default function InputWithTags({
|
||||
setFilters({});
|
||||
setCurrentFilterType(null);
|
||||
setIsSimilaritySearch(false);
|
||||
}, [setFilters, resetSuggestions, setSearch]);
|
||||
}, [setFilters, resetSuggestions, setSearch, setInputFocused]);
|
||||
|
||||
const handleInputBlur = useCallback((e: React.FocusEvent) => {
|
||||
if (
|
||||
commandRef.current &&
|
||||
!commandRef.current.contains(e.relatedTarget as Node)
|
||||
) {
|
||||
setInputFocused(false);
|
||||
}
|
||||
}, []);
|
||||
const handleInputBlur = useCallback(
|
||||
(e: React.FocusEvent) => {
|
||||
if (
|
||||
commandRef.current &&
|
||||
!commandRef.current.contains(e.relatedTarget as Node)
|
||||
) {
|
||||
setInputFocused(false);
|
||||
}
|
||||
},
|
||||
[setInputFocused],
|
||||
);
|
||||
|
||||
const handleSuggestionClick = useCallback(
|
||||
(suggestion: string) => {
|
||||
@@ -449,7 +455,7 @@ export default function InputWithTags({
|
||||
setInputFocused(false);
|
||||
inputRef?.current?.blur();
|
||||
},
|
||||
[setSearch],
|
||||
[setSearch, setInputFocused],
|
||||
);
|
||||
|
||||
const handleInputKeyDown = useCallback(
|
||||
|
||||
@@ -414,17 +414,7 @@ export function DateRangePicker({
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex justify-center gap-2 py-2 pr-4">
|
||||
<Button
|
||||
onClick={() => {
|
||||
setIsOpen(false);
|
||||
resetValues();
|
||||
onReset?.();
|
||||
}}
|
||||
variant="ghost"
|
||||
>
|
||||
Reset
|
||||
</Button>
|
||||
<div className="mx-auto flex w-64 items-center justify-evenly gap-2 py-2">
|
||||
<Button
|
||||
variant="select"
|
||||
onClick={() => {
|
||||
@@ -439,6 +429,16 @@ export function DateRangePicker({
|
||||
>
|
||||
Apply
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setIsOpen(false);
|
||||
resetValues();
|
||||
onReset?.();
|
||||
}}
|
||||
variant="ghost"
|
||||
>
|
||||
Reset
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user