Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 49 additions & 29 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ThemeChanger from './components/theme-changer';

const App = () => {
const [query, setQuery] = useState('');
const [inputValue, setInputValue] = useState('');
const [activeTab, setActiveTab] = useState(getSavedTab());
const [actions, setActions] = useState(rawActions);
const searchInputRef = useRef(null);
Expand All @@ -41,15 +42,15 @@ const App = () => {
let filteredActions = actions;

if (query) {
const searchLower = query.toLowerCase();
filteredActions = filteredActions.filter((item) => {
return (
item.name.toLowerCase().includes(query.toLowerCase()) ||
item.name.toLowerCase().includes(searchLower) ||
(item.description &&
item.description.toLowerCase().includes(query.toLowerCase())) ||
item.description.toLowerCase().includes(searchLower)) ||
(item.tags &&
item.tags.some((tag) =>
tag.toLowerCase().includes(query.toLowerCase())
))
item.tags.some((tag) => tag.toLowerCase().includes(searchLower))) ||
(item.type && item.type.toLowerCase().includes(searchLower))
);
});
}
Expand All @@ -68,6 +69,12 @@ const App = () => {
const clearSearch = () => {
searchInputRef.current.value = '';
setQuery('');
setInputValue('');
};

const handleSearchChange = (value) => {
setInputValue(value);
setQuery(value);
};

const changeTab = (tab) => {
Expand Down Expand Up @@ -205,37 +212,50 @@ const App = () => {
return (
<div className="opacity-90">
<div className="form-control">
<div className="input-group">
<div className="relative">
<input
type="text"
placeholder="Search"
className="input input-md shadow-md"
className="input input-md shadow-md w-full pl-10 pr-10"
ref={searchInputRef}
onKeyDown={(e) => {
if (e.key === 'Enter') {
setQuery(searchInputRef.current.value);
}
}}
value={inputValue}
onChange={(e) => handleSearchChange(e.target.value)}
/>
<button
className="btn btn-square"
onClick={() => setQuery(searchInputRef.current.value)}
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-5 w-5 absolute left-3 top-1/2 transform -translate-y-1/2 opacity-50"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
/>
</svg>
{inputValue && (
<button
className="absolute right-3 top-1/2 transform -translate-y-1/2 opacity-50 hover:opacity-100 transition-opacity"
onClick={() => clearSearch()}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
/>
</svg>
</button>
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-5 w-5"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
)}
</div>
</div>
</div>
Expand Down