diff --git a/frontend/src/components/ui/DataBar/DataBar.jsx b/frontend/src/components/ui/DataBar/DataBar.jsx
index 0a59117..5b58285 100644
--- a/frontend/src/components/ui/DataBar/DataBar.jsx
+++ b/frontend/src/components/ui/DataBar/DataBar.jsx
@@ -17,8 +17,13 @@ const FloatingBar = ({children}) => (
);
const DataBar = ({
- onSearch,
searchPlaceholder = 'Search by name or tag...',
+ searchTerms,
+ currentInput,
+ onInputChange,
+ onAddTerm,
+ onRemoveTerm,
+ onClearTerms,
filterType,
setFilterType,
filterValue,
@@ -34,43 +39,28 @@ const DataBar = ({
className
}) => {
const [isFloating, setIsFloating] = useState(false);
- const [searchTerm, setSearchTerm] = useState('');
- const [activeSearch, setActiveSearch] = useState('');
useEffect(() => {
const handleScroll = () => {
setIsFloating(window.scrollY > 64);
};
-
window.addEventListener('scroll', handleScroll, {passive: true});
return () => window.removeEventListener('scroll', handleScroll);
}, []);
- const handleSearch = term => {
- // First set the search term and trigger the search
- setActiveSearch(term);
- onSearch(term);
-
- // Then smoothly scroll to top
- window.scrollTo({
- top: 0,
- behavior: 'smooth'
- });
- };
-
const controls = (
<>
-
setSortBy(key)}
/>
-
-
{showAddButton && !isSelectionMode && (
)}
-
{
const [isFocused, setIsFocused] = useState(false);
@@ -17,111 +18,103 @@ const SearchBar = ({
const handleKeyDown = e => {
if ((e.ctrlKey || e.metaKey) && e.key === 'f') {
e.preventDefault();
- document.querySelector('input[type="text"]').focus();
+ document.querySelector('input[type="text"]')?.focus();
} else if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
e.preventDefault();
- clearSearch();
+ onClearTerms();
}
};
document.addEventListener('keydown', handleKeyDown);
return () => document.removeEventListener('keydown', handleKeyDown);
- }, []);
-
- const handleChange = e => {
- const newValue = e.target.value;
- setSearchTerm(newValue);
- if (!requireEnter) {
- onSearch(newValue);
- setActiveSearch(newValue);
- }
- };
+ }, [onClearTerms]);
const handleKeyPress = e => {
- if (requireEnter && e.key === 'Enter' && searchTerm.trim()) {
- onSearch(searchTerm);
- setActiveSearch(searchTerm);
- setSearchTerm('');
+ if (requireEnter && e.key === 'Enter' && currentInput.trim()) {
+ onAddTerm(currentInput);
}
};
- const clearSearch = () => {
- setSearchTerm('');
- setActiveSearch('');
- onSearch('');
- };
-
return (
- {searchTerm && !activeSearch && (
+ {(searchTerms.length > 0 || currentInput) && (
)}